我有了一個文本/關鍵字框和一堆濾鏡此搜索功能;我把它實現,現在結構如下:過濾器與布爾塊(輪胎/ ElasticSearch)
query do
boolean do
must { string params[:text], default_operator: "AND" } unless params[:text].blank?
must { } unless
must { } unless
should { } unless
# some more must/should/must_not queries
end
end
# Some sorting
據我已閱讀,這將是利用輪胎提供的實際filter
(在速度和cacheing方面)來實現它一個更好的辦法。
我要問什麼是實現這個的正確方法嗎?我找不到一種將類似boolean
塊傳遞給filter
的方法...那很好。也許我做錯了?
我想到做這樣的事情
# This would be the main query, by text/keyword
query { string params[:text], default_operator: "AND" } unless params[:text].blank?
filter do
boolean do
# My regular filters that I implemented with queries
must { } unless
must { } unless
should { } unless
end
end
# Some sorting
這給了我下面的錯誤(在filter
塊線): ArgumentError - wrong number of arguments (0 for 1):
而且,我知道,這個行爲可以使用ElasticSearch實現JSON查詢,如下所示:http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter/。所以我認爲輪胎在這個功能上提供了類似的功能。
謝謝你的幫助。
編輯
什麼我想現在要做的是使用過濾的搜索,以下列方式:
query do
filtered do
query { string params[:text], default_operator: "AND" } unless params[:text].blank?
# And here I would like to add the filter block... but for now I am using the filter :and
filter :and, { :terms => { } } unless params[:something1].blank?,
{ :terms => { } } unless params[:something2].blank?,
{ :range => { } } unless params[:something3].blank?,
# more filters that need the AND behavior
filter :or, { :terms => { } } unless params[:something4].blank?
# more filters that need the OR behavior
end
end
我想這種做法,因爲我還讀了一個filter :and
更快比一個boolean
之一。它是否正確?
現在,將這些過濾器仍然可以緩存?另外,在這種情況下這是否正確?
謝謝!
編輯
從我在張貼在評論的問題讀過,我想我可以做這樣的事情:
filter :bool => [
{ :must => { :terms => { } } } unless ... ,
{ :must => { :terms => { } } } unless ... ,
{ :should => { :terms => { } } } unless ... ,
# and the other filters
]
這是正確的?
謝謝!
我剛剛發現以下問題https://github.com/karmi/tire/issues/2。看起來像karmi沒有真正實現'filter'的這個特性? – vburca
嘿!你可以發表你的評論作爲答案並接受它嗎?它可以幫助其他有相同問題的人。 – ramseykhalaf
好吧,我還在等,希望卡爾米可能會來清除它:) – vburca