mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-20 03:45:02 +00:00
Checkstyle
This commit is contained in:
parent
cf6e1a4362
commit
153b2ae180
@ -575,18 +575,6 @@
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]fetch[/\\]FetchSearchResult.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]fetch[/\\]FetchSubPhase.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]fetch[/\\]FetchSubPhaseParseElement.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]fetch[/\\]explain[/\\]ExplainFetchSubPhase.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]fetch[/\\]fielddata[/\\]FieldDataFieldsParseElement.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]fetch[/\\]innerhits[/\\]InnerHitsParseElement.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]fetch[/\\]source[/\\]FetchSourceContext.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]highlight[/\\]FastVectorHighlighter.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]highlight[/\\]HighlightPhase.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]highlight[/\\]HighlightUtils.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]highlight[/\\]HighlighterParseElement.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]highlight[/\\]PlainHighlighter.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]highlight[/\\]PostingsHighlighter.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]highlight[/\\]vectorhighlight[/\\]SimpleFragmentsBuilder.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]highlight[/\\]vectorhighlight[/\\]SourceScoreOrderFragmentsBuilder.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]internal[/\\]DefaultSearchContext.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]internal[/\\]FilteredSearchContext.java" checks="LineLength" />
|
||||
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]internal[/\\]InternalSearchHit.java" checks="LineLength" />
|
||||
|
@ -18,8 +18,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Search phase that fetches the top resutls from the shards after the results of the query phase have been merged. Pluggable by
|
||||
* implementing {@link org.elasticsearch.search.fetch.FetchSubPhase} and
|
||||
* Search phase that fetches the top hits from the shards after the results of the query phase have been merged. Pluggable by implementing
|
||||
* {@link org.elasticsearch.search.fetch.FetchSubPhase} and
|
||||
* {@link org.elasticsearch.plugins.SearchPlugin#getFetchSubPhases(org.elasticsearch.plugins.SearchPlugin.FetchPhaseConstructionContext)}.
|
||||
*/
|
||||
package org.elasticsearch.search.fetch;
|
||||
|
@ -21,14 +21,13 @@ package org.elasticsearch.search.fetch.subphase;
|
||||
import org.apache.lucene.search.Explanation;
|
||||
import org.elasticsearch.search.fetch.FetchPhaseExecutionException;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhase;
|
||||
import org.elasticsearch.search.internal.InternalSearchHit;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.search.rescore.RescoreSearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Explains the scoring calculations for the top hits.
|
||||
*/
|
||||
public final class ExplainFetchSubPhase implements FetchSubPhase {
|
||||
|
||||
@ -47,7 +46,8 @@ public final class ExplainFetchSubPhase implements FetchSubPhase {
|
||||
// we use the top level doc id, since we work with the top level searcher
|
||||
hitContext.hit().explanation(explanation);
|
||||
} catch (IOException e) {
|
||||
throw new FetchPhaseExecutionException(context, "Failed to explain doc [" + hitContext.hit().type() + "#" + hitContext.hit().id() + "]", e);
|
||||
throw new FetchPhaseExecutionException(context, "Failed to explain doc [" + hitContext.hit().type() + "#"
|
||||
+ hitContext.hit().id() + "]", e);
|
||||
} finally {
|
||||
context.clearReleasables(SearchContext.Lifetime.COLLECTION);
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Context used to fetch the {@code _source}.
|
||||
*/
|
||||
public class FetchSourceContext implements Streamable, ToXContent {
|
||||
|
||||
@ -175,8 +176,8 @@ public class FetchSourceContext implements Streamable, ToXContent {
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
includesList.add(parser.text());
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].",
|
||||
parser.getTokenLocation());
|
||||
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token
|
||||
+ " in [" + currentFieldName + "].", parser.getTokenLocation());
|
||||
}
|
||||
}
|
||||
includes = includesList.toArray(new String[includesList.size()]);
|
||||
@ -186,14 +187,14 @@ public class FetchSourceContext implements Streamable, ToXContent {
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
excludesList.add(parser.text());
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].",
|
||||
parser.getTokenLocation());
|
||||
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token
|
||||
+ " in [" + currentFieldName + "].", parser.getTokenLocation());
|
||||
}
|
||||
}
|
||||
excludes = excludesList.toArray(new String[excludesList.size()]);
|
||||
} else {
|
||||
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].",
|
||||
parser.getTokenLocation());
|
||||
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token
|
||||
+ " in [" + currentFieldName + "].", parser.getTokenLocation());
|
||||
}
|
||||
} else if (token == XContentParser.Token.VALUE_STRING) {
|
||||
if (context.getParseFieldMatcher().match(currentFieldName, INCLUDES_FIELD)) {
|
||||
|
@ -65,7 +65,8 @@ public class FastVectorHighlighter implements Highlighter {
|
||||
FieldMapper mapper = highlighterContext.mapper;
|
||||
|
||||
if (canHighlight(mapper) == false) {
|
||||
throw new IllegalArgumentException("the field [" + highlighterContext.fieldName + "] should be indexed with term vector with position offsets to be used with fast vector highlighter");
|
||||
throw new IllegalArgumentException("the field [" + highlighterContext.fieldName
|
||||
+ "] should be indexed with term vector with position offsets to be used with fast vector highlighter");
|
||||
}
|
||||
|
||||
Encoder encoder = field.fieldOptions().encoder().equals("html") ? HighlightUtils.Encoders.HTML : HighlightUtils.Encoders.DEFAULT;
|
||||
@ -79,14 +80,22 @@ public class FastVectorHighlighter implements Highlighter {
|
||||
FieldQuery fieldQuery;
|
||||
if (field.fieldOptions().requireFieldMatch()) {
|
||||
if (cache.fieldMatchFieldQuery == null) {
|
||||
// we use top level reader to rewrite the query against all readers, with use caching it across hits (and across readers...)
|
||||
cache.fieldMatchFieldQuery = new CustomFieldQuery(highlighterContext.query, hitContext.topLevelReader(), true, field.fieldOptions().requireFieldMatch());
|
||||
/*
|
||||
* we use top level reader to rewrite the query against all readers, with use caching it across hits (and across
|
||||
* readers...)
|
||||
*/
|
||||
cache.fieldMatchFieldQuery = new CustomFieldQuery(highlighterContext.query, hitContext.topLevelReader(),
|
||||
true, field.fieldOptions().requireFieldMatch());
|
||||
}
|
||||
fieldQuery = cache.fieldMatchFieldQuery;
|
||||
} else {
|
||||
if (cache.noFieldMatchFieldQuery == null) {
|
||||
// we use top level reader to rewrite the query against all readers, with use caching it across hits (and across readers...)
|
||||
cache.noFieldMatchFieldQuery = new CustomFieldQuery(highlighterContext.query, hitContext.topLevelReader(), true, field.fieldOptions().requireFieldMatch());
|
||||
/*
|
||||
* we use top level reader to rewrite the query against all readers, with use caching it across hits (and across
|
||||
* readers...)
|
||||
*/
|
||||
cache.noFieldMatchFieldQuery = new CustomFieldQuery(highlighterContext.query, hitContext.topLevelReader(),
|
||||
true, field.fieldOptions().requireFieldMatch());
|
||||
}
|
||||
fieldQuery = cache.noFieldMatchFieldQuery;
|
||||
}
|
||||
@ -97,31 +106,40 @@ public class FastVectorHighlighter implements Highlighter {
|
||||
BaseFragmentsBuilder fragmentsBuilder;
|
||||
|
||||
BoundaryScanner boundaryScanner = DEFAULT_BOUNDARY_SCANNER;
|
||||
if (field.fieldOptions().boundaryMaxScan() != SimpleBoundaryScanner.DEFAULT_MAX_SCAN || field.fieldOptions().boundaryChars() != SimpleBoundaryScanner.DEFAULT_BOUNDARY_CHARS) {
|
||||
boundaryScanner = new SimpleBoundaryScanner(field.fieldOptions().boundaryMaxScan(), field.fieldOptions().boundaryChars());
|
||||
if (field.fieldOptions().boundaryMaxScan() != SimpleBoundaryScanner.DEFAULT_MAX_SCAN
|
||||
|| field.fieldOptions().boundaryChars() != SimpleBoundaryScanner.DEFAULT_BOUNDARY_CHARS) {
|
||||
boundaryScanner = new SimpleBoundaryScanner(field.fieldOptions().boundaryMaxScan(),
|
||||
field.fieldOptions().boundaryChars());
|
||||
}
|
||||
boolean forceSource = context.highlight().forceSource(field);
|
||||
if (field.fieldOptions().numberOfFragments() == 0) {
|
||||
fragListBuilder = new SingleFragListBuilder();
|
||||
|
||||
if (!forceSource && mapper.fieldType().stored()) {
|
||||
fragmentsBuilder = new SimpleFragmentsBuilder(mapper, field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner);
|
||||
fragmentsBuilder = new SimpleFragmentsBuilder(mapper, field.fieldOptions().preTags(),
|
||||
field.fieldOptions().postTags(), boundaryScanner);
|
||||
} else {
|
||||
fragmentsBuilder = new SourceSimpleFragmentsBuilder(mapper, context, field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner);
|
||||
fragmentsBuilder = new SourceSimpleFragmentsBuilder(mapper, context,
|
||||
field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner);
|
||||
}
|
||||
} else {
|
||||
fragListBuilder = field.fieldOptions().fragmentOffset() == -1 ? new SimpleFragListBuilder() : new SimpleFragListBuilder(field.fieldOptions().fragmentOffset());
|
||||
fragListBuilder = field.fieldOptions().fragmentOffset() == -1 ?
|
||||
new SimpleFragListBuilder() : new SimpleFragListBuilder(field.fieldOptions().fragmentOffset());
|
||||
if (field.fieldOptions().scoreOrdered()) {
|
||||
if (!forceSource && mapper.fieldType().stored()) {
|
||||
fragmentsBuilder = new ScoreOrderFragmentsBuilder(field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner);
|
||||
fragmentsBuilder = new ScoreOrderFragmentsBuilder(field.fieldOptions().preTags(),
|
||||
field.fieldOptions().postTags(), boundaryScanner);
|
||||
} else {
|
||||
fragmentsBuilder = new SourceScoreOrderFragmentsBuilder(mapper, context, field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner);
|
||||
fragmentsBuilder = new SourceScoreOrderFragmentsBuilder(mapper, context,
|
||||
field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner);
|
||||
}
|
||||
} else {
|
||||
if (!forceSource && mapper.fieldType().stored()) {
|
||||
fragmentsBuilder = new SimpleFragmentsBuilder(mapper, field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner);
|
||||
fragmentsBuilder = new SimpleFragmentsBuilder(mapper, field.fieldOptions().preTags(),
|
||||
field.fieldOptions().postTags(), boundaryScanner);
|
||||
} else {
|
||||
fragmentsBuilder = new SourceSimpleFragmentsBuilder(mapper, context, field.fieldOptions().preTags(), field.fieldOptions().postTags(), boundaryScanner);
|
||||
fragmentsBuilder = new SourceSimpleFragmentsBuilder(mapper, context, field.fieldOptions().preTags(),
|
||||
field.fieldOptions().postTags(), boundaryScanner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,16 +161,20 @@ public class FastVectorHighlighter implements Highlighter {
|
||||
String[] fragments;
|
||||
|
||||
// a HACK to make highlighter do highlighting, even though its using the single frag list builder
|
||||
int numberOfFragments = field.fieldOptions().numberOfFragments() == 0 ? Integer.MAX_VALUE : field.fieldOptions().numberOfFragments();
|
||||
int fragmentCharSize = field.fieldOptions().numberOfFragments() == 0 ? Integer.MAX_VALUE : field.fieldOptions().fragmentCharSize();
|
||||
int numberOfFragments = field.fieldOptions().numberOfFragments() == 0 ?
|
||||
Integer.MAX_VALUE : field.fieldOptions().numberOfFragments();
|
||||
int fragmentCharSize = field.fieldOptions().numberOfFragments() == 0 ?
|
||||
Integer.MAX_VALUE : field.fieldOptions().fragmentCharSize();
|
||||
// we highlight against the low level reader and docId, because if we load source, we want to reuse it if possible
|
||||
// Only send matched fields if they were requested to save time.
|
||||
if (field.fieldOptions().matchedFields() != null && !field.fieldOptions().matchedFields().isEmpty()) {
|
||||
fragments = cache.fvh.getBestFragments(fieldQuery, hitContext.reader(), hitContext.docId(), mapper.fieldType().name(), field.fieldOptions().matchedFields(), fragmentCharSize,
|
||||
numberOfFragments, entry.fragListBuilder, entry.fragmentsBuilder, field.fieldOptions().preTags(), field.fieldOptions().postTags(), encoder);
|
||||
fragments = cache.fvh.getBestFragments(fieldQuery, hitContext.reader(), hitContext.docId(), mapper.fieldType().name(),
|
||||
field.fieldOptions().matchedFields(), fragmentCharSize, numberOfFragments, entry.fragListBuilder,
|
||||
entry.fragmentsBuilder, field.fieldOptions().preTags(), field.fieldOptions().postTags(), encoder);
|
||||
} else {
|
||||
fragments = cache.fvh.getBestFragments(fieldQuery, hitContext.reader(), hitContext.docId(), mapper.fieldType().name(), fragmentCharSize,
|
||||
numberOfFragments, entry.fragListBuilder, entry.fragmentsBuilder, field.fieldOptions().preTags(), field.fieldOptions().postTags(), encoder);
|
||||
fragments = cache.fvh.getBestFragments(fieldQuery, hitContext.reader(), hitContext.docId(), mapper.fieldType().name(),
|
||||
fragmentCharSize, numberOfFragments, entry.fragListBuilder, entry.fragmentsBuilder, field.fieldOptions().preTags(),
|
||||
field.fieldOptions().postTags(), encoder);
|
||||
}
|
||||
|
||||
if (fragments != null && fragments.length > 0) {
|
||||
@ -180,14 +202,13 @@ public class FastVectorHighlighter implements Highlighter {
|
||||
|
||||
@Override
|
||||
public boolean canHighlight(FieldMapper fieldMapper) {
|
||||
return fieldMapper.fieldType().storeTermVectors() && fieldMapper.fieldType().storeTermVectorOffsets() && fieldMapper.fieldType().storeTermVectorPositions();
|
||||
return fieldMapper.fieldType().storeTermVectors() && fieldMapper.fieldType().storeTermVectorOffsets()
|
||||
&& fieldMapper.fieldType().storeTermVectorPositions();
|
||||
}
|
||||
|
||||
private class MapperHighlightEntry {
|
||||
public FragListBuilder fragListBuilder;
|
||||
public FragmentsBuilder fragmentsBuilder;
|
||||
|
||||
public org.apache.lucene.search.highlight.Highlighter highlighter;
|
||||
}
|
||||
|
||||
private class HighlighterEntry {
|
||||
|
@ -67,7 +67,8 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase {
|
||||
if (context.highlight().forceSource(field)) {
|
||||
SourceFieldMapper sourceFieldMapper = context.mapperService().documentMapper(hitContext.hit().type()).sourceMapper();
|
||||
if (!sourceFieldMapper.enabled()) {
|
||||
throw new IllegalArgumentException("source is forced for fields " + fieldNamesToHighlight + " but type [" + hitContext.hit().type() + "] has disabled _source");
|
||||
throw new IllegalArgumentException("source is forced for fields " + fieldNamesToHighlight
|
||||
+ " but type [" + hitContext.hit().type() + "] has disabled _source");
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,11 +106,16 @@ public class HighlightPhase extends AbstractComponent implements FetchSubPhase {
|
||||
}
|
||||
Highlighter highlighter = highlighters.get(highlighterType);
|
||||
if (highlighter == null) {
|
||||
throw new IllegalArgumentException("unknown highlighter type [" + highlighterType + "] for the field [" + fieldName + "]");
|
||||
throw new IllegalArgumentException("unknown highlighter type [" + highlighterType
|
||||
+ "] for the field [" + fieldName + "]");
|
||||
}
|
||||
|
||||
Query highlightQuery = field.fieldOptions().highlightQuery() == null ? context.parsedQuery().query() : field.fieldOptions().highlightQuery();
|
||||
HighlighterContext highlighterContext = new HighlighterContext(fieldName, field, fieldMapper, context, hitContext, highlightQuery);
|
||||
Query highlightQuery = field.fieldOptions().highlightQuery();
|
||||
if (highlightQuery == null) {
|
||||
highlightQuery = context.parsedQuery().query();
|
||||
}
|
||||
HighlighterContext highlighterContext = new HighlighterContext(fieldName, field, fieldMapper, context,
|
||||
hitContext, highlightQuery);
|
||||
|
||||
if ((highlighter.canHighlight(fieldMapper) == false) && fieldNameContainsWildcards) {
|
||||
// if several fieldnames matched the wildcard then we want to skip those that we cannot highlight
|
||||
|
@ -43,7 +43,11 @@ public final class HighlightUtils {
|
||||
|
||||
}
|
||||
|
||||
static List<Object> loadFieldValues(SearchContextHighlight.Field field, FieldMapper mapper, SearchContext searchContext, FetchSubPhase.HitContext hitContext) throws IOException {
|
||||
/**
|
||||
* Load field values for highlighting.
|
||||
*/
|
||||
public static List<Object> loadFieldValues(SearchContextHighlight.Field field, FieldMapper mapper, SearchContext searchContext,
|
||||
FetchSubPhase.HitContext hitContext) throws IOException {
|
||||
//percolator needs to always load from source, thus it sets the global force source to true
|
||||
boolean forceSource = searchContext.highlight().forceSource(field);
|
||||
List<Object> textsToHighlight;
|
||||
@ -65,7 +69,7 @@ public final class HighlightUtils {
|
||||
}
|
||||
|
||||
static class Encoders {
|
||||
static Encoder DEFAULT = new DefaultEncoder();
|
||||
static Encoder HTML = new SimpleHTMLEncoder();
|
||||
static final Encoder DEFAULT = new DefaultEncoder();
|
||||
static final Encoder HTML = new SimpleHTMLEncoder();
|
||||
}
|
||||
}
|
||||
|
@ -68,11 +68,13 @@ public class PlainHighlighter implements Highlighter {
|
||||
hitContext.cache().put(CACHE_KEY, mappers);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<FieldMapper, org.apache.lucene.search.highlight.Highlighter> cache = (Map<FieldMapper, org.apache.lucene.search.highlight.Highlighter>) hitContext.cache().get(CACHE_KEY);
|
||||
Map<FieldMapper, org.apache.lucene.search.highlight.Highlighter> cache =
|
||||
(Map<FieldMapper, org.apache.lucene.search.highlight.Highlighter>) hitContext.cache().get(CACHE_KEY);
|
||||
|
||||
org.apache.lucene.search.highlight.Highlighter entry = cache.get(mapper);
|
||||
if (entry == null) {
|
||||
QueryScorer queryScorer = new CustomQueryScorer(highlighterContext.query, field.fieldOptions().requireFieldMatch() ? mapper.fieldType().name() : null);
|
||||
QueryScorer queryScorer = new CustomQueryScorer(highlighterContext.query,
|
||||
field.fieldOptions().requireFieldMatch() ? mapper.fieldType().name() : null);
|
||||
queryScorer.setExpandMultiTermQuery(true);
|
||||
Fragmenter fragmenter;
|
||||
if (field.fieldOptions().numberOfFragments() == 0) {
|
||||
@ -84,7 +86,8 @@ public class PlainHighlighter implements Highlighter {
|
||||
} else if ("span".equals(field.fieldOptions().fragmenter())) {
|
||||
fragmenter = new SimpleSpanFragmenter(queryScorer, field.fieldOptions().fragmentCharSize());
|
||||
} else {
|
||||
throw new IllegalArgumentException("unknown fragmenter option [" + field.fieldOptions().fragmenter() + "] for the field [" + highlighterContext.fieldName + "]");
|
||||
throw new IllegalArgumentException("unknown fragmenter option [" + field.fieldOptions().fragmenter()
|
||||
+ "] for the field [" + highlighterContext.fieldName + "]");
|
||||
}
|
||||
Formatter formatter = new SimpleHTMLFormatter(field.fieldOptions().preTags()[0], field.fieldOptions().postTags()[0]);
|
||||
|
||||
@ -181,7 +184,8 @@ public class PlainHighlighter implements Highlighter {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int findGoodEndForNoHighlightExcerpt(int noMatchSize, Analyzer analyzer, String fieldName, String contents) throws IOException {
|
||||
private static int findGoodEndForNoHighlightExcerpt(int noMatchSize, Analyzer analyzer, String fieldName, String contents)
|
||||
throws IOException {
|
||||
try (TokenStream tokenStream = analyzer.tokenStream(fieldName, contents)) {
|
||||
if (!tokenStream.hasAttribute(OffsetAttribute.class)) {
|
||||
// Can't split on term boundaries without offsets
|
||||
|
@ -33,6 +33,7 @@ import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.search.fetch.FetchPhaseExecutionException;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhase;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightUtils.Encoders;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.BreakIterator;
|
||||
@ -53,7 +54,8 @@ public class PostingsHighlighter implements Highlighter {
|
||||
FieldMapper fieldMapper = highlighterContext.mapper;
|
||||
SearchContextHighlight.Field field = highlighterContext.field;
|
||||
if (canHighlight(fieldMapper) == false) {
|
||||
throw new IllegalArgumentException("the field [" + highlighterContext.fieldName + "] should be indexed with positions and offsets in the postings list to be used with postings highlighter");
|
||||
throw new IllegalArgumentException("the field [" + highlighterContext.fieldName
|
||||
+ "] should be indexed with positions and offsets in the postings list to be used with postings highlighter");
|
||||
}
|
||||
|
||||
SearchContext context = highlighterContext.context;
|
||||
@ -67,8 +69,9 @@ public class PostingsHighlighter implements Highlighter {
|
||||
MapperHighlighterEntry mapperHighlighterEntry = highlighterEntry.mappers.get(fieldMapper);
|
||||
|
||||
if (mapperHighlighterEntry == null) {
|
||||
Encoder encoder = field.fieldOptions().encoder().equals("html") ? HighlightUtils.Encoders.HTML : HighlightUtils.Encoders.DEFAULT;
|
||||
CustomPassageFormatter passageFormatter = new CustomPassageFormatter(field.fieldOptions().preTags()[0], field.fieldOptions().postTags()[0], encoder);
|
||||
Encoder encoder = field.fieldOptions().encoder().equals("html") ? Encoders.HTML : Encoders.DEFAULT;
|
||||
CustomPassageFormatter passageFormatter = new CustomPassageFormatter(
|
||||
field.fieldOptions().preTags()[0], field.fieldOptions().postTags()[0], encoder);
|
||||
mapperHighlighterEntry = new MapperHighlighterEntry(passageFormatter);
|
||||
}
|
||||
|
||||
@ -83,17 +86,20 @@ public class PostingsHighlighter implements Highlighter {
|
||||
//so we don't lose the distinction between the different values of a field and we get back a snippet per value
|
||||
String fieldValue = mergeFieldValues(fieldValues, HighlightUtils.NULL_SEPARATOR);
|
||||
CustomSeparatorBreakIterator breakIterator = new CustomSeparatorBreakIterator(HighlightUtils.NULL_SEPARATOR);
|
||||
highlighter = new CustomPostingsHighlighter(analyzer, mapperHighlighterEntry.passageFormatter, breakIterator, fieldValue, field.fieldOptions().noMatchSize() > 0);
|
||||
highlighter = new CustomPostingsHighlighter(analyzer, mapperHighlighterEntry.passageFormatter, breakIterator,
|
||||
fieldValue, field.fieldOptions().noMatchSize() > 0);
|
||||
numberOfFragments = fieldValues.size(); //we are highlighting the whole content, one snippet per value
|
||||
} else {
|
||||
//using paragraph separator we make sure that each field value holds a discrete passage for highlighting
|
||||
String fieldValue = mergeFieldValues(fieldValues, HighlightUtils.PARAGRAPH_SEPARATOR);
|
||||
highlighter = new CustomPostingsHighlighter(analyzer, mapperHighlighterEntry.passageFormatter, fieldValue, field.fieldOptions().noMatchSize() > 0);
|
||||
highlighter = new CustomPostingsHighlighter(analyzer, mapperHighlighterEntry.passageFormatter,
|
||||
fieldValue, field.fieldOptions().noMatchSize() > 0);
|
||||
numberOfFragments = field.fieldOptions().numberOfFragments();
|
||||
}
|
||||
|
||||
IndexSearcher searcher = new IndexSearcher(hitContext.reader());
|
||||
Snippet[] fieldSnippets = highlighter.highlightField(fieldMapper.fieldType().name(), highlighterContext.query, searcher, hitContext.docId(), numberOfFragments);
|
||||
Snippet[] fieldSnippets = highlighter.highlightField(fieldMapper.fieldType().name(), highlighterContext.query, searcher,
|
||||
hitContext.docId(), numberOfFragments);
|
||||
for (Snippet fieldSnippet : fieldSnippets) {
|
||||
if (Strings.hasText(fieldSnippet.getText())) {
|
||||
snippets.add(fieldSnippet);
|
||||
|
@ -40,6 +40,7 @@ public class SimpleFragmentsBuilder extends org.apache.lucene.search.vectorhighl
|
||||
@Override
|
||||
protected String makeFragment( StringBuilder buffer, int[] index, Field[] values, WeightedFragInfo fragInfo,
|
||||
String[] preTags, String[] postTags, Encoder encoder ){
|
||||
return super.makeFragment(buffer, index, values, FragmentBuilderHelper.fixWeightedFragInfo(mapper, values, fragInfo), preTags, postTags, encoder);
|
||||
return super.makeFragment(buffer, index, values, FragmentBuilderHelper.fixWeightedFragInfo(mapper, values, fragInfo),
|
||||
preTags, postTags, encoder);
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ public class SourceScoreOrderFragmentsBuilder extends ScoreOrderFragmentsBuilder
|
||||
@Override
|
||||
protected String makeFragment( StringBuilder buffer, int[] index, Field[] values, WeightedFragInfo fragInfo,
|
||||
String[] preTags, String[] postTags, Encoder encoder ){
|
||||
return super.makeFragment(buffer, index, values, FragmentBuilderHelper.fixWeightedFragInfo(mapper, values, fragInfo), preTags, postTags, encoder);
|
||||
return super.makeFragment(buffer, index, values, FragmentBuilderHelper.fixWeightedFragInfo(mapper, values, fragInfo),
|
||||
preTags, postTags, encoder);
|
||||
}
|
||||
}
|
||||
|
@ -17,18 +17,17 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.innerhits;
|
||||
package org.elasticsearch.search.fetch.subphase;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.InnerHitBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockScriptEngine;
|
||||
import org.elasticsearch.script.MockScriptPlugin;
|
||||
@ -36,7 +35,6 @@ import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
@ -168,14 +166,16 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
new InnerHitBuilder().setHighlightBuilder(new HighlightBuilder().field("comments.message"))
|
||||
.setExplain(true)
|
||||
.addDocValueField("comments.message")
|
||||
.addScriptField("script", new Script("5", ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap()))
|
||||
.addScriptField("script",
|
||||
new Script("5", ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap()))
|
||||
.setSize(1)
|
||||
)).get();
|
||||
assertNoFailures(response);
|
||||
innerHits = response.getHits().getAt(0).getInnerHits().get("comments");
|
||||
assertThat(innerHits.getTotalHits(), equalTo(2L));
|
||||
assertThat(innerHits.getHits().length, equalTo(1));
|
||||
assertThat(innerHits.getAt(0).getHighlightFields().get("comments.message").getFragments()[0].string(), equalTo("<em>fox</em> eat quick"));
|
||||
assertThat(innerHits.getAt(0).getHighlightFields().get("comments.message").getFragments()[0].string(),
|
||||
equalTo("<em>fox</em> eat quick"));
|
||||
assertThat(innerHits.getAt(0).explanation().toString(), containsString("weight(comments.message:fox in"));
|
||||
assertThat(innerHits.getAt(0).getFields().get("comments.message").getValue().toString(), equalTo("eat"));
|
||||
assertThat(innerHits.getAt(0).getFields().get("script").getValue().toString(), equalTo("5"));
|
||||
@ -334,12 +334,14 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
int numChildDocs = child1InnerObjects[parent] = scaledRandomIntBetween(1, numDocs);
|
||||
int limit = child1 + numChildDocs;
|
||||
for (; child1 < limit; child1++) {
|
||||
requestBuilders.add(client().prepareIndex("idx", "child1", String.format(Locale.ENGLISH, "%04d", child1)).setParent(parentId).setSource("{}"));
|
||||
requestBuilders.add(client().prepareIndex("idx", "child1",
|
||||
String.format(Locale.ENGLISH, "%04d", child1)).setParent(parentId).setSource("{}"));
|
||||
}
|
||||
numChildDocs = child2InnerObjects[parent] = scaledRandomIntBetween(1, numDocs);
|
||||
limit = child2 + numChildDocs;
|
||||
for (; child2 < limit; child2++) {
|
||||
requestBuilders.add(client().prepareIndex("idx", "child2", String.format(Locale.ENGLISH, "%04d", child2)).setParent(parentId).setSource("{}"));
|
||||
requestBuilders.add(client().prepareIndex("idx", "child2",
|
||||
String.format(Locale.ENGLISH, "%04d", child2)).setParent(parentId).setSource("{}"));
|
||||
}
|
||||
}
|
||||
indexRandom(true, requestBuilders);
|
||||
@ -399,10 +401,14 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
.addMapping("answer", "_parent", "type=question", "body", "type=text")
|
||||
);
|
||||
List<IndexRequestBuilder> requests = new ArrayList<>();
|
||||
requests.add(client().prepareIndex("stack", "question", "1").setSource("body", "I'm using HTTPS + Basic authentication to protect a resource. How can I throttle authentication attempts to protect against brute force attacks?"));
|
||||
requests.add(client().prepareIndex("stack", "answer", "1").setParent("1").setSource("body", "install fail2ban and enable rules for apache"));
|
||||
requests.add(client().prepareIndex("stack", "question", "2").setSource("body", "I have firewall rules set up and also denyhosts installed.\\ndo I also need to install fail2ban?"));
|
||||
requests.add(client().prepareIndex("stack", "answer", "2").setParent("2").setSource("body", "Denyhosts protects only ssh; Fail2Ban protects all daemons."));
|
||||
requests.add(client().prepareIndex("stack", "question", "1").setSource("body", "I'm using HTTPS + Basic authentication "
|
||||
+ "to protect a resource. How can I throttle authentication attempts to protect against brute force attacks?"));
|
||||
requests.add(client().prepareIndex("stack", "answer", "1").setParent("1").setSource("body",
|
||||
"install fail2ban and enable rules for apache"));
|
||||
requests.add(client().prepareIndex("stack", "question", "2").setSource("body",
|
||||
"I have firewall rules set up and also denyhosts installed.\\ndo I also need to install fail2ban?"));
|
||||
requests.add(client().prepareIndex("stack", "answer", "2").setParent("2").setSource("body",
|
||||
"Denyhosts protects only ssh; Fail2Ban protects all daemons."));
|
||||
indexRandom(true, requests);
|
||||
|
||||
SearchResponse response = client().prepareSearch("stack")
|
||||
@ -491,7 +497,8 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testNestedMultipleLayers() throws Exception {
|
||||
assertAcked(prepareCreate("articles").addMapping("article", jsonBuilder().startObject().startObject("article").startObject("properties")
|
||||
assertAcked(prepareCreate("articles").addMapping("article", jsonBuilder().startObject()
|
||||
.startObject("article").startObject("properties")
|
||||
.startObject("comments")
|
||||
.field("type", "nested")
|
||||
.startObject("properties")
|
||||
@ -560,8 +567,8 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
|
||||
// Directly refer to the second level:
|
||||
response = client().prepareSearch("articles")
|
||||
.setQuery(nestedQuery("comments.remarks", matchQuery("comments.remarks.message", "bad"), ScoreMode.Avg).innerHit(new InnerHitBuilder()))
|
||||
.get();
|
||||
.setQuery(nestedQuery("comments.remarks", matchQuery("comments.remarks.message", "bad"), ScoreMode.Avg)
|
||||
.innerHit(new InnerHitBuilder())).get();
|
||||
assertNoFailures(response);
|
||||
assertHitCount(response, 1);
|
||||
assertSearchHit(response, 1, hasId("2"));
|
||||
@ -621,7 +628,8 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
assertThat(response.getHits().getAt(0).id(), equalTo("1"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getTotalHits(), equalTo(1L));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).id(), equalTo("1"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getNestedIdentity().getField().string(), equalTo("comments"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getNestedIdentity().getField().string(),
|
||||
equalTo("comments"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getNestedIdentity().getOffset(), equalTo(0));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments").getAt(0).getNestedIdentity().getChild(), nullValue());
|
||||
}
|
||||
@ -654,28 +662,32 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
indexRandom(true, requests);
|
||||
|
||||
SearchResponse response = client().prepareSearch("articles")
|
||||
.setQuery(nestedQuery("comments.messages", matchQuery("comments.messages.message", "fox"), ScoreMode.Avg).innerHit(new InnerHitBuilder()))
|
||||
.get();
|
||||
.setQuery(nestedQuery("comments.messages", matchQuery("comments.messages.message", "fox"), ScoreMode.Avg)
|
||||
.innerHit(new InnerHitBuilder())).get();
|
||||
assertNoFailures(response);
|
||||
assertHitCount(response, 1);
|
||||
assertThat(response.getHits().getAt(0).id(), equalTo("1"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getTotalHits(), equalTo(1L));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).id(), equalTo("1"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).getNestedIdentity().getField().string(), equalTo("comments.messages"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).getNestedIdentity().getOffset(), equalTo(0));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).getNestedIdentity().getChild(), nullValue());
|
||||
SearchHit hit = response.getHits().getAt(0);
|
||||
assertThat(hit.id(), equalTo("1"));
|
||||
SearchHits messages = hit.getInnerHits().get("comments.messages");
|
||||
assertThat(messages.getTotalHits(), equalTo(1L));
|
||||
assertThat(messages.getAt(0).id(), equalTo("1"));
|
||||
assertThat(messages.getAt(0).getNestedIdentity().getField().string(), equalTo("comments.messages"));
|
||||
assertThat(messages.getAt(0).getNestedIdentity().getOffset(), equalTo(0));
|
||||
assertThat(messages.getAt(0).getNestedIdentity().getChild(), nullValue());
|
||||
|
||||
response = client().prepareSearch("articles")
|
||||
.setQuery(nestedQuery("comments.messages", matchQuery("comments.messages.message", "bear"), ScoreMode.Avg).innerHit(new InnerHitBuilder()))
|
||||
.get();
|
||||
.setQuery(nestedQuery("comments.messages", matchQuery("comments.messages.message", "bear"), ScoreMode.Avg)
|
||||
.innerHit(new InnerHitBuilder())).get();
|
||||
assertNoFailures(response);
|
||||
assertHitCount(response, 1);
|
||||
assertThat(response.getHits().getAt(0).id(), equalTo("1"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getTotalHits(), equalTo(1L));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).id(), equalTo("1"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).getNestedIdentity().getField().string(), equalTo("comments.messages"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).getNestedIdentity().getOffset(), equalTo(1));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).getNestedIdentity().getChild(), nullValue());
|
||||
hit = response.getHits().getAt(0);
|
||||
assertThat(hit.id(), equalTo("1"));
|
||||
messages = hit.getInnerHits().get("comments.messages");
|
||||
assertThat(messages.getTotalHits(), equalTo(1L));
|
||||
assertThat(messages.getAt(0).id(), equalTo("1"));
|
||||
assertThat(messages.getAt(0).getNestedIdentity().getField().string(), equalTo("comments.messages"));
|
||||
assertThat(messages.getAt(0).getNestedIdentity().getOffset(), equalTo(1));
|
||||
assertThat(messages.getAt(0).getNestedIdentity().getChild(), nullValue());
|
||||
|
||||
// index the message in an object form instead of an array
|
||||
requests = new ArrayList<>();
|
||||
@ -685,16 +697,18 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
.endObject()));
|
||||
indexRandom(true, requests);
|
||||
response = client().prepareSearch("articles")
|
||||
.setQuery(nestedQuery("comments.messages", matchQuery("comments.messages.message", "fox"), ScoreMode.Avg).innerHit(new InnerHitBuilder()))
|
||||
.get();
|
||||
.setQuery(nestedQuery("comments.messages", matchQuery("comments.messages.message", "fox"), ScoreMode.Avg)
|
||||
.innerHit(new InnerHitBuilder())).get();
|
||||
assertNoFailures(response);
|
||||
assertHitCount(response, 1);
|
||||
assertThat(response.getHits().getAt(0).id(), equalTo("1"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getTotalHits(), equalTo(1L));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).id(), equalTo("1"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).getNestedIdentity().getField().string(), equalTo("comments.messages"));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).getNestedIdentity().getOffset(), equalTo(0));
|
||||
assertThat(response.getHits().getAt(0).getInnerHits().get("comments.messages").getAt(0).getNestedIdentity().getChild(), nullValue());
|
||||
hit = response.getHits().getAt(0);;
|
||||
assertThat(hit.id(), equalTo("1"));
|
||||
messages = hit.getInnerHits().get("comments.messages");
|
||||
assertThat(messages.getTotalHits(), equalTo(1L));
|
||||
assertThat(messages.getAt(0).id(), equalTo("1"));
|
||||
assertThat(messages.getAt(0).getNestedIdentity().getField().string(), equalTo("comments.messages"));
|
||||
assertThat(messages.getAt(0).getNestedIdentity().getOffset(), equalTo(0));
|
||||
assertThat(messages.getAt(0).getNestedIdentity().getChild(), nullValue());
|
||||
}
|
||||
|
||||
public void testRoyals() throws Exception {
|
||||
@ -841,12 +855,14 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
indexRandom(true, requests);
|
||||
waitForRelocation(ClusterHealthStatus.GREEN);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test")
|
||||
.setQuery(nestedQuery("nested1", boolQuery()
|
||||
QueryBuilder query = boolQuery()
|
||||
.should(termQuery("nested1.n_field1", "n_value1_1").queryName("test1"))
|
||||
.should(termQuery("nested1.n_field1", "n_value1_3").queryName("test2"))
|
||||
.should(termQuery("nested1.n_field2", "n_value2_2").queryName("test3")),
|
||||
ScoreMode.Avg).innerHit(new InnerHitBuilder().addSort(new FieldSortBuilder("nested1.n_field1").order(SortOrder.ASC))))
|
||||
.should(termQuery("nested1.n_field2", "n_value2_2").queryName("test3"));
|
||||
query = nestedQuery("nested1", query, ScoreMode.Avg).innerHit(
|
||||
new InnerHitBuilder().addSort(new FieldSortBuilder("nested1.n_field1").order(SortOrder.ASC)));
|
||||
SearchResponse searchResponse = client().prepareSearch("test")
|
||||
.setQuery(query)
|
||||
.setSize(numDocs)
|
||||
.addSort("field1", SortOrder.ASC)
|
||||
.get();
|
||||
@ -885,7 +901,8 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
indexRandom(true, requests);
|
||||
|
||||
SearchResponse response = client().prepareSearch("index")
|
||||
.setQuery(hasChildQuery("child", matchQuery("field", "value1").queryName("_name1"), ScoreMode.None).innerHit(new InnerHitBuilder()))
|
||||
.setQuery(hasChildQuery("child", matchQuery("field", "value1").queryName("_name1"), ScoreMode.None)
|
||||
.innerHit(new InnerHitBuilder()))
|
||||
.addSort("_uid", SortOrder.ASC)
|
||||
.get();
|
||||
assertHitCount(response, 2);
|
||||
@ -899,8 +916,10 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
assertThat(response.getHits().getAt(1).getInnerHits().get("child").getAt(0).getMatchedQueries().length, equalTo(1));
|
||||
assertThat(response.getHits().getAt(1).getInnerHits().get("child").getAt(0).getMatchedQueries()[0], equalTo("_name1"));
|
||||
|
||||
QueryBuilder query = hasChildQuery("child", matchQuery("field", "value2").queryName("_name2"), ScoreMode.None)
|
||||
.innerHit(new InnerHitBuilder());
|
||||
response = client().prepareSearch("index")
|
||||
.setQuery(hasChildQuery("child", matchQuery("field", "value2").queryName("_name2"), ScoreMode.None).innerHit(new InnerHitBuilder()))
|
||||
.setQuery(query)
|
||||
.addSort("_uid", SortOrder.ASC)
|
||||
.get();
|
||||
assertHitCount(response, 1);
|
||||
@ -917,8 +936,10 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
requests.add(client().prepareIndex("index1", "child", "1").setParent("1").setSource("field", "value1"));
|
||||
indexRandom(true, requests);
|
||||
|
||||
QueryBuilder query = hasChildQuery("child", matchQuery("field", "value1"), ScoreMode.None)
|
||||
.innerHit(new InnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1));
|
||||
SearchResponse response = client().prepareSearch("index1")
|
||||
.setQuery(hasChildQuery("child", matchQuery("field", "value1"), ScoreMode.None).innerHit(new InnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1)))
|
||||
.setQuery(query)
|
||||
.addSort("_uid", SortOrder.ASC)
|
||||
.get();
|
||||
assertNoFailures(response);
|
||||
@ -935,8 +956,10 @@ public class InnerHitsIT extends ESIntegTestCase {
|
||||
.setRefreshPolicy(IMMEDIATE)
|
||||
.get();
|
||||
|
||||
query = nestedQuery("nested", matchQuery("nested.field", "value1"), ScoreMode.Avg)
|
||||
.innerHit(new InnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1));
|
||||
response = client().prepareSearch("index2")
|
||||
.setQuery(nestedQuery("nested", matchQuery("nested.field", "value1"), ScoreMode.Avg).innerHit(new InnerHitBuilder().setSize(ArrayUtil.MAX_ARRAY_LENGTH - 1)))
|
||||
.setQuery(query)
|
||||
.addSort("_uid", SortOrder.ASC)
|
||||
.get();
|
||||
assertNoFailures(response);
|
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.matchedqueries;
|
||||
package org.elasticsearch.search.fetch.subphase;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
@ -69,8 +69,10 @@ public class MatchedQueriesIT extends ESIntegTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
searchResponse = client().prepareSearch()
|
||||
.setQuery(boolQuery().should(rangeQuery("number").lte(2).queryName("test1")).should(rangeQuery("number").gt(2).queryName("test2"))).get();
|
||||
searchResponse = client().prepareSearch().setQuery(
|
||||
boolQuery()
|
||||
.should(rangeQuery("number").lte(2).queryName("test1"))
|
||||
.should(rangeQuery("number").gt(2).queryName("test2"))).get();
|
||||
assertHitCount(searchResponse, 3L);
|
||||
for (SearchHit hit : searchResponse.getHits()) {
|
||||
if (hit.id().equals("1") || hit.id().equals("2")) {
|
@ -19,6 +19,7 @@
|
||||
package org.elasticsearch.search.fetch.subphase.highlight;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
@ -38,14 +39,10 @@ import org.elasticsearch.index.query.Operator;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.search.MatchQuery;
|
||||
import org.elasticsearch.index.search.MatchQuery.Type;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightUtils;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder.Field;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
@ -245,7 +242,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
* query. We cut off and extract terms if there are more than 16 terms in the query
|
||||
*/
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("test", "body", "type=text,analyzer=custom_analyzer,search_analyzer=custom_analyzer,term_vector=with_positions_offsets")
|
||||
.addMapping("test",
|
||||
"body", "type=text,analyzer=custom_analyzer,search_analyzer=custom_analyzer,term_vector=with_positions_offsets")
|
||||
.setSettings(
|
||||
Settings.builder().put(indexSettings())
|
||||
.put("analysis.filter.wordDelimiter.type", "word_delimiter")
|
||||
@ -261,32 +259,33 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
|
||||
ensureGreen();
|
||||
client().prepareIndex("test", "test", "1")
|
||||
.setSource("body", "Test: http://www.facebook.com http://elasticsearch.org http://xing.com http://cnn.com http://quora.com http://twitter.com this is a test for highlighting feature Test: http://www.facebook.com http://elasticsearch.org http://xing.com http://cnn.com http://quora.com http://twitter.com this is a test for highlighting feature")
|
||||
.setSource("body", "Test: http://www.facebook.com http://elasticsearch.org http://xing.com "
|
||||
+ "http://cnn.com http://quora.com http://twitter.com this is a test for highlighting feature Test: "
|
||||
+ "http://www.facebook.com http://elasticsearch.org http://xing.com http://cnn.com http://quora.com "
|
||||
+ "http://twitter.com this is a test for highlighting feature")
|
||||
.get();
|
||||
refresh();
|
||||
SearchResponse search = client().prepareSearch().setQuery(matchQuery("body", "Test: http://www.facebook.com ").type(Type.PHRASE))
|
||||
SearchResponse search = client().prepareSearch().setQuery(matchPhraseQuery("body", "Test: http://www.facebook.com "))
|
||||
.highlighter(new HighlightBuilder().field("body")).execute().actionGet();
|
||||
assertHighlight(search, 0, "body", 0, startsWith("<em>Test: http://www.facebook.com</em>"));
|
||||
search = client()
|
||||
.prepareSearch()
|
||||
.setQuery(
|
||||
matchQuery(
|
||||
"body",
|
||||
"Test: http://www.facebook.com http://elasticsearch.org http://xing.com http://cnn.com http://quora.com http://twitter.com this is a test for highlighting feature Test: http://www.facebook.com http://elasticsearch.org http://xing.com http://cnn.com http://quora.com http://twitter.com this is a test for highlighting feature")
|
||||
.type(Type.PHRASE)).highlighter(new HighlightBuilder().field("body")).execute().actionGet();
|
||||
assertHighlight(
|
||||
search,
|
||||
0,
|
||||
"body",
|
||||
0,
|
||||
equalTo("<em>Test</em>: <em>http://www.facebook.com</em> <em>http://elasticsearch.org</em> <em>http://xing.com</em> <em>http://cnn.com</em> http://quora.com"));
|
||||
.setQuery(matchPhraseQuery("body", "Test: http://www.facebook.com http://elasticsearch.org http://xing.com "
|
||||
+ "http://cnn.com http://quora.com http://twitter.com this is a test for highlighting feature Test: "
|
||||
+ "http://www.facebook.com http://elasticsearch.org http://xing.com http://cnn.com http://quora.com "
|
||||
+ "http://twitter.com this is a test for highlighting feature"))
|
||||
.highlighter(new HighlightBuilder().field("body")).execute().actionGet();
|
||||
assertHighlight(search, 0, "body", 0, equalTo("<em>Test</em>: <em>http://www.facebook.com</em> "
|
||||
+ "<em>http://elasticsearch.org</em> <em>http://xing.com</em> <em>http://cnn.com</em> http://quora.com"));
|
||||
}
|
||||
|
||||
public void testNgramHighlighting() throws IOException {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("test",
|
||||
"name", "type=text,analyzer=name_index_analyzer,search_analyzer=name_search_analyzer,term_vector=with_positions_offsets",
|
||||
"name2", "type=text,analyzer=name2_index_analyzer,search_analyzer=name_search_analyzer,term_vector=with_positions_offsets")
|
||||
"name", "type=text,analyzer=name_index_analyzer,search_analyzer=name_search_analyzer,"
|
||||
+ "term_vector=with_positions_offsets",
|
||||
"name2", "type=text,analyzer=name2_index_analyzer,search_analyzer=name_search_analyzer,"
|
||||
+ "term_vector=with_positions_offsets")
|
||||
.setSettings(Settings.builder()
|
||||
.put(indexSettings())
|
||||
.put("analysis.filter.my_ngram.max_gram", 20)
|
||||
@ -307,7 +306,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
ensureGreen();
|
||||
SearchResponse search = client().prepareSearch().setQuery(matchQuery("name", "logica m"))
|
||||
.highlighter(new HighlightBuilder().field("name")).get();
|
||||
assertHighlight(search, 0, "name", 0, equalTo("<em>logica</em>c<em>m</em>g ehe<em>m</em>als avinci - the know how co<em>m</em>pany"));
|
||||
assertHighlight(search, 0, "name", 0,
|
||||
equalTo("<em>logica</em>c<em>m</em>g ehe<em>m</em>als avinci - the know how co<em>m</em>pany"));
|
||||
|
||||
search = client().prepareSearch().setQuery(matchQuery("name", "logica ma")).highlighter(new HighlightBuilder().field("name")).get();
|
||||
assertHighlight(search, 0, "name", 0, equalTo("<em>logica</em>cmg ehe<em>ma</em>ls avinci - the know how company"));
|
||||
@ -335,7 +335,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
|
||||
client().prepareIndex("test", "type1", "1")
|
||||
.setSource("no_long_term", "This is a test where foo is highlighed and should be highlighted",
|
||||
"long_term", "This is a test thisisaverylongwordandmakessurethisfails where foo is highlighed and should be highlighted")
|
||||
"long_term", "This is a test thisisaverylongwordandmakessurethisfails where foo is highlighed "
|
||||
+ "and should be highlighted")
|
||||
.get();
|
||||
refresh();
|
||||
|
||||
@ -346,13 +347,13 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertHighlight(search, 0, "long_term", 0, 1, equalTo("<em>thisisaverylongwordandmakessurethisfails</em>"));
|
||||
|
||||
search = client().prepareSearch()
|
||||
.setQuery(matchQuery("no_long_term", "test foo highlighed").type(Type.PHRASE).slop(3))
|
||||
.setQuery(matchPhraseQuery("no_long_term", "test foo highlighed").slop(3))
|
||||
.highlighter(new HighlightBuilder().field("no_long_term", 18, 1).postTags("</b>").preTags("<b>"))
|
||||
.get();
|
||||
assertNotHighlighted(search, 0, "no_long_term");
|
||||
|
||||
search = client().prepareSearch()
|
||||
.setQuery(matchQuery("no_long_term", "test foo highlighed").type(Type.PHRASE).slop(3))
|
||||
.setQuery(matchPhraseQuery("no_long_term", "test foo highlighed").slop(3))
|
||||
.highlighter(new HighlightBuilder().field("no_long_term", 30, 1).postTags("</b>").preTags("<b>"))
|
||||
.get();
|
||||
|
||||
@ -363,8 +364,17 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
// we don't store title and don't use term vector, now lets see if it works...
|
||||
.startObject("title").field("type", "text").field("store", false).field("term_vector", "no").endObject()
|
||||
.startObject("attachments").startObject("properties").startObject("body").field("type", "text").field("store", false).field("term_vector", "no").endObject().endObject().endObject()
|
||||
.startObject("title")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("term_vector", "no")
|
||||
.endObject()
|
||||
.startObject("attachments").startObject("properties")
|
||||
.startObject("body")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("term_vector", "no")
|
||||
.endObject().endObject().endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
|
||||
IndexRequestBuilder[] indexRequestBuilders = new IndexRequestBuilder[5];
|
||||
@ -372,8 +382,10 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
indexRequestBuilders[i] = client().prepareIndex("test", "type1", Integer.toString(i))
|
||||
.setSource(XContentFactory.jsonBuilder().startObject()
|
||||
.field("title", "This is a test on the highlighting bug present in elasticsearch")
|
||||
.startArray("attachments").startObject().field("body", "attachment 1").endObject().startObject().field("body", "attachment 2").endObject().endArray()
|
||||
.endObject());
|
||||
.startArray("attachments")
|
||||
.startObject().field("body", "attachment 1").endObject()
|
||||
.startObject().field("body", "attachment 2").endObject()
|
||||
.endArray().endObject());
|
||||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
|
||||
@ -401,8 +413,20 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
// we don't store title, now lets see if it works...
|
||||
.startObject("title").field("type", "text").field("store", false).field("term_vector", "with_positions_offsets").endObject()
|
||||
.startObject("attachments").startObject("properties").startObject("body").field("type", "text").field("store", false).field("term_vector", "with_positions_offsets").endObject().endObject().endObject()
|
||||
.startObject("title")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("term_vector", "with_positions_offsets")
|
||||
.endObject()
|
||||
.startObject("attachments")
|
||||
.startObject("properties")
|
||||
.startObject("body")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("term_vector", "with_positions_offsets")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
|
||||
IndexRequestBuilder[] indexRequestBuilders = new IndexRequestBuilder[5];
|
||||
@ -410,8 +434,10 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
indexRequestBuilders[i] = client().prepareIndex("test", "type1", Integer.toString(i))
|
||||
.setSource(XContentFactory.jsonBuilder().startObject()
|
||||
.field("title", "This is a test on the highlighting bug present in elasticsearch")
|
||||
.startArray("attachments").startObject().field("body", "attachment 1").endObject().startObject().field("body", "attachment 2").endObject().endArray()
|
||||
.endObject());
|
||||
.startArray("attachments")
|
||||
.startObject().field("body", "attachment 1").endObject()
|
||||
.startObject().field("body", "attachment 2").endObject()
|
||||
.endArray().endObject());
|
||||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
|
||||
@ -439,8 +465,20 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
// we don't store title, now lets see if it works...
|
||||
.startObject("title").field("type", "text").field("store", false).field("index_options", "offsets").endObject()
|
||||
.startObject("attachments").startObject("properties").startObject("body").field("type", "text").field("store", false).field("index_options", "offsets").endObject().endObject().endObject()
|
||||
.startObject("title")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("index_options", "offsets")
|
||||
.endObject()
|
||||
.startObject("attachments")
|
||||
.startObject("properties")
|
||||
.startObject("body")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("index_options", "offsets")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
|
||||
IndexRequestBuilder[] indexRequestBuilders = new IndexRequestBuilder[5];
|
||||
@ -449,8 +487,10 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.setSource(XContentFactory.jsonBuilder().startObject()
|
||||
.array("title", "This is a test on the highlighting bug present in elasticsearch. Hopefully it works.",
|
||||
"This is the second bug to perform highlighting on.")
|
||||
.startArray("attachments").startObject().field("body", "attachment for this test").endObject().startObject().field("body", "attachment 2").endObject().endArray()
|
||||
.endObject());
|
||||
.startArray("attachments")
|
||||
.startObject().field("body", "attachment for this test").endObject()
|
||||
.startObject().field("body", "attachment 2").endObject()
|
||||
.endArray().endObject());
|
||||
}
|
||||
indexRandom(true, indexRequestBuilders);
|
||||
|
||||
@ -460,7 +500,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.highlighter(new HighlightBuilder().field("title", -1, 0)).get();
|
||||
|
||||
for (int i = 0; i < indexRequestBuilders.length; i++) {
|
||||
assertHighlight(search, i, "title", 0, equalTo("This is a test on the highlighting <em>bug</em> present in elasticsearch. Hopefully it works."));
|
||||
assertHighlight(search, i, "title", 0,
|
||||
equalTo("This is a test on the highlighting <em>bug</em> present in elasticsearch. Hopefully it works."));
|
||||
assertHighlight(search, i, "title", 1, 2, equalTo("This is the second <em>bug</em> to perform highlighting on."));
|
||||
}
|
||||
|
||||
@ -487,11 +528,12 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
|
||||
public void testHighlightIssue1994() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", "title", "type=text,store=false", "titleTV", "type=text,store=false,term_vector=with_positions_offsets"));
|
||||
.addMapping("type1",
|
||||
"title", "type=text,store=false",
|
||||
"titleTV", "type=text,store=false,term_vector=with_positions_offsets"));
|
||||
|
||||
indexRandom(false, client().prepareIndex("test", "type1", "1")
|
||||
.setSource("title", new String[]{"This is a test on the highlighting bug present in elasticsearch", "The bug is bugging us"},
|
||||
"titleTV", new String[]{"This is a test on the highlighting bug present in elasticsearch", "The bug is bugging us"}));
|
||||
String[] titles = new String[] {"This is a test on the highlighting bug present in elasticsearch", "The bug is bugging us"};
|
||||
indexRandom(false, client().prepareIndex("test", "type1", "1").setSource("title", titles, "titleTV", titles));
|
||||
|
||||
indexRandom(true, client().prepareIndex("test", "type1", "2")
|
||||
.setSource("titleTV", new String[]{"some text to highlight", "highlight other text"}));
|
||||
@ -529,7 +571,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.query(termQuery("field1", "test"))
|
||||
.highlighter(highlight().order("score").preTags("<global>").postTags("</global>").fragmentSize(1).numOfFragments(1)
|
||||
.field(new HighlightBuilder.Field("field1").numOfFragments(2))
|
||||
.field(new HighlightBuilder.Field("field2").preTags("<field2>").postTags("</field2>").fragmentSize(50).requireFieldMatch(false)));
|
||||
.field(new HighlightBuilder.Field("field2").preTags("<field2>").postTags("</field2>")
|
||||
.fragmentSize(50).requireFieldMatch(false)));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
@ -707,7 +750,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
logger.info("--> searching on _all, highlighting on field1");
|
||||
source = searchSource()
|
||||
.query(termQuery("_all", "test"))
|
||||
.highlighter(highlight().field("field1", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field1", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>")
|
||||
.requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
@ -716,7 +760,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
logger.info("--> searching on _all, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(termQuery("_all", "quick"))
|
||||
.highlighter(highlight().field("field2", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field2", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>")
|
||||
.requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
@ -725,7 +770,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
logger.info("--> searching on _all, highlighting on field2");
|
||||
source = searchSource()
|
||||
.query(prefixQuery("_all", "qui"))
|
||||
.highlighter(highlight().field("field2", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>").requireFieldMatch(false));
|
||||
.highlighter(highlight().field("field2", 100, 0).order("score").preTags("<xxx>").postTags("</xxx>")
|
||||
.requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
|
||||
@ -776,7 +822,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
logger.info("--> highlighting and searching on field1 with large phrase limit");
|
||||
source = searchSource()
|
||||
.query(termQuery("field1", "t"))
|
||||
.highlighter(highlight().highlighterType("fvh").field("field1", 20, 1).order("score").preTags("<xxx>").postTags("</xxx>").phraseLimit(30000));
|
||||
.highlighter(highlight().highlighterType("fvh").field("field1", 20, 1).order("score").preTags("<xxx>").postTags("</xxx>")
|
||||
.phraseLimit(30000));
|
||||
SearchResponse largePhraseLimit = client().search(searchRequest("test").source(source)).actionGet();
|
||||
assertHighlight(largePhraseLimit, 0, "field1", 0, 1, containsString("<xxx>t</xxx>"));
|
||||
|
||||
@ -1058,7 +1105,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.get();
|
||||
|
||||
for (int i = 0; i < indexRequestBuilders.length; i++) {
|
||||
assertHighlight(search, i, "title", 0, 1, equalTo("This is a html escaping highlighting <em>test</em> for *&? elasticsearch"));
|
||||
assertHighlight(search, i, "title", 0, 1,
|
||||
equalTo("This is a html escaping highlighting <em>test</em> for *&? elasticsearch"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1086,11 +1134,20 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
public void testMultiMapperVectorWithStore() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("title").field("type", "text").field("store", true).field("term_vector", "with_positions_offsets").field("analyzer", "classic")
|
||||
.startObject("title")
|
||||
.field("type", "text")
|
||||
.field("store", true)
|
||||
.field("term_vector", "with_positions_offsets")
|
||||
.field("analyzer", "classic")
|
||||
.startObject("fields")
|
||||
.startObject("key").field("type", "text").field("store", true).field("term_vector", "with_positions_offsets").field("analyzer", "whitespace").endObject()
|
||||
.endObject().endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
.startObject("key")
|
||||
.field("type", "text")
|
||||
.field("store", true)
|
||||
.field("term_vector", "with_positions_offsets")
|
||||
.field("analyzer", "whitespace")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().endObject().endObject()));
|
||||
ensureGreen();
|
||||
client().prepareIndex("test", "type1", "1").setSource("title", "this is a test").get();
|
||||
refresh();
|
||||
@ -1114,11 +1171,20 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
public void testMultiMapperVectorFromSource() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("title").field("type", "text").field("store", false).field("term_vector", "with_positions_offsets").field("analyzer", "classic")
|
||||
.startObject("title")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("term_vector", "with_positions_offsets")
|
||||
.field("analyzer", "classic")
|
||||
.startObject("fields")
|
||||
.startObject("key").field("type", "text").field("store", false).field("term_vector", "with_positions_offsets").field("analyzer", "whitespace").endObject()
|
||||
.endObject().endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
.startObject("key")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("term_vector", "with_positions_offsets")
|
||||
.field("analyzer", "whitespace")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().endObject().endObject()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1", "1").setSource("title", "this is a test").get();
|
||||
@ -1144,10 +1210,20 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
public void testMultiMapperNoVectorWithStore() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("title").field("type", "text").field("store", true).field("term_vector", "no").field("analyzer", "classic")
|
||||
.startObject("title")
|
||||
.field("type", "text")
|
||||
.field("store", true)
|
||||
.field("term_vector", "no")
|
||||
.field("analyzer", "classic")
|
||||
.startObject("fields")
|
||||
.startObject("key").field("type", "text").field("store", true).field("term_vector", "no").field("analyzer", "whitespace").endObject()
|
||||
.endObject().endObject()
|
||||
.startObject("key")
|
||||
.field("type", "text")
|
||||
.field("store", true)
|
||||
.field("term_vector", "no")
|
||||
.field("analyzer", "whitespace")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
|
||||
ensureGreen();
|
||||
@ -1174,10 +1250,20 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
public void testMultiMapperNoVectorFromSource() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("title").field("type", "text").field("store", false).field("term_vector", "no").field("analyzer", "classic")
|
||||
.startObject("title")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("term_vector", "no")
|
||||
.field("analyzer", "classic")
|
||||
.startObject("fields")
|
||||
.startObject("key").field("type", "text").field("store", false).field("term_vector", "no").field("analyzer", "whitespace").endObject()
|
||||
.endObject().endObject()
|
||||
.startObject("key")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("term_vector", "no")
|
||||
.field("analyzer", "whitespace")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
ensureGreen();
|
||||
client().prepareIndex("test", "type1", "1").setSource("title", "this is a test").get();
|
||||
@ -1222,7 +1308,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.setQuery(matchPhraseQuery("title", "this is a test"))
|
||||
.highlighter(new HighlightBuilder().field("title", 50, 1, 10).highlighterType("fvh")),
|
||||
RestStatus.BAD_REQUEST,
|
||||
containsString("the field [title] should be indexed with term vector with position offsets to be used with fast vector highlighter"));
|
||||
containsString("the field [title] should be indexed with term vector with position offsets to be "
|
||||
+ "used with fast vector highlighter"));
|
||||
|
||||
//should not fail if there is a wildcard
|
||||
assertNoFailures(client().prepareSearch()
|
||||
@ -1259,7 +1346,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.get();
|
||||
|
||||
for (int i = 0; i < indexRequestBuilders.length; i++) {
|
||||
assertHighlight(search, i, "title", 0, 1, equalTo("This is a <em>test</em> for the <em>workaround</em> for the fast vector highlighting SOLR-3724"));
|
||||
assertHighlight(search, i, "title", 0, 1,
|
||||
equalTo("This is a <em>test</em> for the <em>workaround</em> for the fast vector highlighting SOLR-3724"));
|
||||
}
|
||||
|
||||
// Using plain highlighter instead of FVH on the field level
|
||||
@ -1271,7 +1359,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.get();
|
||||
|
||||
for (int i = 0; i < indexRequestBuilders.length; i++) {
|
||||
assertHighlight(search, i, "title", 0, 1, equalTo("This is a <em>test</em> for the <em>workaround</em> for the fast vector highlighting SOLR-3724"));
|
||||
assertHighlight(search, i, "title", 0, 1,
|
||||
equalTo("This is a <em>test</em> for the <em>workaround</em> for the fast vector highlighting SOLR-3724"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1290,7 +1379,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.highlighter(new HighlightBuilder().field("tags", -1, 0)).get();
|
||||
|
||||
assertHighlight(response, 0, "tags", 0, equalTo("this is a really long <em>tag</em> i would like to highlight"));
|
||||
assertHighlight(response, 0, "tags", 1, 2, equalTo("here is another one that is very long and has the <em>tag</em> token near the end"));
|
||||
assertHighlight(response, 0, "tags", 1, 2,
|
||||
equalTo("here is another one that is very long and has the <em>tag</em> token near the end"));
|
||||
}
|
||||
|
||||
public void testBoostingQuery() {
|
||||
@ -1314,8 +1404,9 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
public void testBoostingQueryTermVector() throws IOException {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping()));
|
||||
ensureGreen();
|
||||
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog")
|
||||
.get();
|
||||
client().prepareIndex("test", "type1").setSource(
|
||||
"field1", "this is a test",
|
||||
"field2", "The quick brown fox jumps over the lazy dog").get();
|
||||
refresh();
|
||||
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
@ -1350,7 +1441,9 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog").get();
|
||||
client().prepareIndex("test", "type1").setSource(
|
||||
"field1", "this is a test",
|
||||
"field2", "The quick brown fox jumps over the lazy dog").get();
|
||||
refresh();
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource().query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100))
|
||||
@ -1375,10 +1468,10 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
"field3", "type=text,analyzer=synonym"));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1", "0")
|
||||
.setSource("field0", "The quick brown fox jumps over the lazy dog", "field1", "The quick brown fox jumps over the lazy dog").get();
|
||||
client().prepareIndex("test", "type1", "1")
|
||||
.setSource("field1", "The quick browse button is a fancy thing, right bro?").get();
|
||||
client().prepareIndex("test", "type1", "0").setSource(
|
||||
"field0", "The quick brown fox jumps over the lazy dog",
|
||||
"field1", "The quick brown fox jumps over the lazy dog").get();
|
||||
client().prepareIndex("test", "type1", "1").setSource("field1", "The quick browse button is a fancy thing, right bro?").get();
|
||||
refresh();
|
||||
logger.info("--> highlighting and searching on field0");
|
||||
SearchSourceBuilder source = searchSource()
|
||||
@ -1396,16 +1489,21 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, anyOf(equalTo("The <x>quick browse</x> button is a fancy thing, right bro?"), equalTo("The <x>quick brown</x> fox jumps over the lazy dog")));
|
||||
assertHighlight(searchResponse, 1, "field1", 0, 1, anyOf(equalTo("The <x>quick browse</x> button is a fancy thing, right bro?"), equalTo("The <x>quick brown</x> fox jumps over the lazy dog")));
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, anyOf(
|
||||
equalTo("The <x>quick browse</x> button is a fancy thing, right bro?"),
|
||||
equalTo("The <x>quick brown</x> fox jumps over the lazy dog")));
|
||||
assertHighlight(searchResponse, 1, "field1", 0, 1, anyOf(
|
||||
equalTo("The <x>quick browse</x> button is a fancy thing, right bro?"),
|
||||
equalTo("The <x>quick brown</x> fox jumps over the lazy dog")));
|
||||
|
||||
// with synonyms
|
||||
client().prepareIndex("test", "type2", "0")
|
||||
.setSource("field4", "The quick brown fox jumps over the lazy dog", "field3", "The quick brown fox jumps over the lazy dog").get();
|
||||
client().prepareIndex("test", "type2", "1")
|
||||
.setSource("field4", "The quick browse button is a fancy thing, right bro?").get();
|
||||
client().prepareIndex("test", "type2", "2")
|
||||
.setSource("field4", "a quick fast blue car").get();
|
||||
client().prepareIndex("test", "type2", "0").setSource(
|
||||
"field4", "The quick brown fox jumps over the lazy dog",
|
||||
"field3", "The quick brown fox jumps over the lazy dog").get();
|
||||
client().prepareIndex("test", "type2", "1").setSource(
|
||||
"field4", "The quick browse button is a fancy thing, right bro?").get();
|
||||
client().prepareIndex("test", "type2", "2").setSource(
|
||||
"field4", "a quick fast blue car").get();
|
||||
refresh();
|
||||
|
||||
source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field3", "fast bro"))
|
||||
@ -1420,8 +1518,12 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.highlighter(highlight().field("field4").order("score").preTags("<x>").postTags("</x>"));
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field4", 0, 1, anyOf(equalTo("<x>The quick browse</x> button is a fancy thing, right bro?"), equalTo("<x>The quick brown</x> fox jumps over the lazy dog")));
|
||||
assertHighlight(searchResponse, 1, "field4", 0, 1, anyOf(equalTo("<x>The quick browse</x> button is a fancy thing, right bro?"), equalTo("<x>The quick brown</x> fox jumps over the lazy dog")));
|
||||
assertHighlight(searchResponse, 0, "field4", 0, 1, anyOf(
|
||||
equalTo("<x>The quick browse</x> button is a fancy thing, right bro?"),
|
||||
equalTo("<x>The quick brown</x> fox jumps over the lazy dog")));
|
||||
assertHighlight(searchResponse, 1, "field4", 0, 1, anyOf(
|
||||
equalTo("<x>The quick browse</x> button is a fancy thing, right bro?"),
|
||||
equalTo("<x>The quick brown</x> fox jumps over the lazy dog")));
|
||||
|
||||
logger.info("--> highlighting and searching on field4");
|
||||
source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field4", "a fast quick blue ca"))
|
||||
@ -1448,7 +1550,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.fragmenter("simple"))).get();
|
||||
|
||||
assertHighlight(response, 0, "tags", 0, equalTo("this is a really <em>long</em> <em>tag</em> i would like to highlight"));
|
||||
assertHighlight(response, 0, "tags", 1, 2, equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the tag token near the end"));
|
||||
assertHighlight(response, 0, "tags", 1, 2,
|
||||
equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the tag token near the end"));
|
||||
|
||||
response = client().prepareSearch("test")
|
||||
.setQuery(QueryBuilders.matchQuery("tags", "long tag").type(MatchQuery.Type.PHRASE))
|
||||
@ -1456,8 +1559,10 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
new HighlightBuilder().field(new HighlightBuilder.Field("tags").fragmentSize(-1).numOfFragments(2)
|
||||
.fragmenter("span"))).get();
|
||||
|
||||
assertHighlight(response, 0, "tags", 0, equalTo("this is a really <em>long</em> <em>tag</em> i would like to highlight"));
|
||||
assertHighlight(response, 0, "tags", 1, 2, equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the tag token near the end"));
|
||||
assertHighlight(response, 0, "tags", 0,
|
||||
equalTo("this is a really <em>long</em> <em>tag</em> i would like to highlight"));
|
||||
assertHighlight(response, 0, "tags", 1, 2,
|
||||
equalTo("here is another one that is very <em>long</em> <em>tag</em> and has the tag token near the end"));
|
||||
|
||||
assertFailures(client().prepareSearch("test")
|
||||
.setQuery(QueryBuilders.matchQuery("tags", "long tag").type(MatchQuery.Type.PHRASE))
|
||||
@ -1487,8 +1592,9 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testFastVectorHighlighterMultipleFields() {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", "field1", "type=text,term_vector=with_positions_offsets", "field2", "type=text,term_vector=with_positions_offsets"));
|
||||
assertAcked(prepareCreate("test").addMapping("type1",
|
||||
"field1", "type=text,term_vector=with_positions_offsets",
|
||||
"field2", "type=text,term_vector=with_positions_offsets"));
|
||||
ensureGreen();
|
||||
|
||||
index("test", "type1", "1", "field1", "The <b>quick<b> brown fox", "field2", "The <b>slow<b> brown fox");
|
||||
@ -1527,9 +1633,14 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
// Issue #3211
|
||||
public void testNumericHighlighting() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("test", "text", "type=text",
|
||||
"byte", "type=byte", "short", "type=short", "int", "type=integer", "long", "type=long",
|
||||
"float", "type=float", "double", "type=double"));
|
||||
.addMapping("test",
|
||||
"text", "type=text",
|
||||
"byte", "type=byte",
|
||||
"short", "type=short",
|
||||
"int", "type=integer",
|
||||
"long", "type=long",
|
||||
"float", "type=float",
|
||||
"double", "type=double"));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "test", "1").setSource("text", "elasticsearch test",
|
||||
@ -1569,8 +1680,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testHighlightUsesHighlightQuery() throws IOException {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", "text", "type=text," + randomStoreField() + "term_vector=with_positions_offsets,index_options=offsets"));
|
||||
assertAcked(prepareCreate("test").addMapping("type1", "text",
|
||||
"type=text," + randomStoreField() + "term_vector=with_positions_offsets,index_options=offsets"));
|
||||
ensureGreen();
|
||||
|
||||
index("test", "type1", "1", "text", "Testing the highlight query feature");
|
||||
@ -1635,8 +1746,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testHighlightNoMatchSize() throws IOException {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", "text", "type=text," + randomStoreField() + "term_vector=with_positions_offsets,index_options=offsets"));
|
||||
assertAcked(prepareCreate("test").addMapping("type1", "text",
|
||||
"type=text," + randomStoreField() + "term_vector=with_positions_offsets,index_options=offsets"));
|
||||
ensureGreen();
|
||||
|
||||
String text = "I am pretty long so some of me should get cut off. Second sentence";
|
||||
@ -1743,8 +1854,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testHighlightNoMatchSizeWithMultivaluedFields() throws IOException {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", "text", "type=text," + randomStoreField() + "term_vector=with_positions_offsets,index_options=offsets"));
|
||||
assertAcked(prepareCreate("test").addMapping("type1",
|
||||
"text", "type=text," + randomStoreField() + "term_vector=with_positions_offsets,index_options=offsets"));
|
||||
ensureGreen();
|
||||
|
||||
String text1 = "I am pretty long so some of me should get cut off. We'll see how that goes.";
|
||||
@ -1855,8 +1966,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
}
|
||||
|
||||
public void testHighlightNoMatchSizeNumberOfFragments() throws IOException {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", "text", "type=text," + randomStoreField() + "term_vector=with_positions_offsets,index_options=offsets"));
|
||||
assertAcked(prepareCreate("test").addMapping("type1",
|
||||
"text", "type=text," + randomStoreField() + "term_vector=with_positions_offsets,index_options=offsets"));
|
||||
ensureGreen();
|
||||
|
||||
String text1 = "This is the first sentence. This is the second sentence." + HighlightUtils.PARAGRAPH_SEPARATOR;
|
||||
@ -1933,7 +2044,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <xxx>quick</xxx> brown fox jumps over the lazy <xxx>quick</xxx> dog"));
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1,
|
||||
equalTo("The <xxx>quick</xxx> brown fox jumps over the lazy <xxx>quick</xxx> dog"));
|
||||
|
||||
logger.info("--> searching on field2, highlighting on field2");
|
||||
source = searchSource()
|
||||
@ -1943,24 +2055,29 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
//phrase query results in highlighting all different terms regardless of their positions
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <xxx>quick</xxx> <xxx>brown</xxx> fox jumps over the lazy <xxx>quick</xxx> dog"));
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1,
|
||||
equalTo("The <xxx>quick</xxx> <xxx>brown</xxx> fox jumps over the lazy <xxx>quick</xxx> dog"));
|
||||
|
||||
//lets fall back to the standard highlighter then, what people would do to highlight query matches
|
||||
logger.info("--> searching on field2, highlighting on field2, falling back to the plain highlighter");
|
||||
source = searchSource()
|
||||
.query(matchPhraseQuery("_all", "quick brown"))
|
||||
.highlighter(highlight().field("field2").preTags("<xxx>").postTags("</xxx>").highlighterType("plain").requireFieldMatch(false));
|
||||
.highlighter(highlight()
|
||||
.field("field2").preTags("<xxx>").postTags("</xxx>").highlighterType("plain").requireFieldMatch(false));
|
||||
|
||||
searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <xxx>quick</xxx> <xxx>brown</xxx> fox jumps over the lazy quick dog"));
|
||||
assertHighlight(searchResponse, 0, "field2", 0, 1,
|
||||
equalTo("The <xxx>quick</xxx> <xxx>brown</xxx> fox jumps over the lazy quick dog"));
|
||||
}
|
||||
|
||||
public void testPostingsHighlighterMultipleFields() throws Exception {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()).get());
|
||||
ensureGreen();
|
||||
|
||||
index("test", "type1", "1", "field1", "The <b>quick<b> brown fox. Second sentence.", "field2", "The <b>slow<b> brown fox. Second sentence.");
|
||||
index("test", "type1", "1",
|
||||
"field1", "The <b>quick<b> brown fox. Second sentence.",
|
||||
"field2", "The <b>slow<b> brown fox. Second sentence.");
|
||||
refresh();
|
||||
|
||||
SearchResponse response = client().prepareSearch("test")
|
||||
@ -1976,9 +2093,11 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1", "1")
|
||||
.setSource("field1", "The quick brown fox jumps over the lazy dog. The lazy red fox jumps over the quick dog. The quick brown dog jumps over the lazy fox.",
|
||||
"field2", "The quick brown fox jumps over the lazy dog. The lazy red fox jumps over the quick dog. The quick brown dog jumps over the lazy fox.").get();
|
||||
client().prepareIndex("test", "type1", "1").setSource(
|
||||
"field1", "The quick brown fox jumps over the lazy dog. The lazy red fox jumps over the quick dog. "
|
||||
+ "The quick brown dog jumps over the lazy fox.",
|
||||
"field2", "The quick brown fox jumps over the lazy dog. The lazy red fox jumps over the quick dog. "
|
||||
+ "The quick brown dog jumps over the lazy fox.").get();
|
||||
refresh();
|
||||
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
@ -1994,7 +2113,10 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertHighlight(searchResponse, 0, "field1", 2, 3, equalTo("The quick brown dog jumps over the lazy <field1>fox</field1>."));
|
||||
|
||||
client().prepareIndex("test", "type1", "2")
|
||||
.setSource("field1", new String[]{"The quick brown fox jumps over the lazy dog. Second sentence not finished", "The lazy red fox jumps over the quick dog.", "The quick brown dog jumps over the lazy fox."}).get();
|
||||
.setSource("field1", new String[] {
|
||||
"The quick brown fox jumps over the lazy dog. Second sentence not finished",
|
||||
"The lazy red fox jumps over the quick dog.",
|
||||
"The quick brown dog jumps over the lazy fox."}).get();
|
||||
refresh();
|
||||
|
||||
source = searchSource()
|
||||
@ -2007,9 +2129,12 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
|
||||
for (SearchHit searchHit : searchResponse.getHits()) {
|
||||
if ("1".equals(searchHit.id())) {
|
||||
assertHighlight(searchHit, "field1", 0, 1, equalTo("The quick brown <field1>fox</field1> jumps over the lazy dog. The lazy red <field1>fox</field1> jumps over the quick dog. The quick brown dog jumps over the lazy <field1>fox</field1>."));
|
||||
assertHighlight(searchHit, "field1", 0, 1, equalTo("The quick brown <field1>fox</field1> jumps over the lazy dog. "
|
||||
+ "The lazy red <field1>fox</field1> jumps over the quick dog. "
|
||||
+ "The quick brown dog jumps over the lazy <field1>fox</field1>."));
|
||||
} else if ("2".equals(searchHit.id())) {
|
||||
assertHighlight(searchHit, "field1", 0, 3, equalTo("The quick brown <field1>fox</field1> jumps over the lazy dog. Second sentence not finished"));
|
||||
assertHighlight(searchHit, "field1", 0, 3,
|
||||
equalTo("The quick brown <field1>fox</field1> jumps over the lazy dog. Second sentence not finished"));
|
||||
assertHighlight(searchHit, "field1", 1, 3, equalTo("The lazy red <field1>fox</field1> jumps over the quick dog."));
|
||||
assertHighlight(searchHit, "field1", 2, 3, equalTo("The quick brown dog jumps over the lazy <field1>fox</field1>."));
|
||||
} else {
|
||||
@ -2023,8 +2148,16 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
|
||||
.startObject("_all").field("store", true).field("index_options", "offsets").endObject()
|
||||
.startObject("properties")
|
||||
.startObject("field1").field("type", "text").field("index_options", "offsets").field("term_vector", "with_positions_offsets").endObject()
|
||||
.startObject("field2").field("type", "text").field("index_options", "offsets").field("term_vector", "with_positions_offsets").endObject()
|
||||
.startObject("field1")
|
||||
.field("type", "text")
|
||||
.field("index_options", "offsets")
|
||||
.field("term_vector", "with_positions_offsets")
|
||||
.endObject()
|
||||
.startObject("field2")
|
||||
.field("type", "text")
|
||||
.field("index_options", "offsets")
|
||||
.field("term_vector", "with_positions_offsets")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject();
|
||||
assertAcked(prepareCreate("test").addMapping("type1", mapping));
|
||||
@ -2038,17 +2171,25 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
String highlighterType = rarely() ? null : RandomPicks.randomFrom(random(), highlighterTypes);
|
||||
MultiMatchQueryBuilder.Type[] supportedQueryTypes;
|
||||
if ("postings".equals(highlighterType)) {
|
||||
//phrase_prefix is not supported by postings highlighter, as it rewrites against an empty reader, the prefix will never match any term
|
||||
supportedQueryTypes = new MultiMatchQueryBuilder.Type[]{MultiMatchQueryBuilder.Type.BEST_FIELDS, MultiMatchQueryBuilder.Type.CROSS_FIELDS, MultiMatchQueryBuilder.Type.MOST_FIELDS, MultiMatchQueryBuilder.Type.PHRASE};
|
||||
/*
|
||||
* phrase_prefix is not supported by postings highlighter, as it rewrites against an empty reader, the prefix will never
|
||||
* match any term
|
||||
*/
|
||||
supportedQueryTypes = new MultiMatchQueryBuilder.Type[]{
|
||||
MultiMatchQueryBuilder.Type.BEST_FIELDS,
|
||||
MultiMatchQueryBuilder.Type.CROSS_FIELDS,
|
||||
MultiMatchQueryBuilder.Type.MOST_FIELDS,
|
||||
MultiMatchQueryBuilder.Type.PHRASE};
|
||||
} else {
|
||||
supportedQueryTypes = MultiMatchQueryBuilder.Type.values();
|
||||
}
|
||||
MultiMatchQueryBuilder.Type matchQueryType = RandomPicks.randomFrom(random(), supportedQueryTypes);
|
||||
final MultiMatchQueryBuilder multiMatchQueryBuilder = multiMatchQuery("the quick brown fox", "field1", "field2").type(matchQueryType);
|
||||
MultiMatchQueryBuilder multiMatchQueryBuilder = multiMatchQuery("the quick brown fox", "field1", "field2").type(matchQueryType);
|
||||
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(multiMatchQueryBuilder)
|
||||
.highlighter(highlight().highlightQuery(randomBoolean() ? multiMatchQueryBuilder : null).highlighterType(highlighterType)
|
||||
.highlighter(highlight().highlightQuery(randomBoolean() ? multiMatchQueryBuilder : null)
|
||||
.highlighterType(highlighterType)
|
||||
.field(new Field("field1").requireFieldMatch(true).preTags("<field1>").postTags("</field1>")));
|
||||
logger.info("Running multi-match type: [{}] highlight with type: [{}]", matchQueryType, highlighterType);
|
||||
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
|
||||
@ -2063,9 +2204,13 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1")
|
||||
.setSource("field1", new String[]{"This sentence contains one match, not that short. This sentence contains two 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();
|
||||
.setSource("field1", new String[]{
|
||||
"This sentence contains one match, not that short. This sentence contains two 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");
|
||||
@ -2079,11 +2224,13 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertThat(highlightFieldMap.size(), equalTo(1));
|
||||
HighlightField field1 = highlightFieldMap.get("field1");
|
||||
assertThat(field1.fragments().length, equalTo(5));
|
||||
assertThat(field1.fragments()[0].string(), equalTo("This <em>sentence</em> contains three <em>sentence</em> occurrences (<em>sentence</em>)."));
|
||||
assertThat(field1.fragments()[0].string(),
|
||||
equalTo("This <em>sentence</em> contains three <em>sentence</em> occurrences (<em>sentence</em>)."));
|
||||
assertThat(field1.fragments()[1].string(), equalTo("This <em>sentence</em> contains two <em>sentence</em> matches."));
|
||||
assertThat(field1.fragments()[2].string(), equalTo("This is the second value's first <em>sentence</em>."));
|
||||
assertThat(field1.fragments()[3].string(), equalTo("This <em>sentence</em> contains one match, not that short."));
|
||||
assertThat(field1.fragments()[4].string(), equalTo("One <em>sentence</em> match here and scored lower since the text is quite long, not that appealing."));
|
||||
assertThat(field1.fragments()[4].string(),
|
||||
equalTo("One <em>sentence</em> match here and scored lower since the text is quite long, not that appealing."));
|
||||
}
|
||||
|
||||
public void testPostingsHighlighterEscapeHtml() throws Exception {
|
||||
@ -2108,13 +2255,21 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
|
||||
public void testPostingsHighlighterMultiMapperWithStore() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1")
|
||||
.startObject("properties")
|
||||
.startObject("title").field("type", "text").field("store", true).field("index_options", "offsets").field("analyzer", "classic")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("title")
|
||||
.field("type", "text")
|
||||
.field("store", true)
|
||||
.field("index_options", "offsets")
|
||||
.field("analyzer", "classic")
|
||||
.startObject("fields")
|
||||
.startObject("key").field("type", "text").field("store", true).field("index_options", "offsets").field("analyzer", "whitespace").endObject()
|
||||
.endObject().endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
.startObject("key")
|
||||
.field("type", "text")
|
||||
.field("store", true)
|
||||
.field("index_options", "offsets")
|
||||
.field("analyzer", "whitespace")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().endObject().endObject()));
|
||||
ensureGreen();
|
||||
client().prepareIndex("test", "type1", "1").setSource("title", "this is a test . Second sentence.").get();
|
||||
refresh();
|
||||
@ -2142,11 +2297,20 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
public void testPostingsHighlighterMultiMapperFromSource() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("title").field("type", "text").field("store", false).field("index_options", "offsets").field("analyzer", "classic")
|
||||
.startObject("title")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("index_options", "offsets")
|
||||
.field("analyzer", "classic")
|
||||
.startObject("fields")
|
||||
.startObject("key").field("type", "text").field("store", false).field("index_options", "offsets").field("analyzer", "whitespace").endObject()
|
||||
.endObject().endObject()
|
||||
.endObject().endObject().endObject()));
|
||||
.startObject("key")
|
||||
.field("type", "text")
|
||||
.field("store", false)
|
||||
.field("index_options", "offsets")
|
||||
.field("analyzer", "whitespace")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject().endObject().endObject()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1", "1").setSource("title", "this is a test").get();
|
||||
@ -2192,14 +2356,16 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.setQuery(matchQuery("title", "this is a test"))
|
||||
.highlighter(new HighlightBuilder().field("title").highlighterType("postings")),
|
||||
RestStatus.BAD_REQUEST,
|
||||
containsString("the field [title] should be indexed with positions and offsets in the postings list to be used with postings highlighter"));
|
||||
containsString("the field [title] should be indexed with positions and offsets in the "
|
||||
+ "postings list to be used with postings highlighter"));
|
||||
|
||||
|
||||
assertFailures(client().prepareSearch()
|
||||
.setQuery(matchQuery("title", "this is a test"))
|
||||
.highlighter(new HighlightBuilder().field("title").highlighterType("postings")),
|
||||
RestStatus.BAD_REQUEST,
|
||||
containsString("the field [title] should be indexed with positions and offsets in the postings list to be used with postings highlighter"));
|
||||
containsString("the field [title] should be indexed with positions and offsets in the "
|
||||
+ "postings list to be used with postings highlighter"));
|
||||
|
||||
//should not fail if there is a wildcard
|
||||
assertNoFailures(client().prepareSearch()
|
||||
@ -2210,8 +2376,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
public void testPostingsHighlighterBoostingQuery() throws IOException {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
|
||||
ensureGreen();
|
||||
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.")
|
||||
.get();
|
||||
client().prepareIndex("test", "type1")
|
||||
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
refresh();
|
||||
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
@ -2227,7 +2393,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
client().prepareIndex("test", "type1")
|
||||
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
refresh();
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource().query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100))
|
||||
@ -2251,7 +2418,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
client().prepareIndex("test", "type1")
|
||||
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
|
||||
@ -2266,7 +2434,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
client().prepareIndex("test", "type1")
|
||||
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
SearchSourceBuilder source = searchSource().query(fuzzyQuery("field2", "quck"))
|
||||
@ -2280,7 +2449,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
client().prepareIndex("test", "type1")
|
||||
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
SearchSourceBuilder source = searchSource().query(regexpQuery("field2", "qu[a-l]+k"))
|
||||
@ -2294,7 +2464,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
client().prepareIndex("test", "type1")
|
||||
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
SearchSourceBuilder source = searchSource().query(wildcardQuery("field2", "qui*"))
|
||||
@ -2329,7 +2500,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
|
||||
ensureGreen();
|
||||
|
||||
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
client().prepareIndex("test", "type1")
|
||||
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
|
||||
refresh();
|
||||
logger.info("--> highlighting and searching on field2");
|
||||
SearchSourceBuilder source = searchSource().query(queryStringQuery("qui*").defaultField("field2"))
|
||||
@ -2377,7 +2549,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
refresh();
|
||||
|
||||
logger.info("--> highlighting and searching on field1");
|
||||
SearchSourceBuilder source = searchSource().query(boolQuery().must(prefixQuery("field1", "photo")).should(matchQuery("field1", "test").minimumShouldMatch("0")))
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(boolQuery().must(prefixQuery("field1", "photo")).should(matchQuery("field1", "test").minimumShouldMatch("0")))
|
||||
.highlighter(highlight().field("field1"));
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
|
||||
assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
|
||||
@ -2604,12 +2777,13 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.setSource(jsonBuilder().startObject().field("keyword_field", "some text").endObject())
|
||||
.get();
|
||||
refresh();
|
||||
SearchResponse search = client().prepareSearch().setSource(
|
||||
new SearchSourceBuilder().query(QueryBuilders.matchQuery("keyword_field", "some text")).highlighter(new HighlightBuilder().field("*")))
|
||||
.get();
|
||||
SearchResponse search = client().prepareSearch().setSource(new SearchSourceBuilder()
|
||||
.query(QueryBuilders.matchQuery("keyword_field", "some text"))
|
||||
.highlighter(new HighlightBuilder().field("*"))).get();
|
||||
assertNoFailures(search);
|
||||
assertThat(search.getHits().totalHits(), equalTo(1L));
|
||||
assertThat(search.getHits().getAt(0).getHighlightFields().get("keyword_field").getFragments()[0].string(), equalTo("<em>some text</em>"));
|
||||
assertThat(search.getHits().getAt(0).getHighlightFields().get("keyword_field").getFragments()[0].string(),
|
||||
equalTo("<em>some text</em>"));
|
||||
}
|
||||
|
||||
public void testStringFieldHighlighting() throws IOException {
|
||||
@ -2632,12 +2806,13 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
||||
.setSource(jsonBuilder().startObject().field("string_field", "some text").endObject())
|
||||
.get();
|
||||
refresh();
|
||||
SearchResponse search = client().prepareSearch().setSource(
|
||||
new SearchSourceBuilder().query(QueryBuilders.matchQuery("string_field", "some text")).highlighter(new HighlightBuilder().field("*")))
|
||||
.get();
|
||||
SearchResponse search = client().prepareSearch().setSource(new SearchSourceBuilder()
|
||||
.query(QueryBuilders.matchQuery("string_field", "some text"))
|
||||
.highlighter(new HighlightBuilder().field("*"))).get();
|
||||
assertNoFailures(search);
|
||||
assertThat(search.getHits().totalHits(), equalTo(1L));
|
||||
assertThat(search.getHits().getAt(0).getHighlightFields().get("string_field").getFragments()[0].string(), equalTo("<em>some</em> <em>text</em>"));
|
||||
assertThat(search.getHits().getAt(0).getHighlightFields().get("string_field").getFragments()[0].string(),
|
||||
equalTo("<em>some</em> <em>text</em>"));
|
||||
}
|
||||
|
||||
public void testACopyFieldWithNestedQuery() throws Exception {
|
||||
|
Loading…
x
Reference in New Issue
Block a user