-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add ability to set "max_analyzed_offset" implicitly to "index.highlight #118895
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2faea54
Add ability to set "max_analyzed_offet" implicitly to "index.highlight
svilen-mihaylov-elastic f26f2c7
Add test
svilen-mihaylov-elastic b18a696
Tweak tests
svilen-mihaylov-elastic a6a4623
Merge branch 'main' into svilen-mihaylov/112822
svilen-mihaylov-elastic f139e85
Fix test and update docs
svilen-mihaylov-elastic 1285b01
Remove logger info
svilen-mihaylov-elastic eb6725e
Added test for zero
svilen-mihaylov-elastic 4ae0be1
Add a capability
svilen-mihaylov-elastic c0c2127
Add test for -1
svilen-mihaylov-elastic c6d2920
Exclude test from REST compatibility
svilen-mihaylov-elastic 703f438
Add Highlight_ to search capability name
svilen-mihaylov-elastic bf90d9a
Merge branch 'main' into svilen-mihaylov/112822
svilen-mihaylov-elastic 9fc0fcb
Disallow 0
svilen-mihaylov-elastic 6fd85f3
Fix test
svilen-mihaylov-elastic 5abd2c4
Should SUCCEED -> Should FAIL
svilen-mihaylov-elastic 0867480
Oops wrong test
svilen-mihaylov-elastic f889a61
Rename another test
svilen-mihaylov-elastic dc54b64
Remove test with =0 for now.
svilen-mihaylov-elastic 909d90f
Restore test with zero
svilen-mihaylov-elastic 7337f1d
Merge branch 'main' into svilen-mihaylov/112822
svilen-mihaylov-elastic 13cda1e
Merge branch 'main' into svilen-mihaylov/112822
svilen-mihaylov-elastic 15bc509
Fix merge
svilen-mihaylov-elastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2632,6 +2632,42 @@ public void testPostingsHighlighterOrderByScore() throws Exception { | |
| }); | ||
| } | ||
|
|
||
| public void testMaxQueryOffsetDefault() throws Exception { | ||
| assertAcked( | ||
| prepareCreate("test").setMapping(type1PostingsffsetsMapping()) | ||
| .setSettings(Settings.builder().put("index.highlight.max_analyzed_offset", "10").build()) | ||
| ); | ||
| ensureGreen(); | ||
|
|
||
| prepareIndex("test").setSource( | ||
| "field1", | ||
| new String[] { | ||
| "This sentence contains one match, not that short. This sentence contains zero sentence matches. " | ||
| + "This one contains no matches.", | ||
| "This is the second value's first sentence. This one contains no matches. " | ||
| + "This sentence contains three sentence occurrences (sentence).", | ||
| "One sentence match here and scored lower since the text is quite long, not that appealing. " | ||
| + "This one contains no matches." } | ||
| ).get(); | ||
| refresh(); | ||
|
|
||
| logger.info("--> highlighting and searching on field1"); | ||
svilen-mihaylov-elastic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Specific for this test: by passing "-1" as "maxAnalyzedOffset", the index highlight setting above will be used. | ||
| SearchSourceBuilder source = searchSource().query(termQuery("field1", "sentence")) | ||
| .highlighter(highlight().field("field1").order("score").maxAnalyzedOffset(-1)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Observe query offset is -1 |
||
|
|
||
| assertResponse(client().search(new SearchRequest("test").source(source)), response -> { | ||
| Map<String, HighlightField> highlightFieldMap = response.getHits().getAt(0).getHighlightFields(); | ||
| assertThat(highlightFieldMap.size(), equalTo(1)); | ||
| HighlightField field1 = highlightFieldMap.get("field1"); | ||
| assertThat(field1.fragments().length, equalTo(1)); | ||
| assertThat( | ||
| field1.fragments()[0].string(), | ||
| equalTo("This <em>sentence</em> contains one match, not that short. This sentence contains zero sentence matches.") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Observe only one match |
||
| ); | ||
| }); | ||
| } | ||
|
|
||
| public void testPostingsHighlighterEscapeHtml() throws Exception { | ||
| assertAcked(prepareCreate("test").setMapping("title", "type=text," + randomStoreField() + "index_options=offsets")); | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
server/src/main/java/org/elasticsearch/lucene/search/uhighlight/QueryMaxAnalyzedOffset.java
This file contains hidden or 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,30 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.lucene.search.uhighlight; | ||
|
|
||
| public class QueryMaxAnalyzedOffset { | ||
mayya-sharipova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private final int queryMaxAnalyzedOffset; | ||
|
|
||
| private QueryMaxAnalyzedOffset(final int queryMaxAnalyzedOffset) { | ||
| // If we have a negative value, grab value for the actual maximum from the index. | ||
| this.queryMaxAnalyzedOffset = queryMaxAnalyzedOffset; | ||
| } | ||
|
|
||
| public static QueryMaxAnalyzedOffset create(final Integer queryMaxAnalyzedOffset, final int indexMaxAnalyzedOffset) { | ||
| if (queryMaxAnalyzedOffset == null) { | ||
| return null; | ||
| } | ||
| return new QueryMaxAnalyzedOffset(queryMaxAnalyzedOffset < 0 ? indexMaxAnalyzedOffset : queryMaxAnalyzedOffset); | ||
| } | ||
|
|
||
| public int getNotNull() { | ||
| return queryMaxAnalyzedOffset; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observe index offset is 10