dev
dev

Reputation: 31

Searching multiple fields in SOLR

I am trying to search on 2 fields without having to specify a field name in the query. In my schema.xml I have added 2 fields that correspond to 2 columns in a database table.

<field name="title" type="string" indexed="true" stored="true" required="true"/>
<field name="description" type="string" indexed="true" stored="true"/>

In addition I added a 3rd field which I want to use as a destination in "copyField"
and also as the "defaultSearchField"

<field name="combinedSearch" type="string" indexed="true" stored="true" multiValued="true"/>

<copyField source="*" dest="combinedSearch"/>

<uniqueKey>title</uniqueKey> 

<defaultSearchField>combinedSearch</defaultSearchField>

Now in the Solr Admin UI, if I enter some title it will return results but if I enter some description it won't return anything. It seems only the first field is used for searching. Am I using copyField and defaultSearchField in the right way? I've restarted the solr server and regenerated the index. Thanks.

Upvotes: 3

Views: 7290

Answers (3)

The Bndr
The Bndr

Reputation: 13394

Probably it ends in the same result, but for your information, i use copyField at the end of the schema.xml (but i dont think, the order is relevant) in the following syntax:

   <copyField source="title" dest="combinedSearch" />
   <copyField source="description" dest="combinedSearch" />

next:

<field name="combinedSearch" type="string"

If type="text" is the better choise depends on the definition of "string". If you are using default fieldTypes, type="string" could better for your case, because for string there is no analyzing per default, which means (probably) there is also no tokenyzing.

//update

An other way instead of copyfields is to use the (e)dsimax query parser. On solrconfig.xml you can specify all the field you like to search by default, like this:

  <requestHandler name="/select" class="solr.SearchHandler" default="true">
    <!-- default values for query parameters can be specified, these
         will be overridden by parameters in the request
      -->
     <lst name="defaults">
       <str name="defType">edismax</str>
       <float name="tie">0.01</float>
       <bool name="tv">true</bool>
       <str name="qf">
             title^1 description^1
       </str>
     ...

Upvotes: 2

egeek
egeek

Reputation: 301

Here's how I approached it. Instead of using * alias, I defined which fields to copy to my combined field. I also sat multiValued to false on my normal fields (title and description). Instead of defining my fields as string, I used "text_general" - both for my normal fields and my combined field.

Furthermore I set "stored=false" on my combined field, as I don't need to return the value, as it is only used for searching - in my case at least.

<field name="title" type="text_general" indexed="true" stored="true" required="true" multiValued="false" />
<field name="description" type="text_general" indexed="true" stored="true" multiValued="false"/>

<field name="combinedSearch" type="text_general" indexed="true" stored="false" multiValued="true"/>
<copyField source="title" dest="combinedSearch"/>
<copyField source="description" dest="combinedSearch"/>

<uniqueKey>title</uniqueKey> 
<defaultSearchField>combinedSearch</defaultSearchField>

Upvotes: 0

pricco
pricco

Reputation: 2783

Try change your combinedSearch type to text and then regenerate the index.

Upvotes: 1

Related Questions