You could use a boost query. The boost query would be a constant score OR query on a multi-value field containing genres:
(genre:1)^=1 OR (genre:2)^=1 The genre field contains the integer value genres. ^=1 assigns a score of one to the match. The scores will get added together for each match. Joel Bernstein http://joelsolr.blogspot.com/ On Wed, Apr 13, 2022 at 10:12 AM Marko Avlijas <[email protected]> wrote: > Hello everyone, > > I am working on a music app. We have songs and songs can have > multiple genres. > We have a song - genre join table. > We are indexing genre ids for each song as integers. > > I would like to add feature for users to search by genre. > > Given user searches for rock, pop, blues > I'd like to order search results so that > > 1. Give me all songs where genres contain all 3: rock, pop AND blues > 2. Give me all songs that are rock and pop, rock and blues or blues and pop > 3. Give me all songs where genre is either rock, pop or blues > > In other words, first songs that match all the genres, then songs that > match 2/3 genres, then songs that match only 1 genre. > > Is this even possible? How to do it? > > Thank you, > > Marko Avlijaš >
