views:

113

answers:

1

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?

A: 

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
Michael Rush