타이어는 JSON API를 반영하기 위해 설계된 DSL을 사용하여 elasticsearch 쿼리를 구축 할 수 있도록 여러 루비 블록에서 타이어 쿼리를 구성 :예를 들어,
search = Tire::Search::Search.new
search.query do
boolean do
should { match :title, "Red" }
should { match :synopsis, "Red" }
should { match :brand_title, "Red" }
end
boolean do
must { term :excluded, false }
end
end
나는이 점을 분리 해하고 싶습니다 내 자신의 DSL 종류의 레일 범위와 같이 구축 할 수 쿼리 그룹을 정의합니다 :
class Proxy
def initialize
@queries = []
end
def results
search = Tire::Search::Search.new
queries = @queries
search.query do
# …? What should go here to search the combined set of conditions?
end
end
def term t
query do
boolean do
should { match :title, t }
should { match :synopsis, t }
should { match :brand_title, t }
end
end
end
def included bool
query do
boolean do
must { term :excluded, !bool }
end
end
end
private
def query &block
@queries << block
end
end
p = Proxy.new
p.term "Red"
p.included true
p.results
문제는, 타이어 두 개 이상의 search.query
블록을 허용하지 않습니다 - 이후 query
의 이전을 대체. instance_eval과 같은 것을 사용하여 쿼리 블록의 올바른 컨텍스트에서 여러 블록을 실행할 수 있습니까?
용어가 다음과 같은 필터와 함께 작동하는지 알고 싶습니다. 나는 그것을 시도했다. 마지막 proc만이 instance_eval이 될 것으로 보인다. ES를 보낸다. 고마워. – brupm