如何获得suggester成分SolrNet工作吗? [英] How to get the suggester component working in SolrNet?
问题描述
我已经配置我的solrconfig.xml中和schema.xml中查询您的建议。
I have configured my solrconfig.xml and schema.xml to query for the suggestions.
我能够从URL中得到的建议
I am able to get the suggestions from the url
http://localhost:8080/solr/collection1/suggest?q=ha&wt=xml
我的solrconfig.xml中看起来像
My SolrConfig.xml looks like
有curently,我Solr的查询看起来像
Curently, My solr query looks like
<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中看起来像这样
And my schema.xml looks like this
<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看起来如下
My code to call the SolrNet API looks as below
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;
不过,我没有得到任何数据。
。结果计数为零。而且在结果中拼写检查也是零。
However, I am not getting any data. results count is zero. And also the spellcheck in the results is also zero.
我还没有看到结果内部推荐列表。
I also dont see the suggestion list inside the results.
请帮忙
推荐答案
我有完全相同的要求,但找不到任何办法能够轻松地处理的 Suggester 与SolrNet结果。不幸的是,SolrNet似乎周围的默认 /选择
请求处理待建,目前不支持任何其他处理程序,包括 /提示
对象类型映射( T
)。该公司预计所有映射与索引文件Solr的结果,而不是suggester结果发生。
I had the exact same requirement but could not find any way to easily handle Suggester results with SolrNet. Unfortunately, SolrNet seems to be built around the default /select
request handler and does not currently support any other handler including /suggest
for object type mappings (T
). It expects all mappings to occur with indexed Solr document results and not suggester results.
因此,的 @佩奇库克的回答没有为我工作。 T
键入与映射不兼容与suggester结果的回应。要查询( ISolrQueryResults< T>所有的初始化请求(; T>()
Startup.Init<)的标准管道代码的结果= solr.Query ()
)的需求映射Solr的文档类型和其suggester提供的字符串不是一个简单的数组。
Hence, @Paige Cook's answer did not work for me. T
type with mappings is not compatible with a suggester results response. All the standard plumbing code from initializing the request (Startup.Init<T>()
) to querying (ISolrQueryResults<T> results = solr.Query()
) needs a mapped Solr document type and not a simple array of strings which the suggester provides.
因此,(类似于 @dfay )我去提出一个web请求,并解析出从XML的Web响应建议的结果。在 SolrConnection
被用于这个类:
Therefore, (similar to @dfay) I went with making a web request and parsing out the suggested results from the XML web response. The SolrConnection
class was used for this:
string searchTerm = "ha";
string solrUrl = "http://localhost:8080/solr/collection1";
string relativeUrl = "/suggest";
var parameters = new Dictionary<string, string>
{
{"q", searchTerm},
{"wt", "xml"},
};
var solrConnection = new SolrConnection(solrUrl);
string response = solrConnection.Get(relativeUrl, parameters);
// then use your favorite XML parser to extract
// suggestions from the reponse string
$ B $
//建议b
另外,除了XML,要求能使用重量= JSON
参数返回一个JSON响应:
Alternatively, instead of XML, the request can return a JSON response using the wt=json
parameter:
var parameters = new Dictionary<string, string>
{
{"q", searchTerm},
{"wt", "json"}, // change this!
};
// then use your favorite JSON parser
这篇关于如何获得suggester成分SolrNet工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!