i tried to succeed using this form for auto suggest, but i can't. can you describe how to implement the auto suggest using solr- scheme.xml,solrconig.xml, Searchcontroller.java and javascript?
Code: Select all
<field name="suggest_phrase" type="suggest_phrase" indexed="true" stored="false" multiValued="true" />
<copyField source="fullproductname_t" dest="suggest_phrase" />
<!-- A general text field that has reasonable, generic cross-language defaults:
it tokenizes with StandardTokenizer and down cases. -->
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="suggest_phrase" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
Code: Select all
<searchComponent name="suggest_phrase" class="solr.SpellCheckComponent" lazy="true">
<lst name="spellchecker">
<str name="name">suggest_phrase</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.jaspell.JaspellLookup</str>
<str name="field">suggest_phrase</str>
<str name="buildOnCommit">true</str>
<str name="suggestAnalyzerFieldType">suggest_phrase</str>
</lst>
</searchComponent>
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest_phrase">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest_phrase</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.collate">false</str>
</lst>
<arr name="components">
<str>suggest_phrase</str>
</arr>
</requestHandler>
Code: Select all
@RequestMapping(value = "/suggest", produces = "application/json")
public @ResponseBody List<Map<String, String>> suggest(Model model, HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = "q") String q) throws ServletException, IOException, ServiceException, SolrServerException {
List<Map<String, String>> results = new ArrayList<Map<String, String>>();
SolrQuery params = new SolrQuery()
.setRequestHandler("/suggest_phrase");
params.set("spellcheck", true);
params.set("spellcheck.q", q);
QueryResponse queryResponse = SolrContext.getServer().query(params);
SpellCheckResponse spellCheckResponse = queryResponse.getSpellCheckResponse();
for(SpellCheckResponse.Suggestion suggestion : spellCheckResponse.getSuggestions()){
for(String suggestionItem : suggestion.getAlternatives()){
Map<String, String> suggestionMap = new HashMap<String, String>();
suggestionMap.put("productName", suggestionItem);
results.add(suggestionMap);
}
}
return results;
}
Thanks in advance
Cyril A