This post is about configuring autosuggest on Solr search using SilverStripe CMS. Solr is a powerfull search tool and it has a Suggester component which is used for autosuggesting purposes.
Below are steps for configuring autosuggest.
1. On the page that extends SolrIndex, add the following functions
public function getFieldDefinitions() { $xml = parent::getFieldDefinitions(); $xml .= "\n\n\t\t"; $xml .= "\n\t\t"; return $xml; } public function getCopyFieldDefinitions() { $xml = parent::getCopyFieldDefinitions(); // copy autosuggest fields to 'spell' field type $xml .= "\n\t\t "; $xml .= "\n\t\t "; return $xml; }
Add the below xml to the solrconfig.xml at /mysite/conf/extras/.
suggest org.apache.solr.spelling.suggest.Suggester org.apache.solr.spelling.suggest.tst.TSTLookup spell 0.005 true true suggest true suggest true 5 false suggest
Run a dev/tasks/Solr_Configure to build the new schema.xml and config file in the solrindex directory.
Check to see that the above xml is written to solrconfig.xml file. Also make sure that schema.xml in the solrindex directory contains the above fields defined in getFieldDefinitions() and getCopyFieldDefinitions() methods.
Now run a dev/tasks/Solr_Reindex to build new indexes.
Browse the url, http://{solrserver:port}/{solrindex}/suggest?q=drivi and view xml generated suggestions.
For more auto suggest tweaking, consult the following article.