How to use SpellingResult class in SolrJ

为君一笑 提交于 2019-12-10 17:13:37

问题


I'm using SolrJ. But through the API documentation could not figure out how to use the particular class to receive the response of the spell checker. i have a search component defined in solrconfig.xml for performing the checking


回答1:


Maybe you already found the solution, anyway the SpellingResult class comes with Solr, while you're using SolrJ to access a Solr server, if I'm not wrong. So, you should use the specific classes that come with SolrJ; the QueryResponse object contains a SpellCheckResponse object with all the information you're looking for.

SolrServer solr = new CommonsHttpSolrServer("http://localhost:8080/solr");
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/spell");
params.set("q", "whatever");
params.set("spellcheck", "on");
//params.set("spellcheck.build", "true");

QueryResponse response = solr.query(params);
SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse();
if (!spellCheckResponse.isCorrectlySpelled()) {
    for (Suggestion suggestion : response.getSpellCheckResponse().getSuggestions()) {
        logger.debug("original token: " + suggestion.getToken() + " - alternatives: " + suggestion.getAlternatives());
    }
}

Hope this helps.



来源:https://stackoverflow.com/questions/6466626/how-to-use-spellingresult-class-in-solrj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!