Skip to content

Commit

Permalink
Updated Elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
pyromaniac committed Mar 3, 2014
1 parent 9b32a33 commit 453a602
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ rvm:
- 2.1.0
# - rbx
before_install:
- curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.10.tar.gz | tar xz -C /tmp
- curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz | tar xz -C /tmp
before_script:
- TEST_CLUSTER_COMMAND="/tmp/elasticsearch-0.90.10/bin/elasticsearch" rake elasticsearch:start
- TEST_CLUSTER_COMMAND="/tmp/elasticsearch-1.0.1/bin/elasticsearch" rake elasticsearch:start
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# master

* Using source filtering instead of fields filter (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-source-filtering.html).

# Version 0.2.3

* `.import!` indexes method, raises import errors.
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def _response

def _results
@_results ||= (criteria.none? ? [] : _response['hits']['hits']).map do |hit|
attributes = hit['_source'] || hit['fields'] || {}
attributes = hit['_source'] || {}
attributes.reverse_merge!(id: hit['_id'])
.merge!(_score: hit['_score'], _explanation: hit['_explanation'])
index.type_hash[hit['_type']].new attributes
Expand Down
2 changes: 1 addition & 1 deletion lib/chewy/query/criteria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def request_body
body = (_composed_query(_request_query, _request_filter) || {}).tap do |body|
body.merge!(facets: facets) if facets?
body.merge!(sort: sort) if sort?
body.merge!(fields: fields) if fields?
body.merge!(_source: fields) if fields?
end

{body: body.merge!(_request_options)}
Expand Down
2 changes: 1 addition & 1 deletion spec/chewy/index/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Chewy::Index::Actions do
include ClassHelpers
before { Chewy::Index.client.indices.delete }
before { Chewy.client.indices.delete index: '*' }

before { stub_index :dummies }

Expand Down
2 changes: 1 addition & 1 deletion spec/chewy/index/aliases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Chewy::Index::Aliases do
include ClassHelpers
before { Chewy::Index.client.indices.delete }
before { Chewy.client.indices.delete index: '*' }

before { stub_index :dummies }

Expand Down
2 changes: 1 addition & 1 deletion spec/chewy/query/criteria_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def request_body &block
specify { request_body { update_queries(:query) }.should == {body: {query: :query}} }
specify { request_body {
update_options(from: 10); update_sort(:field); update_fields(:field); update_queries(:query)
}.should == {body: {query: :query, from: 10, sort: [:field], fields: ['field']}} }
}.should == {body: {query: :query, from: 10, sort: [:field], _source: ['field']}} }
end

describe '#_composed_query' do
Expand Down
7 changes: 2 additions & 5 deletions spec/chewy/query/loading_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Chewy::Query::Loading do
include ClassHelpers
before { Chewy::Index.client.indices.delete }
before { Chewy.client.indices.delete index: '*' }

before do
stub_model(:city)
Expand All @@ -24,10 +24,7 @@
end
end

before do
PlacesIndex::City.import(cities)
PlacesIndex::Country.import(countries)
end
before { PlacesIndex.import!(cities: cities, countries: countries) }

specify { PlacesIndex.order(:rating).limit(6).load.total_count.should == 12 }
specify { PlacesIndex.order(:rating).limit(6).load.should =~ cities.first(3) + countries.first(3) }
Expand Down
4 changes: 2 additions & 2 deletions spec/chewy/query/pagination_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Chewy::Query::Pagination do
include ClassHelpers
before { Chewy::Index.client.indices.delete }
before { Chewy.client.indices.delete index: '*' }

before do
stub_index(:products) do
Expand All @@ -13,7 +13,7 @@
end
let(:data) { 10.times.map { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }

before { ProductsIndex::Product.import(data.map { |h| double(h) }) }
before { ProductsIndex::Product.import!(data.map { |h| double(h) }) }
before { Kaminari.config.stub(default_per_page: 3) }

let(:search) { ProductsIndex.order(:age) }
Expand Down
20 changes: 9 additions & 11 deletions spec/chewy/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe Chewy::Query do
include ClassHelpers
before { Chewy.client.indices.delete index: '*' }

before { Chewy::Index.client.indices.delete }
before do
stub_index(:products) do
define_type :product do
Expand All @@ -20,9 +20,11 @@
let(:products) { 3.times.map { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
let(:cities) { 3.times.map { |i| {id: i.next.to_s}.stringify_keys! } }
let(:countries) { 3.times.map { |i| {id: i.next.to_s}.stringify_keys! } }
before { ProductsIndex::Product.import(products.map { |h| double(h) }) }
before { ProductsIndex::City.import(cities.map { |h| double(h) }) }
before { ProductsIndex::Country.import(countries.map { |h| double(h) }) }
before do
ProductsIndex::Product.import!(products.map { |h| double(h) })
ProductsIndex::City.import!(cities.map { |h| double(h) })
ProductsIndex::Country.import!(countries.map { |h| double(h) })
end

specify { subject.count.should == 9 }
specify { subject.limit(6).count.should == 6 }
Expand All @@ -35,7 +37,7 @@

describe '#==' do
let(:data) { 3.times.map { |i| {id: i.next.to_s, name: "Name#{i.next}", age: 10 * i.next}.stringify_keys! } }
before { ProductsIndex::Product.import(data.map { |h| double(h) }) }
before { ProductsIndex::Product.import!(data.map { |h| double(h) }) }

specify { subject.query(match: 'hello').should == subject.query(match: 'hello') }
specify { subject.query(match: 'hello').should_not == subject.query(match: 'world') }
Expand Down Expand Up @@ -194,7 +196,7 @@
end.tap(&:create!)
end

before { CitiesIndex::City.import cities }
before { CitiesIndex::City.import! cities }

specify { CitiesIndex.order(:rating).first.should be_a CitiesIndex::City }
specify { CitiesIndex.order(:rating).first.name.should == 'name0' }
Expand Down Expand Up @@ -226,16 +228,12 @@
end
end.tap(&:create!)
end
before { CitiesIndex::City.import cities }
before { CitiesIndex::City.import! cities }

specify { CitiesIndex.order(:rating).first.should be_a CitiesIndex::City }
specify { CitiesIndex.order(:rating).first.name.should be_nil }
specify { CitiesIndex.order(:rating).first.rating.should be_nil }
specify { CitiesIndex.order(:rating).first.nested.should be_nil }

specify { CitiesIndex.order(:rating).only(:name).first.name.should be_nil }
specify { CitiesIndex.order(:rating).only(:name).first.rating.should be_nil }
specify { CitiesIndex.order(:rating).only(:nested).first.nested.should be_nil }
end
end
end
2 changes: 1 addition & 1 deletion spec/chewy/rspec/update_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe :update_index do
include ClassHelpers
before { Chewy::Index.client.indices.delete }
before { Chewy.client.indices.delete index: '*' }

before do
stub_index(:dummies) do
Expand Down
2 changes: 1 addition & 1 deletion spec/chewy/type/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Chewy::Type::Import do
include ClassHelpers

before { Chewy.client.indices.delete }
before { Chewy.client.indices.delete index: '*' }

before do
stub_model(:city)
Expand Down

0 comments on commit 453a602

Please sign in to comment.