Skip to content

Commit

Permalink
fix: add max matches option to riddle query select
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarinEA committed Apr 19, 2017
1 parent fc78d46 commit 0a53cd6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/sphinx/integration/mysql/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def select(values, index_name, where, limit = nil)
from(index_name).
where(where).
limit(limit).
with_options(max_matches: ThinkingSphinx.max_matches).
to_sql

read(sql).to_a
Expand All @@ -62,6 +63,7 @@ def find_in_batches(index_name, options = {})
where_not(where_not).
order_by(batch_order).
limit(batch_size).
with_options(max_matches: ThinkingSphinx.max_matches).
matching(options[:matching])

records = read(query.to_sql).to_a
Expand Down
10 changes: 7 additions & 3 deletions spec/sphinx/integration/mysql/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@

describe "#select" do
it do
expect(connection).to receive(:execute).with("SELECT company_id FROM product WHERE `id` = 1").once
expect(connection).to receive(:execute).with(
"SELECT company_id FROM product WHERE `id` = 1 OPTION max_matches=#{ThinkingSphinx.max_matches}"
).once
client.select("company_id", "product", id: 1)
end
end
Expand All @@ -81,15 +83,17 @@
"FROM product " +
"WHERE MATCH('@company_id_idx 1') " +
"AND `company_id` = 1 AND `sphinx_internal_id` > 0 " +
"ORDER BY `sphinx_internal_id` ASC LIMIT 1"
"ORDER BY `sphinx_internal_id` ASC LIMIT 1 " +
"OPTION max_matches=#{ThinkingSphinx.max_matches}"
).and_return([{"sphinx_internal_id" => "1"}])

expect(connection).to receive(:execute).with(
"SELECT sphinx_internal_id " +
"FROM product " +
"WHERE MATCH('@company_id_idx 1') " +
"AND `company_id` = 1 AND `sphinx_internal_id` > 1 " +
"ORDER BY `sphinx_internal_id` ASC LIMIT 1"
"ORDER BY `sphinx_internal_id` ASC LIMIT 1 " +
"OPTION max_matches=#{ThinkingSphinx.max_matches}"
).and_return([])

result = []
Expand Down

0 comments on commit 0a53cd6

Please sign in to comment.