This repository has been archived by the owner on Jun 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 533
/
filtered_queries_test.rb
66 lines (51 loc) · 1.72 KB
/
filtered_queries_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'test_helper'
module Tire
class FilteredQueriesIntegrationTest < Test::Unit::TestCase
include Test::Integration
context "Filtered queries" do
should "restrict the results with a filter" do
# 2.json > Begins with "T" and is tagged "ruby"
s = Tire.search('articles-test') do
query do
filtered do
query { string 'title:T*' }
filter :terms, :tags => ['ruby']
end
end
end
assert_equal 1, s.results.count
assert_equal 'Two', s.results.first.title
end
should "restrict the results with multiple filters, chained with AND by default" do
# 2.json > Is tagged "ruby" and has 250 words
s = Tire.search('articles-test') do
query do
filtered do
query { all }
filter :terms, :tags => ['ruby', 'python']
filter :range, :words => { :from => '250', :to => '250' }
end
end
end
assert_equal 1, s.results.count
assert_equal 'Two', s.results.first.title
end
should "restrict the results with multiple OR filters" do
# 1.json > Is tagged "ruby"
# 1.json > Is tagged "ruby" and has 250 words
# 4.json > Has 250 words
s = Tire.search('articles-test') do
query do
filtered do
query { all }
filter :or, { :terms => { :tags => ['ruby', 'python'] } },
{ :range => { :words => { :from => '250', :to => '250' } } }
end
end
end
assert_equal 3, s.results.count
assert_equal %w(Four One Two), s.results.map(&:title)
end
end
end
end