我已經配置了我的solrconfig.xml和schema.xml來查詢建議。如何讓SolrNet中的建議器組件工作?
我能夠從URL中得到的建議
http://localhost:8080/solr/collection1/suggest?q=ha&wt=xml
我solrconfig.xml中看起來像
Curently,我Solr的查詢看起來像
<fields>
<!-- declare fields of entity class -->
<!-- type will specify the table name -->
<field name="type" type="string" indexed="true" stored="true" />
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="name" type="text_general" indexed="true" stored="true" omitNorms="true"/>
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
<field name="_version_" type="long" indexed="true" stored="true"/>
<!-- unique field -->
<field name="uid" type="uuid" indexed="true" stored="true" />
</fields>
<uniqueKey>uid</uniqueKey>
<copyField source="name" dest="text"/>
<types>
<fieldType name="uuid" class="solr.UUIDField" indexed="true" />
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
.....
</types>
而我的schema.xml看起來像這樣
<searchComponent name="suggest" class="solr.SpellCheckComponent">
<!-- a spellchecker built from a field of the main index -->
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="field">name</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<str name="buildOnCommit">true</str>
<str name="distanceMeasure">internal</str>
<float name="accuracy">0.5</float>
<int name="maxEdits">2</int>
int name="minPrefix">1</int>
<int name="maxInspections">5</int>
<int name="minQueryLength">4</int>
<float name="maxQueryFrequency">0.01</float>
<float name="thresholdTokenFrequency">.01</float>
</lst>
<!-- a spellchecker that can break or combine words. See "/spell" handler below for usage -->
<lst name="spellchecker">
<str name="name">wordbreak</str>
<str name="classname">solr.WordBreakSolrSpellChecker</str>
<str name="field">name</str>
<str name="combineWords">true</str>
<str name="breakWords">true</str>
<int name="maxChanges">10</int>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="df">text</str>
<!-- Solr will use suggestions from both the 'default' spellchecker
and from the 'wordbreak' spellchecker and combine them.
collations (re-written queries) can include a combination of
corrections from both spellcheckers -->
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<!--<str name="spellcheck.dictionary">wordbreak</str>-->
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.alternativeTermCount">5</str>
<str name="spellcheck.maxResultsForSuggest">5</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.collateExtendedResults">true</str>
<str name="spellcheck.maxCollationTries">10</str>
<str name="spellcheck.maxCollations">5</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
我的代碼來調用API SolrNet看起來如下
new SolrBaseRepository.Instance<T>().Start();
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<T>>();
var options = new QueryOptions
{
FilterQueries = new ISolrQuery[] { new SolrQueryByField("type", type) }
};
var results = solr.Query(keyword, options);
return results;
但是,我沒有得到任何數據。 結果計數爲零。結果中的拼寫檢查也爲零。
我也沒有看到結果中的建議列表。
請幫
我按建議進行了更改,但仍未得到結果 – Prasad
您在SolrNet查詢中爲關鍵字和類型使用了什麼值?此外,你是否直接針對Solr運行相同的查詢。我從您的問題中看到,您使用'q = ha'運行了一個,嘗試添加篩選器查詢以確保其按預期工作......可能會出現這種情況,當您使用不想過濾的建議程序查詢結果... –