Solr查询行为

时间:2011-04-05 21:03:45

标签: syntax solr lucene edismax

我有一个包含食谱的Solr安装。

每个食谱都有多种成分,我正在建立一个食谱搜索,你可以输入'包含/排除'然后我有一个自制重量系统,在此之后出现。

然而,查询构建已关闭,因此需要进行优化。

// 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 

我尝试以任何方式构建此查询,但无法找出可接受的“模糊过滤器”

2 个答案:

答案 0 :(得分:1)

我愿意:

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

这适合我。

您可以添加以下所有排除:

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

答案 1 :(得分:0)

尝试ingredients:chicken OR tomatoes OR bacon AND (-ingredients:garlic)

我假设您使用的是Solr 3.1 edismax

我发现在括号中包含否定查询有效。我没有时间更详细地研究这个,并弄清楚这是预期的行为还是一个bug。如果您更详细地调查此问题并确认这是一个错误,请打开Jira问题here

请注意,我上面建议的查询将根据您的配置在默认字段中搜索tomato / bacon。如果您只想在ingredients中搜索它们,请使用ingredients:(chicken OR tomatoes OR bacon) AND (-ingredients:garlic)