Question

I am new to solr. I want to search database. I am able to import the values and index it.but while searching it seems the field name is necessary to mention in the search query.how can it be done without specifying the field names.

Was it helpful?

Solution

You can import all data into the default field. Then you don't need to explicitly mention the field names. (Although you still can if you want)

The default schema.xml with Solr already contains an example for using such a "catchall" field:

First the field has to be declared like any other field:

<field name="text" type="text_general" indexed="true"
       stored="false" multiValued="true"/>

Then this new field has to be declared the default field. Whenever no specific field is searched, this one will be searched:

<defaultSearchField>text</defaultSearchField>

You also need some copyField statements which copy all existing fields into the catchall field:

<copyField source="cat" dest="text"/>
<copyField source="name" dest="text"/>
<copyField source="my_special_field_1" dest="text"/>
<copyField source="my_special_field_2" dest="text"/>
...

So whenever the field my_special_field_1 is indexed its value is also added to the text field.

As a shortcut you can copy all fields into the text field with

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

After that you can perform searches without specifying any field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top