1

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'

javanna
  • 59,145
  • 14
  • 144
  • 125
bluedaniel
  • 2,079
  • 5
  • 31
  • 49

2 Answers2

1

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))
morja
  • 8,297
  • 2
  • 39
  • 59
  • 1
    This worked perfectly for me. Thank you. You can see the search working over at http://www.guardian.co.uk/lifeandstyle/recipe-search/search – bluedaniel Apr 06 '11 at 10:27
0

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)

nikhil500
  • 3,458
  • 19
  • 23