Search in sources :

Example 31 with BinaryDocValues

use of org.apache.lucene.index.BinaryDocValues in project lucene-solr by apache.

the class TaxonomyFacetSumIntAssociations method sumValues.

private final void sumValues(List<MatchingDocs> matchingDocs) throws IOException {
    //System.out.println("count matchingDocs=" + matchingDocs + " facetsField=" + facetsFieldName);
    for (MatchingDocs hits : matchingDocs) {
        BinaryDocValues dv = hits.context.reader().getBinaryDocValues(indexFieldName);
        if (dv == null) {
            // this reader does not have DocValues for the requested category list
            continue;
        }
        DocIdSetIterator docs = hits.bits.iterator();
        int doc;
        while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            // BytesRef getAssociation()?
            if (dv.docID() < doc) {
                dv.advance(doc);
            }
            if (dv.docID() == doc) {
                final BytesRef bytesRef = dv.binaryValue();
                byte[] bytes = bytesRef.bytes;
                int end = bytesRef.offset + bytesRef.length;
                int offset = bytesRef.offset;
                while (offset < end) {
                    int ord = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF);
                    offset += 4;
                    int value = ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF);
                    offset += 4;
                    values[ord] += value;
                }
            }
        }
    }
}
Also used : MatchingDocs(org.apache.lucene.facet.FacetsCollector.MatchingDocs) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) BinaryDocValues(org.apache.lucene.index.BinaryDocValues) BytesRef(org.apache.lucene.util.BytesRef)

Example 32 with BinaryDocValues

use of org.apache.lucene.index.BinaryDocValues in project lucene-solr by apache.

the class FieldCacheImpl method getTerms.

public BinaryDocValues getTerms(LeafReader reader, String field, float acceptableOverheadRatio) throws IOException {
    BinaryDocValues valuesIn = reader.getBinaryDocValues(field);
    if (valuesIn == null) {
        valuesIn = reader.getSortedDocValues(field);
    }
    if (valuesIn != null) {
        // per-thread by SegmentReader):
        return valuesIn;
    }
    final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
    if (info == null) {
        return DocValues.emptyBinary();
    } else if (info.getDocValuesType() != DocValuesType.NONE) {
        throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
    } else if (info.getIndexOptions() == IndexOptions.NONE) {
        return DocValues.emptyBinary();
    }
    BinaryDocValuesImpl impl = (BinaryDocValuesImpl) caches.get(BinaryDocValues.class).get(reader, new CacheKey(field, acceptableOverheadRatio));
    return impl.iterator();
}
Also used : BinaryDocValues(org.apache.lucene.index.BinaryDocValues) FieldInfo(org.apache.lucene.index.FieldInfo)

Example 33 with BinaryDocValues

use of org.apache.lucene.index.BinaryDocValues in project lucene-solr by apache.

the class UninvertingReader method getBinaryDocValues.

@Override
public BinaryDocValues getBinaryDocValues(String field) throws IOException {
    BinaryDocValues values = in.getBinaryDocValues(field);
    if (values != null) {
        return values;
    }
    Type v = getType(field);
    if (v == Type.BINARY) {
        return FieldCache.DEFAULT.getTerms(in, field);
    } else {
        return null;
    }
}
Also used : DocValuesType(org.apache.lucene.index.DocValuesType) BinaryDocValues(org.apache.lucene.index.BinaryDocValues)

Example 34 with BinaryDocValues

use of org.apache.lucene.index.BinaryDocValues in project lucene-solr by apache.

the class Lucene70DocValuesConsumer method addBinaryField.

@Override
public void addBinaryField(FieldInfo field, DocValuesProducer valuesProducer) throws IOException {
    meta.writeInt(field.number);
    meta.writeByte(Lucene70DocValuesFormat.BINARY);
    BinaryDocValues values = valuesProducer.getBinary(field);
    long start = data.getFilePointer();
    meta.writeLong(start);
    int numDocsWithField = 0;
    int minLength = Integer.MAX_VALUE;
    int maxLength = 0;
    for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
        numDocsWithField++;
        BytesRef v = values.binaryValue();
        int length = v.length;
        data.writeBytes(v.bytes, v.offset, v.length);
        minLength = Math.min(length, minLength);
        maxLength = Math.max(length, maxLength);
    }
    assert numDocsWithField <= maxDoc;
    meta.writeLong(data.getFilePointer() - start);
    if (numDocsWithField == 0) {
        meta.writeLong(-2);
        meta.writeLong(0L);
    } else if (numDocsWithField == maxDoc) {
        meta.writeLong(-1);
        meta.writeLong(0L);
    } else {
        long offset = data.getFilePointer();
        meta.writeLong(offset);
        values = valuesProducer.getBinary(field);
        IndexedDISI.writeBitSet(values, data);
        meta.writeLong(data.getFilePointer() - offset);
    }
    meta.writeInt(numDocsWithField);
    meta.writeInt(minLength);
    meta.writeInt(maxLength);
    if (maxLength > minLength) {
        start = data.getFilePointer();
        meta.writeLong(start);
        meta.writeVInt(DIRECT_MONOTONIC_BLOCK_SHIFT);
        final DirectMonotonicWriter writer = DirectMonotonicWriter.getInstance(meta, data, numDocsWithField + 1, DIRECT_MONOTONIC_BLOCK_SHIFT);
        long addr = 0;
        writer.add(addr);
        values = valuesProducer.getBinary(field);
        for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
            addr += values.binaryValue().length;
            writer.add(addr);
        }
        writer.finish();
        meta.writeLong(data.getFilePointer() - start);
    }
}
Also used : DirectMonotonicWriter(org.apache.lucene.util.packed.DirectMonotonicWriter) BinaryDocValues(org.apache.lucene.index.BinaryDocValues) BytesRef(org.apache.lucene.util.BytesRef)

Example 35 with BinaryDocValues

use of org.apache.lucene.index.BinaryDocValues in project lucene-solr by apache.

the class BlendedInfixSuggester method createResults.

@Override
protected List<Lookup.LookupResult> createResults(IndexSearcher searcher, TopFieldDocs hits, int num, CharSequence key, boolean doHighlight, Set<String> matchedTokens, String prefixToken) throws IOException {
    TreeSet<Lookup.LookupResult> results = new TreeSet<>(LOOKUP_COMP);
    // we reduce the num to the one initially requested
    int actualNum = num / numFactor;
    for (int i = 0; i < hits.scoreDocs.length; i++) {
        FieldDoc fd = (FieldDoc) hits.scoreDocs[i];
        BinaryDocValues textDV = MultiDocValues.getBinaryValues(searcher.getIndexReader(), TEXT_FIELD_NAME);
        assert textDV != null;
        textDV.advance(fd.doc);
        final String text = textDV.binaryValue().utf8ToString();
        long weight = (Long) fd.fields[0];
        // This will just be null if app didn't pass payloads to build():
        // TODO: maybe just stored fields?  they compress...
        BinaryDocValues payloadsDV = MultiDocValues.getBinaryValues(searcher.getIndexReader(), "payloads");
        BytesRef payload;
        if (payloadsDV != null) {
            if (payloadsDV.advance(fd.doc) == fd.doc) {
                payload = BytesRef.deepCopyOf(payloadsDV.binaryValue());
            } else {
                payload = new BytesRef(BytesRef.EMPTY_BYTES);
            }
        } else {
            payload = null;
        }
        double coefficient;
        if (text.startsWith(key.toString())) {
            // if hit starts with the key, we don't change the score
            coefficient = 1;
        } else {
            coefficient = createCoefficient(searcher, fd.doc, matchedTokens, prefixToken);
        }
        long score = (long) (weight * coefficient);
        LookupResult result;
        if (doHighlight) {
            result = new LookupResult(text, highlight(text, matchedTokens, prefixToken), score, payload);
        } else {
            result = new LookupResult(text, score, payload);
        }
        boundedTreeAdd(results, result, actualNum);
    }
    return new ArrayList<>(results.descendingSet());
}
Also used : FieldDoc(org.apache.lucene.search.FieldDoc) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BinaryDocValues(org.apache.lucene.index.BinaryDocValues) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

BinaryDocValues (org.apache.lucene.index.BinaryDocValues)37 BytesRef (org.apache.lucene.util.BytesRef)29 Document (org.apache.lucene.document.Document)13 LeafReader (org.apache.lucene.index.LeafReader)12 SortedDocValues (org.apache.lucene.index.SortedDocValues)12 NumericDocValues (org.apache.lucene.index.NumericDocValues)11 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)11 Directory (org.apache.lucene.store.Directory)10 ArrayList (java.util.ArrayList)9 BinaryDocValuesField (org.apache.lucene.document.BinaryDocValuesField)9 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)9 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)7 DirectoryReader (org.apache.lucene.index.DirectoryReader)7 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)7 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)6 Bits (org.apache.lucene.util.Bits)6 IOException (java.io.IOException)5 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)5 IndexReader (org.apache.lucene.index.IndexReader)5 SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)5