Implementing the autocomplete feature using PHP and Solr
Autocomplete feature can be built by creating a Suggester in Solr and using the Suggester available in Solarium. The purpose of autocomplete is to suggest query terms based on incomplete user input. Suggester works very similarly to the spellcheck feature. It can be made to work either on the main index or any other dictionary.
First let us change the schema.xml
file to add a spellcheck component named suggest
:
<searchComponent name="suggest" class="solr.SpellCheckComponent"> <lst name="spellchecker"> <str name="name">suggest</str> <str name="field">suggestfld</str> <str name="classname">org.apache.solr.spelling.suggest.Suggester</str> <str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str> <str name="storeDir">suggest_idx</str> <float name="threshold">0.005</float> <str name="buildOnCommit">true</str> </lst> <...