Skip to content
Newer
Older
100644 67 lines (51 sloc) 1.72 KB
937db3f @ralph Added support for filtered queries [#134]
ralph authored
1 require 'test_helper'
2
3 module Tire
4
5 class FilteredQueriesIntegrationTest < Test::Unit::TestCase
6 include Test::Integration
7
8 context "Filtered queries" do
9
d500624 @ralph [FIX] FilteredQuery: chain multiple filters with `and` by default
ralph authored
10 should "restrict the results with a filter" do
937db3f @ralph Added support for filtered queries [#134]
ralph authored
11 # 2.json > Begins with "T" and is tagged "ruby"
12
13 s = Tire.search('articles-test') do
14 query do
15 filtered do
16 query { string 'title:T*' }
17 filter :terms, :tags => ['ruby']
18 end
19 end
20 end
21
22 assert_equal 1, s.results.count
23 assert_equal 'Two', s.results.first.title
24 end
25
d500624 @ralph [FIX] FilteredQuery: chain multiple filters with `and` by default
ralph authored
26 should "restrict the results with multiple filters, chained with AND by default" do
d2feb84 @karmi Cleaned up the test suite for the "filtered queries" support (karmi/r…
authored
27 # 2.json > Is tagged "ruby" and has 250 words
28
29 s = Tire.search('articles-test') do
30 query do
31 filtered do
32 query { all }
d500624 @ralph [FIX] FilteredQuery: chain multiple filters with `and` by default
ralph authored
33 filter :terms, :tags => ['ruby', 'python']
34 filter :range, :words => { :from => '250', :to => '250' }
d2feb84 @karmi Cleaned up the test suite for the "filtered queries" support (karmi/r…
authored
35 end
36 end
37 end
38
39 assert_equal 1, s.results.count
40 assert_equal 'Two', s.results.first.title
41 end
42
d500624 @ralph [FIX] FilteredQuery: chain multiple filters with `and` by default
ralph authored
43 should "restrict the results with multiple OR filters" do
44 # 1.json > Is tagged "ruby"
45 # 1.json > Is tagged "ruby" and has 250 words
46 # 4.json > Has 250 words
47
48 s = Tire.search('articles-test') do
49 query do
50 filtered do
51 query { all }
52 filter :or, { :terms => { :tags => ['ruby', 'python'] } },
53 { :range => { :words => { :from => '250', :to => '250' } } }
54 end
55 end
56 end
57
58 assert_equal 3, s.results.count
59 assert_equal %w(Four One Two), s.results.map(&:title)
60 end
61
937db3f @ralph Added support for filtered queries [#134]
ralph authored
62 end
63
64 end
65
66 end
Something went wrong with that request. Please try again.