Solr SuggestComponent 是否能够返回带状疱疹而不是整个字段值? [英] Is Solr SuggestComponent able to return shingles instead of whole field values?

查看:21
本文介绍了Solr SuggestComponent 是否能够返回带状疱疹而不是整个字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 solr 5.0.0 并想创建一个自动完成功能,从我的文档的 word-gram(或带状疱疹)生成建议.问题是,作为建议查询的回报,我只能得到可能非常长的搜索字段的完整术语".

I use solr 5.0.0 and want to create an autocomplete functionality generating suggestions from the word-grams (or shingles) of my documents. The problem is that in return of a suggest-query I only get complete "terms" of the search field which can be extremly long.

当前问题:

输入:"so"建议:......非常长的文本所以n 长文本继续......"

Input:"so" Suggestions: "......extremly long text son long text continuing......"

......下一个长文本所以下一个文本继续......"

"......next long text solar next text continuing......"

目标:

输入:所以"

带状疱疹的建议:

"所以n"

所以拉"

solar 测试"

<searchComponent name="suggest" class="solr.SuggestComponent" 
               enable="${solr.suggester.enabled:true}"     >
<lst name="suggester">
  <str name="name">mySuggester</str>
  <str name="lookupImpl">AnalyzingInfixLookupFactory</str>      
  <str name="dictionaryImpl">DocumentDictionaryFactory</str>
  <str name="field">title_and_description_suggest</str>
  <str name="weightField">price</str>
  <str name="suggestAnalyzerFieldType">autocomplete</str>
  <str name="queryAnalyzerFieldType">autocomplete</str>
 <str name="buildOnCommit">true</str>
</lst>

schema.xml:

schema.xml:

<fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_de.txt" format="snowball"/>
      <filter class="solr.ShingleFilterFactory" maxShingleSize="2" outputUnigrams="true" outputUnigramsIfNoShingles="true"/>
      <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
    </analyzer>
</fieldType>

我想返回最多 3 个单词作为自动完成词.SuggestComponent 是否可以做到这一点,或者您将如何做到这一点?无论我尝试什么,我总是收到匹配文档的完整字段值.

I want to return max 3 words as autocomplete term. Is this possible with the SuggestComponent or how would you do it? No matter what I try I always receive the complete field value of matching documents.

这是预期的行为还是我做错了什么?

Is that expected behaviour or what did I do wrong?

非常感谢

推荐答案

在schema.xml中定义fieldType如下:

 <fieldType name="text_autocomplete" class="solr.TextField" positionIncrementGap="100">
        <analyzer type="index">
            <tokenizer class="solr.WhitespaceTokenizerFactory"/>
            <filter class="solr.LowerCaseFilterFactory"/>
            <filter class="solr.ShingleFilterFactory" minShingleSize="2" maxShingleSize="5"/>
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.KeywordTokenizerFactory"/>
            <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
    </fieldType>

在 schema.xml 中定义您的字段如下:

<field name="example_field" type="text_autocomplete" indexed="true" stored="true"/>

按如下方式编写您的查询:

query?q=*&
rows=0&
facet=true&
facet.field=example_field&
facet.limit=-1&
wt=json&
indent=true&
facet.prefix=so

在 facet.prefix 字段中,指定要搜索的术语(在本例中为so").如果您需要在建议中少于 5 个单词,请相应减少 fieldType 定义中的 maxShingleSize.默认情况下,您将获得按出现频率降序排列的结果.

In the facet.prefix field, specify the term being searched for which you want suggestions ('so', in this example). If you need less than 5 words in the suggestion, reduce maxShingleSize in the fieldType definition accordingly. By default, you will get the results in decreasing order of their frequency of occurrence.

这篇关于Solr SuggestComponent 是否能够返回带状疱疹而不是整个字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆