Solr - 查询所有字段最佳实践 [英] Solr - Query over all fields best practice
问题描述
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
块必须在BELOW下面定义:
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屋!