0

How to sort results which are retrieving from Solr so that most relevant comes up in the order means if document matches 100% than it comes first then other documents whose percentage of matching is less comes down.

<field name="key_word" type="text_ar" indexed="true" stored="true"/>
    <fieldType name="text_ar" class="solr.TextField" positionIncrementGap="100">    <analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/> 
    <filter class="solr.LowerCaseFilterFactory"/> 
    <filter class="solr.StopFilterFactory" words="lang/stopwords_ar.txt" ignoreCase="true"/> 
    <filter class="solr.ArabicNormalizationFilterFactory"/> 
    <filter class="solr.ArabicStemFilterFactory"/> 
</analyzer> 

Query is http://localhost:8983/solr/QNB_ARABIC/select?indent=on&q=key_word:%D8%B3%D8%A7%D9%85%D9%8A&wt=json

"key_word":"هو لسان سامية الأكثر", "key_word":"هو لسان سامية الأكثر", "key_word":"هو لسان سامية الأكثر", "key_word":"هو لسان سامية الأكثر", "key_word":"هو لسان سامية الأكثر", "key_word":"هو لسان سامية الأكثر", "key_word":"إمكانات الأسرة سامي","key_word":"هو لسان سامية الأكثر", "key_word":"هو لسان سامية الأكثر","key_word":"هو لسان سامية الأكثر",

Look at exact word comes at 7th position. I want exact match document at top of list means it should comes first.

  • The exact match should have a higher score. Add &fl=score and &sort=score desc. It will sort the best matches descending by their score. – user3606329 Apr 02 '17 at 13:58
  • would you give me complete query after adding these parameters – Waleed Raza Apr 02 '17 at 14:15
  • /select?q=Your query string&sort=score+desc&fl=score%2C*&wt=json&indent=true - It will print you the relevance (score) and you're sorting them by the highest to the lowest with descending. If you're getting odd results you should probably add a configuration in your schema for those fields (for example ngram filter). Let me know if you have success. – user3606329 Apr 02 '17 at 15:43
  • http://localhost:8983/solr/QNB_ARABIC/select?indent=on&q=key_word:%D8%B3%D8%A7%D9%85%D9%8A&sort=score+desc&fl=score%2C*&wt=json&indent=true i execute this query and reply is same – Waleed Raza Apr 02 '17 at 16:00
  • maxScore":0.66865796 In every document score is same – Waleed Raza Apr 02 '17 at 16:03
  • I just checked your indexed documents and your query. They all contain the word you're searching for. Solr gives them a different relevance. You have to apply filters to archive what you want and reindex your documents. Read here to understand how it's done: http://stackoverflow.com/questions/29103155/solr-exact-match-boost-over-text-containing-the-exact-match – user3606329 Apr 02 '17 at 16:42

0 Answers0