我是Solr的初學者。我正在使用Solr 4.6和Spring 3.xSpring數據Solr如何獲得建議
我已經成功地將Solr配置到我的Spring應用程序,並且能夠使用下面的代碼搜索地址。
@Query("text:*?0*")
public List<AddressDocument> findAll(String searchText);
我的架構是
<fields>
<field name="id" type="long" indexed="true" stored="true" required="true" multiValued="false" />
<field name="name" type="string" indexed="false" stored="true" required="true" multiValued="false"/>
<field name="number" type="string" indexed="false" stored="true" required="true" multiValued="false"/>
<field name="address" type="text_general" indexed="false" stored="true" required="true" multiValued="false"/>
<field name="city" type="string" indexed="false" stored="true" multiValued="false"/>
<field name="state" type="string" indexed="false" stored="true" multiValued="false"/>
<field name="zipcode" type="string" indexed="false" stored="true" multiValued="false"/>
<field name="country" type="string" indexed="false" stored="true" multiValued="false"/>
<field name="latlng" type="string" indexed="false" stored="true" multiValued="false"/>
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
<field name="_version_" type="long" indexed="true" stored="true"/>
</fields>
<!-- Configure unique key -->
<uniqueKey>id</uniqueKey>
<copyField source="name" dest="text"/>
<copyField source="number" dest="text"/>
<copyField source="address" dest="text"/>
<copyField source="city" dest="text"/>
<copyField source="state" dest="text"/>
<copyField source="zipcode" dest="text"/>
<copyField source="country" dest="text"/>
現在我已經集成了拼寫檢查,當我輸入任何不正確的拼寫那麼就說明我按照測井響應。
例如,正確的城市名稱是Fargo
,如果我輸入Frgo
,那麼它會在輸出下方顯示我。
2014-01-30 04:09:10,903 DEBUG [http-8080-2] (DirectSolrSpellChecker.java:179) - getSuggestions: [frgo]
2014-01-30 04:09:10,940 DEBUG [http-8080-2] (SpellCheckCollator.java:180) - Collation: text:*fargo* will return 3 hits.
2014-01-30 04:09:10,941 INFO [http-8080-2] (SolrCore.java:1864) - [customer_site_address] webapp=null path=/select params={q=text%3A*frgo*&start=0&rows=0} hits=0 status=0 QTime=43
2014-01-30 04:09:10,944 DEBUG [http-8080-2] (SolrTemplate.java:326) - Executing query 'q=text%3A*frgo*&start=0&rows=1' against solr.
2014-01-30 04:09:10,951 DEBUG [http-8080-2] (DirectSolrSpellChecker.java:179) - getSuggestions: [frgo]
2014-01-30 04:09:10,959 DEBUG [http-8080-2] (SpellCheckCollator.java:180) - Collation: text:*fargo* will return 3 hits.
2014-01-30 04:09:10,960 INFO [http-8080-2] (SolrCore.java:1864) - [customer_site_address] webapp=null path=/select params={q=text%3A*frgo*&start=0&rows=1} hits=0 status=0 QTime=15
2014-01-30 04:09:10,961 DEBUG [http-8080-2] (AbstractMessageConverterMethodProcessor.java:150) - Written [[]] as "application/json;charset=UTF-8" using [org.springf[email protected]1fb032d]
正如你可以看到記錄它建議正確的單詞,但我不知道我怎樣才能使用@Query
或任何其它註釋這個建議。
我做了很多谷歌,但沒有找到任何完美的解決方案。
請分享您的投票理由 –