Select query for search with 2 or more words without double quotes in solr

774 views Asked by At

I have a column named title. I want to search this column. There is no problem when I use single word like title:'sport' OR title:"sport". Both giving same number of record.

My problem is when I search with 2 or more words without double quotes(with double quotes giving exact result ex: title:"sport education").

title:'sport education' - returning irrelevant records(more title's don't have sport or education word)

+title:'sport education' - returns the same number of record for the search oftitle:'sport' / title:"sport".

what should I do to get atleast any one search word must match in the column?

Note: Solr version 6.3.0

Thank you in advance!

2

There are 2 answers

1
Pavel Vasilev On BEST ANSWER

I bet what you are looking for is the following chain of parameters:

http://$solr_host:8983/solr/magazines/select&q=sport+education&df=title&q.op=OR

Let me decipher it for you:

  • q=sport+education. You are free to use query in such free form.
  • df=title. Here you are specifying default field for search.
  • q.op=OR (which is default, feel free to omit it). $q will be tokenized according to $df fieldType and the clauses will be joined via OR like this: title:sport OR title:education

For more information you can follow Common Query Parameters or Local Parameters in Queries.

1
Vinod On

After parsing your query title:'sport education' will look like this

title:sport text:education single quote doesn't work as double quotes.

so term education is searched in default field df(text, check it in solr-config file)

In schema file you might have copied many other field into text using copyfield so you get other documents(fields which have education in it)

You should specify field name to search different term in different field liketitle:sport name:sachin.

In phrase query using double quotes title:"sport education" this gives you all documents with title field having sport education in it.