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
- I am Software Engineer
- Microsoft is a Software Company
- Software is build by Engineer
- I am an Engineer
- SOLR is best Search Engine
- I am Software Engineer.
- 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"
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!!!!
Nice article :)
ReplyDelete