forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unified Highlighter to support matched_fields
Add support to the Uunified highlighter to combine matches on multiple fields to highlight a single field: "matched_fields". Based on Lucene PR: apache/lucene#13268 Lucene PR is based on the concept of masked fields where masked fields are different from the original highlighted field. This PR in Elasticsearch uses the already existing highlighter parameter "matched_fields" Closes elastic#5172
- Loading branch information
1 parent
daa63d2
commit 7c79a3e
Showing
3 changed files
with
142 additions
and
27 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
.../yamlRestTest/resources/rest-api-spec/test/search.highlight/60_unified_matched_fields.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
setup: | ||
- requires: | ||
cluster_features: ["gte_v8.13.0"] | ||
reason: matched_fields for unified highlighter were added in 8.14.0 | ||
- do: | ||
indices.create: | ||
index: index1 | ||
body: | ||
settings: | ||
analysis: | ||
filter: | ||
my_edge_ngram: | ||
type: edge_ngram | ||
min_gram: 2 | ||
max_gram: 20 | ||
analyzer: | ||
my_analyzer: | ||
tokenizer: whitespace | ||
filter: [ my_edge_ngram ] | ||
mappings: | ||
properties: | ||
title: | ||
type: text | ||
fields: | ||
english: | ||
type: text | ||
analyzer: english | ||
ngram: | ||
type: text | ||
analyzer: my_analyzer | ||
body : | ||
type: text | ||
|
||
|
||
- do: | ||
bulk: | ||
refresh: true | ||
index: index1 | ||
body: | ||
- '{"index": {"_id": 1 }}' | ||
- '{"title": "dancing with the stars", "body": "Dancing with the Stars is a popular TV show"}' | ||
- '{"index": {"_id": 2 }}' | ||
- '{"title": "dance with star", "body": "Dancing with the Stars is a popular TV show"}' | ||
|
||
--- | ||
"Highlight based on single masked field": | ||
- do: | ||
search: | ||
index: index1 | ||
body: | ||
query: | ||
query_string: | ||
query: "\"dancing with the stars\"" | ||
fields: ["title^5", "title.english"] | ||
phrase_slop: 2 | ||
highlight: | ||
fields: | ||
title: | ||
matched_fields: ["title.english"] | ||
|
||
- length: {hits.hits: 2} | ||
- match: {hits.hits.0.highlight.title.0: "<em>dancing with the stars</em>"} | ||
- match: {hits.hits.1.highlight.title.0: "<em>dance with star</em>"} | ||
|
||
--- | ||
"Highlight based on multiple masked fields": | ||
- do: | ||
search: | ||
index: index1 | ||
body: | ||
query: | ||
query_string: | ||
query: "dan with star" | ||
fields: ["title^5", "title.ngram", "title.english"] | ||
highlight: | ||
fields: | ||
title: | ||
matched_fields: ["title.ngram", "title.english"] | ||
|
||
- length: {hits.hits: 2} | ||
- match: {hits.hits.0.highlight.title.0: "<em>dance</em> <em>with</em> <em>star</em>" } | ||
- match: {hits.hits.1.highlight.title.0: "<em>dancing</em> <em>with</em> the <em>stars</em>"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters