Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkamel committed Jan 18, 2024
1 parent 7a9e554 commit 51353bc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/search_flip/criteria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def delete(params = {})
http_request = connection.http_client
http_request = http_request.timeout(http_timeout_value) if http_timeout_value

if connection.distribution.nil? && connection.version.to_i >= 5
if connection.distribution || connection.version.to_i >= 5
url = connection.version.to_i < 8 ? target.type_url : target.index_url

http_request.post("#{url}/_delete_by_query", params: request_params.merge(params), json: dupped_request)
Expand Down
2 changes: 1 addition & 1 deletion spec/search_flip/bulk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

it "uses the specified http_client" do
product = create(:product)
url = ProductIndex.connection.version.to_i < 8 ? ProductIndex.type_url : ProductIndex.index_url
url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? ProductIndex.type_url : ProductIndex.index_url

stub_request(:put, "#{url}/_bulk").with(headers: { "X-Header" => "Value" }).to_return(status: 200, body: "{}")

Expand Down
30 changes: 15 additions & 15 deletions spec/search_flip/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
it "freezes the specified index" do
connection = SearchFlip::Connection.new

if connection.version.to_f >= 6.6 && connection.version.to_i < 8
if connection.distribution.nil? && connection.version.to_f >= 6.6 && connection.version.to_i < 8
begin
connection.create_index("index_name")
connection.freeze_index("index_name")
Expand All @@ -187,7 +187,7 @@
it "unfreezes the specified index" do
connection = SearchFlip::Connection.new

if connection.version.to_f >= 6.6 && connection.version.to_i < 8
if connection.distribution.nil? && connection.version.to_f >= 6.6 && connection.version.to_i < 8
begin
connection.create_index("index_name")
connection.freeze_index("index_name")
Expand Down Expand Up @@ -241,7 +241,7 @@
end

describe "#update_mapping" do
if SearchFlip::Connection.new.version.to_i >= 7
if SearchFlip::Connection.new.then { |connection| connection.distribution || connection.version.to_i >= 7 }
it "updates the mapping of an index without type name" do
begin
connection = SearchFlip::Connection.new
Expand All @@ -266,7 +266,7 @@

connection.create_index("index_name")

if connection.version.to_i < 8
if connection.distribution.nil? && connection.version.to_i < 8
connection.update_mapping("index_name", { "type_name" => mapping }, type_name: "type_name")

expect(connection.get_mapping("index_name", type_name: "type_name")).to eq("index_name" => { "mappings" => { "type_name" => mapping } })
Expand Down Expand Up @@ -321,9 +321,9 @@

bulk = proc do
connection.bulk do |indexer|
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 1, { id: 1 }, _index: CommentIndex.index_name, ** connection.version.to_i < 8 ? { _type: CommentIndex.type_name } : {}
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 1, { id: 1 }, _index: CommentIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: CommentIndex.type_name } : {}
end
end

Expand All @@ -346,23 +346,23 @@
connection = SearchFlip::Connection.new

connection.bulk do |indexer|
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
end

bulk = proc do
connection.bulk do |indexer|
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
end
end

expect(&bulk).to raise_error(SearchFlip::Bulk::Error)

bulk = proc do
connection.bulk ignore_errors: [409] do |indexer|
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
end
end

Expand All @@ -375,7 +375,7 @@
connection = SearchFlip::Connection.new

connection.bulk do |indexer|
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
end

expect(SearchFlip::Bulk).to have_received(:new).with(
Expand All @@ -398,7 +398,7 @@
}

connection.bulk(options) do |indexer|
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
end

expect(SearchFlip::Bulk).to have_received(:new).with(anything, options)
Expand Down
14 changes: 7 additions & 7 deletions spec/search_flip/criteria_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@

describe "#match_none" do
it "does not match any documents" do
if ProductIndex.connection.version.to_i >= 5
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
ProductIndex.import create(:product)

query = ProductIndex.match_none
Expand Down Expand Up @@ -479,7 +479,7 @@

describe "#post_search" do
it "sets up the constraints correctly and is chainable" do
if ProductIndex.connection.version.to_i >= 2
if Productindex.connection.distribution || ProductIndex.connection.version.to_i >= 2
product1 = create(:product, title: "title1", category: "category1")
product2 = create(:product, title: "title2", category: "category2")
product3 = create(:product, title: "title3", category: "category1")
Expand Down Expand Up @@ -886,7 +886,7 @@

describe "#profile" do
it "sets up the constraints correctly" do
if ProductIndex.connection.version.to_i >= 2
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 2
expect(ProductIndex.profile(true).raw_response["profile"]).not_to be_nil
end
end
Expand Down Expand Up @@ -1322,7 +1322,7 @@

describe "#track_total_hits" do
it "is added to the request" do
if ProductIndex.connection.version.to_i >= 7
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 7
query = ProductIndex.track_total_hits(false)

expect(query.request[:track_total_hits]).to eq(false)
Expand Down Expand Up @@ -1350,7 +1350,7 @@

describe "#preference" do
it "sets the preference" do
url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"

stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?preference=value")
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
Expand All @@ -1363,7 +1363,7 @@

describe "#search_type" do
it "sets the search_type" do
url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"

stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?search_type=value")
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
Expand All @@ -1376,7 +1376,7 @@

describe "#routing" do
it "sets the search_type" do
url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"

stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?routing=value")
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
Expand Down
16 changes: 8 additions & 8 deletions spec/search_flip/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
include SearchFlip::Index
end

expect(klass.include_type_name?).to eq(klass.connection.version.to_i < 7)
expect(klass.include_type_name?).to eq(klass.connection.distribution.nil? && klass.connection.version.to_i < 7)
end

it "returns true if the type name is not equal to _doc" do
Expand Down Expand Up @@ -185,7 +185,7 @@ def self.type_name
end

describe ".update_mapping" do
if TestIndex.connection.version.to_i >= 7
if TestIndex.connection.distribution || TestIndex.connection.version.to_i >= 7
context "without type name" do
it "delegates to connection" do
TestIndex.create_index
Expand Down Expand Up @@ -215,7 +215,7 @@ def self.type_name

TestIndex.update_mapping

if TestIndex.connection.version.to_i < 8
if TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8
expect(TestIndex.connection).to have_received(:update_mapping).with("test", { "test" => mapping }, type_name: "test")
else
expect(TestIndex.connection).to have_received(:update_mapping).with("test", mapping)
Expand Down Expand Up @@ -245,7 +245,7 @@ def self.include_type_name?
end

describe ".get_mapping" do
if TestIndex.connection.version.to_i >= 7
if TestIndex.connection.distribution || TestIndex.connection.version.to_i >= 7
context "without type name" do
it "delegates to connection" do
allow(TestIndex).to receive(:include_type_name?).and_return(false)
Expand All @@ -272,7 +272,7 @@ def self.include_type_name?

TestIndex.get_mapping

if TestIndex.connection.version.to_i < 8
if TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8
expect(TestIndex.connection).to have_received(:get_mapping).with("test", type_name: "test")
else
expect(TestIndex.connection).to have_received(:get_mapping).with("test")
Expand Down Expand Up @@ -340,7 +340,7 @@ def self.include_type_name?

TestIndex.type_url

expect(TestIndex.connection).to have_received(:type_url).with("test", TestIndex.connection.version.to_i < 8 ? "test" : "_doc")
expect(TestIndex.connection).to have_received(:type_url).with("test", TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8 ? "test" : "_doc")
end
end

Expand Down Expand Up @@ -433,7 +433,7 @@ def self.include_type_name?

products = create_list(:product, 2)

if ProductIndex.connection.version.to_i >= 5
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
expect { ProductIndex.create products, {}, routing: "r1" }.to(change { ProductIndex.total_count }.by(2))

expect(ProductIndex.get(products.first.id, routing: "r1")["_routing"]).to eq("r1")
Expand All @@ -447,7 +447,7 @@ def self.include_type_name?
it "allows respects class options" do
products = create_list(:product, 2)

if ProductIndex.connection.version.to_i >= 5
if Productindex.connection.distribution || ProductIndex.connection.version.to_i >= 5
allow(ProductIndex).to receive(:index_options).and_return(routing: "r1")

expect { ProductIndex.create products }.to(change { ProductIndex.total_count }.by(2))
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ProductIndex
include SearchFlip::Index

def self.mapping
if ProductIndex.connection.version.to_i >= 5
if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
{
properties: {
category: {
Expand Down

0 comments on commit 51353bc

Please sign in to comment.