Java Code Examples for org.apache.lucene.util.LongBitSet#get()
The following examples show how to use
org.apache.lucene.util.LongBitSet#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocValuesTermsQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { return new ConstantScoreWeight(this, boost) { @Override public Scorer scorer(LeafReaderContext context) throws IOException { final SortedSetDocValues values = DocValues.getSortedSet(context.reader(), field); final LongBitSet bits = new LongBitSet(values.getValueCount()); boolean matchesAtLeastOneTerm = false; TermIterator iterator = termData.iterator(); for (BytesRef term = iterator.next(); term != null; term = iterator.next()) { final long ord = values.lookupTerm(term); if (ord >= 0) { matchesAtLeastOneTerm = true; bits.set(ord); } } if (matchesAtLeastOneTerm == false) { return null; } return new ConstantScoreScorer(this, score(), scoreMode, new TwoPhaseIterator(values) { @Override public boolean matches() throws IOException { for (long ord = values.nextOrd(); ord != SortedSetDocValues.NO_MORE_ORDS; ord = values.nextOrd()) { if (bits.get(ord)) { return true; } } return false; } @Override public float matchCost() { return 3; // lookup in a bitset } }); } @Override public boolean isCacheable(LeafReaderContext ctx) { return DocValues.isCacheable(ctx, field); } }; }
Example 2
Source File: TermsQParserPlugin.java From lucene-solr with Apache License 2.0 | 4 votes |
public Weight createWeight(IndexSearcher searcher, final ScoreMode scoreMode, float boost) throws IOException { if (! (searcher instanceof SolrIndexSearcher)) { log.debug("Falling back to DocValuesTermsQuery because searcher [{}] is not the required SolrIndexSearcher", searcher); return super.createWeight(searcher, scoreMode, boost); } topLevelDocValues = DocValues.getSortedSet(((SolrIndexSearcher)searcher).getSlowAtomicReader(), fieldName); topLevelTermOrdinals = new LongBitSet(topLevelDocValues.getValueCount()); PrefixCodedTerms.TermIterator iterator = getTerms().iterator(); long lastTermOrdFound = 0; for(BytesRef term = iterator.next(); term != null; term = iterator.next()) { long currentTermOrd = lookupTerm(topLevelDocValues, term, lastTermOrdFound); if (currentTermOrd >= 0L) { matchesAtLeastOneTerm = true; topLevelTermOrdinals.set(currentTermOrd); lastTermOrdFound = currentTermOrd; } } return new ConstantScoreWeight(this, boost) { public Scorer scorer(LeafReaderContext context) throws IOException { if (! matchesAtLeastOneTerm) { return null; } SortedSetDocValues segmentDocValues = context.reader().getSortedSetDocValues(fieldName); if (segmentDocValues == null) { return null; } final int docBase = context.docBase; return new ConstantScoreScorer(this, this.score(), scoreMode, new TwoPhaseIterator(segmentDocValues) { public boolean matches() throws IOException { topLevelDocValues.advanceExact(docBase + approximation.docID()); for(long ord = topLevelDocValues.nextOrd(); ord != -1L; ord = topLevelDocValues.nextOrd()) { if (topLevelTermOrdinals.get(ord)) { return true; } } return false; } public float matchCost() { return 10.0F; } }); } public boolean isCacheable(LeafReaderContext ctx) { return DocValues.isCacheable(ctx, new String[]{fieldName}); } }; }
Example 3
Source File: TopLevelJoinQuery.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { if (! (searcher instanceof SolrIndexSearcher)) { log.debug("Falling back to JoinQueryWeight because searcher [{}] is not the required SolrIndexSearcher", searcher); return super.createWeight(searcher, scoreMode, boost); } final SolrIndexSearcher solrSearcher = (SolrIndexSearcher) searcher; final JoinQueryWeight weight = new JoinQueryWeight(solrSearcher, ScoreMode.COMPLETE_NO_SCORES, 1.0f); final SolrIndexSearcher fromSearcher = weight.fromSearcher; final SolrIndexSearcher toSearcher = weight.toSearcher; try { final SortedSetDocValues topLevelFromDocValues = validateAndFetchDocValues(fromSearcher, fromField, "from"); final SortedSetDocValues topLevelToDocValues = validateAndFetchDocValues(toSearcher, toField, "to"); if (topLevelFromDocValues.getValueCount() == 0 || topLevelToDocValues.getValueCount() == 0) { return createNoMatchesWeight(boost); } final LongBitSet fromOrdBitSet = findFieldOrdinalsMatchingQuery(q, fromField, fromSearcher, topLevelFromDocValues); final LongBitSet toOrdBitSet = new LongBitSet(topLevelToDocValues.getValueCount()); final BitsetBounds toBitsetBounds = convertFromOrdinalsIntoToField(fromOrdBitSet, topLevelFromDocValues, toOrdBitSet, topLevelToDocValues); final boolean toMultivalued = toSearcher.getSchema().getFieldOrNull(toField).multiValued(); return new ConstantScoreWeight(this, boost) { public Scorer scorer(LeafReaderContext context) throws IOException { if (toBitsetBounds.lower == BitsetBounds.NO_MATCHES) { return null; } final DocIdSetIterator toApproximation = (toMultivalued) ? context.reader().getSortedSetDocValues(toField) : context.reader().getSortedDocValues(toField); if (toApproximation == null) { return null; } final int docBase = context.docBase; return new ConstantScoreScorer(this, this.score(), scoreMode, new TwoPhaseIterator(toApproximation) { public boolean matches() throws IOException { final boolean hasDoc = topLevelToDocValues.advanceExact(docBase + approximation.docID()); if (hasDoc) { for (long ord = topLevelToDocValues.nextOrd(); ord != -1L; ord = topLevelToDocValues.nextOrd()) { if (toOrdBitSet.get(ord)) { return true; } } } return false; } public float matchCost() { return 10.0F; } }); } public boolean isCacheable(LeafReaderContext ctx) { return false; } }; } catch (IOException e) { throw new RuntimeException(e); } }