Tjirp
Tjirp

Reputation: 2455

SOLR Combined and weigthed results

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

  1. The document shares 1 actor and is from the same director (5 points)
  2. The document shares 2 or more actors (3 points)
  3. The document shares the director (3 points)
  4. The document is of the same genre and shares an actor (2 points)
  5. The document is of the same genre (1 point)

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:

  1. Id: 1, points: 14 (matches all 5 conditions)
  2. Id: 3, points: 4 (matches condition 3 and 5)
  3. Id: 2, points: 0 (matches 0 conditions)

Is there anyway to do this directly within SOLR?

As always thanks in advance :)

Upvotes: 1

Views: 329

Answers (2)

Evan
Evan

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

Okke Klein
Okke Klein

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

Related Questions