Search in sources :

Example 6 with FieldInfo

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

the class FSTOrdTermsWriter method write.

@Override
public void write(Fields fields) throws IOException {
    for (String field : fields) {
        Terms terms = fields.terms(field);
        if (terms == null) {
            continue;
        }
        FieldInfo fieldInfo = fieldInfos.fieldInfo(field);
        boolean hasFreq = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) >= 0;
        TermsEnum termsEnum = terms.iterator();
        TermsWriter termsWriter = new TermsWriter(fieldInfo);
        long sumTotalTermFreq = 0;
        long sumDocFreq = 0;
        FixedBitSet docsSeen = new FixedBitSet(maxDoc);
        while (true) {
            BytesRef term = termsEnum.next();
            if (term == null) {
                break;
            }
            BlockTermState termState = postingsWriter.writeTerm(term, termsEnum, docsSeen);
            if (termState != null) {
                termsWriter.finishTerm(term, termState);
                sumTotalTermFreq += termState.totalTermFreq;
                sumDocFreq += termState.docFreq;
            }
        }
        termsWriter.finish(hasFreq ? sumTotalTermFreq : -1, sumDocFreq, docsSeen.cardinality());
    }
}
Also used : BlockTermState(org.apache.lucene.codecs.BlockTermState) FixedBitSet(org.apache.lucene.util.FixedBitSet) Terms(org.apache.lucene.index.Terms) FieldInfo(org.apache.lucene.index.FieldInfo) BytesRef(org.apache.lucene.util.BytesRef) TermsEnum(org.apache.lucene.index.TermsEnum)

Example 7 with FieldInfo

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

the class DocNameExtractor method docName.

/**
   * Extract the name of the input doc from the index.
   * @param searcher access to the index.
   * @param docid ID of doc whose name is needed.
   * @return the name of the input doc as extracted from the index.
   * @throws IOException if cannot extract the doc name from the index.
   */
public String docName(IndexSearcher searcher, int docid) throws IOException {
    final List<String> name = new ArrayList<>();
    searcher.getIndexReader().document(docid, new StoredFieldVisitor() {

        @Override
        public void stringField(FieldInfo fieldInfo, byte[] bytes) {
            String value = new String(bytes, StandardCharsets.UTF_8);
            name.add(value);
        }

        @Override
        public Status needsField(FieldInfo fieldInfo) {
            if (!name.isEmpty()) {
                return Status.STOP;
            } else if (fieldInfo.name.equals(docNameField)) {
                return Status.YES;
            } else {
                return Status.NO;
            }
        }
    });
    if (name.size() != 0) {
        return name.get(0);
    } else {
        return null;
    }
}
Also used : StoredFieldVisitor(org.apache.lucene.index.StoredFieldVisitor) ArrayList(java.util.ArrayList) FieldInfo(org.apache.lucene.index.FieldInfo)

Example 8 with FieldInfo

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

the class CompressingStoredFieldsReader method visitDocument.

@Override
public void visitDocument(int docID, StoredFieldVisitor visitor) throws IOException {
    final SerializedDocument doc = document(docID);
    for (int fieldIDX = 0; fieldIDX < doc.numStoredFields; fieldIDX++) {
        final long infoAndBits = doc.in.readVLong();
        final int fieldNumber = (int) (infoAndBits >>> TYPE_BITS);
        final FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldNumber);
        final int bits = (int) (infoAndBits & TYPE_MASK);
        assert bits <= NUMERIC_DOUBLE : "bits=" + Integer.toHexString(bits);
        switch(visitor.needsField(fieldInfo)) {
            case YES:
                readField(doc.in, visitor, fieldInfo, bits);
                break;
            case NO:
                if (fieldIDX == doc.numStoredFields - 1) {
                    // don't skipField on last field value; treat like STOP
                    return;
                }
                skipField(doc.in, bits);
                break;
            case STOP:
                return;
        }
    }
}
Also used : FieldInfo(org.apache.lucene.index.FieldInfo)

Example 9 with FieldInfo

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

the class Lucene70DocValuesProducer method readFields.

private void readFields(ChecksumIndexInput meta, FieldInfos infos) throws IOException {
    for (int fieldNumber = meta.readInt(); fieldNumber != -1; fieldNumber = meta.readInt()) {
        FieldInfo info = infos.fieldInfo(fieldNumber);
        if (info == null) {
            throw new CorruptIndexException("Invalid field number: " + fieldNumber, meta);
        }
        byte type = meta.readByte();
        if (type == Lucene70DocValuesFormat.NUMERIC) {
            numerics.put(info.name, readNumeric(meta));
        } else if (type == Lucene70DocValuesFormat.BINARY) {
            binaries.put(info.name, readBinary(meta));
        } else if (type == Lucene70DocValuesFormat.SORTED) {
            sorted.put(info.name, readSorted(meta));
        } else if (type == Lucene70DocValuesFormat.SORTED_SET) {
            sortedSets.put(info.name, readSortedSet(meta));
        } else if (type == Lucene70DocValuesFormat.SORTED_NUMERIC) {
            sortedNumerics.put(info.name, readSortedNumeric(meta));
        } else {
            throw new CorruptIndexException("invalid type: " + type, meta);
        }
    }
}
Also used : CorruptIndexException(org.apache.lucene.index.CorruptIndexException) FieldInfo(org.apache.lucene.index.FieldInfo)

Example 10 with FieldInfo

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

the class Lucene70NormsProducer method readFields.

private void readFields(IndexInput meta, FieldInfos infos) throws IOException {
    for (int fieldNumber = meta.readInt(); fieldNumber != -1; fieldNumber = meta.readInt()) {
        FieldInfo info = infos.fieldInfo(fieldNumber);
        if (info == null) {
            throw new CorruptIndexException("Invalid field number: " + fieldNumber, meta);
        } else if (!info.hasNorms()) {
            throw new CorruptIndexException("Invalid field: " + info.name, meta);
        }
        NormsEntry entry = new NormsEntry();
        entry.docsWithFieldOffset = meta.readLong();
        entry.docsWithFieldLength = meta.readLong();
        entry.numDocsWithField = meta.readInt();
        entry.bytesPerNorm = meta.readByte();
        switch(entry.bytesPerNorm) {
            case 0:
            case 1:
            case 2:
            case 4:
            case 8:
                break;
            default:
                throw new CorruptIndexException("Invalid bytesPerValue: " + entry.bytesPerNorm + ", field: " + info.name, meta);
        }
        entry.normsOffset = meta.readLong();
        norms.put(info.number, entry);
    }
}
Also used : CorruptIndexException(org.apache.lucene.index.CorruptIndexException) FieldInfo(org.apache.lucene.index.FieldInfo)

Aggregations

FieldInfo (org.apache.lucene.index.FieldInfo)53 BytesRef (org.apache.lucene.util.BytesRef)13 LeafReader (org.apache.lucene.index.LeafReader)12 ArrayList (java.util.ArrayList)10 Terms (org.apache.lucene.index.Terms)9 TermsEnum (org.apache.lucene.index.TermsEnum)9 IOException (java.io.IOException)8 FieldInfos (org.apache.lucene.index.FieldInfos)8 HashMap (java.util.HashMap)7 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)7 DocValuesType (org.apache.lucene.index.DocValuesType)6 PointValues (org.apache.lucene.index.PointValues)6 IndexOutput (org.apache.lucene.store.IndexOutput)6 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)5 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)5 StoredFieldVisitor (org.apache.lucene.index.StoredFieldVisitor)5 Map (java.util.Map)4 Document (org.apache.lucene.document.Document)4 EmptyDocValuesProducer (org.apache.lucene.index.EmptyDocValuesProducer)4 IndexReader (org.apache.lucene.index.IndexReader)4