Imagine I have a set of houses I want to sell and I want to present then on a website. The user should be able to filter the house they want by price, city, number of floors, area etc. However, I don't want it to be like this:
First select price only, then you can select city and only after that can you select the number of floors etc.
I want the user to be able to pick the order of attributes he wants.
For each iteration (attribute selection) the set of remaining attributes will have a limited range depending on the previous interaction and so on.
I have seen this implemented on some sale sites but I don't know how this is implemented, specifically with regards to the the data structure.
It doesn't look easy to add new houses for example. It feels like there is a complicated combination of binary trees and linked lists but there is probably a far better way that I haven't figured out.
1 Answer 1
This is easily implemented in SQL. Even better is the realization that any reasonable DBMS will give you the option to store the data as a btree+ or a hash table. You also have the option to put multiple indexes on the table structure. You don't have to configure this.
You project reminded me of a project I did about 20 years ago. For fast access, I was told to implement a tree like structure, perform some calculations on the data and then produce a report, all done in C - we didn't want the overhead of a DBMS.
Due to the complexity of the tree like structure and ever changing sample data, it took about 6 months to work out the data collection and storage in the tree. We then dicovered that we were attempting the knapsack problem. We gave up on that project after that.
This experience informs my decisions to this day. Looking back with hindsight, I could get to the same place with a trivial database structure and maybe a couple of weeks of programming.
In summary: use C for what it is good for, and use SQL for what it is good for. First do the database solution with a combination of C and SQL. Only consider replacing the DB with C structures when it proves to be too slow.
-
6My experience has taught me that when you get to the heart of it, data management is exactly what a database does best, and it does it well. Therefore if you can do it through the database without compromising flexibility, you do it, no questions asked.Neil– Neil2018年01月10日 07:34:32 +00:00Commented Jan 10, 2018 at 7:34
-
3"I want a round thing with a hole in the center, that rolls along the ground carrying things for me, but I don't want the overhead of a wheel." The knapsack problem then becomes: how can I pack up my knapsack and leave fast enough?user251748– user2517482018年01月10日 17:04:03 +00:00Commented Jan 10, 2018 at 17:04
-
No comprrnde, you certainly deserve a award for that. It made my night.Robert Baron– Robert Baron2018年01月10日 23:58:37 +00:00Commented Jan 10, 2018 at 23:58
price < 200000
. It's entirely possible that, when you apply this clause to Number of Garages, the range for number of garages will shrink to 1 or less.