开发者

search in all fields for multiple values?

开发者 https://www.devze.com 2022-12-13 21:50 出处:网络
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

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

but it doesnt work.

how should i type it?开发者_运维技巧

PS. could i enter default search field = ALL fields in schema.xml in someway?


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. In that scenario, you define the copyField, and then set the fields that get copied to it.

<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:

<defaultSearchField>mysearchfield</defaultSearchField>

After that, the query would just become:

q=dog cat
0

精彩评论

暂无评论...
验证码 换一张
取 消