Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 76 lines (54 sloc) 2.048 kb
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 67 68 69 70 71 72 73 74 75
require 'test_helper'

module Tire

  class FiltersIntegrationTest < Test::Unit::TestCase
    include Test::Integration

    context "Filters" do

      should "filter the results" do
        # 2.json > Begins with "T" and is tagged "ruby"

        s = Tire.search('articles-test') do
          query { string 'title:T*' }
          filter :terms, :tags => ['ruby']
        end

        assert_equal 1, s.results.count
        assert_equal 'Two', s.results.first.title
      end

      should "filter the results with multiple terms" do
        # 2.json > Is tagged *both* "ruby" and "python"

        s = Tire.search('articles-test') do
          query { all }
          filter :terms, :tags => ['ruby', 'python'], :execution => 'and'
        end

        assert_equal 1, s.results.count
        assert_equal 'Two', s.results.first.title
      end

      should "filter the results with multiple 'or' filters" do
        # 4.json > Begins with "F" and is tagged "erlang"

        s = Tire.search('articles-test') do
          query { string 'title:F*' }
          filter :or, {:terms => {:tags => ['ruby']}},
                      {:terms => {:tags => ['erlang']}}
        end

        assert_equal 1, s.results.count
        assert_equal 'Four', s.results.first.title
      end

      should "filter the results with multiple 'and' filters" do
        # 5.json > Is tagged ["java", "javascript"] and is published on 2011-01-04

        s = Tire.search('articles-test') do
          filter :terms, :tags => ["java"]
          filter :term, :published_on => "2011-01-04"
        end

        assert_equal 1, s.results.count
        assert_equal 'Five', s.results.first.title
      end

      should "not influence facets" do
        s = Tire.search('articles-test') do
          query { string 'title:T*' }
          filter :terms, :tags => ['ruby']

          facet('tags') { terms :tags }
        end

        assert_equal 1, s.results.count
        assert_equal 3, s.results.facets['tags']['terms'].size
      end

    end

  end

end
Something went wrong with that request. Please try again.