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.
Relevance is the degree to which a query response satisfies a user who is searching for information. The relevance of a query response depends on the context in which the query was performed. A single search application may be used in different contexts by users with different needs and expectations.
The ranking function takes in information from a query and from each matching document. And for each document, the ranking function computes a score representing how well the document matches the query. The ranking function can be complicated; chapters 5–7 teach you how to modify the ranking function.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With