Reputation: 2455
I have the following task: Query SOLR and return a weighted list based on multiple conditions.
Example: I have documents with the following fields, they mostly represent movies:
name, genre, actors, director
I want to return 20 documents sorted on the following condition
Then take these 4 movies:
Id: 1
Name: Harry Potter and the Philosopher's Stone
Genre: Adventure
Director: Chris Columbus
Actors: Daniel Radcliffe, Rupert Grint, Emma Watson
Id: 2
Name: My Week with Marilyn
Genre: Drama
Director: Simon Curtis
Actors: Michelle Williams, Eddie Redmayne, Emma Watson
Id: 3
Name: Percy Jackson & the Olympians: The Lightning Thief
Genre: Adventure
Directory: Chris Columbus
Actors: Logan Lerman, Brandon T. Jackson, Alexandra Daddario
Id: 4
Name: Harry Potter and the Chamber of Secrets
Genre: Adventure
Director: Chris Columbus
Actors: Daniel Radcliffe, Rupert Grint, Emma Watson
I want to query the SOLR as such: Return me a list of relevant movies based on movie id==4
The returned result should be:
Is there anyway to do this directly within SOLR?
As always thanks in advance :)
Upvotes: 1
Views: 329
Reputation: 540
You can return weighted results with the DisMax Query Parser, it's called boosting. You can give varying weights to the columns in your document by using a Query Filter like in the following example. You'll have to modify it to come up with your own formula, but you should be able to get close. Start with tweaking the numbers in the boost, but you might end up doing some more advanced Function Queries
From your example where you want to find documents that match #4
?q=Genre:'Adventure' Director:'Chris Columnbus' Actors:('Daniel Radcliffe' 'Rupert Grint' 'Emma Watson')&qf=Director^2.0+Actor^1.5+Genre^1.0&fl=*,score
//Get everything that matches #4 ?q=Genre:'Adventure' Director:'Chris Columnbus' Actors:('Daniel Radcliffe' 'Rupert Grint' 'Emma Watson') //use dismax &defType=dismax //boost some fields with a "query filter" //this will make a match on director worth the most //each actor will be worth a little bit less, but 2+ actors will be more //all matches will be added together to create a score similar to your example &qf=Director^2.0+Actor^1.5+Genre^1.0 //Make sure you can see the score for debugging &fl=*,score
Upvotes: 2
Reputation: 2549
I don't think there is a way to do this with Solr out of the box. You could check out http://solr-ra.tgels.com/ to see if this might be something better suited to your needs or maybe show you how to make your own ranking algorithm.
Upvotes: 0