Search code examples
solr

How to order Solr results by relevance to the input?


I am new to Solr and I am trying to order the results I get by their relevance to the input keyword. For example, if I have a field which is the title of a document and I have two documents with the following titles A:"The book of Martin" and B:"The book of Angela", when I search for "book angela" I want B to appear first than A which is not happening. This is the code I have for this case:

  <fieldType name="gramText" class="solr.TextField">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.ASCIIFoldingFilterFactory" preserveOriginal="true"/>
    </analyzer>
  </fieldType>

The query I use is "titles:book angela".

Is there something I am doing wrong?


Solution

  • Note that the intent of your query is not same as how solr interprets it. Based on your requirement, you should try this -

    title: book OR title: angela