Solr 在查询中搜索多个单词 [英] Solr search multiple word in query

查看:67
本文介绍了Solr 在查询中搜索多个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 solr 架构中有以下字段

I have following fields in solr schema

make
model
city
province

我创建了一个 copyfield 搜索并将这 4 个字段复制到其中

I created a copyfield search and copy these 4 field in it

现在我想要,如果用户正在搜索

now I want, if a user is searching for

'audi a4' where audi is a make and a4 is model, 

我应该得到连续制造是奥迪和型号是 a4 的结果.

I should get result where in a row make is audi and model is a4.

如果我搜索

'asd audi asd' 

那么我应该只得到奥迪的结果.

then i should get result of audi only.

如果我搜索

'asd aasd audi asd a4',

然后它应该显示奥迪 a4 结果.

then it should display audi a4 results.

请帮助我实现这一目标.

Please help me to achieve this.

请参阅复制字段的架构

   <copyField source="Make" dest="search"/>
   <copyField source="Model" dest="search"/>
   <copyField source="City" dest="search"/>

创建的字段如下

<field name="search" type="string" indexed="true" stored="false" multiValued="true"/>

推荐答案

您可以为您的领域尝试这个 fieldType.

You can try this fieldType for your field.

<fieldType name="text" class="solr.TextField">
    <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

或者你可以试试这个字段输入搜索字段

or you can try this field Type for search field

<fieldType name="text_ws" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.WordDelimiterFilterFactory" generateWordParts="0" generateNumberParts="1" catenateWords="0" catenateNumbers="0" preserveOriginal="1" catenateAll="0" splitOnCaseChange="0"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
      <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
    </fieldType>

所以你的领域现在是

<field name="search" type="text_ws" indexed="true" stored="false" multiValued="true"/>

这篇关于Solr 在查询中搜索多个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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