我已经配置了我的 solrconfig.xml 和 schema.xml 来查询建议。
我能够从 url 获得建议
http://localhost:8080/solr/collection1/suggest?q=ha&wt=xml
我的 SolrConfig.xml 看起来像
目前,我的 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>
我调用 SolrNet API 的代码如下所示
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;
但是,我没有得到任何数据。结果计数为零。结果中的拼写检查也为零。
我也没有在结果中看到建议列表。
请帮忙