Search in sources :

Example 1 with BinaryDocValuesUpdate

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

the class BufferedUpdates method addBinaryUpdate.

public void addBinaryUpdate(BinaryDocValuesUpdate update, int docIDUpto) {
    LinkedHashMap<Term, BinaryDocValuesUpdate> fieldUpdates = binaryUpdates.get(update.field);
    if (fieldUpdates == null) {
        fieldUpdates = new LinkedHashMap<>();
        binaryUpdates.put(update.field, fieldUpdates);
        bytesUsed.addAndGet(BYTES_PER_BINARY_FIELD_ENTRY);
    }
    final BinaryDocValuesUpdate current = fieldUpdates.get(update.term);
    if (current != null && docIDUpto < current.docIDUpto) {
        // got a higher docID is scheduled before the other threads.
        return;
    }
    update.docIDUpto = docIDUpto;
    // it's added last (we're interested in insertion-order).
    if (current != null) {
        fieldUpdates.remove(update.term);
    }
    fieldUpdates.put(update.term, update);
    numBinaryUpdates.incrementAndGet();
    if (current == null) {
        bytesUsed.addAndGet(BYTES_PER_BINARY_UPDATE_ENTRY + update.sizeInBytes());
    }
}
Also used : BinaryDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.BinaryDocValuesUpdate)

Example 2 with BinaryDocValuesUpdate

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

the class IndexWriter method updateBinaryDocValue.

/**
   * Updates a document's {@link BinaryDocValues} for <code>field</code> to the
   * given <code>value</code>. You can only update fields that already exist in
   * the index, not add new fields through this method.
   * 
   * <p>
   * <b>NOTE:</b> this method currently replaces the existing value of all
   * affected documents with the new value.
   * 
   * @param term
   *          the term to identify the document(s) to be updated
   * @param field
   *          field name of the {@link BinaryDocValues} field
   * @param value
   *          new value for the field
   *
   * @return The <a href="#sequence_number">sequence number</a>
   * for this operation
   *
   * @throws CorruptIndexException
   *           if the index is corrupt
   * @throws IOException
   *           if there is a low-level IO error
   */
public long updateBinaryDocValue(Term term, String field, BytesRef value) throws IOException {
    ensureOpen();
    if (value == null) {
        throw new IllegalArgumentException("cannot update a field to a null value: " + field);
    }
    if (!globalFieldNumberMap.contains(field, DocValuesType.BINARY)) {
        throw new IllegalArgumentException("can only update existing binary-docvalues fields!");
    }
    try {
        long seqNo = docWriter.updateDocValues(new BinaryDocValuesUpdate(term, field, value));
        if (seqNo < 0) {
            seqNo = -seqNo;
            processEvents(true, false);
        }
        return seqNo;
    } catch (VirtualMachineError tragedy) {
        tragicEvent(tragedy, "updateBinaryDocValue");
        // dead code but javac disagrees:
        return -1;
    }
}
Also used : BinaryDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.BinaryDocValuesUpdate)

Example 3 with BinaryDocValuesUpdate

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

the class IndexWriter method updateDocValues.

/**
   * Updates documents' DocValues fields to the given values. Each field update
   * is applied to the set of documents that are associated with the
   * {@link Term} to the same value. All updates are atomically applied and
   * flushed together.
   * 
   * @param updates
   *          the updates to apply
   *
   * @return The <a href="#sequence_number">sequence number</a>
   * for this operation
   *
   * @throws CorruptIndexException
   *           if the index is corrupt
   * @throws IOException
   *           if there is a low-level IO error
   */
public long updateDocValues(Term term, Field... updates) throws IOException {
    ensureOpen();
    DocValuesUpdate[] dvUpdates = new DocValuesUpdate[updates.length];
    for (int i = 0; i < updates.length; i++) {
        final Field f = updates[i];
        final DocValuesType dvType = f.fieldType().docValuesType();
        if (dvType == null) {
            throw new NullPointerException("DocValuesType must not be null (field: \"" + f.name() + "\")");
        }
        if (dvType == DocValuesType.NONE) {
            throw new IllegalArgumentException("can only update NUMERIC or BINARY fields! field=" + f.name());
        }
        if (!globalFieldNumberMap.contains(f.name(), dvType)) {
            throw new IllegalArgumentException("can only update existing docvalues fields! field=" + f.name() + ", type=" + dvType);
        }
        if (config.getIndexSortFields().contains(f.name())) {
            throw new IllegalArgumentException("cannot update docvalues field involved in the index sort, field=" + f.name() + ", sort=" + config.getIndexSort());
        }
        switch(dvType) {
            case NUMERIC:
                dvUpdates[i] = new NumericDocValuesUpdate(term, f.name(), (Long) f.numericValue());
                break;
            case BINARY:
                dvUpdates[i] = new BinaryDocValuesUpdate(term, f.name(), f.binaryValue());
                break;
            default:
                throw new IllegalArgumentException("can only update NUMERIC or BINARY fields: field=" + f.name() + ", type=" + dvType);
        }
    }
    try {
        long seqNo = docWriter.updateDocValues(dvUpdates);
        if (seqNo < 0) {
            seqNo = -seqNo;
            processEvents(true, false);
        }
        return seqNo;
    } catch (VirtualMachineError tragedy) {
        tragicEvent(tragedy, "updateDocValues");
        // dead code but javac disagrees:
        return -1;
    }
}
Also used : Field(org.apache.lucene.document.Field) BinaryDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.BinaryDocValuesUpdate) NumericDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.NumericDocValuesUpdate) AtomicLong(java.util.concurrent.atomic.AtomicLong) BinaryDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.BinaryDocValuesUpdate) NumericDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.NumericDocValuesUpdate)

Example 4 with BinaryDocValuesUpdate

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

the class CoalescedUpdates method update.

void update(FrozenBufferedUpdates in) {
    totalTermCount += in.terms.size();
    terms.add(in.terms);
    for (int queryIdx = 0; queryIdx < in.queries.length; queryIdx++) {
        final Query query = in.queries[queryIdx];
        queries.put(query, BufferedUpdates.MAX_INT);
    }
    List<DocValuesUpdate> numericPacket = new ArrayList<>();
    numericDVUpdates.add(numericPacket);
    for (NumericDocValuesUpdate nu : in.numericDVUpdates) {
        NumericDocValuesUpdate clone = new NumericDocValuesUpdate(nu.term, nu.field, (Long) nu.value);
        clone.docIDUpto = Integer.MAX_VALUE;
        numericPacket.add(clone);
    }
    List<DocValuesUpdate> binaryPacket = new ArrayList<>();
    binaryDVUpdates.add(binaryPacket);
    for (BinaryDocValuesUpdate bu : in.binaryDVUpdates) {
        BinaryDocValuesUpdate clone = new BinaryDocValuesUpdate(bu.term, bu.field, (BytesRef) bu.value);
        clone.docIDUpto = Integer.MAX_VALUE;
        binaryPacket.add(clone);
    }
}
Also used : BinaryDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.BinaryDocValuesUpdate) Query(org.apache.lucene.search.Query) NumericDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.NumericDocValuesUpdate) ArrayList(java.util.ArrayList) BinaryDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.BinaryDocValuesUpdate) NumericDocValuesUpdate(org.apache.lucene.index.DocValuesUpdate.NumericDocValuesUpdate)

Aggregations

BinaryDocValuesUpdate (org.apache.lucene.index.DocValuesUpdate.BinaryDocValuesUpdate)4 NumericDocValuesUpdate (org.apache.lucene.index.DocValuesUpdate.NumericDocValuesUpdate)2 ArrayList (java.util.ArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Field (org.apache.lucene.document.Field)1 Query (org.apache.lucene.search.Query)1