elastic_searchable 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -111,7 +111,7 @@ module ElasticSearchable
111
111
  # see http://www.elasticsearch.org/guide/reference/api/index_.html
112
112
  def reindex(lifecycle = nil)
113
113
  query = {}
114
- query.merge! :percolate => "*" if _percolate_callbacks.any?
114
+ query[:percolate] = "*" if _percolate_callbacks.any?
115
115
  response = ElasticSearchable.request :put, self.class.index_type_path(self.id), :query => query, :json_body => self.as_json_for_index
116
116
 
117
117
  self.index_lifecycle = lifecycle ? lifecycle.to_sym : nil
@@ -136,8 +136,10 @@ module ElasticSearchable
136
136
  # can be done on transient/non-persisted objects!
137
137
  # can be done automatically when indexing using :percolate => true config option
138
138
  # http://www.elasticsearch.org/blog/2011/02/08/percolator.html
139
- def percolate
140
- response = ElasticSearchable.request :get, self.class.index_type_path('_percolate'), :json_body => {:doc => self.as_json_for_index}
139
+ def percolate(percolator_query = nil)
140
+ body = {:doc => self.as_json_for_index}
141
+ body[:query] = percolator_query if percolator_query
142
+ response = ElasticSearchable.request :get, self.class.index_type_path('_percolate'), :json_body => body
141
143
  self.percolations = response['matches'] || []
142
144
  self.percolations
143
145
  end
@@ -1,4 +1,4 @@
1
1
  module ElasticSearchable
2
- VERSION = '1.2.2'
2
+ VERSION = '1.3.0'
3
3
  end
4
4
 
@@ -325,11 +325,9 @@ class TestElasticSearchable < Test::Unit::TestCase
325
325
  should 'have set mapping' do
326
326
  @status = ElasticSearchable.request :get, '/elastic_searchable/users/_mapping'
327
327
  expected = {
328
- "properties"=> {
329
- "name"=> {"type"=>"string", "index"=>"not_analyzed"}
330
- }
328
+ "name"=> {"type"=>"string", "index"=>"not_analyzed"}
331
329
  }
332
- assert_equal expected, @status['users'], @status.inspect
330
+ assert_equal expected, @status['users']['properties'], @status.inspect
333
331
  end
334
332
  end
335
333
  end
@@ -417,6 +415,29 @@ class TestElasticSearchable < Test::Unit::TestCase
417
415
  assert_equal ['myfilter'], @matches
418
416
  end
419
417
  end
418
+ context "with multiple percolators" do
419
+ setup do
420
+ ElasticSearchable.request :put, '/_percolator/elastic_searchable/greenfilter', :json_body => { :color => 'green', :query => {:query_string => {:query => 'foo' }}}
421
+ ElasticSearchable.request :put, '/_percolator/elastic_searchable/bluefilter', :json_body => { :color => 'blue', :query => {:query_string => {:query => 'foo' }}}
422
+ ElasticSearchable.request :post, '/_percolator/_refresh'
423
+ end
424
+ context 'percolating a non-persisted object with no limitation' do
425
+ setup do
426
+ @matches = Book.new(:title => 'foo').percolate
427
+ end
428
+ should 'return all percolated matches' do
429
+ assert_equal ['bluefilter','greenfilter','myfilter'], @matches.sort
430
+ end
431
+ end
432
+ context 'percolating a non-persisted object with limitations' do
433
+ setup do
434
+ @matches = Book.new(:title => 'foo').percolate( { :term => { :color => 'green' }} )
435
+ end
436
+ should 'return limited percolated matches' do
437
+ assert_equal ['greenfilter'], @matches
438
+ end
439
+ end
440
+ end
420
441
  end
421
442
  end
422
443
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 2
10
- version: 1.2.2
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Sonnek
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-14 00:00:00 Z
18
+ date: 2011-11-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord