Skip to content

Commit

Permalink
Merge pull request #417 from dmitry/add-track-scores
Browse files Browse the repository at this point in the history
Add the `track_scores` option to the query
  • Loading branch information
pyromaniac authored Sep 28, 2016
2 parents 4ae2065 + 54c5c02 commit 13d0baf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
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

0 comments on commit 13d0baf

Please sign in to comment.