Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the track_scores option to the query #417

Merged
merged 3 commits into from
Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Metrics/AbcSize:
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 274
Max: 277

# Offense count: 14
Metrics/CyclomaticComplexity:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* Rake tasks support multiple indexes and exceptions: `rake chewy:reset[users,projects]`, `rake chewy:update[-projects]`

* Witchcraft™ supports dynamically generated procs with variables from closure.

* Add the `track_scores` option to the query; `_score` to be computed and tracked even when there are no `_score` in sort. (@dmitry)

## Bugfixes

Expand Down
8 changes: 8 additions & 0 deletions lib/chewy/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ def min_score(value)
chain { criteria.update_request_options min_score: value }
end

# Elasticsearch track_scores option support
#
# UsersIndex.query(...).track_scores(true)
#
def track_scores(value)
chain { criteria.update_request_options track_scores: value }
end

# Adds facets section to the search request.
# All the chained facets a merged and added to the
# search request
Expand Down
3 changes: 2 additions & 1 deletion lib/chewy/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module Search
:boost_factor, :weight, :random_score, :field_value_factor, :decay, :aggregations,
:suggest, :none, :strategy, :query, :filter, :post_filter, :boost_mode,
:score_mode, :order, :reorder, :only, :types, :delete_all, :find, :total,
:total_count, :total_entries, :unlimited, :script_fields, to: :all
:total_count, :total_entries, :unlimited, :script_fields, :track_scores,
to: :all
end

module ClassMethods
Expand Down
8 changes: 8 additions & 0 deletions spec/chewy/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@
specify { expect(subject.offset { 20 / 2 }.criteria.request_body[:body]).to include(from: 10) }
end

describe '#track_scores' do
specify { expect(subject.track_scores(true)).to be_a described_class }
specify { expect(subject.track_scores(true)).not_to eq(subject) }
specify { expect(subject.track_scores(true).criteria.request_options).to include(track_scores: true) }
specify { expect { subject.track_scores(true) }.not_to change { subject.criteria.request_options } }
specify { expect(subject.track_scores(false).criteria.request_body[:body]).to include(track_scores: false) }
end

describe '#script_fields' do
specify { expect(subject.script_fields(distance: 'test()')).to be_a described_class }
specify { expect(subject.script_fields(distance: 'test()')).not_to eq(subject) }
Expand Down