2011-04-05 59 views
1

我有一个包含食谱的Solr安装。Solr查询行为

每个食谱有多个成分,我目前正在建立一个食谱搜索,你可以键入'includes/excludes',然后我有一个自制的重量系统,在此之后进来。

但是查询建筑已关闭,因此需要改进。

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

我试图建立这个查询的任何哪种方式,但无法找出可以接受的“模糊过滤器”

+1

这可能帮助:http://stackoverflow.com/questions/634765/using-or-and-not-in-solr-query – 2011-04-05 21:47:18

+0

并非如此很多,我不知道如何将它应用到我的查询 – bluedaniel 2011-04-05 22:57:31

+0

它似乎是同一个问题......你有没有尝试过所有的建议?你有没有读过solr-user线程? – 2011-04-06 00:31:41

回答

1

我会做:

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

这对我的作品。

您可以添加排除这样的:

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

这对我来说非常合适。谢谢。您可以通过http://www.guardian.co.uk/lifeandstyle/recipe-search/search查看搜索结果 – bluedaniel 2011-04-06 10:27:03

0

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

我假设你使用的是3.1的Solr与edismax

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

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