Multiple Word Search in SOLR

Multi Word Search In SOLR

 While working with SOLR in a project I came to a scenario where I to find all document in SOLR which contains all words of the string. 

For Example -: 
I have these indexed documents in SOLR  with title as below

  1. I am Software Engineer
  2. Microsoft is a Software Company
  3. Software is build by Engineer
  4. I am an Engineer 
  5. SOLR is best Search Engine




User Enter "Software Engineer" in some application as input then my expected output will be will be below documents
  1. I am Software Engineer.
  2. Software is build by Engineers.
This mean i want all document containing both words of the input i.e. Title should contains Software and Engineer words in full text.

To make search like this we have multiple option but my preferred and easy escapes to perform this search is use Proximity Search in SOLR

Solr Query:
Title:"Software Engineer"~1000000

With query like this in SOLR, I will get the expected results.



So question is what is the proximity search is, Finding words at a max distance from each other. To explain this what i mean lets take example
We have document is SOLR with property name title and string as "SOLR is best Search Engine"

Now we do few queries and see results:
Query 1:
Title:"SOLR Engine"~2



So in this query we are searching "SOLR Engine" with at distance of 2 that i.e between SOLR and engine any two words can come but in input string SOLR and Engine is at a distance of 3. So if query like below then we get the output as "SOLR is best Search Engine"

Title:"SOLR Engine"~3




So with providing value as "1000000"in our actual example we setting the distance between two words as "1000000". So if you have string containing more than this length then please increase this length.
There are other ways to do so like below
Title:Software AND Title:Engineer

This will yield  same output as expected and may be it is more perform ant then above but to do so you have split input string and create query like above. 
Choice is yours!!!!!! Happy coding!!!!




Comments

Post a Comment