SuUbha
SuUbha

Reputation: 167

SOLR sort by relevancy

I need to sort a solr result by relevancy. I used the following code for sort:

fq={!tag=resourcetag}(post_type:resource AND (siec_database_item:no OR siec_database_item:"") )&showposts=10&solrsearch=1&paged=0&sortby=score desc

But it didn't get any result. I searched the web but received only theory about relevancy sort. I need some practical solution.

Upvotes: 5

Views: 8108

Answers (2)

Piyush_Rana
Piyush_Rana

Reputation: 305

I was also facing the exact same problem, I did lot of R&D and came up with my own solution of relevancy search.

Please have a look at the solution:

https://blog.knoldus.com/2016/12/13/solr-relevance-search-using-solrj-in-scala/

and the question I asked on Stack Overflow:

relevance search in Solr

Upvotes: 2

Vinod
Vinod

Reputation: 1953

FYI showing one example I am just using id and score field for fl

http://localhost:8983/solr/test/select?fl=id,score&indent=on&q=ipod&wt=json

for query q=ipod we have 6 documents returned from solr, here is how it looks. You can notice docs are sorted on relevancy score value.(desc order, default)

response":{"numFound":6,"start":0,"maxScore":4.391201,"docs":[
      {
        "id":"IW-02",
        "score":4.391201},
      {
        "id":"F8V7067-APL-KIT",
        "score":4.1061177},
      {
        "id":"09",
        "score":3.690675},
      {
        "id":"01",
        "score":3.597126},
      {
        "id":"3007WFRD",
        "score":3.1348155},
      {
        "id":"MA147LL/A",
        "score":1.9562671}]

if you want results in ascending order, just add sort param to url &sort=score asc and results will change. you can do the same sorting with other fields as well. (ex: sort=price asc).

Upvotes: 4

Related Questions