2

My question is same as this - Solr Index appears to be valid - but returns no results but for newly announced solr 7.3.

I have created a Solr index and write a whole bunch of docs into it. I can see from the Solr admin page that the docs exist and the schema is fine as well. But when I perform a search using a test keyword I do not get any results back.

On entering * : * into the query (in Solr admin page) I get all the results.

However, when I enter any other query (e.g. a term or phrase) I get no results. I have verified that the field being queried is Indexed and contains the values I am searching for.

Solr 7.3 however have removed the <defaultSearchField> in the new release. Is there any alternate solution? How to make it search and return results from all documents?

Kabhi
  • 135
  • 1
  • 12

2 Answers2

4

So starting from solr 7.3 , the support for default field has removed.

see here https://lucene.apache.org/solr/guide/7_3/major-changes-in-solr-7.html?hl=defaultSearchField#other-deprecations-and-removals

Now when you do not specify a field while searching there is no default field to search on. The only way to do it is using the df operator. So in your case if you want that if the field is not specified then you wnat to search in the category field then use the following query:

q=https://ip:port/select?q=apple&wt=json&df=category

so you need to specify the default field in the query itself.

Now the question to if you want to search in all the fields. you can use the copyField.

So you can create a copy field in you scheam file. copy all the fields whcih you want to search when nothing is specified and then use that field in the df.

e.g define a field called text in your schema

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

Now define some copy fields for this.

 <copyField source="category" dest="_text_" />
 <copyField source="first_name" dest="_text_" />

and then in your queries you can do like this

q=https://ip:port/select?q=apple&wt=json&df=_text_

Read more about copy fileds here : https://lucene.apache.org/solr/guide/7_3/copying-fields.html

Be aware though copying field is duplicating data and it will increase your index size.

root
  • 3,517
  • 2
  • 19
  • 25
  • This answer is clear. Just to make it a bit precise, it works for `&df=_text_` instead of text because of default of fieldType being _text_ – Kabhi Apr 15 '18 at 16:31
  • As you mentioned regarding duplication upon copying field - Every time I import data from the database, it's duplicating the data in Index. How can I avoid that? – Kabhi Apr 15 '18 at 17:00
  • Importing data from what database and duplicating in what sense – root Apr 15 '18 at 17:01
  • So I use DIH to connect to MySQL database. My database has 5000 records. Now after copyfield implementation, whenever I import data (i.e refresh the data) it adds up the additional 5000 records again in the index. Meaning If I import 5 times, the total size of index becomes 25000. – Kabhi Apr 15 '18 at 17:06
  • That is why there was a warning at the last line. Copyfield will duplicate the data. So your index size will grow. however are you loading the same 5000 records again and again or is it a different set of records ? – root Apr 15 '18 at 17:09
  • Yeah. I got the warning and appreciate it. Thanks. But I need to keep only unique records and not their duplication in the Index. I'm loading the same 5000 records. They are not different. – Kabhi Apr 15 '18 at 17:12
  • 1
    Do you use a uniqueKey in the schema ? check here about it https://wiki.apache.org/solr/UniqueKey – root Apr 15 '18 at 17:15
  • Great. Yeah, I just defined one of my columns as UniqueKey and made the default one (Id) as `required=false`. It worked. Thanks much. – Kabhi Apr 15 '18 at 17:26
0

Generated queries are always best made explicit but you can still use the df request parameter to specify a default search field.

With dismax parsers you can also specify default values for the qf parameter in your requestHandler defintion, in solrconfig.xml (df won't take effect if qf is defined).

It is still worth noting that fields must be indexed as text not string to be properly searchabe.

EricLavault
  • 12,130
  • 3
  • 23
  • 45
  • I had tried with `df` but for some reason the search still gives 0 results ` explicit json true name ` – Kabhi Apr 15 '18 at 09:44