【问题标题】:solr autocomplete keywords from multiple fields来自多个字段的 solr 自动完成关键字
【发布时间】:2012-11-02 07:56:12
【问题描述】:

我是 Solr 的新手,想实现基于两个字段标题和描述的自动完成功能。此外,结果集还应进一步受到 id 和类别等其他字段的限制。样本数据:

Title: The brown fox lives in the woods
Description: The fox is found in the woods where brown leaves cover the ground. The animal's fur is brown in color and has a long tail.

所需的自动完成结果:

brown fox
brown leaves
brown color

以下是 schema.xml 中的相关条目:

<fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
 <analyzer type="index">
   <tokenizer class="solr.WhitespaceTokenizerFactory"/>
   <filter class="solr.LowerCaseFilterFactory"/>
   <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="25" />
 </analyzer>
 <analyzer type="query">
   <tokenizer class="solr.WhitespaceTokenizerFactory"/>
   <filter class="solr.LowerCaseFilterFactory"/>
 </analyzer>
</fieldType>


<field name="id" type="int" indexed="true" stored="true"/>
<field name="category" type="string" indexed="true" stored="true"/>
<field name="title" type="text_general" indexed="true" stored="true"/>
<field name="description" type="text_general" indexed="true" stored="true"/>

<field name="ac-terms" type="autocomplete" indexed="true" stored="false" multiValued="true" omitNorms="true" omitTermFreqAndPositions="false" />
<copyField source="title" dest="ac-terms"/> 
<copyField source="description" dest="ac-terms"/>

查询请求:

http://localhost:9090/solr/select?q=(ac-terms:brown)

【问题讨论】:

    标签: solr autocomplete


    【解决方案1】:

    使用 ShingleFilterFactory 解决,配置如下:

    <fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/>
        <filter class="solr.ShingleFilterFactory" maxShingleSize="2" outputUnigrams="false"/>
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
    </fieldType>
    
    <field name="ac-terms" type="autocomplete" indexed="true" stored="false" multiValued="true" omitNorms="true" omitTermFreqAndPositions="false" />
    <copyField source="title" dest="ac-terms"/>
    <copyField source="description" dest="ac-terms"/>
    

    查询请求:

    http://localhost:9090/solr/select?q=&facet=true&facet.field=ac-terms&facet.prefix=brown 
    

    结果:

    brown color
    brown fox
    brown leaves
    

    希望这对某人有所帮助

    【讨论】:

    • 感谢您提供了这样一个很好的例子。有没有办法给这些结果一个权重来排序?
    【解决方案2】:

    如何创建一个字段spellcheck_text 并使用复制字段功能使titledescription 自动指向spellcheck_text

    ...指示 Solr 您希望它复制它在 添加到索引的文档的“源”字段,在“dest”中 该文档的字段。 ... 原始文本是从 “source”字段到“dest”字段,在任何配置的分析器之前 为起始或目的地字段被调用。

    http://wiki.apache.org/solr/SchemaXml#Copy_Fields

    【讨论】:

    • 我不是通过声明 ac-terms 来做到这一点的吗?我错过了什么?
    猜你喜欢
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多