Proximity search using eDismax

1.8k views Asked by At

I have created a search engine using solr. I want to create a query such that if the user searches for the word "college", the score of the document which has the word "famous" in close proximity (within 2 words ie "famous college" or "college is famous") should be higher. If the word famous is not present in close proximity then it should calculate score based on the word "college" only.

What I want is something like this "famous college"~2^10 OR "college famous"~1^10 OR "college"

How to achieve this in eDismax?

1

There are 1 answers

4
Kevin On

What you are looking for is called a phrase search with a phrase slop of 2. For example setting defaults in solrconfig.xml might look something like:

  <requestHandler name="/phraseSearch" class="solr.SearchHandler">
    <lst name="defaults">
        <str name="defType">edismax</str>
        <str name="wt">xml</str>
        <str name="fl">Title</str>
        <str name="qf">Name^2 Description</str> <!-- The fields (and their weightings) to search in.-->
        <str name="rows">500</str>
        <str name="pf">Name^4 Description^2</str> <!-- Phrase field (and their weightings). Fields to search for closely located matches -->
        <str name="ps">2</str> <!-- Phrase slop. How many tokens apart must words be to be able to qualify as a phrase-->
     </lst>
  </requestHandler>

Controlling the phrase search in the query might look like:

http://mySolrHost:8983/solr/myEDismaxQuery?q=Title:famous+college&defType=edismax&pf=Title&ps=2

More information on phrase queries using eDismax can be found in the Solr Reference page for eDismax.