-
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
Changes from all commits
2faea54
f26f2c7
b18a696
a6a4623
f139e85
1285b01
eb6725e
4ae0be1
c0c2127
c6d2920
703f438
bf90d9a
9fc0fcb
6fd85f3
5abd2c4
0867480
f889a61
dc54b64
909d90f
7337f1d
13cda1e
15bc509
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2632,6 +2632,41 @@ 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()) | ||
|
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 index offset is 10 |
||
| ); | ||
| 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(); | ||
|
|
||
| // 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")); | ||
|
|
||
|
|
||
| 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; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.