Is it possible to have a Solr Query that brings me "all matches" or "some matches" in the same result?

StackOverflow https://stackoverflow.com/questions/21366319

  •  03-10-2022
  •  | 
  •  

Question

For example. I have these rows stored in my Solr.

{city: "Boston", country: "USA"}, 
{city: "Miami", country: "USA"}, 
{city: "Orlando", country: "USA"}

I'll search by "Boston USA". In that case I'd like to return a single result because my search matches all words. That's "AND" behavior or like "mm" param with 100% value.

But if I search by "Texas USA", I'd like to return three results because it can't match all words, but it found at least one word. Now, I think that's "OR" behavior or like "mm" param with 0 value.

In short, I'd like to match all words. If haven't any results, it should try to match at least one word. Is it possible to have two different behaviors in the unique query?

ps: I'm using eDismax parser.

Was it helpful?

Solution

one way to do this is to write your own SearchComponent and implement that logic there. First run a edismax request with mm=100%, if you get results, return them, if not then run it with mm=0% etc (you can even do it in more steps, 50%...).

Or you can also run with mm=0% always but look at the score/matches and keep only the best results on the client side. You could use highlighting to see which words were matched.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top