Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default search on all fields

Tags:

solr

lucene

I can only get Solr to work when I include a field in the query, for example:

http://localhost:8983/solr/collection1/select?q=lastname:johnson

The above query returns approximately 18 results.

Shouldn't it be possible to use Solr (/Lucene) without specifying the field? Such as:

http://localhost:8983/solr/collection1/select?q=johnson

I also tried adding the fields list:

http://localhost:8983/solr/collection1/select?q=johnson&fl=cus_id%2Cinitials%2Clastname%2Cpostcode%2Ccity

But all these queries return zero results.

These are the fields from my schema.xml:

<field name="cus_id" type="string" indexed="true" stored="true"/>
<field name="initials" type="text_general" indexed="true" stored="true" />
<field name="lastname" type="text_general" indexed="true" stored="true"/>
<field name="postcode" type="string" indexed="true" stored="true" />
<field name="city" type="text_general" indexed="true" stored="true"/>

I don't know what else to try. Any suggestions?

like image 360
jao Avatar asked Feb 15 '23 13:02

jao


1 Answers

For Solr if not field is specified the search happens on the default field (df).
So when you search q=johnson and debug the query you will find it searching on the default field which is usually the field text.
You can copyfield all the fields to the single field text and have it as the default field (if not default already), so that all your search queries would be searched across the default field.
Also, fl lists the fields that would be returned as part of the result and is not related to the fields on which the search is performed.
With dismax, You can check the qf param to specify multiple fields with variable boosts.

like image 181
Jayendra Avatar answered Mar 03 '23 16:03

Jayendra