2011-04-05 57 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)