Rodrigo Pires
Rodrigo Pires

Reputation: 574

Solr query suggestions

I'm building a customized e-commerce website and using SOLR (4.8.1) for indexing/searching products.

I want to provide a search field with autocomplete to help users by prompting suggestions, as they type:

Just like in this example (taken from www.extra.com.br)

enter image description here

The second part (products suggestions) is easy, basically is just querying SOLR as a normal search would do and taking the top 5.

The first part (queries suggestions) that's keeping me awake at night :)

I've already tried some alternatives, like Suggester component (/suggest) and also trying the regular search (/select) with facets.

I've accomplished to get suggestions for individual words, but what I REALLY WANT is predictive suggestions, like the print above. If the user types "monit", it brings suggestions of queries/products based on products that really exists. If user types "monitor banana", for example, it should bring nothing (because it doesn't exists), but in my case it's suggesting "monitor banana" because the 2 words exists separately in the index. (even having no relationship between them)

Can anyone point me in the right direction to accomplish this? A tutorial with an example (or even a book) would be very appreciated.

To make clear what I need, exactly what Google Commerce Search offered (I think they've discontinued it): https://www.youtube.com/watch?v=nje9fUcIkKc

Thank you!

Upvotes: 2

Views: 1619

Answers (2)

Rodrigo Pires
Rodrigo Pires

Reputation: 574

Thank you @frances for your answer.

I've managed to accomplish what I needed (sort of) by doing:

  • Created a new core called "suggestions";
  • Created a new stored procedure to populate the core with combinations of suggestions, such as: models, category + models, models + category, vendor + model + category, and so on

  • Created a new endpoint (action) in my web application which performs 2 internal HTTP requests to SOLR, being the first one to the "suggestions" core, and the second one to the regular products search core.

  • Grouped the results in one JSON answer to return to the autocomplete javascript component (I'm using this one: https://www.devbridge.com/sourcery/components/jquery-autocomplete/)

I know that a more perfect solution will be when the suggestions are actually based on previous user search records, but while I don't have that, the result is good enough.

Print below:

enter image description here

Upvotes: 1

frances
frances

Reputation: 1242

The suggested searches might be popular past searches (but only ones that return results), or a set of administrator-added suggested searches, or statistically generated combinations of terms that will return results. (Or, possibly a combination.) But one way or another, you're going to have to come up with a list of searches that can be suggested. The list may or may not include ratings (the most popular or important searches being rated highest).

I would take that list, and insert it into Solr as a set of documents completely separate from your product records. You could put them in the same Solr core (and filter searches appropriately) or in their own core. And you'd want to make sure that the search strings are indexed the same way as the important text fields in your product records. (It looks like you'll be using a lot of n-grams indexing if your auto-complete works like the screenshot you included.) If your searches are rated, I'd use those ratings to provide record-level boosting on the individual search records.

Now, if the searches and products are in two separate cores, you will be doing two auto-complete searches for whatever a user types in. If they are in the same Solr core, you can theoretically get top hits for both at once using Result Grouping. For that you would need to have a record type field that is encoded as multiValued="false", but is otherwise set up like you would a facet field (i.e. indexed="true" stored="true") If this field has only two possible values (product and search, maybe?), then you can get the top hits for each "group" with a query like:

http://localhost:8080/solr/core0/search?group=true&
                         group.field=recordType&group.limit=5&q=monit

That would give you the top 5 searches and the top 5 products matching "monit". You'll inevitably have a search mode where you don't want to suggest searches. At that point, you can dispense with getting search suggestions by executing a filtered query instead of the grouped one.

http://localhost:8080/solr/core0/search?fq=recordType:product&q=tv monitor

Or, the two separate cores may be a better idea depending on how you plan to maintain the two sets of records, how large the index is going to get, etc.

Upvotes: 1

Related Questions