dweiss commented on a change in pull request #521: URL: https://github.com/apache/lucene/pull/521#discussion_r763712209
########## File path: lucene/highlighter/src/test/org/apache/lucene/search/matchhighlight/TestMatchRegionRetriever.java ########## @@ -379,17 +379,17 @@ public void testIntervalQueries() throws Exception { Intervals.containedBy( Intervals.term("foo"), Intervals.unordered(Intervals.term("foo"), Intervals.term("bar"))))), - containsInAnyOrder(fmt("2: (field_text_offs: '>bar baz foo< xyz')", field))); Review comment: Oh, awesome that this is fixed too. ########## File path: lucene/highlighter/src/test/org/apache/lucene/search/matchhighlight/TestMatchHighlighter.java ########## @@ -541,6 +539,234 @@ protected TokenStreamComponents createComponents(String fieldName) { }); } + /** + * Almost the same as the one above, make sure the fields indexed with offsets are also + * highlighted correctly + */ + @Test + public void testIntervalFunctionsWithOffsetField() throws Exception { + Analyzer analyzer = + new Analyzer() { + @Override + protected TokenStreamComponents createComponents(String fieldName) { + Tokenizer tokenizer = new StandardTokenizer(); + TokenStream ts = tokenizer; + ts = new LowerCaseFilter(ts); + return new TokenStreamComponents(tokenizer, ts); + } + }; + + String field = FLD_TEXT1; + new IndexBuilder(this::toField) + // Just one document and multiple interval queries. + .doc(field, "The quick brown fox jumps over the lazy dog") + .build( + analyzer, + reader -> { + IndexSearcher searcher = new IndexSearcher(reader); + Sort sortOrder = Sort.INDEXORDER; // So that results are consistently ordered. + + MatchHighlighter highlighter = + new MatchHighlighter(searcher, analyzer) + .appendFieldHighlighter( + FieldValueHighlighters.highlighted( + 80 * 3, 1, new PassageFormatter("...", ">", "<"), fld -> true)) + .appendFieldHighlighter(FieldValueHighlighters.skipRemaining()); + + StandardQueryParser qp = new StandardQueryParser(analyzer); + + // Run all pairs of query-expected highlight. + List<String> errors = new ArrayList<>(); + for (var queryHighlightPair : + new String[][] { + { + "fn:ordered(brown dog)", + "0. %s: The quick >brown fox jumps over the lazy dog<" + }, + { + "fn:within(fn:or(lazy quick) 1 fn:or(dog fox))", + "0. %s: The quick brown fox jumps over the >lazy< dog" + }, + { + "fn:containedBy(fox fn:ordered(brown fox dog))", + "0. %s: The quick brown >fox< jumps over the lazy dog" + }, + { + "fn:atLeast(2 quick fox \"furry dog\")", + "0. %s: The >quick brown fox< jumps over the lazy dog" + }, + { + "fn:maxgaps(0 fn:ordered(fn:or(quick lazy) fn:or(fox dog)))", + "0. %s: The quick brown fox jumps over the >lazy dog<" + }, + { + "fn:maxgaps(1 fn:ordered(fn:or(quick lazy) fn:or(fox dog)))", + "0. %s: The >quick brown fox< jumps over the >lazy dog<" + }, + { + "fn:maxwidth(2 fn:ordered(fn:or(quick lazy) fn:or(fox dog)))", + "0. %s: The quick brown fox jumps over the >lazy dog<" + }, + { + "fn:maxwidth(3 fn:ordered(fn:or(quick lazy) fn:or(fox dog)))", + "0. %s: The >quick brown fox< jumps over the >lazy dog<" + }, + { + "fn:or(quick \"fox\")", + "0. %s: The >quick< brown >fox< jumps over the lazy dog" + }, + {"fn:or(\"quick fox\")"}, + { + "fn:phrase(quick brown fox)", + "0. %s: The >quick brown fox< jumps over the lazy dog" + }, + {"fn:wildcard(jump*)", "0. %s: The quick brown fox >jumps< over the lazy dog"}, + {"fn:wildcard(br*n)", "0. %s: The quick >brown< fox jumps over the lazy dog"}, + {"fn:or(dog fox)", "0. %s: The quick brown >fox< jumps over the lazy >dog<"}, + { + "fn:phrase(fn:ordered(quick fox) jumps)", + "0. %s: The >quick brown fox jumps< over the lazy dog" + }, + { + "fn:ordered(quick jumps dog)", + "0. %s: The >quick brown fox jumps over the lazy dog<" + }, + { + "fn:ordered(quick fn:or(fox dog))", + "0. %s: The >quick brown fox< jumps over the lazy dog" + }, + { + "fn:ordered(quick jumps fn:or(fox dog))", + "0. %s: The >quick brown fox jumps over the lazy dog<" + }, + { + "fn:unordered(dog jumps quick)", + "0. %s: The >quick brown fox jumps over the lazy dog<" + }, + { + "fn:unordered(fn:or(fox dog) quick)", + "0. %s: The >quick brown fox< jumps over the lazy dog" + }, + { + "fn:unordered(fn:phrase(brown fox) fn:phrase(fox jumps))", + "0. %s: The quick >brown fox jumps< over the lazy dog" + }, + {"fn:ordered(fn:phrase(brown fox) fn:phrase(fox jumps))"}, + {"fn:unorderedNoOverlaps(fn:phrase(brown fox) fn:phrase(fox jumps))"}, + { + "fn:before(fn:or(brown lazy) fox)", + "0. %s: The quick >brown< fox jumps over the lazy dog" + }, + { + "fn:before(fn:or(brown lazy) fn:or(dog fox))", + "0. %s: The quick >brown< fox jumps over the >lazy< dog" + }, + { + "fn:after(fn:or(brown lazy) fox)", + "0. %s: The quick brown fox jumps over the >lazy< dog" + }, + { + "fn:after(fn:or(brown lazy) fn:or(dog fox))", + "0. %s: The quick brown fox jumps over the >lazy< dog" + }, + { + "fn:within(fn:or(fox dog) 1 fn:or(quick lazy))", + "0. %s: The quick brown fox jumps over the lazy >dog<" + }, + { + "fn:within(fn:or(fox dog) 2 fn:or(quick lazy))", + "0. %s: The quick brown >fox< jumps over the lazy >dog<" + }, + { + "fn:notWithin(fn:or(fox dog) 1 fn:or(quick lazy))", + "0. %s: The quick brown >fox< jumps over the lazy dog" + }, + { + "fn:containedBy(fn:or(fox dog) fn:ordered(quick lazy))", + "0. %s: The quick brown >fox< jumps over the lazy dog" + }, + { + "fn:notContainedBy(fn:or(fox dog) fn:ordered(quick lazy))", + "0. %s: The quick brown fox jumps over the lazy >dog<" + }, + { + "fn:containing(fn:atLeast(2 quick fox dog) jumps)", + "0. %s: The quick brown >fox jumps over the lazy dog<" + }, + { + "fn:notContaining(fn:ordered(fn:or(the The) fn:or(fox dog)) brown)", + "0. %s: The quick brown fox jumps over >the lazy dog<" + }, + { + "fn:overlapping(fn:phrase(brown fox) fn:phrase(fox jumps))", + "0. %s: The quick >brown fox< jumps over the lazy dog" + }, + { + "fn:overlapping(fn:or(fox dog) fn:extend(lazy 2 2))", + "0. %s: The quick brown fox jumps over the lazy >dog<" + }, + { + "fn:nonOverlapping(fn:phrase(brown fox) fn:phrase(lazy dog))", + "0. %s: The quick >brown fox< jumps over the lazy dog" + }, + { + "fn:nonOverlapping(fn:or(fox dog) fn:extend(lazy 2 2))", + "0. %s: The quick brown >fox< jumps over the lazy dog" + }, + { + "fn:atLeast(2 fn:unordered(furry dog) fn:unordered(brown dog) lazy quick)", + "0. %s: The >quick >brown fox jumps over the lazy<<> dog<" + }, + /* + The test cases below does not work for fields enabled with offset yet: Review comment: Add a todo, maybe? Also: "do not work" (plural). ########## File path: lucene/queries/src/java/org/apache/lucene/queries/intervals/Intervals.java ########## @@ -275,7 +275,10 @@ public static IntervalsSource ordered(IntervalsSource... subSources) { } /** - * Create an unordered {@link IntervalsSource} + * Create an unordered {@link IntervalsSource}. Note that if there are multiple intervals ends at Review comment: It does look like a bug - all c..d alternatives should be considered here, @romseygeek ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org