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

Return matched queries #74

Merged
merged 5 commits into from
May 28, 2020
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]


## [0.13.5] - 2020-05-21
### Changed
- expose 'matched_queries' property

## [0.13.4] - 2020-05-20
### Changed
- Compatibility with Rails 6


## [0.13.3] - 2020-01-30
### Changed
- Release on RubyGems using gem-publisher CircleCI Orb
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
es-elasticity (0.13.4)
es-elasticity (0.13.5)
activemodel (>= 4.0.0, < 7)
activerecord (>= 4.0.0, < 7)
activesupport (>= 4.0.0, < 7)
Expand Down
2 changes: 1 addition & 1 deletion lib/elasticity/base_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.configure(&block)
end

# Define common attributes for all documents
attr_accessor :_id, :highlighted, :_score, :sort, :_explanation, :highlighted_attrs
attr_accessor :_id, :highlighted, :_score, :sort, :_explanation, :highlighted_attrs, :matched_queries

def attributes=(attributes)
attributes.each do |attr, value|
Expand Down
1 change: 1 addition & 0 deletions lib/elasticity/index_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def map_hit(hit)
attrs.merge!(_score: hit["_score"])
attrs.merge!(sort: hit["sort"])
attrs.merge!(hit["_source"]) if hit["_source"]
attrs.merge!(matched_queries: hit["matched_queries"]) if hit["matched_queries"]

highlighted = nil

Expand Down
2 changes: 1 addition & 1 deletion lib/elasticity/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Elasticity
VERSION = "0.13.4"
VERSION = "0.13.5"
end
19 changes: 19 additions & 0 deletions spec/functional/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ def get_explanations(results)
end
end

describe "matched_queries" do
it "returns a list of named queries that were matched on the result" do
query = {
query: {
match: {
description: {
query: "old",
_name: "description_query"
}
}
}
}
results = CatDoc.search(query).search_results
expect(results.size).to eq(1)
result = results.first
expect(result.matched_queries).to eq(["description_query"])
end
end

describe "highlight" do
it "is nil when the highlight does not return" do
results = CatDoc.search({}).search_results
Expand Down