简体   繁体   English

在所有字段中搜索多个值?

[英]search in all fields for multiple values?

i have two fields: 我有两个领域:

title body 标题主体

and i want to search for two words 我想搜索两个词

dog OR cat 狗或猫

in each of them. 在每个人中。

i have tried q=*:dog OR cat 我尝试过q = *:狗或猫

but it doesnt work. 但它不起作用。

how should i type it? 我应该如何输入?

PS. PS。 could i enter default search field = ALL fields in schema.xml in someway? 我是否可以以某种方式在schema.xml中输入默认搜索字段=所有字段?

As Mauricio noted, using a copyField (see http://wiki.apache.org/solr/SchemaXml#Copy_Fields ) is one way to allow searching across multiple fields without specifying them in the query string. 正如Mauricio指出的那样,使用copyField(请参阅http://wiki.apache.org/solr/SchemaXml#Copy_Fields )是一种允许跨多个字段搜索而无需在查询字符串中指定它们的方法。 In that scenario, you define the copyField, and then set the fields that get copied to it. 在那种情况下,您定义copyField,然后设置要复制到它的字段。

<field name="mysearchfield" type="string" indexed="true" stored="false"/>
...
<copyField source="title" dest="mysearchfield"/>
<copyField source="body" dest="mysearchfield"/>

Once you've done that, you could do your search like: 完成此操作后,您可以按照以下方式进行搜索:

q=mysearchfield:dog OR mysearchfield:cat

If your query analyzer is setup to split on spaces (typical), that could be simplified to: 如果您的查询分析器设置为按空格分割(典型值),则可以简化为:

q=mysearchfield:dog cat

If "mysearchfield" is going to be your standard search, you can simplify things even further by defining that copyField as the defaultSearchField in the schema: 如果将“ mysearchfield”作为您的标准搜索,则可以通过将copyField定义为架构中的defaultSearchField来进一步简化操作:

<defaultSearchField>mysearchfield</defaultSearchField>

After that, the query would just become: 之后,查询将变为:

q=dog cat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM