bluedaniel
bluedaniel

Reputation: 2109

Solr query behaviour

I have a Solr installation that contains recipes.

Each recipe has multiple ingredients and I'm currently building a recipe search that you can type 'includes/excludes' and then I have a homebrew weight system that comes in after this.

The query building is off however and so needs refining.

// Works perfect - 109 results
ingredients:chicken OR tomatoes OR bacon

// Down to 7 results - Definitely wrong
ingredients:chicken OR tomatoes OR bacon AND -ingredients:garlic 

I've tried building this query any which way but can't figure out an acceptable 'fuzzy filter'

Upvotes: 1

Views: 568

Answers (2)

nikhil500
nikhil500

Reputation: 3450

Try ingredients:chicken OR tomatoes OR bacon AND (-ingredients:garlic)

I am assuming that you are you are using Solr 3.1 with edismax.

I have found that enclosing negative queries in parenthesis works. I have not had the time to look into this in more detail and figure out if this is the expected behaviour or is it a bug. If you investigate this in more detail and confirm that this is a bug, then please open a Jira issue here.

Note that the query I suggested above will search for tomatoes / bacon in the default field(s) as per your config. If you want to search for them in ingredients only, then use ingredients:(chicken OR tomatoes OR bacon) AND (-ingredients:garlic)

Upvotes: 0

morja
morja

Reputation: 8560

I would do:

ingredients:((chicken OR tomatoes OR bacon) AND NOT garlic)

This works for me.

You can add all excludes like this:

ingredients:((chicken OR tomatoes OR bacon) AND NOT (garlic OR peanuts OR spinach))

Upvotes: 1

Related Questions