Skip to content

Commit 14f507e

Browse files
ahornaceVladimir Kotal
authored andcommitted
Use BitSet for holding positions
1 parent c5dfd15 commit 14f507e

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

suggester/src/main/java/org/opengrok/suggest/query/customized/CustomExactPhraseScorer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import org.apache.lucene.search.TwoPhaseIterator;
3030
import org.apache.lucene.search.Weight;
3131
import org.opengrok.suggest.query.PhraseScorer;
32+
import org.opengrok.suggest.query.data.BitIntsHolder;
3233
import org.opengrok.suggest.query.data.IntsHolder;
33-
import org.opengrok.suggest.query.data.HashIntsHolder;
3434

3535
/**
3636
* Modified Apache Lucene's ExactPhraseScorer (now {@link org.apache.lucene.search.ExactPhraseMatcher}) to support
@@ -138,7 +138,7 @@ private int phraseFreq() throws IOException {
138138
int freq = 0;
139139
final PostingsAndPosition lead = postings[0];
140140

141-
HashIntsHolder positions = new HashIntsHolder();
141+
BitIntsHolder positions = new BitIntsHolder();
142142

143143
advanceHead:
144144
while (true) {
@@ -162,7 +162,7 @@ private int phraseFreq() throws IOException {
162162
}
163163

164164
freq += 1;
165-
positions.add(phrasePos + offset);
165+
positions.set(phrasePos + offset);
166166

167167
if (lead.upTo == lead.freq) {
168168
break;

suggester/src/main/java/org/opengrok/suggest/query/customized/CustomSloppyPhraseScorer.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.HashSet;
2525
import java.util.LinkedHashMap;
2626
import java.util.Map;
27-
import java.util.Set;
2827

2928
import org.apache.lucene.index.Term;
3029
import org.apache.lucene.search.ConjunctionDISI;
@@ -34,8 +33,8 @@
3433
import org.apache.lucene.search.Weight;
3534
import org.apache.lucene.util.FixedBitSet;
3635
import org.opengrok.suggest.query.PhraseScorer;
36+
import org.opengrok.suggest.query.data.BitIntsHolder;
3737
import org.opengrok.suggest.query.data.IntsHolder;
38-
import org.opengrok.suggest.query.data.HashIntsHolder;
3938

4039
/**
4140
* Modified Apache Lucene's SloppyPhraseScorer (now {@link org.apache.lucene.search.SloppyPhraseMatcher}) to remember
@@ -103,9 +102,9 @@ final class CustomSloppyPhraseScorer extends Scorer implements PhraseScorer {
103102
* We may want to fix this in the future (currently not, for performance reasons).
104103
*/
105104
private float phraseFreq() throws IOException {
106-
Set<Integer> allPositions = new HashSet<>();
105+
BitIntsHolder allPositions = new BitIntsHolder();
107106

108-
HashIntsHolder positions = new HashIntsHolder();
107+
BitIntsHolder positions = new BitIntsHolder();
109108

110109
if (phrasePositions.length == 1) { // special handling for one term
111110
end = Integer.MIN_VALUE;
@@ -116,7 +115,7 @@ private float phraseFreq() throws IOException {
116115
}
117116
int matchCount = 0;
118117
while (advancePP(pp)) {
119-
allPositions.add(pp.position + pp.offset);
118+
allPositions.set(pp.position + pp.offset);
120119
addPositions(positions, allPositions, pp.position + pp.offset,0);
121120
matchCount++;
122121
}
@@ -131,7 +130,7 @@ private float phraseFreq() throws IOException {
131130
}
132131

133132
for (PhrasePositions phrasePositions : this.pq) {
134-
allPositions.add(phrasePositions.position + phrasePositions.offset);
133+
allPositions.set(phrasePositions.position + phrasePositions.offset);
135134
}
136135

137136
int numMatches = 0;
@@ -147,7 +146,7 @@ private float phraseFreq() throws IOException {
147146
break; // pps exhausted
148147
}
149148

150-
allPositions.add(pp.position + pp.offset);
149+
allPositions.set(pp.position + pp.offset);
151150

152151
if (pp.position > next) { // done minimizing current match-length
153152
if (matchLength <= slop) {
@@ -180,14 +179,14 @@ private float phraseFreq() throws IOException {
180179
return numMatches;
181180
}
182181

183-
private void addPositions(Set<Integer> positions, Set<Integer> allPositions, int lastEnd, int matchLength) {
182+
private void addPositions(BitIntsHolder positions, IntsHolder allPositions, int lastEnd, int matchLength) {
184183
int expectedPos = lastEnd + offset;
185184

186185
int range = this.slop - matchLength;
187186
for (int i = 0; i < (2 * range) + 1; i++) {
188187
int pos = expectedPos + i - range;
189-
if (pos > 0 && !allPositions.contains(pos)) {
190-
positions.add(pos);
188+
if (pos > 0 && !allPositions.has(pos)) {
189+
positions.set(pos);
191190
}
192191
}
193192
}

0 commit comments

Comments
 (0)