Reputation: 18325
To work with Solr, I need my searchbox to be suggesting whenever user type.. with a dropdown menu. How can i get it done? Any existing example?
Upvotes: 4
Views: 10297
Reputation: 9320
There are multiple ways of providing autosuggest capabilities.
Single term suggestion
This method looks for the first letter, then the first word in a phrase, a search for “men’s shirts” must begin with “m,” then “men’s,” to bring up “men’s shirts” as a response.
This could be done by using following field type and querying with my little po*
<fieldType name="suggestion_text" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory" />
</analyzer>
</fieldType>
Multiterm unordered suggestions
This autocomplete method recognizes “shirts” as part of the phrase, like “men’s shirts,” and suggests it to the customer along with “women’s shirts,” “work shirts,” and other phrases that contain “men’s.”
This one could be done by using following field type and querying with my AND little AND po*
<fieldType name="prefix_text" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory" />
</analyzer>
</fieldType>
Multiterm ordered suggestions
The third method matches everything that contains a subphrase of the complete phrase as long as it’s in the correct order, i.e. “men’s shir,” but not “shirts me.”
Solr doesn’t have built-in features to generate this, but we can implement our own token filter. For more information on this and previous implementation (as well as complete information) - take a look at this blog post
Upvotes: 0
Reputation: 60195
Here is an article I wrote about different ways to make auto suggestions and how to make the right choice. If you want something even more advanced and flexible there is this other article, which contains an example as well.
Upvotes: 5
Reputation: 301037
Have a look at the Suggester component - http://wiki.apache.org/solr/Suggester/
Upvotes: 2