How do I provide quality search results of products from multiple vendors in MySQL Database?
I have a MySQL database that contains a table called products, with, as an example a structure of:
- product_id
- name
- price
- vendor
Products are imported to the database from a file from each vendor, so for example Vendor 1 might have imported records 1 - 1500, then vendor 2 might have imported records 1500 - 4500, vendor 3 4500 - 5250 and so on.
Each vendor might have multiple types of the same product. Lets use the example of dinner plates. So each vendor might have many different brands and styles of dinner plates.
When a users searches for dinner plates, using a MATCH...AGAINST query I get a l开发者_高级运维ot of results from each vendor, however, the results of the search will be in the same order they are in the database from the vendors, so, I might see a hundred dinner plates from vendor 1 before I even see any dinner plates from vendor 2.
Is there a better approach for displaying the search results if they arent specific so that it mixes up the results a little?
You need to use ORDER BY
with an arbitrary column. Sort them by date added, or some other field to give the appearance of random results.
A rather bad solution to this would be to use ORDER BY RAND()
, but note that this would give a different random order every time the page was reloaded.
Another solution might be to FULLTEXT
search (and index) more than one column; this would give a more varied resultset.
精彩评论