我正在嘗試使用建議器使用SOLR創建一個typehead自動完成功能。SOLR建議器突出顯示
搜索將針對聚合用戶的用戶和組名進行。搜索將在用戶名,生物,網頁和其他東西上完成。我想要實現的是類似於「臉譜」或「微博」的搜索。爲此,我需要通過附加數據(用戶類型,個人資料網址,他的頭像網址等)豐富SOLR的結果。
用戶和組將在SOLR中具有ID字段,該字段對應於DB中的ID以獲取這些信息。我被困在如何做到這一點。
目前我有建議的工作,但它只返回建議值,當我嘗試從文檔中返回其他屬性它不起作用。
這裏是solrconfig的一部分:
<searchComponent class="solr.SpellCheckComponent" name="suggest">
<!-- configure the spellchecker used
for autocomplete (dictionary) -->
<lst name="spellchecker">
<str name="name">suggester_dictionary</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.fst.FSTLookupFactory</str>
<!-- The indexed field to derive suggestions from -->
<str name="field">autocomplete</str>
<!-- buildOnCommit must be set to true because
suggester keeps data in memory -->
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
<requestHandler class="solr.SearchHandler" name="/suggest">
<lst name="defaults">
<!-- by default use the suggester_dictionary -->
<str name="spellcheck.dictionary">suggester_dictionary</str>
<str name="spellcheck.count">5</str>
<str name="spellcheck.onlyMorePopular">false</str>
</lst>
<lst name="invariants">
<!-- always run the Suggester for queries to this handler -->
<str name="spellcheck">true</str>
<!-- collate not needed, query if tokenized as keyword, we need only suggestions for that term -->
<str name="spellcheck.collate">false</str>
</lst>
<!-- this handler uses only the needed component :
suggest defined above -->
<arr name="components">
<str>suggest</str>
<str>highlight</str>
</arr>
</requestHandler>
和方案:
<field name="groupid" type="int" indexed="true" stored="true"
required="true" multiValued="false"/>
<field name="groupusername" type="text_general" indexed="true"
stored="true" multiValued="true"/>
<field name="groupname" type="text_general" indexed="true"
stored="true" multiValued="false"/>
<field name="grouporuser" type="boolean" indexed="true"
stored="true" multiValued="false"/>
<field name="autocomplete" type="text_autocomplete"/>
<copyField source="groupusername" dest="autocomplete"/>
<copyField source="groupname" dest="autocomplete"/>
查詢: http://gruppu.com:8983/solr/suggest?q=: & spellcheck.q =裘&拼寫檢查=真& HL = on & hl.fl = groupid
的迴應:
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
</lst>
<lst name="spellcheck">
<lst name="suggestions">
<lst name="jo">
<int name="numFound">2</int>
<int name="startOffset">0</int>
<int name="endOffset">2</int>
<arr name="suggestion">
<str>jorge</str>
<str>jorgen</str>
</arr>
</lst>
</lst>
</lst>
</response>
我想有groupId和grouporuser領域返回......至今沒有運氣。