Pergunta

I have a database full of items, which should be searchable by any or all of the following criteria:

item_id, supplier, price range, color

Now, that's easy - user's selection of checkboxes is POSTed, and I turn it into appropriate query.

QUESTION: how to make it so that search dynamically modifies itself. What I mean is - if you select a certain price range, all suppliers and colors that don't conform to it are removed from selection, and any selected items are deselected as well.

Likewise, if user checks certain color, all suppliers that don't offer it, and all price ranges that don't have it are removed from selection. And also all items a user may have previously selected, but which are not in that color.

Sub-question: is this even good idea at all, if you're against it, please let me know why?

NOTE: Architectural advice is all I need, how to approach it, and answer is HIGHLY appreciated, I'm bashing my head over this for 2 days.

Won't refuse code as well, and it may be in any language or pseudo code, I need to decode the way of thinking here.

EDIT: Here's an example - by clicking any of the search criteria on the left, you affect search results:

http://www.wanajob.com/emploi?search=informatique&fpc=&fpr=

Foi útil?

Solução

I'm not an expert on facets so I defer to Brent's answer in that direction but what you are describing is fairly easy to implement in MySQL for your basic search data.

Let's say the customer searches on "red" being the colour. You could then construct the list of suppliers and price ranges within the search results like this

SELECT DISTINCT supplier FROM items WHERE color = 'red';
SELECT DISTINCT price_range FROM items WHERE color = 'red';

Note that these would have to be separate queries as

SELECT DISTINCT supplier,price_range FROM items WHERE color = 'red';

would return all DISTINCT combinations of the two fields.

If you require a COUNT of each criteria then you can use GROUP BY

SELECT supplier,COUNT(*) FROM items WHERE color = 'red' GROUP BY supplier;
SELECT price_range,COUNT(*) FROM items WHERE color = 'red' GROUP BY price_range;

Outras dicas

Seems like you are asking about facets. While facets are the opposite of what you are asking, since they are the opposite, you can deduce what to remove. Facets will tell you that within the search, there are X blue, Y red, and Z yellow items. So if you narrowed the search by one of those colors, you know how many items would be in the new search result. This is fairly common on the web now, especially on shopping sites. So there are plenty of examples.

Search systems like Solr, Elastic Search, Sphinx, etc provide facet information. Mysql does not. Solr is the most mature, Elastic Search is probably the most scalable, and Sphinx can read directly from mysql.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top