File tree Expand file tree Collapse file tree 3 files changed +40
-4
lines changed
lucene/core/src/java/org/apache/lucene Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -94,13 +94,21 @@ public SloppyPhraseMatcher(
9494 this .numPostings = postings .length ;
9595 this .captureLeadMatch = captureLeadMatch ;
9696 pq =
97- PriorityQueue .usingComparator (
97+ PriorityQueue .usingLessThan (
9898 postings .length ,
99- Comparator .<PhrasePositions >comparingInt (pp -> pp .position )
99+ (pp1 , pp2 ) -> {
100+ if (pp1 .position == pp2 .position )
100101 // same doc and pp.position, so decide by actual term positions.
101102 // rely on: pp.position == tp.position - offset.
102- .thenComparingInt (pp -> pp .offset )
103- .thenComparingInt (pp -> pp .ord ));
103+ if (pp1 .offset == pp2 .offset ) {
104+ return pp1 .ord < pp2 .ord ;
105+ } else {
106+ return pp1 .offset < pp2 .offset ;
107+ }
108+ else {
109+ return pp1 .position < pp2 .position ;
110+ }
111+ });
104112 phrasePositions = new PhrasePositions [postings .length ];
105113 for (int i = 0 ; i < postings .length ; ++i ) {
106114 phrasePositions [i ] =
Original file line number Diff line number Diff line change 1919import java .util .Comparator ;
2020
2121/** A specialization of {@link Comparator} that compares {@code float} values */
22+ @ FunctionalInterface
2223public interface FloatComparator {
2324
25+ @ FunctionalInterface
2426 interface ToFloatFunction <T > {
2527 float applyAsFloat (T obj );
2628 }
Original file line number Diff line number Diff line change 3737 */
3838public abstract class PriorityQueue <T > implements Iterable <T > {
3939
40+ @ FunctionalInterface
41+ public interface LessThan <T > {
42+ boolean lessThan (T a , T b );
43+ }
44+
45+ /** Create a {@code PriorityQueue} that orders elements using the specified {@code lessThan} */
46+ public static <T > PriorityQueue <T > usingLessThan (int maxSize , LessThan <? super T > lessThan ) {
47+ return new PriorityQueue <>(maxSize ) {
48+ @ Override
49+ protected boolean lessThan (T a , T b ) {
50+ return lessThan .lessThan (a , b );
51+ }
52+ };
53+ }
54+
55+ /** Create a {@code PriorityQueue} that orders elements using the specified {@code lessThan} */
56+ public static <T > PriorityQueue <T > usingLessThan (
57+ int maxSize , Supplier <T > sentinelObjectSupplier , LessThan <? super T > lessThan ) {
58+ return new PriorityQueue <>(maxSize , sentinelObjectSupplier ) {
59+ @ Override
60+ protected boolean lessThan (T a , T b ) {
61+ return lessThan .lessThan (a , b );
62+ }
63+ };
64+ }
65+
4066 /** Create a {@code PriorityQueue} that orders elements using the specified {@code comparator} */
4167 public static <T > PriorityQueue <T > usingComparator (
4268 int maxSize , Comparator <? super T > comparator ) {
You can’t perform that action at this time.
0 commit comments