我正在使用 SuggestComponent 来获取自动建议关键字。我在 solrconfig.xml 中正确配置了搜索组件和请求处理程序。我也得到了预期的结果。
现在我的问题是我无法使用 SolrJ api 读取 XML 输出。我在 SolrJ API 上花了几个小时,但找不到读取建议关键字的方法。
我的 Java 代码
SolrServer server = //solrserver object creation
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/suggest");
params.set("q", q);
QueryResponse rsp = server.query(params);
**//How to read from QueryResponse?**
这是我的 solrconfig.xml 配置
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">name</str>
<str name="weightField">reviewsNum</str>
<str name="suggestAnalyzerFieldType">text_general</str>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="suggest">true</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="suggest.count">10</str>
<str name="suggest.dictionary">mySuggester</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
回复:
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">24</int>
</lst>
<lst name="suggest">
<lst name="mySuggester">
<lst name="a">
<int name="numFound">10</int>
<arr name="suggestions">
<lst>
<str name="term">JNTU <b>A</b>nantapur</str>
<long name="weight">2</long>
<str name="payload"/>
</lst>
<lst>
<str name="term"><b>A</b>merican School of Bombay</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">
Society For <b>A</b>dvanced Study In Rehabilitation
</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term"><b>a</b>mrita vishwa vidyapeetham</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">
shanmugha <b>a</b>rts science technology & research <b>a</b>cademy (sastra)
</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">Montesorri Hs <b>A</b>lampur</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term"><b>A</b>ditya Ps Nehru Road Proddutur</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">Zphs <b>A</b>rakatavemula Rajupalem</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">Sri <b>A</b>ditya Ps,pamur Pamuru</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">
ramakrishna mission vivekananda educational <b>a</b>nd research institute
</str>
<long name="weight">0</long>
<str name="payload"/>
</lst>
</arr>
</lst>
</lst>
</lst>
</response>