Example usage for org.apache.lucene.document Document removeFields

List of usage examples for org.apache.lucene.document Document removeFields

Introduction

In this page you can find the example usage for org.apache.lucene.document Document removeFields.

Prototype

public final void removeFields(String name) 

Source Link

Document

Removes all fields with the given name from the document.

Usage

From source file:com.b2international.index.lucene.IndexFieldBase.java

License:Apache License

@Override
public final void removeAll(Document doc) {
    doc.removeFields(fieldName());
}

From source file:com.browseengine.bobo.index.digest.DataDigester.java

License:Open Source License

public static void populateDocument(Document doc, FieldConfiguration fConf) {
    String[] fields = fConf.getFieldNames();

    StringBuilder tokenBuffer = new StringBuilder();

    for (int i = 0; i < fields.length; ++i) {
        String[] values = doc.getValues(fields[i]);
        if (values != null) {
            doc.removeFields(fields[i]);
            for (int k = 0; k < values.length; ++k) {
                doc.add(new Field(fields[i], values[i], Store.NO, Index.NOT_ANALYZED));
                tokenBuffer.append(' ').append(values[i]);
            }//  www.  j a  va  2 s.c o m
        }
    }
}

From source file:com.gnizr.core.search.DocumentCreator.java

License:Mozilla Public License

/**
 * Removes the <code>Field</code> that indicates the document being a 
 * leading document. Nothing happens if the input document doesn't
 * have a <code>indexType</code> field with value <code>lead</code>. 
 * /*from   ww  w .  jav  a 2  s. c  o m*/
 * @param doc removes the leading document field from this document
 * @return the same input instance with the leading document field
 * removed, if it exists.
 */
@SuppressWarnings("unchecked")
public static Document removeIndexTypeLead(Document doc) {
    if (doc == null) {
        throw new NullPointerException("input Document object is NULL");
    }
    Field[] fields = doc.getFields(FIELD_INDEX_TYPE);
    if (fields != null && fields.length > 0) {
        List<Field> f2keep = new ArrayList<Field>();
        for (Field f : fields) {
            if (!f.stringValue().equals(INDEX_TYPE_LEAD)) {
                f2keep.add(f);
            }
        }
        doc.removeFields(FIELD_INDEX_TYPE);
        for (Field f : f2keep) {
            doc.add(f);
        }
    }
    return doc;
}

From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactory.java

License:Apache License

private Document lookup(SolrIndexSearcher lookup, String id, BytesRef idRef, Set<String> fields)
        throws IOException {
    idRef.copyChars(id);/*  www.  j ava  2  s  .  c om*/
    Term t = new Term("id", idRef);
    if (lookup.docFreq(t) == 0) {
        return null;
    }

    int docId = lookup.getFirstMatch(t);
    if (docId == -1) {
        return null;
    }
    Document doc = lookup.doc(docId, fields);
    if (doc == null) {
        return null;
    }
    doc.removeFields("id");
    return doc;
}

From source file:com.mothsoft.alexis.domain.ByteArrayAsStringFieldBridge.java

License:Apache License

public void set(String name, Object value, org.apache.lucene.document.Document luceneDocument,
        LuceneOptions luceneOptions) {//ww  w .j  ava 2 s  .co  m
    luceneDocument.removeFields(name);
    final byte[] bytes = (byte[]) value;
    luceneOptions.addFieldToDocument(name, new String(bytes), luceneDocument);
}

From source file:com.mothsoft.alexis.domain.DateAsLongFieldBridge.java

License:Apache License

public void set(String name, Object value, org.apache.lucene.document.Document luceneDocument,
        LuceneOptions luceneOptions) {//from  w ww .j a  v  a  2  s .  c  o  m
    luceneDocument.removeFields(name);
    final Date date = (Date) value;
    luceneOptions.addNumericFieldToDocument(name, date.getTime(), luceneDocument);
}

From source file:com.mothsoft.alexis.domain.DocumentStateFieldBridge.java

License:Apache License

public void set(String name, Object value, org.apache.lucene.document.Document luceneDocument,
        LuceneOptions luceneOptions) {/*from  w  ww  . ja  va2s  . c  om*/
    luceneDocument.removeFields(name);
    final Integer state = (Integer) value;
    luceneOptions.addNumericFieldToDocument(name, state, luceneDocument);
}

From source file:com.mothsoft.alexis.domain.DocumentUserFieldBridge.java

License:Apache License

public void set(String name, Object value, org.apache.lucene.document.Document luceneDocument,
        LuceneOptions luceneOptions) {//from w w w  . j  a v a 2 s.co  m
    luceneDocument.removeFields(name);

    @SuppressWarnings("unchecked")
    final List<DocumentUser> documentUsers = (List<DocumentUser>) value;
    for (final DocumentUser docUser : documentUsers) {
        final Long userId = docUser.getUser().getId();
        luceneOptions.addNumericFieldToDocument(name, userId, luceneDocument);
    }
}

From source file:com.mothsoft.alexis.domain.TopicDocumentFieldBridge.java

License:Apache License

public void set(String name, Object value, org.apache.lucene.document.Document luceneDocument,
        LuceneOptions luceneOptions) {//from w  ww  .  j a va 2 s  .  c o  m
    luceneDocument.removeFields(name);

    if (value != null) {
        @SuppressWarnings("unchecked")
        final List<TopicDocument> topicDocuments = (List<TopicDocument>) value;
        for (final TopicDocument topicDocument : topicDocuments) {
            final Long userId = topicDocument.getTopic().getUserId();
            luceneOptions.addNumericFieldToDocument(name, userId, luceneDocument);
        }
    }
}

From source file:de.dfki.km.leech.parser.incremental.IncrementalCrawlingHistory.java

License:Open Source License

/**
 * Sets a data entities 'last crawled/checked time' entry to the current time. In the case this data entity is a master entity, all slave documents will be updated
 * also. You can set an entity as a master entity with {@link #addDataEntity(String, String, String)} or {@link #updateDataEntity(String, String, String)}
 * /*w ww.j a  v  a 2 s .co  m*/
 * @param strDataEntityId the data entity which is finally checked/crawled
 * 
 * @throws IOException
 * @throws CorruptIndexException
 */
public void updateDataEntityLastCrawledTime(String strDataEntityId) throws CorruptIndexException, IOException {

    Term termId = new Term(dataEntityId, strDataEntityId);

    refreshIndexReaderz();
    TopDocs topDocs = m_indexSearcher.search(new TermQuery(termId), 1);

    if (topDocs.totalHits == 0)
        throw new IllegalStateException("there has to be an data entry with Id " + strDataEntityId
                + " for updating. Nothing was found.");

    long lCurrentTime = System.currentTimeMillis();

    Document doc = m_indexReader.document(topDocs.scoreDocs[0].doc);

    doc.removeFields(lastCrawledTime);
    doc.add(new LongPoint(lastCrawledTime, lCurrentTime));
    doc.add(new StoredField(lastCrawledTime, lCurrentTime));

    m_indexWriter.updateDocument(termId, doc);

    // wenn das Teil eine MasterDataEntity ist, dann mssen alle assoziierten Sklaven auch noch aktualisiert werden

    termId = new Term(masterDataEntityId, strDataEntityId);

    topDocs = m_indexSearcher.search(new TermQuery(termId), Integer.MAX_VALUE);

    for (int i = 0; i < topDocs.scoreDocs.length; i++) {

        Document slaveDoc = m_indexReader.document(topDocs.scoreDocs[i].doc);

        slaveDoc.removeFields(lastCrawledTime);
        slaveDoc.add(new LongPoint(lastCrawledTime, lCurrentTime));
        slaveDoc.add(new StoredField(lastCrawledTime, lCurrentTime));

        m_indexWriter.updateDocument(termId, doc);
    }

}