javasolrlucenesolr5

How can I add both AND and OR operators in Solr 5.5.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.


Solution

  • 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.