Search code examples
solrautocompleteautosuggest

Solr 5.3 autocompletion: suggestions restricted to user role, location, campaign etc


We are working on implementing an autocompletion feature for an e-commerce site. We currently favorite the SuggestComponent implementation, but could probably try out some other options (FacetComponent,...). We have a single core with monolingual content.

Our problem is: Autocomplete query suggestions need to be restricted to several segments with their respective requirements, such as user role (new customer, special customer of group A, etc.), campaigns (products available during a special campaign, flash sales...), geographical target groups etc.

I have been researching the web, but haven't found any solutions for this use case, unfortunately. It actually goes beyond access control to documents according to user roles: there mustn't even be suggestions of terms that only lead to restricted content.

I'd be really glad if somebody had some hints, advice, best practices for me. Thank you in advance!


Solution

  • In cases with a lot of business rules on top of suggestions, I'd recommend going with creating a separate collection for your auto completion requirements. This will allow you to attach any identifiers to any term that can be completed, and you can filter out those with regular fq clauses. It also allows you to apply boosts like you'd expect, so that you can boost those products in campaigns while the campaigns are in effect.

    In general you'd have a ngram-ed or a edgengram-ed field that contains the terms that can be autocompleted (the actual search), metadata about the document and a reference so you can look up the document if it's actually being selected.

    If we use Amazon as an example, you'd have the name of the product / string to be autocompleted, its department (books/music/tv/regular search string/etc.), the product id and for example a relevant photo of the object.

    The collection would then be used exclusively for auto completion. When updating or adding a product, you'd submit the document to your main index, and then submit the autocomplete information to the secondary index. Attaching proper metadata (role/campaigns/geotarget) can then be done for the autocomplete by itself, and you have total control over what's in your autocomplete base.

    Another option is to embed this in each product and use a separate ngram/edgengram field for autocomplete - this will grow the size of your main index which might not be ideal, but it'd work the same as the separate collection strategy, without having to submit documents to two collections.