|
19 | 19 |
|
20 | 20 | import java.util.ArrayList; |
21 | 21 | import java.util.Collections; |
| 22 | +import java.util.LinkedHashMap; |
22 | 23 | import java.util.List; |
| 24 | +import java.util.Map; |
23 | 25 | import java.util.function.Function; |
24 | 26 | import org.apache.lucene.search.IndexSearcher; |
25 | 27 |
|
@@ -73,24 +75,26 @@ public static List<IntervalsSource> pullUp( |
73 | 75 | } |
74 | 76 |
|
75 | 77 | // Separate out disjunctions into individual sources |
76 | | - // Clauses that have a minExtent of 1 are grouped together and treated as a single |
77 | | - // source, as any overlapping intervals of length 1 can be treated as identical, |
78 | | - // and we know that all combinatorial sources have a minExtent > 1 |
| 78 | + // Clauses that always match intervals of the same fixed width are grouped together by width |
| 79 | + // and treated as a single source, as intervals of equal width can never strictly contain one |
| 80 | + // another, so minimization cannot cause one to hide another. This covers single terms (width 1) |
| 81 | + // and, for example, phrases of the same length. Variable-width clauses are kept separate. |
79 | 82 | private static List<IntervalsSource> splitDisjunctions(IntervalsSource source) { |
80 | | - List<IntervalsSource> singletons = new ArrayList<>(); |
81 | | - List<IntervalsSource> nonSingletons = new ArrayList<>(); |
| 83 | + Map<Integer, List<IntervalsSource>> fixedByWidth = new LinkedHashMap<>(); |
| 84 | + List<IntervalsSource> variableWidth = new ArrayList<>(); |
82 | 85 | for (IntervalsSource disj : source.pullUpDisjunctions()) { |
83 | | - if (disj.minExtent() == 1) { |
84 | | - singletons.add(disj); |
| 86 | + int width = disj.minExtent(); |
| 87 | + if (width == disj.maxExtent()) { |
| 88 | + fixedByWidth.computeIfAbsent(width, _ -> new ArrayList<>()).add(disj); |
85 | 89 | } else { |
86 | | - nonSingletons.add(disj); |
| 90 | + variableWidth.add(disj); |
87 | 91 | } |
88 | 92 | } |
89 | 93 | List<IntervalsSource> split = new ArrayList<>(); |
90 | | - if (singletons.size() > 0) { |
91 | | - split.add(Intervals.or(singletons.toArray(IntervalsSource[]::new))); |
| 94 | + for (List<IntervalsSource> group : fixedByWidth.values()) { |
| 95 | + split.add(group.size() == 1 ? group.get(0) : Intervals.or(group)); |
92 | 96 | } |
93 | | - split.addAll(nonSingletons); |
| 97 | + split.addAll(variableWidth); |
94 | 98 | return split; |
95 | 99 | } |
96 | 100 | } |
0 commit comments