use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.
the class TestConjunctionDISI method testCollapseSubConjunctions.
public void testCollapseSubConjunctions(boolean wrapWithScorer) throws IOException {
final int iters = atLeast(100);
for (int iter = 0; iter < iters; ++iter) {
final int maxDoc = TestUtil.nextInt(random(), 100, 10000);
final int numIterators = TestUtil.nextInt(random(), 5, 10);
final FixedBitSet[] sets = new FixedBitSet[numIterators];
final List<Scorer> scorers = new LinkedList<>();
for (int i = 0; i < numIterators; ++i) {
final FixedBitSet set = randomSet(maxDoc);
if (random().nextBoolean()) {
// simple iterator
sets[i] = set;
scorers.add(new ConstantScoreScorer(null, 0f, new BitDocIdSet(set).iterator()));
} else {
// scorer with approximation
final FixedBitSet confirmed = clearRandomBits(set);
sets[i] = confirmed;
final TwoPhaseIterator approximation = approximation(new BitDocIdSet(set).iterator(), confirmed);
scorers.add(scorer(approximation));
}
}
// make some sub sequences into sub conjunctions
final int subIters = atLeast(3);
for (int subIter = 0; subIter < subIters && scorers.size() > 3; ++subIter) {
final int subSeqStart = TestUtil.nextInt(random(), 0, scorers.size() - 2);
final int subSeqEnd = TestUtil.nextInt(random(), subSeqStart + 2, scorers.size());
List<Scorer> subIterators = scorers.subList(subSeqStart, subSeqEnd);
Scorer subConjunction;
if (wrapWithScorer) {
subConjunction = new ConjunctionScorer(null, subIterators, Collections.emptyList());
} else {
subConjunction = new ConstantScoreScorer(null, 0f, ConjunctionDISI.intersectScorers(subIterators));
}
scorers.set(subSeqStart, subConjunction);
int toRemove = subSeqEnd - subSeqStart - 1;
while (toRemove-- > 0) {
scorers.remove(subSeqStart + 1);
}
}
if (scorers.size() == 1) {
// ConjunctionDISI needs two iterators
scorers.add(new ConstantScoreScorer(null, 0f, DocIdSetIterator.all(maxDoc)));
}
final DocIdSetIterator conjunction = ConjunctionDISI.intersectScorers(scorers);
assertEquals(intersect(sets), toBitSet(maxDoc, conjunction));
}
}
use of org.apache.lucene.util.FixedBitSet in project lucene-solr by apache.
the class TestConjunctionDISI method intersect.
private static FixedBitSet intersect(FixedBitSet[] bitSets) {
final FixedBitSet intersection = new FixedBitSet(bitSets[0].length());
intersection.or(bitSets[0]);
for (int i = 1; i < bitSets.length; ++i) {
intersection.and(bitSets[i]);
}
return intersection;
}
use of org.apache.lucene.util.FixedBitSet in project Krill by KorAP.
the class Match method getSnippetHTML.
@JsonProperty("snippet")
public String getSnippetHTML() {
if (!this._processHighlight())
return null;
if (this.processed && this.snippetHTML != null)
return this.snippetHTML;
if (DEBUG)
log.trace("Create HTML Snippet");
StringBuilder sb = new StringBuilder();
StringBuilder rightContext = new StringBuilder();
// Remember ids already defined to
// have joined elements
HashSet<String> joins = new HashSet<>(100);
// Snippet stack sizes
short start = (short) 0;
short end = this.snippetArray.size();
// Create context
sb.append("<span class=\"context-left\">");
if (this.startMore)
sb.append("<span class=\"more\"></span>");
// Set levels for highlights
FixedBitSet level = new FixedBitSet(255);
level.set(0, 255);
byte[] levelCache = new byte[255];
HighlightCombinatorElement elem;
end--;
if (end > 0) {
// First element of sorted array
elem = this.snippetArray.getFirst();
// First element is textual
if (elem.type == 0) {
sb.append(elem.toHTML(this, level, levelCache, joins));
// Move start position
start++;
}
;
sb.append("</span>");
// Last element of sorted array
elem = this.snippetArray.getLast();
// Create right context, if there is any
rightContext.append("<span class=\"context-right\">");
// Last element is textual
if (elem != null && elem.type == 0) {
rightContext.append(elem.toHTML(this, level, levelCache, joins));
// decrement end
end--;
}
;
}
;
if (this.endMore)
rightContext.append("<span class=\"more\"></span>");
rightContext.append("</span>");
// Iterate through all remaining elements
sb.append("<span class=\"match\">");
for (short i = start; i <= end; i++) {
elem = this.snippetArray.get(i);
// UNTESTED
if (elem != null) {
String elemString = elem.toHTML(this, level, levelCache, joins);
if (DEBUG) {
log.trace("Add node {}", elemString);
}
;
sb.append(elemString);
}
}
;
sb.append("</span>");
sb.append(rightContext);
return (this.snippetHTML = sb.toString());
}
use of org.apache.lucene.util.FixedBitSet in project Krill by KorAP.
the class KrillCollection method bits.
/**
* Create a bit vector representing the live documents of the
* virtual collection to be used in searches.
* This will respect deleted documents.
*
* @param The
* {@link LeafReaderContext} to search in.
* @return A bit vector representing the live documents of the
* virtual collection.
* @throws IOException
*/
public FixedBitSet bits(LeafReaderContext atomic) throws IOException {
LeafReader r = atomic.reader();
FixedBitSet bitset = new FixedBitSet(r.maxDoc());
DocIdSet docids = this.getDocIdSet(atomic, (Bits) r.getLiveDocs());
if (docids == null) {
if (this.cbi != null) {
bitset.clear(0, bitset.length());
} else {
bitset.set(0, bitset.length());
}
;
} else
bitset.or(docids.iterator());
return bitset;
}
use of org.apache.lucene.util.FixedBitSet in project SearchServices by Alfresco.
the class BitsFilter method and.
public void and(BitsFilter bitsFilter) {
List<FixedBitSet> andSets = bitsFilter.bitSets;
for (int i = 0; i < bitSets.size(); i++) {
FixedBitSet a = bitSets.get(i);
FixedBitSet b = andSets.get(i);
a.and(b);
}
}
Aggregations