Solr-查询所有字段的最佳做法 [英] Solr - Query over all fields best practice

查看:547
本文介绍了Solr-查询所有字段的最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

schema.xml代码段:

schema.xml snippet:

   <field name="id" type="string" indexed="true" stored="true" required="true" />
   <field name="notes" type="text_general" indexed="true" stored="true"/>
   <field name="missionFocus" type="text_general" indexed="true" stored="true"/>
   <field name="name" type="text_general" indexed="true" stored="true"/>
   <field name="first_name" type="text_general" indexed="true" stored="true"/>
   <field name="last_name" type="text_general" indexed="true" stored="true"/>
   <field name="about_me" type="text_general" indexed="true" stored="true"/>
   <field name="message" type="text_general" indexed="true" stored="true"/>
   <field name="title" type="text_general" indexed="true" stored="true"/>  
   <field name="table_type" type="string" indexed="true" stored="true"/>  

   <field name="text" type="text_general" indexed="true" stored="false" 
          multiValued="true"/>

现在,我想在所有字段("id"和"table_type"除外)中搜索例如你好".我该怎么做?我真的必须写以下内容吗?

Now I want to search in all fields (except "id" and "table_type") for e.g. "hello". How I can do this? Do I really have to write following?

/solr/select/?q=notes:hello missionFocus:hello name:hello first_name:hello ..

我听说了有关DisMaxRequestHandler的信息,但是如何使用该处理程序进行查询?我是否需要为此更改solrconfig.xml中的内容?

I heard something about DisMaxRequestHandler but how I have to query with this handler? Do I need to change something in solrconfig.xml for that?

推荐答案

最好的解决方案是构建一个字段,该字段将收集所有此类字段的数据

The best solution is to build a field, that collects the data of all fields like this

<field 
    name="collector" 
    type="text_general" 
    indexed="true" 
    stored="false" 
    multiValued="true"
/>

您现在唯一要做的就是将所有字段的内容复制到该字段中:

The only thing you have to do now is, copy the contents of all fields into that field:

<copyField source="notes"        dest="collector"/>
<copyField source="missionFocus" dest="collector"/>
<copyField source="name"         dest="collector"/>
....

请注意,必须在以下以下定义copyField块:

Be aware that the copyField block has to be defined BELOW this:

<fields>
....
</fields>

现在您只能在collector字段中搜索,您会在任何字段中找到任何文本.

Now you can search only on the field collector and you will find any text in any of your fields.

这篇关于Solr-查询所有字段的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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