3

On our new site (a shopping site), we will use Solr for our site's search engine. In the Solr index we keep a list of product id's, and a list of keywords for each product. The search query is done against the keywords.

Solr returns a list of product id's. These id's are then inserted into a MySQL query to select all product data from the database. MySQL also handles the sorting of results. E.g., the MySQL query might look like:

SELECT * FROM product WHERE id IN (1,4,42,32,46,...,39482) ORDER BY price ASC

We have around 100,000 products on the site. This method works fine when there are a couple of thousand of results, but becomes slow when there are - for example - 50,000 results.

My assumption is that the bottleneck is the "WHERE IN" clause. A long-term solution will be to move all product data to Solr so it can handle sorting the results and also applying refine filters to the search (e.g., perhaps the user only wants to view products in a certain price range). However, we are inexperienced with Solr and need a short-term fix before we can implement this.

One option is to abandon Solr in the short-term and store keywords in a table in MySQL and do the search against this using a FULL-TEXT search.

Am I missing any other options?

2
  • Can you create a VIEW? Commented Feb 19, 2013 at 14:35
  • isn't a VIEW created from a select statement? i don't know how the results from a Solr query would be used to create a view. Solr returns an array of product id's. Commented Feb 19, 2013 at 14:45

1 Answer 1

6

The main problem for you is that Solr is going to return the results sorted by number of matching keywords, but you want the results to be sorted by price. Like you correctly mention, moving all your data to Solr is the best option - you would be very happy with Solr for your searching, sorting, faceting and pagination needs.

For the short-term however, it will be well worth to just add the price field to Solr. When you get a search query like tooth paste you can issue a Solr query like

q=keywords:(tooth AND paste)&rows=10&fl=id&sort=price%20asc

to get only the first 10 results and then do pagination by specifying the start parameter, so like:

q=keywords:(tooth AND paste)&rows=10&start=10&fl=id&sort=price%20asc
Sign up to request clarification or add additional context in comments.

1 Comment

You can use the FULL TEXT SEARCH in SOLR changing the field type as <field name="keywords" type="text_en_splitting" stored="true" indexed="true"/> in schema.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.