0

I am using Solr 5.5.0 and currently the application is searching with the "AND" operator without it being specified. For example: I search for programmer developer and it gives me the result of the files with the words programmer and developers. The configuration is done in the solrconfig.xml

<str name="mm">100%</str>

But I need now to change it to make it use of both operators :

  1. when I write programmer AND developer and gives me the results of the files that contains both words;
  2. when I write programmer OR developer and gives me the results of the files that contains one or another word;

Can you please advice me on what should I do and how? I went through the information on the internet but couldn't figure it out.

Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
ttdol2506
  • 103
  • 1
  • 10

2 Answers2

0

As far as I understood the problem, you have a field in SOLR on which you need to search for the word. I am naming the SOLR field "job" which have values "programmer" or "developer". You do not need to change anything in solrconfig, you can make changes in the query.

The default Query Parser used by SOLR is Standard Query Parser. This parser supports boolean operator like AND, OR etc.

You can search for the results like this:

for searching programmer AND developer

localhost:8983/solr/select?q=job:programmer AND job:developer

for searching programmer OR developer

localhost:8983/solr/select?q=job:programmer OR job:developer

Hope this helps.

vsri293
  • 541
  • 4
  • 7
0

You can define the default operator in solrconfig.xml by setting the defaults on your requestHandler:

<requestHandler name="search" class="solr.SearchHandler" default="true">
    <lst name="defaults">
      <str name="q.op">AND</str>
      ...

or with LocalParams. Assume we have the existing query parameter

q=solr rocks

We can prefix this query string with LocalParams to provide more information to the query parser, for example changing the default operator type to "AND" and the default field to "title" for the lucene query parser:

q={!q.op=AND df=title}solr rocks
Mico
  • 1,978
  • 2
  • 13
  • 17