Skip to content

Commit

Permalink
Merge pull request #74 from doximity/return_matched_queries
Browse files Browse the repository at this point in the history
Return matched queries
  • Loading branch information
davidbl committed May 28, 2020
2 parents 48ec0dc + de2f543 commit 04f275c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
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

0 comments on commit 04f275c

Please sign in to comment.