searchkick 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/README.md +4 -4
- data/lib/searchkick/query.rb +4 -4
- data/lib/searchkick/version.rb +1 -1
- data/test/aggs_test.rb +3 -3
- data/test/dangerous_reindex_test.rb +27 -0
- data/test/index_test.rb +6 -28
- data/test/misspellings_test.rb +36 -0
- data/test/order_test.rb +38 -0
- data/test/pagination_test.rb +53 -0
- data/test/sql_test.rb +4 -259
- data/test/synonyms_test.rb +5 -4
- data/test/where_test.rb +138 -0
- metadata +13 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 12242ee03581e51bcb73eb5301309a0ba85b0c8b
         | 
| 4 | 
            +
              data.tar.gz: 94f6e444569e05c8d1a56054da8f079cdf43bf50
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 56a50ceacda73f6aee353c22b84191d721afe481808ed69beb7d79601d4e6cd57deed76ac8f70f4ccc37d753ee4d16758b5b269359cbd79ec363180290c4ee99
         | 
| 7 | 
            +
              data.tar.gz: 71953014b0b9233519f0088da6d3246a2f45fa3babff843dcce2143b0b9f24b8ddeb0523418b5b764485785921c11a2ad6f723b028cd84d420162bba15bf4438
         | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -280,7 +280,7 @@ Call `Product.reindex` after changing synonyms. | |
| 280 280 |  | 
| 281 281 | 
             
            ### WordNet
         | 
| 282 282 |  | 
| 283 | 
            -
            Prepopulate English synonyms with the [WordNet database]( | 
| 283 | 
            +
            Prepopulate English synonyms with the [WordNet database](https://en.wikipedia.org/wiki/WordNet).
         | 
| 284 284 |  | 
| 285 285 | 
             
            Download [WordNet 3.0](http://wordnetcode.princeton.edu/3.0/WNprolog-3.0.tar.gz) to each Elasticsearch server and move `wn_s.pl` to the `/var/lib` directory.
         | 
| 286 286 |  | 
| @@ -301,7 +301,7 @@ end | |
| 301 301 |  | 
| 302 302 | 
             
            ### Misspellings
         | 
| 303 303 |  | 
| 304 | 
            -
            By default, Searchkick handles misspelled queries by returning results with an [edit distance]( | 
| 304 | 
            +
            By default, Searchkick handles misspelled queries by returning results with an [edit distance](https://en.wikipedia.org/wiki/Levenshtein_distance) of one.
         | 
| 305 305 |  | 
| 306 306 | 
             
            You can change this with:
         | 
| 307 307 |  | 
| @@ -893,7 +893,7 @@ Searchkick uses `ENV["ELASTICSEARCH_URL"]` for the Elasticsearch server.  This d | |
| 893 893 |  | 
| 894 894 | 
             
            ### Heroku
         | 
| 895 895 |  | 
| 896 | 
            -
            Choose an add-on: [SearchBox](https:// | 
| 896 | 
            +
            Choose an add-on: [SearchBox](https://elements.heroku.com/addons/searchbox), [Bonsai](https://elements.heroku.com/addons/bonsai), or [Found](https://addons.heroku.com/foundelasticsearch).
         | 
| 897 897 |  | 
| 898 898 | 
             
            ```sh
         | 
| 899 899 | 
             
            # SearchBox
         | 
| @@ -1318,7 +1318,7 @@ For convenience, this is set by default in the test environment. | |
| 1318 1318 |  | 
| 1319 1319 | 
             
            ## Thanks
         | 
| 1320 1320 |  | 
| 1321 | 
            -
            Thanks to Karel Minarik for [Elasticsearch Ruby](https://github.com/elasticsearch/elasticsearch-ruby) and [Tire](https://github.com/karmi/ | 
| 1321 | 
            +
            Thanks to Karel Minarik for [Elasticsearch Ruby](https://github.com/elasticsearch/elasticsearch-ruby) and [Tire](https://github.com/karmi/retire), Jaroslav Kalistsuk for [zero downtime reindexing](https://gist.github.com/jarosan/3124884), and Alex Leschenko for [Elasticsearch autocomplete](https://github.com/leschenko/elasticsearch_autocomplete).
         | 
| 1322 1322 |  | 
| 1323 1323 | 
             
            ## Roadmap
         | 
| 1324 1324 |  | 
    
        data/lib/searchkick/query.rb
    CHANGED
    
    | @@ -49,7 +49,7 @@ module Searchkick | |
| 49 49 |  | 
| 50 50 | 
             
                  # pagination
         | 
| 51 51 | 
             
                  page = [options[:page].to_i, 1].max
         | 
| 52 | 
            -
                  per_page = (options[:limit] || options[:per_page] ||  | 
| 52 | 
            +
                  per_page = (options[:limit] || options[:per_page] || 1_000).to_i
         | 
| 53 53 | 
             
                  padding = [options[:padding].to_i, 0].max
         | 
| 54 54 | 
             
                  offset = options[:offset] || (page - 1) * per_page + padding
         | 
| 55 55 |  | 
| @@ -300,7 +300,7 @@ module Searchkick | |
| 300 300 | 
             
                      facets.each do |field, facet_options|
         | 
| 301 301 | 
             
                        # ask for extra facets due to
         | 
| 302 302 | 
             
                        # https://github.com/elasticsearch/elasticsearch/issues/1305
         | 
| 303 | 
            -
                        size = facet_options[:limit] ? facet_options[:limit] + 150 :  | 
| 303 | 
            +
                        size = facet_options[:limit] ? facet_options[:limit] + 150 : 1_000
         | 
| 304 304 |  | 
| 305 305 | 
             
                        if facet_options[:ranges]
         | 
| 306 306 | 
             
                          payload[:facets][field] = {
         | 
| @@ -347,10 +347,10 @@ module Searchkick | |
| 347 347 | 
             
                      aggs = options[:aggs]
         | 
| 348 348 | 
             
                      payload[:aggs] = {}
         | 
| 349 349 |  | 
| 350 | 
            -
                      aggs = aggs.map { |f| [f, {}] } | 
| 350 | 
            +
                      aggs = Hash[aggs.map { |f| [f, {}] }] if aggs.is_a?(Array) # convert to more advanced syntax
         | 
| 351 351 |  | 
| 352 352 | 
             
                      aggs.each do |field, agg_options|
         | 
| 353 | 
            -
                        size = agg_options[:limit] ? agg_options[:limit] :  | 
| 353 | 
            +
                        size = agg_options[:limit] ? agg_options[:limit] : 1_000
         | 
| 354 354 | 
             
                        shared_agg_options = agg_options.slice(:order)
         | 
| 355 355 |  | 
| 356 356 | 
             
                        if agg_options[:ranges]
         | 
    
        data/lib/searchkick/version.rb
    CHANGED
    
    
    
        data/test/aggs_test.rb
    CHANGED
    
    | @@ -95,7 +95,7 @@ class AggsTest < Minitest::Test | |
| 95 95 | 
             
              protected
         | 
| 96 96 |  | 
| 97 97 | 
             
              def buckets_as_hash(agg)
         | 
| 98 | 
            -
                agg["buckets"].map { |v| [v["key"], v["doc_count"]] } | 
| 98 | 
            +
                Hash[agg["buckets"].map { |v| [v["key"], v["doc_count"]] }]
         | 
| 99 99 | 
             
              end
         | 
| 100 100 |  | 
| 101 101 | 
             
              def store_agg(options, agg_key = "store_id")
         | 
| @@ -104,8 +104,8 @@ class AggsTest < Minitest::Test | |
| 104 104 | 
             
              end
         | 
| 105 105 |  | 
| 106 106 | 
             
              def store_multiple_aggs(options)
         | 
| 107 | 
            -
                Product.search("Product", options).aggs.map do |field, filtered_agg|
         | 
| 107 | 
            +
                Hash[Product.search("Product", options).aggs.map do |field, filtered_agg|
         | 
| 108 108 | 
             
                  [field, buckets_as_hash(filtered_agg)]
         | 
| 109 | 
            -
                end | 
| 109 | 
            +
                end]
         | 
| 110 110 | 
             
              end
         | 
| 111 111 | 
             
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require_relative "test_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class DangerousReindexTest < Minitest::Test
         | 
| 4 | 
            +
              def setup
         | 
| 5 | 
            +
                skip if mongoid2? || nobrainer? || activerecord_below41?
         | 
| 6 | 
            +
                super
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              def test_dangerous_reindex
         | 
| 10 | 
            +
                assert_raises(Searchkick::DangerousOperation) { Product.where(id: [1, 2, 3]).reindex }
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def test_dangerous_index_associations
         | 
| 14 | 
            +
                Store.create!(name: "Test")
         | 
| 15 | 
            +
                assert_raises(Searchkick::DangerousOperation) { Store.first.products.reindex }
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def test_dangerous_reindex_accepted
         | 
| 19 | 
            +
                store_names ["Product A", "Product B"]
         | 
| 20 | 
            +
                Product.where(name: "Product A").reindex(accept_danger: true)
         | 
| 21 | 
            +
                assert_search "product", ["Product A"]
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              def test_dangerous_reindex_inheritance
         | 
| 25 | 
            +
                assert_raises(Searchkick::DangerousOperation) { Dog.where(id: [1, 2, 3]).reindex }
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
    
        data/test/index_test.rb
    CHANGED
    
    | @@ -102,34 +102,12 @@ class IndexTest < Minitest::Test | |
| 102 102 | 
             
                assert_raises(Searchkick::InvalidQueryError) { Product.search(query: {boom: true}) }
         | 
| 103 103 | 
             
              end
         | 
| 104 104 |  | 
| 105 | 
            -
               | 
| 106 | 
            -
                 | 
| 107 | 
            -
             | 
| 108 | 
            -
             | 
| 109 | 
            -
             | 
| 110 | 
            -
                def test_dangerous_index_associations
         | 
| 111 | 
            -
                  Store.create!(name: "Test")
         | 
| 112 | 
            -
                  assert_raises(Searchkick::DangerousOperation) { Store.first.products.reindex }
         | 
| 113 | 
            -
                end
         | 
| 114 | 
            -
             | 
| 115 | 
            -
                def test_dangerous_reindex_accepted
         | 
| 116 | 
            -
                  store_names ["Product A", "Product B"]
         | 
| 117 | 
            -
                  Product.where(name: "Product A").reindex(accept_danger: true)
         | 
| 118 | 
            -
                  assert_search "product", ["Product A"]
         | 
| 119 | 
            -
                end
         | 
| 120 | 
            -
             | 
| 121 | 
            -
                def test_dangerous_reindex_inheritance
         | 
| 122 | 
            -
                  assert_raises(Searchkick::DangerousOperation) { Dog.where(id: [1, 2, 3]).reindex }
         | 
| 123 | 
            -
                end
         | 
| 124 | 
            -
              end
         | 
| 125 | 
            -
             | 
| 126 | 
            -
              if defined?(ActiveRecord)
         | 
| 127 | 
            -
                def test_transaction
         | 
| 128 | 
            -
                  Product.transaction do
         | 
| 129 | 
            -
                    store_names ["Product A"]
         | 
| 130 | 
            -
                    raise ActiveRecord::Rollback
         | 
| 131 | 
            -
                  end
         | 
| 132 | 
            -
                  assert_search "product", []
         | 
| 105 | 
            +
              def test_transaction
         | 
| 106 | 
            +
                skip unless defined?(ActiveRecord)
         | 
| 107 | 
            +
                Product.transaction do
         | 
| 108 | 
            +
                  store_names ["Product A"]
         | 
| 109 | 
            +
                  raise ActiveRecord::Rollback
         | 
| 133 110 | 
             
                end
         | 
| 111 | 
            +
                assert_search "product", []
         | 
| 134 112 | 
             
              end
         | 
| 135 113 | 
             
            end
         | 
| @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            require_relative "test_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class MisspellingsTest < Minitest::Test
         | 
| 4 | 
            +
              def test_misspellings
         | 
| 5 | 
            +
                store_names ["abc", "abd", "aee"]
         | 
| 6 | 
            +
                assert_search "abc", ["abc"], misspellings: false
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              def test_misspellings_distance
         | 
| 10 | 
            +
                store_names ["abbb", "aabb"]
         | 
| 11 | 
            +
                assert_search "aaaa", ["aabb"], misspellings: {distance: 2}
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def test_misspellings_prefix_length
         | 
| 15 | 
            +
                store_names ["ap", "api", "apt", "any", "nap", "ah", "ahi"]
         | 
| 16 | 
            +
                assert_search "ap", ["ap"], misspellings: {prefix_length: 2}
         | 
| 17 | 
            +
                assert_search "api", ["ap", "api", "apt"], misspellings: {prefix_length: 2}
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def test_misspellings_prefix_length_operator
         | 
| 21 | 
            +
                store_names ["ap", "api", "apt", "any", "nap", "ah", "aha"]
         | 
| 22 | 
            +
                assert_search "ap ah", ["ap", "ah"], operator: "or", misspellings: {prefix_length: 2}
         | 
| 23 | 
            +
                assert_search "api ahi", ["ap", "api", "apt", "ah", "aha"], operator: "or", misspellings: {prefix_length: 2}
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              def test_misspellings_fields_operator
         | 
| 27 | 
            +
                store [
         | 
| 28 | 
            +
                  {name: "red", color: "red"},
         | 
| 29 | 
            +
                  {name: "blue", color: "blue"},
         | 
| 30 | 
            +
                  {name: "cyan", color: "blue green"},
         | 
| 31 | 
            +
                  {name: "magenta", color: "red blue"},
         | 
| 32 | 
            +
                  {name: "green", color: "green"}
         | 
| 33 | 
            +
                ]
         | 
| 34 | 
            +
                assert_search "red blue", ["red", "blue", "cyan", "magenta"], operator: "or", fields: ["color"], misspellings: false
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
            end
         | 
    
        data/test/order_test.rb
    ADDED
    
    | @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            require_relative "test_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class OrderTest < Minitest::Test
         | 
| 4 | 
            +
              def test_order_hash
         | 
| 5 | 
            +
                store_names ["Product A", "Product B", "Product C", "Product D"]
         | 
| 6 | 
            +
                assert_order "product", ["Product D", "Product C", "Product B", "Product A"], order: {name: :desc}
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              def test_order_string
         | 
| 10 | 
            +
                store_names ["Product A", "Product B", "Product C", "Product D"]
         | 
| 11 | 
            +
                assert_order "product", ["Product A", "Product B", "Product C", "Product D"], order: "name"
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def test_order_id
         | 
| 15 | 
            +
                store_names ["Product A", "Product B"]
         | 
| 16 | 
            +
                product_a = Product.where(name: "Product A").first
         | 
| 17 | 
            +
                product_b = Product.where(name: "Product B").first
         | 
| 18 | 
            +
                assert_order "product", [product_a, product_b].sort_by(&:id).map(&:name), order: {id: :asc}
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              def test_order_multiple
         | 
| 22 | 
            +
                store [
         | 
| 23 | 
            +
                  {name: "Product A", color: "blue", store_id: 1},
         | 
| 24 | 
            +
                  {name: "Product B", color: "red", store_id: 3},
         | 
| 25 | 
            +
                  {name: "Product C", color: "red", store_id: 2}
         | 
| 26 | 
            +
                ]
         | 
| 27 | 
            +
                assert_order "product", ["Product A", "Product B", "Product C"], order: {color: :asc, store_id: :desc}
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              def test_order_ignore_unmapped
         | 
| 31 | 
            +
                assert_order "product", [], order: {not_mapped: {ignore_unmapped: true}}
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              def test_order_array
         | 
| 35 | 
            +
                store [{name: "San Francisco", latitude: 37.7833, longitude: -122.4167}]
         | 
| 36 | 
            +
                assert_order "francisco", ["San Francisco"], order: [{_geo_distance: {location: "0,0"}}]
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
| @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            require_relative "test_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class PaginationTest < Minitest::Test
         | 
| 4 | 
            +
              def test_limit
         | 
| 5 | 
            +
                store_names ["Product A", "Product B", "Product C", "Product D"]
         | 
| 6 | 
            +
                assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              def test_no_limit
         | 
| 10 | 
            +
                names = 20.times.map { |i| "Product #{i}" }
         | 
| 11 | 
            +
                store_names names
         | 
| 12 | 
            +
                assert_search "product", names
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              def test_offset
         | 
| 16 | 
            +
                store_names ["Product A", "Product B", "Product C", "Product D"]
         | 
| 17 | 
            +
                assert_order "product", ["Product C", "Product D"], order: {name: :asc}, offset: 2
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def test_pagination
         | 
| 21 | 
            +
                store_names ["Product A", "Product B", "Product C", "Product D", "Product E", "Product F"]
         | 
| 22 | 
            +
                products = Product.search("product", order: {name: :asc}, page: 2, per_page: 2, padding: 1)
         | 
| 23 | 
            +
                assert_equal ["Product D", "Product E"], products.map(&:name)
         | 
| 24 | 
            +
                assert_equal "product", products.entry_name
         | 
| 25 | 
            +
                assert_equal 2, products.current_page
         | 
| 26 | 
            +
                assert_equal 1, products.padding
         | 
| 27 | 
            +
                assert_equal 2, products.per_page
         | 
| 28 | 
            +
                assert_equal 2, products.size
         | 
| 29 | 
            +
                assert_equal 2, products.length
         | 
| 30 | 
            +
                assert_equal 3, products.total_pages
         | 
| 31 | 
            +
                assert_equal 6, products.total_count
         | 
| 32 | 
            +
                assert_equal 6, products.total_entries
         | 
| 33 | 
            +
                assert_equal 2, products.limit_value
         | 
| 34 | 
            +
                assert_equal 3, products.offset_value
         | 
| 35 | 
            +
                assert_equal 3, products.offset
         | 
| 36 | 
            +
                assert_equal 3, products.next_page
         | 
| 37 | 
            +
                assert_equal 1, products.previous_page
         | 
| 38 | 
            +
                assert_equal 1, products.prev_page
         | 
| 39 | 
            +
                assert !products.first_page?
         | 
| 40 | 
            +
                assert !products.last_page?
         | 
| 41 | 
            +
                assert !products.empty?
         | 
| 42 | 
            +
                assert !products.out_of_range?
         | 
| 43 | 
            +
                assert products.any?
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              def test_pagination_nil_page
         | 
| 47 | 
            +
                store_names ["Product A", "Product B", "Product C", "Product D", "Product E"]
         | 
| 48 | 
            +
                products = Product.search("product", order: {name: :asc}, page: nil, per_page: 2)
         | 
| 49 | 
            +
                assert_equal ["Product A", "Product B"], products.map(&:name)
         | 
| 50 | 
            +
                assert_equal 1, products.current_page
         | 
| 51 | 
            +
                assert products.first_page?
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
    
        data/test/sql_test.rb
    CHANGED
    
    | @@ -1,226 +1,6 @@ | |
| 1 1 | 
             
            require_relative "test_helper"
         | 
| 2 2 |  | 
| 3 3 | 
             
            class SqlTest < Minitest::Test
         | 
| 4 | 
            -
              def test_limit
         | 
| 5 | 
            -
                store_names ["Product A", "Product B", "Product C", "Product D"]
         | 
| 6 | 
            -
                assert_order "product", ["Product A", "Product B"], order: {name: :asc}, limit: 2
         | 
| 7 | 
            -
              end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
              def test_no_limit
         | 
| 10 | 
            -
                names = 20.times.map { |i| "Product #{i}" }
         | 
| 11 | 
            -
                store_names names
         | 
| 12 | 
            -
                assert_search "product", names
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              def test_offset
         | 
| 16 | 
            -
                store_names ["Product A", "Product B", "Product C", "Product D"]
         | 
| 17 | 
            -
                assert_order "product", ["Product C", "Product D"], order: {name: :asc}, offset: 2
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              def test_pagination
         | 
| 21 | 
            -
                store_names ["Product A", "Product B", "Product C", "Product D", "Product E", "Product F"]
         | 
| 22 | 
            -
                products = Product.search("product", order: {name: :asc}, page: 2, per_page: 2, padding: 1)
         | 
| 23 | 
            -
                assert_equal ["Product D", "Product E"], products.map(&:name)
         | 
| 24 | 
            -
                assert_equal "product", products.entry_name
         | 
| 25 | 
            -
                assert_equal 2, products.current_page
         | 
| 26 | 
            -
                assert_equal 1, products.padding
         | 
| 27 | 
            -
                assert_equal 2, products.per_page
         | 
| 28 | 
            -
                assert_equal 2, products.size
         | 
| 29 | 
            -
                assert_equal 2, products.length
         | 
| 30 | 
            -
                assert_equal 3, products.total_pages
         | 
| 31 | 
            -
                assert_equal 6, products.total_count
         | 
| 32 | 
            -
                assert_equal 6, products.total_entries
         | 
| 33 | 
            -
                assert_equal 2, products.limit_value
         | 
| 34 | 
            -
                assert_equal 3, products.offset_value
         | 
| 35 | 
            -
                assert_equal 3, products.offset
         | 
| 36 | 
            -
                assert_equal 3, products.next_page
         | 
| 37 | 
            -
                assert_equal 1, products.previous_page
         | 
| 38 | 
            -
                assert_equal 1, products.prev_page
         | 
| 39 | 
            -
                assert !products.first_page?
         | 
| 40 | 
            -
                assert !products.last_page?
         | 
| 41 | 
            -
                assert !products.empty?
         | 
| 42 | 
            -
                assert !products.out_of_range?
         | 
| 43 | 
            -
                assert products.any?
         | 
| 44 | 
            -
              end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
              def test_pagination_nil_page
         | 
| 47 | 
            -
                store_names ["Product A", "Product B", "Product C", "Product D", "Product E"]
         | 
| 48 | 
            -
                products = Product.search("product", order: {name: :asc}, page: nil, per_page: 2)
         | 
| 49 | 
            -
                assert_equal ["Product A", "Product B"], products.map(&:name)
         | 
| 50 | 
            -
                assert_equal 1, products.current_page
         | 
| 51 | 
            -
                assert products.first_page?
         | 
| 52 | 
            -
              end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
              def test_where
         | 
| 55 | 
            -
                now = Time.now
         | 
| 56 | 
            -
                store [
         | 
| 57 | 
            -
                  {name: "Product A", store_id: 1, in_stock: true, backordered: true, created_at: now, orders_count: 4, user_ids: [1, 2, 3]},
         | 
| 58 | 
            -
                  {name: "Product B", store_id: 2, in_stock: true, backordered: false, created_at: now - 1, orders_count: 3, user_ids: [1]},
         | 
| 59 | 
            -
                  {name: "Product C", store_id: 3, in_stock: false, backordered: true, created_at: now - 2, orders_count: 2, user_ids: [1, 3]},
         | 
| 60 | 
            -
                  {name: "Product D", store_id: 4, in_stock: false, backordered: false, created_at: now - 3, orders_count: 1}
         | 
| 61 | 
            -
                ]
         | 
| 62 | 
            -
                assert_search "product", ["Product A", "Product B"], where: {in_stock: true}
         | 
| 63 | 
            -
                # date
         | 
| 64 | 
            -
                assert_search "product", ["Product A"], where: {created_at: {gt: now - 1}}
         | 
| 65 | 
            -
                assert_search "product", ["Product A", "Product B"], where: {created_at: {gte: now - 1}}
         | 
| 66 | 
            -
                assert_search "product", ["Product D"], where: {created_at: {lt: now - 2}}
         | 
| 67 | 
            -
                assert_search "product", ["Product C", "Product D"], where: {created_at: {lte: now - 2}}
         | 
| 68 | 
            -
                # integer
         | 
| 69 | 
            -
                assert_search "product", ["Product A"], where: {store_id: {lt: 2}}
         | 
| 70 | 
            -
                assert_search "product", ["Product A", "Product B"], where: {store_id: {lte: 2}}
         | 
| 71 | 
            -
                assert_search "product", ["Product D"], where: {store_id: {gt: 3}}
         | 
| 72 | 
            -
                assert_search "product", ["Product C", "Product D"], where: {store_id: {gte: 3}}
         | 
| 73 | 
            -
                # range
         | 
| 74 | 
            -
                assert_search "product", ["Product A", "Product B"], where: {store_id: 1..2}
         | 
| 75 | 
            -
                assert_search "product", ["Product A"], where: {store_id: 1...2}
         | 
| 76 | 
            -
                assert_search "product", ["Product A", "Product B"], where: {store_id: [1, 2]}
         | 
| 77 | 
            -
                assert_search "product", ["Product B", "Product C", "Product D"], where: {store_id: {not: 1}}
         | 
| 78 | 
            -
                assert_search "product", ["Product C", "Product D"], where: {store_id: {not: [1, 2]}}
         | 
| 79 | 
            -
                assert_search "product", ["Product A"], where: {user_ids: {lte: 2, gte: 2}}
         | 
| 80 | 
            -
                # or
         | 
| 81 | 
            -
                assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{in_stock: true}, {store_id: 3}]]}
         | 
| 82 | 
            -
                assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{orders_count: [2, 4]}, {store_id: [1, 2]}]]}
         | 
| 83 | 
            -
                assert_search "product", ["Product A", "Product D"], where: {or: [[{orders_count: 1}, {created_at: {gte: now - 1}, backordered: true}]]}
         | 
| 84 | 
            -
                # all
         | 
| 85 | 
            -
                assert_search "product", ["Product A", "Product C"], where: {user_ids: {all: [1, 3]}}
         | 
| 86 | 
            -
                assert_search "product", [], where: {user_ids: {all: [1, 2, 3, 4]}}
         | 
| 87 | 
            -
                # any / nested terms
         | 
| 88 | 
            -
                assert_search "product", ["Product B", "Product C"], where: {user_ids: {not: [2], in: [1, 3]}}
         | 
| 89 | 
            -
                # not / exists
         | 
| 90 | 
            -
                assert_search "product", ["Product D"], where: {user_ids: nil}
         | 
| 91 | 
            -
                assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {not: nil}}
         | 
| 92 | 
            -
                assert_search "product", ["Product A", "Product C", "Product D"], where: {user_ids: [3, nil]}
         | 
| 93 | 
            -
                assert_search "product", ["Product B"], where: {user_ids: {not: [3, nil]}}
         | 
| 94 | 
            -
              end
         | 
| 95 | 
            -
             | 
| 96 | 
            -
              def test_regexp
         | 
| 97 | 
            -
                store_names ["Product A"]
         | 
| 98 | 
            -
                assert_search "*", ["Product A"], where: {name: /Pro.+/}
         | 
| 99 | 
            -
              end
         | 
| 100 | 
            -
             | 
| 101 | 
            -
              def test_alternate_regexp
         | 
| 102 | 
            -
                store_names ["Product A", "Item B"]
         | 
| 103 | 
            -
                assert_search "*", ["Product A"], where: {name: {regexp: "Pro.+"}}
         | 
| 104 | 
            -
              end
         | 
| 105 | 
            -
             | 
| 106 | 
            -
              def test_where_string
         | 
| 107 | 
            -
                store [
         | 
| 108 | 
            -
                  {name: "Product A", color: "RED"}
         | 
| 109 | 
            -
                ]
         | 
| 110 | 
            -
                assert_search "product", ["Product A"], where: {color: "RED"}
         | 
| 111 | 
            -
              end
         | 
| 112 | 
            -
             | 
| 113 | 
            -
              def test_where_nil
         | 
| 114 | 
            -
                store [
         | 
| 115 | 
            -
                  {name: "Product A"},
         | 
| 116 | 
            -
                  {name: "Product B", color: "red"}
         | 
| 117 | 
            -
                ]
         | 
| 118 | 
            -
                assert_search "product", ["Product A"], where: {color: nil}
         | 
| 119 | 
            -
              end
         | 
| 120 | 
            -
             | 
| 121 | 
            -
              def test_where_id
         | 
| 122 | 
            -
                store_names ["Product A"]
         | 
| 123 | 
            -
                product = Product.last
         | 
| 124 | 
            -
                assert_search "product", ["Product A"], where: {id: product.id.to_s}
         | 
| 125 | 
            -
              end
         | 
| 126 | 
            -
             | 
| 127 | 
            -
              def test_where_empty
         | 
| 128 | 
            -
                store_names ["Product A"]
         | 
| 129 | 
            -
                assert_search "product", ["Product A"], where: {}
         | 
| 130 | 
            -
              end
         | 
| 131 | 
            -
             | 
| 132 | 
            -
              def test_where_empty_array
         | 
| 133 | 
            -
                store_names ["Product A"]
         | 
| 134 | 
            -
                assert_search "product", [], where: {store_id: []}
         | 
| 135 | 
            -
              end
         | 
| 136 | 
            -
             | 
| 137 | 
            -
              # http://elasticsearch-users.115913.n3.nabble.com/Numeric-range-quey-or-filter-in-an-array-field-possible-or-not-td4042967.html
         | 
| 138 | 
            -
              # https://gist.github.com/jprante/7099463
         | 
| 139 | 
            -
              def test_where_range_array
         | 
| 140 | 
            -
                store [
         | 
| 141 | 
            -
                  {name: "Product A", user_ids: [11, 23, 13, 16, 17, 23]},
         | 
| 142 | 
            -
                  {name: "Product B", user_ids: [1, 2, 3, 4, 5, 6, 7, 8, 9]},
         | 
| 143 | 
            -
                  {name: "Product C", user_ids: [101, 230, 150, 200]}
         | 
| 144 | 
            -
                ]
         | 
| 145 | 
            -
                assert_search "product", ["Product A"], where: {user_ids: {gt: 10, lt: 24}}
         | 
| 146 | 
            -
              end
         | 
| 147 | 
            -
             | 
| 148 | 
            -
              def test_where_range_array_again
         | 
| 149 | 
            -
                store [
         | 
| 150 | 
            -
                  {name: "Product A", user_ids: [19, 32, 42]},
         | 
| 151 | 
            -
                  {name: "Product B", user_ids: [13, 40, 52]}
         | 
| 152 | 
            -
                ]
         | 
| 153 | 
            -
                assert_search "product", ["Product A"], where: {user_ids: {gt: 26, lt: 36}}
         | 
| 154 | 
            -
              end
         | 
| 155 | 
            -
             | 
| 156 | 
            -
              def test_near
         | 
| 157 | 
            -
                store [
         | 
| 158 | 
            -
                  {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
         | 
| 159 | 
            -
                  {name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
         | 
| 160 | 
            -
                ]
         | 
| 161 | 
            -
                assert_search "san", ["San Francisco"], where: {location: {near: [37.5, -122.5]}}
         | 
| 162 | 
            -
              end
         | 
| 163 | 
            -
             | 
| 164 | 
            -
              def test_near_within
         | 
| 165 | 
            -
                store [
         | 
| 166 | 
            -
                  {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
         | 
| 167 | 
            -
                  {name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
         | 
| 168 | 
            -
                  {name: "San Marino", latitude: 43.9333, longitude: 12.4667}
         | 
| 169 | 
            -
                ]
         | 
| 170 | 
            -
                assert_search "san", ["San Francisco", "San Antonio"], where: {location: {near: [37, -122], within: "2000mi"}}
         | 
| 171 | 
            -
              end
         | 
| 172 | 
            -
             | 
| 173 | 
            -
              def test_top_left_bottom_right
         | 
| 174 | 
            -
                store [
         | 
| 175 | 
            -
                  {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
         | 
| 176 | 
            -
                  {name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
         | 
| 177 | 
            -
                ]
         | 
| 178 | 
            -
                assert_search "san", ["San Francisco"], where: {location: {top_left: [38, -123], bottom_right: [37, -122]}}
         | 
| 179 | 
            -
              end
         | 
| 180 | 
            -
             | 
| 181 | 
            -
              def test_multiple_locations
         | 
| 182 | 
            -
                store [
         | 
| 183 | 
            -
                  {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
         | 
| 184 | 
            -
                  {name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
         | 
| 185 | 
            -
                ]
         | 
| 186 | 
            -
                assert_search "san", ["San Francisco"], where: {multiple_locations: {near: [37.5, -122.5]}}
         | 
| 187 | 
            -
              end
         | 
| 188 | 
            -
             | 
| 189 | 
            -
              def test_order_hash
         | 
| 190 | 
            -
                store_names ["Product A", "Product B", "Product C", "Product D"]
         | 
| 191 | 
            -
                assert_order "product", ["Product D", "Product C", "Product B", "Product A"], order: {name: :desc}
         | 
| 192 | 
            -
              end
         | 
| 193 | 
            -
             | 
| 194 | 
            -
              def test_order_string
         | 
| 195 | 
            -
                store_names ["Product A", "Product B", "Product C", "Product D"]
         | 
| 196 | 
            -
                assert_order "product", ["Product A", "Product B", "Product C", "Product D"], order: "name"
         | 
| 197 | 
            -
              end
         | 
| 198 | 
            -
             | 
| 199 | 
            -
              def test_order_id
         | 
| 200 | 
            -
                store_names ["Product A", "Product B"]
         | 
| 201 | 
            -
                product_a = Product.where(name: "Product A").first
         | 
| 202 | 
            -
                product_b = Product.where(name: "Product B").first
         | 
| 203 | 
            -
                assert_order "product", [product_a, product_b].sort_by(&:id).map(&:name), order: {id: :asc}
         | 
| 204 | 
            -
              end
         | 
| 205 | 
            -
             | 
| 206 | 
            -
              def test_order_multiple
         | 
| 207 | 
            -
                store [
         | 
| 208 | 
            -
                  {name: "Product A", color: "blue", store_id: 1},
         | 
| 209 | 
            -
                  {name: "Product B", color: "red", store_id: 3},
         | 
| 210 | 
            -
                  {name: "Product C", color: "red", store_id: 2}
         | 
| 211 | 
            -
                ]
         | 
| 212 | 
            -
                assert_order "product", ["Product A", "Product B", "Product C"], order: {color: :asc, store_id: :desc}
         | 
| 213 | 
            -
              end
         | 
| 214 | 
            -
             | 
| 215 | 
            -
              def test_order_ignore_unmapped
         | 
| 216 | 
            -
                assert_order "product", [], order: {not_mapped: {ignore_unmapped: true}}
         | 
| 217 | 
            -
              end
         | 
| 218 | 
            -
             | 
| 219 | 
            -
              def test_order_array
         | 
| 220 | 
            -
                store [{name: "San Francisco", latitude: 37.7833, longitude: -122.4167}]
         | 
| 221 | 
            -
                assert_order "francisco", ["San Francisco"], order: [{_geo_distance: {location: "0,0"}}]
         | 
| 222 | 
            -
              end
         | 
| 223 | 
            -
             | 
| 224 4 | 
             
              def test_partial
         | 
| 225 5 | 
             
                store_names ["Honey"]
         | 
| 226 6 | 
             
                assert_search "fresh honey", []
         | 
| @@ -233,39 +13,6 @@ class SqlTest < Minitest::Test | |
| 233 13 | 
             
                assert_search "fresh honey", ["Honey"], operator: "or"
         | 
| 234 14 | 
             
              end
         | 
| 235 15 |  | 
| 236 | 
            -
              def test_misspellings
         | 
| 237 | 
            -
                store_names ["abc", "abd", "aee"]
         | 
| 238 | 
            -
                assert_search "abc", ["abc"], misspellings: false
         | 
| 239 | 
            -
              end
         | 
| 240 | 
            -
             | 
| 241 | 
            -
              def test_misspellings_distance
         | 
| 242 | 
            -
                store_names ["abbb", "aabb"]
         | 
| 243 | 
            -
                assert_search "aaaa", ["aabb"], misspellings: {distance: 2}
         | 
| 244 | 
            -
              end
         | 
| 245 | 
            -
             | 
| 246 | 
            -
              def test_misspellings_prefix_length
         | 
| 247 | 
            -
                store_names ["ap", "api", "apt", "any", "nap", "ah", "ahi"]
         | 
| 248 | 
            -
                assert_search "ap", ["ap"], misspellings: {prefix_length: 2}
         | 
| 249 | 
            -
                assert_search "api", ["ap", "api", "apt"], misspellings: {prefix_length: 2}
         | 
| 250 | 
            -
              end
         | 
| 251 | 
            -
             | 
| 252 | 
            -
              def test_misspellings_prefix_length_operator
         | 
| 253 | 
            -
                store_names ["ap", "api", "apt", "any", "nap", "ah", "aha"]
         | 
| 254 | 
            -
                assert_search "ap ah", ["ap", "ah"], operator: "or", misspellings: {prefix_length: 2}
         | 
| 255 | 
            -
                assert_search "api ahi", ["ap", "api", "apt", "ah", "aha"], operator: "or", misspellings: {prefix_length: 2}
         | 
| 256 | 
            -
              end
         | 
| 257 | 
            -
             | 
| 258 | 
            -
              def test_misspellings_fields_operator
         | 
| 259 | 
            -
                store [
         | 
| 260 | 
            -
                  {name: "red", color: "red"},
         | 
| 261 | 
            -
                  {name: "blue", color: "blue"},
         | 
| 262 | 
            -
                  {name: "cyan", color: "blue green"},
         | 
| 263 | 
            -
                  {name: "magenta", color: "red blue"},
         | 
| 264 | 
            -
                  {name: "green", color: "green"}
         | 
| 265 | 
            -
                ]
         | 
| 266 | 
            -
                assert_search "red blue", ["red", "blue", "cyan", "magenta"], operator: "or", fields: ["color"], misspellings: false
         | 
| 267 | 
            -
              end
         | 
| 268 | 
            -
             | 
| 269 16 | 
             
              def test_fields_operator
         | 
| 270 17 | 
             
                store [
         | 
| 271 18 | 
             
                  {name: "red", color: "red"},
         | 
| @@ -355,11 +102,9 @@ class SqlTest < Minitest::Test | |
| 355 102 | 
             
                assert_equal aisle, Product.search("product", load: false).first.aisle.to_hash
         | 
| 356 103 | 
             
              end
         | 
| 357 104 |  | 
| 358 | 
            -
               | 
| 359 | 
            -
             | 
| 360 | 
            -
                 | 
| 361 | 
            -
             | 
| 362 | 
            -
                  assert Product.search("product", include: [:store]).first.association(:store).loaded?
         | 
| 363 | 
            -
                end
         | 
| 105 | 
            +
              def test_include
         | 
| 106 | 
            +
                skip unless defined?(ActiveRecord)
         | 
| 107 | 
            +
                store_names ["Product A"]
         | 
| 108 | 
            +
                assert Product.search("product", include: [:store]).first.association(:store).loaded?
         | 
| 364 109 | 
             
              end
         | 
| 365 110 | 
             
            end
         | 
    
        data/test/synonyms_test.rb
    CHANGED
    
    | @@ -41,8 +41,9 @@ class SynonymsTest < Minitest::Test | |
| 41 41 | 
             
                assert_search "scallions", ["Green Onions"]
         | 
| 42 42 | 
             
              end
         | 
| 43 43 |  | 
| 44 | 
            -
               | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 44 | 
            +
              def test_wordnet
         | 
| 45 | 
            +
                skip unless ENV["TEST_WORDNET"]
         | 
| 46 | 
            +
                store_names ["Creature", "Beast", "Dragon"], Animal
         | 
| 47 | 
            +
                assert_search "animal", ["Creature", "Beast"], {}, Animal
         | 
| 48 | 
            +
              end
         | 
| 48 49 | 
             
            end
         | 
    
        data/test/where_test.rb
    ADDED
    
    | @@ -0,0 +1,138 @@ | |
| 1 | 
            +
            require_relative "test_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class WhereTest < Minitest::Test
         | 
| 4 | 
            +
              def test_where
         | 
| 5 | 
            +
                now = Time.now
         | 
| 6 | 
            +
                store [
         | 
| 7 | 
            +
                  {name: "Product A", store_id: 1, in_stock: true, backordered: true, created_at: now, orders_count: 4, user_ids: [1, 2, 3]},
         | 
| 8 | 
            +
                  {name: "Product B", store_id: 2, in_stock: true, backordered: false, created_at: now - 1, orders_count: 3, user_ids: [1]},
         | 
| 9 | 
            +
                  {name: "Product C", store_id: 3, in_stock: false, backordered: true, created_at: now - 2, orders_count: 2, user_ids: [1, 3]},
         | 
| 10 | 
            +
                  {name: "Product D", store_id: 4, in_stock: false, backordered: false, created_at: now - 3, orders_count: 1}
         | 
| 11 | 
            +
                ]
         | 
| 12 | 
            +
                assert_search "product", ["Product A", "Product B"], where: {in_stock: true}
         | 
| 13 | 
            +
                # date
         | 
| 14 | 
            +
                assert_search "product", ["Product A"], where: {created_at: {gt: now - 1}}
         | 
| 15 | 
            +
                assert_search "product", ["Product A", "Product B"], where: {created_at: {gte: now - 1}}
         | 
| 16 | 
            +
                assert_search "product", ["Product D"], where: {created_at: {lt: now - 2}}
         | 
| 17 | 
            +
                assert_search "product", ["Product C", "Product D"], where: {created_at: {lte: now - 2}}
         | 
| 18 | 
            +
                # integer
         | 
| 19 | 
            +
                assert_search "product", ["Product A"], where: {store_id: {lt: 2}}
         | 
| 20 | 
            +
                assert_search "product", ["Product A", "Product B"], where: {store_id: {lte: 2}}
         | 
| 21 | 
            +
                assert_search "product", ["Product D"], where: {store_id: {gt: 3}}
         | 
| 22 | 
            +
                assert_search "product", ["Product C", "Product D"], where: {store_id: {gte: 3}}
         | 
| 23 | 
            +
                # range
         | 
| 24 | 
            +
                assert_search "product", ["Product A", "Product B"], where: {store_id: 1..2}
         | 
| 25 | 
            +
                assert_search "product", ["Product A"], where: {store_id: 1...2}
         | 
| 26 | 
            +
                assert_search "product", ["Product A", "Product B"], where: {store_id: [1, 2]}
         | 
| 27 | 
            +
                assert_search "product", ["Product B", "Product C", "Product D"], where: {store_id: {not: 1}}
         | 
| 28 | 
            +
                assert_search "product", ["Product C", "Product D"], where: {store_id: {not: [1, 2]}}
         | 
| 29 | 
            +
                assert_search "product", ["Product A"], where: {user_ids: {lte: 2, gte: 2}}
         | 
| 30 | 
            +
                # or
         | 
| 31 | 
            +
                assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{in_stock: true}, {store_id: 3}]]}
         | 
| 32 | 
            +
                assert_search "product", ["Product A", "Product B", "Product C"], where: {or: [[{orders_count: [2, 4]}, {store_id: [1, 2]}]]}
         | 
| 33 | 
            +
                assert_search "product", ["Product A", "Product D"], where: {or: [[{orders_count: 1}, {created_at: {gte: now - 1}, backordered: true}]]}
         | 
| 34 | 
            +
                # all
         | 
| 35 | 
            +
                assert_search "product", ["Product A", "Product C"], where: {user_ids: {all: [1, 3]}}
         | 
| 36 | 
            +
                assert_search "product", [], where: {user_ids: {all: [1, 2, 3, 4]}}
         | 
| 37 | 
            +
                # any / nested terms
         | 
| 38 | 
            +
                assert_search "product", ["Product B", "Product C"], where: {user_ids: {not: [2], in: [1, 3]}}
         | 
| 39 | 
            +
                # not / exists
         | 
| 40 | 
            +
                assert_search "product", ["Product D"], where: {user_ids: nil}
         | 
| 41 | 
            +
                assert_search "product", ["Product A", "Product B", "Product C"], where: {user_ids: {not: nil}}
         | 
| 42 | 
            +
                assert_search "product", ["Product A", "Product C", "Product D"], where: {user_ids: [3, nil]}
         | 
| 43 | 
            +
                assert_search "product", ["Product B"], where: {user_ids: {not: [3, nil]}}
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              def test_regexp
         | 
| 47 | 
            +
                store_names ["Product A"]
         | 
| 48 | 
            +
                assert_search "*", ["Product A"], where: {name: /Pro.+/}
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
              def test_alternate_regexp
         | 
| 52 | 
            +
                store_names ["Product A", "Item B"]
         | 
| 53 | 
            +
                assert_search "*", ["Product A"], where: {name: {regexp: "Pro.+"}}
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
              def test_where_string
         | 
| 57 | 
            +
                store [
         | 
| 58 | 
            +
                  {name: "Product A", color: "RED"}
         | 
| 59 | 
            +
                ]
         | 
| 60 | 
            +
                assert_search "product", ["Product A"], where: {color: "RED"}
         | 
| 61 | 
            +
              end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              def test_where_nil
         | 
| 64 | 
            +
                store [
         | 
| 65 | 
            +
                  {name: "Product A"},
         | 
| 66 | 
            +
                  {name: "Product B", color: "red"}
         | 
| 67 | 
            +
                ]
         | 
| 68 | 
            +
                assert_search "product", ["Product A"], where: {color: nil}
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
              def test_where_id
         | 
| 72 | 
            +
                store_names ["Product A"]
         | 
| 73 | 
            +
                product = Product.last
         | 
| 74 | 
            +
                assert_search "product", ["Product A"], where: {id: product.id.to_s}
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
              def test_where_empty
         | 
| 78 | 
            +
                store_names ["Product A"]
         | 
| 79 | 
            +
                assert_search "product", ["Product A"], where: {}
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              def test_where_empty_array
         | 
| 83 | 
            +
                store_names ["Product A"]
         | 
| 84 | 
            +
                assert_search "product", [], where: {store_id: []}
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
              # http://elasticsearch-users.115913.n3.nabble.com/Numeric-range-quey-or-filter-in-an-array-field-possible-or-not-td4042967.html
         | 
| 88 | 
            +
              # https://gist.github.com/jprante/7099463
         | 
| 89 | 
            +
              def test_where_range_array
         | 
| 90 | 
            +
                store [
         | 
| 91 | 
            +
                  {name: "Product A", user_ids: [11, 23, 13, 16, 17, 23]},
         | 
| 92 | 
            +
                  {name: "Product B", user_ids: [1, 2, 3, 4, 5, 6, 7, 8, 9]},
         | 
| 93 | 
            +
                  {name: "Product C", user_ids: [101, 230, 150, 200]}
         | 
| 94 | 
            +
                ]
         | 
| 95 | 
            +
                assert_search "product", ["Product A"], where: {user_ids: {gt: 10, lt: 24}}
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              def test_where_range_array_again
         | 
| 99 | 
            +
                store [
         | 
| 100 | 
            +
                  {name: "Product A", user_ids: [19, 32, 42]},
         | 
| 101 | 
            +
                  {name: "Product B", user_ids: [13, 40, 52]}
         | 
| 102 | 
            +
                ]
         | 
| 103 | 
            +
                assert_search "product", ["Product A"], where: {user_ids: {gt: 26, lt: 36}}
         | 
| 104 | 
            +
              end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
              def test_near
         | 
| 107 | 
            +
                store [
         | 
| 108 | 
            +
                  {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
         | 
| 109 | 
            +
                  {name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
         | 
| 110 | 
            +
                ]
         | 
| 111 | 
            +
                assert_search "san", ["San Francisco"], where: {location: {near: [37.5, -122.5]}}
         | 
| 112 | 
            +
              end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
              def test_near_within
         | 
| 115 | 
            +
                store [
         | 
| 116 | 
            +
                  {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
         | 
| 117 | 
            +
                  {name: "San Antonio", latitude: 29.4167, longitude: -98.5000},
         | 
| 118 | 
            +
                  {name: "San Marino", latitude: 43.9333, longitude: 12.4667}
         | 
| 119 | 
            +
                ]
         | 
| 120 | 
            +
                assert_search "san", ["San Francisco", "San Antonio"], where: {location: {near: [37, -122], within: "2000mi"}}
         | 
| 121 | 
            +
              end
         | 
| 122 | 
            +
             | 
| 123 | 
            +
              def test_top_left_bottom_right
         | 
| 124 | 
            +
                store [
         | 
| 125 | 
            +
                  {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
         | 
| 126 | 
            +
                  {name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
         | 
| 127 | 
            +
                ]
         | 
| 128 | 
            +
                assert_search "san", ["San Francisco"], where: {location: {top_left: [38, -123], bottom_right: [37, -122]}}
         | 
| 129 | 
            +
              end
         | 
| 130 | 
            +
             | 
| 131 | 
            +
              def test_multiple_locations
         | 
| 132 | 
            +
                store [
         | 
| 133 | 
            +
                  {name: "San Francisco", latitude: 37.7833, longitude: -122.4167},
         | 
| 134 | 
            +
                  {name: "San Antonio", latitude: 29.4167, longitude: -98.5000}
         | 
| 135 | 
            +
                ]
         | 
| 136 | 
            +
                assert_search "san", ["San Francisco"], where: {multiple_locations: {near: [37.5, -122.5]}}
         | 
| 137 | 
            +
              end
         | 
| 138 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: searchkick
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Andrew Kane
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-11- | 
| 11 | 
            +
            date: 2015-11-28 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activemodel
         | 
| @@ -123,6 +123,7 @@ files: | |
| 123 123 | 
             
            - test/autocomplete_test.rb
         | 
| 124 124 | 
             
            - test/boost_test.rb
         | 
| 125 125 | 
             
            - test/ci/before_install.sh
         | 
| 126 | 
            +
            - test/dangerous_reindex_test.rb
         | 
| 126 127 | 
             
            - test/facets_test.rb
         | 
| 127 128 | 
             
            - test/gemfiles/activerecord31.gemfile
         | 
| 128 129 | 
             
            - test/gemfiles/activerecord32.gemfile
         | 
| @@ -137,7 +138,10 @@ files: | |
| 137 138 | 
             
            - test/index_test.rb
         | 
| 138 139 | 
             
            - test/inheritance_test.rb
         | 
| 139 140 | 
             
            - test/match_test.rb
         | 
| 141 | 
            +
            - test/misspellings_test.rb
         | 
| 140 142 | 
             
            - test/model_test.rb
         | 
| 143 | 
            +
            - test/order_test.rb
         | 
| 144 | 
            +
            - test/pagination_test.rb
         | 
| 141 145 | 
             
            - test/query_test.rb
         | 
| 142 146 | 
             
            - test/records_test.rb
         | 
| 143 147 | 
             
            - test/reindex_job_test.rb
         | 
| @@ -149,6 +153,7 @@ files: | |
| 149 153 | 
             
            - test/suggest_test.rb
         | 
| 150 154 | 
             
            - test/synonyms_test.rb
         | 
| 151 155 | 
             
            - test/test_helper.rb
         | 
| 156 | 
            +
            - test/where_test.rb
         | 
| 152 157 | 
             
            homepage: https://github.com/ankane/searchkick
         | 
| 153 158 | 
             
            licenses:
         | 
| 154 159 | 
             
            - MIT
         | 
| @@ -169,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 169 174 | 
             
                  version: '0'
         | 
| 170 175 | 
             
            requirements: []
         | 
| 171 176 | 
             
            rubyforge_project: 
         | 
| 172 | 
            -
            rubygems_version: 2.4.5
         | 
| 177 | 
            +
            rubygems_version: 2.4.5.1
         | 
| 173 178 | 
             
            signing_key: 
         | 
| 174 179 | 
             
            specification_version: 4
         | 
| 175 180 | 
             
            summary: Searchkick learns what your users are looking for. As more people search,
         | 
| @@ -180,6 +185,7 @@ test_files: | |
| 180 185 | 
             
            - test/autocomplete_test.rb
         | 
| 181 186 | 
             
            - test/boost_test.rb
         | 
| 182 187 | 
             
            - test/ci/before_install.sh
         | 
| 188 | 
            +
            - test/dangerous_reindex_test.rb
         | 
| 183 189 | 
             
            - test/facets_test.rb
         | 
| 184 190 | 
             
            - test/gemfiles/activerecord31.gemfile
         | 
| 185 191 | 
             
            - test/gemfiles/activerecord32.gemfile
         | 
| @@ -194,7 +200,10 @@ test_files: | |
| 194 200 | 
             
            - test/index_test.rb
         | 
| 195 201 | 
             
            - test/inheritance_test.rb
         | 
| 196 202 | 
             
            - test/match_test.rb
         | 
| 203 | 
            +
            - test/misspellings_test.rb
         | 
| 197 204 | 
             
            - test/model_test.rb
         | 
| 205 | 
            +
            - test/order_test.rb
         | 
| 206 | 
            +
            - test/pagination_test.rb
         | 
| 198 207 | 
             
            - test/query_test.rb
         | 
| 199 208 | 
             
            - test/records_test.rb
         | 
| 200 209 | 
             
            - test/reindex_job_test.rb
         | 
| @@ -206,4 +215,4 @@ test_files: | |
| 206 215 | 
             
            - test/suggest_test.rb
         | 
| 207 216 | 
             
            - test/synonyms_test.rb
         | 
| 208 217 | 
             
            - test/test_helper.rb
         | 
| 209 | 
            -
             | 
| 218 | 
            +
            - test/where_test.rb
         |