当使用solrTemplate时,我没有办法得到建议中的结果。使用solrj可以使用getSuggesterResponse()获得此结果。

我调试了它,发现它没有使用getSuggesterResponse()来获取建议。

索尔吉

    HttpSolrClient httpSolrServer = SolrUtil.createSolrServer();
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.set("qt", "/suggest");
    solrQuery.setQuery("mm");
    QueryResponse response = httpSolrServer.query(solrQuery);
    SuggesterResponse suggesterResponse = response.getSuggesterResponse();
    Map<String, List<String>> suggestedTerms =
    suggesterResponse.getSuggestedTerms();
    List<String> terms = suggestedTerms.get("suggest");


solrTemplate:

    TermsQuery query = new SimpleTermsQuery();
    query.setRequestHandler("/suggest");
    query.addCriteria(new Criteria().is("mm"));
    TermsPage terms = solrTemplate.queryForTermsPage("core2", query);


我检查了所有文档,但没有找到方法。

最佳答案

我认为solrTemplate没有对本地建议的支持。
但是您可以在solrTemplate中使用solrJ

SolrQuery q = new SolrQuery();

q.setRequestHandler("/suggest");
q.setParam("suggest.q", searchTerm);
q.setParam("suggest", "true");
q.setParam("suggest.dictionary", "mySuggester");
q.setParam("suggest.build", "true");

QueryResponse queryResponse = solrTemplate.execute(solrClient -> solrClient.query("collectionName", q));

SuggesterResponse suggesterResponse = queryResponse.getSuggesterResponse();

09-11 20:15