mirror of https://github.com/apache/lucene.git
tidy-ed
This commit is contained in:
parent
e2a961a509
commit
8801851525
|
@ -100,11 +100,8 @@ public class UnifiedHighlighter {
|
|||
|
||||
public static final int DEFAULT_CACHE_CHARS_THRESHOLD = 524288; // ~ 1 MB (2 byte chars)
|
||||
|
||||
public static final Set<Class<? extends Query>> QUERIES_WITH_NO_HL_EFFECT = Set.of(
|
||||
MatchAllDocsQuery.class,
|
||||
MatchNoDocsQuery.class,
|
||||
FunctionQuery.class
|
||||
);
|
||||
public static final Set<Class<? extends Query>> QUERIES_WITH_NO_HL_EFFECT =
|
||||
Set.of(MatchAllDocsQuery.class, MatchNoDocsQuery.class, FunctionQuery.class);
|
||||
|
||||
protected static final LabelledCharArrayMatcher[] ZERO_LEN_AUTOMATA_ARRAY =
|
||||
new LabelledCharArrayMatcher[0];
|
||||
|
@ -1138,7 +1135,8 @@ public class UnifiedHighlighter {
|
|||
public void visitLeaf(Query query) {
|
||||
if (MultiTermHighlighting.canExtractAutomataFromLeafQuery(query) == false) {
|
||||
boolean no_effect_query = false;
|
||||
for (Class<? extends Query> queryType: UnifiedHighlighter.QUERIES_WITH_NO_HL_EFFECT) {
|
||||
for (Class<? extends Query> queryType :
|
||||
UnifiedHighlighter.QUERIES_WITH_NO_HL_EFFECT) {
|
||||
if (queryType.isInstance(query)) {
|
||||
no_effect_query = true;
|
||||
break;
|
||||
|
|
|
@ -1669,15 +1669,17 @@ public class TestUnifiedHighlighter extends UnifiedHighlighterTestBase {
|
|||
|
||||
public void testPostingsOffsetStrategy() throws Exception {
|
||||
if (this.fieldType.indexOptions() != IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS
|
||||
|| this.fieldType.storeTermVectors())
|
||||
|| this.fieldType.storeTermVectors()) {
|
||||
// ignore if fieldType is not POSTINGS only
|
||||
return;
|
||||
}
|
||||
|
||||
final UnifiedHighlighter.OffsetSource expectedOffsetSource;
|
||||
if (this.fieldType.storeTermVectors())
|
||||
if (this.fieldType.storeTermVectors()) {
|
||||
expectedOffsetSource = UnifiedHighlighter.OffsetSource.POSTINGS_WITH_TERM_VECTORS;
|
||||
else
|
||||
} else {
|
||||
expectedOffsetSource = UnifiedHighlighter.OffsetSource.POSTINGS;
|
||||
}
|
||||
|
||||
RandomIndexWriter iw = newIndexOrderPreservingWriter();
|
||||
|
||||
|
@ -1700,22 +1702,40 @@ public class TestUnifiedHighlighter extends UnifiedHighlighterTestBase {
|
|||
TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER);
|
||||
|
||||
Set<Term> queryTerms = UnifiedHighlighter.extractTerms(query);
|
||||
FieldHighlighter fieldHighlighter = highlighter.getFieldHighlighter("body", query, queryTerms, 1);
|
||||
assertEquals(expectedOffsetSource, fieldHighlighter.getOffsetSource()); // TermQuery is compatible with POSTINGS offset strategy
|
||||
FieldHighlighter fieldHighlighter =
|
||||
highlighter.getFieldHighlighter("body", query, queryTerms, 1);
|
||||
assertEquals(
|
||||
expectedOffsetSource,
|
||||
fieldHighlighter
|
||||
.getOffsetSource()); // TermQuery is compatible with POSTINGS offset strategy
|
||||
|
||||
String[] snippets = highlighter.highlight("body", query, topDocs);
|
||||
|
||||
for (Query noEffectQuery: new Query[] {new MatchAllDocsQuery(), new MatchNoDocsQuery(), new FunctionQuery(new ConstValueSource(5))}) {
|
||||
final Query booleanQuery = new BooleanQuery.Builder()
|
||||
.add(noEffectQuery, BooleanClause.Occur.MUST)
|
||||
.add(query, BooleanClause.Occur.MUST)
|
||||
.build();
|
||||
for (Query noEffectQuery :
|
||||
new Query[] {
|
||||
new MatchAllDocsQuery(),
|
||||
new MatchNoDocsQuery(),
|
||||
new FunctionQuery(new ConstValueSource(5))
|
||||
}) {
|
||||
final Query booleanQuery =
|
||||
new BooleanQuery.Builder()
|
||||
.add(noEffectQuery, BooleanClause.Occur.MUST)
|
||||
.add(query, BooleanClause.Occur.MUST)
|
||||
.build();
|
||||
queryTerms = UnifiedHighlighter.extractTerms(booleanQuery);
|
||||
fieldHighlighter = highlighter.getFieldHighlighter("body", booleanQuery, queryTerms, 1);
|
||||
assertEquals(noEffectQuery.getClass().toString(), expectedOffsetSource, fieldHighlighter.getOffsetSource()); // combining to a query with no effet (on highlighting) should lead to the same highlighter behavior
|
||||
assertEquals(
|
||||
noEffectQuery.getClass().toString(),
|
||||
expectedOffsetSource,
|
||||
fieldHighlighter
|
||||
.getOffsetSource()); // combining to a query with no effet (on highlighting) should
|
||||
// lead to the same highlighter behavior
|
||||
|
||||
String[] bqSnippets = highlighter.highlight("body", query, topDocs);
|
||||
assertArrayEquals(bqSnippets.toString(), snippets, bqSnippets); // ensuring that the combined query does produce the same output
|
||||
assertArrayEquals(
|
||||
Arrays.toString(bqSnippets),
|
||||
snippets,
|
||||
bqSnippets); // ensuring that the combined query does produce the same output
|
||||
}
|
||||
|
||||
ir.close();
|
||||
|
|
Loading…
Reference in New Issue