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

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

Introduction

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

Prototype

public final void removeField(String name) 

Source Link

Document

Removes field with the specified name from the document.

Usage

From source file:ca.gnewton.lusql.core.DocumentFactory.java

License:Apache License

public void passivateObject(Object obj) {
    ++returned;/*from ww w  .  j  a  v  a 2  s . co m*/
    //if(returned%1000 == 0)
    //System.out.println("DocumentFactory returned: " + returned);
    Document doc = (Document) obj;
    List<Fieldable> fields = doc.getFields();
    Iterator<Fieldable> it = fields.iterator();
    while (it.hasNext()) {
        doc.removeField(((Field) it.next()).name());
    }
}

From source file:com.browseengine.bobo.api.BoboSegmentReader.java

License:Open Source License

@Override
public void document(int docID, StoredFieldVisitor visitor) throws IOException {
    super.document(docID, visitor);
    if (!(visitor instanceof DocumentStoredFieldVisitor)) {
        return;/*from www .  j  a  va2s . c o m*/
    }

    Document doc = ((DocumentStoredFieldVisitor) visitor).getDocument();

    Collection<FacetHandler<?>> facetHandlers = _facetHandlerMap.values();
    for (FacetHandler<?> facetHandler : facetHandlers) {
        String[] vals = facetHandler.getFieldValues(this, docID);
        if (vals != null) {
            String[] values = doc.getValues(facetHandler.getName());
            Set<String> storedVals = new HashSet<String>(Arrays.asList(values));

            for (String val : vals) {
                storedVals.add(val);
            }
            doc.removeField(facetHandler.getName());

            for (String val : storedVals) {
                doc.add(new StringField(facetHandler.getName(), val, Field.Store.NO));
            }
        }
    }
}

From source file:com.ideabase.repository.common.object.GenericItem.java

License:Open Source License

@Override
public Document getDocument() {
    final Document document = super.getDocument();
    // Add fields to indexable. (no store)
    acceptVisitor(new Visitor() {
        public void visitField(final String pName, final String pValue) {
            // remove existing field
            if (document.getFields(pName) != null) {
                document.removeField(pName);
            }/*from   w w w .  ja  v  a2s. c o m*/

            // TODO: hardcoded behavior for indexing price or number type field
            final String name = pName.toLowerCase();
            if (name.startsWith(FIELD_PREFIX_PRICE) || name.endsWith(FIELD_SUFFIX_DATE)
                    || name.endsWith(FIELD_SUFFIX_NUMBER)) {
                document.add(new Field(pName, NumberTools.longToString(Long.parseLong(pValue)), Field.Store.NO,
                        Field.Index.UN_TOKENIZED));
            } else if (name.endsWith(FIELD_SUFFIX_ID)) {
                document.add(new Field(pName, pValue, Field.Store.NO, Field.Index.UN_TOKENIZED));
            } else {
                document.add(new Field(pName, pValue, Field.Store.NO, Field.Index.TOKENIZED,
                        Field.TermVector.WITH_POSITIONS_OFFSETS));
            }
        }
    });
    return document;
}

From source file:com.lithium.luces.LucesTest.java

License:Apache License

@Test(expected = NumberFormatException.class)
public void testErrorOnEmptyFloatValue() {
    Document doc = createMockFlatUserDocument();
    doc.removeField(RATING);
    doc.add(new Field(RATING, "   ", Store.NO, Index.ANALYZED));
    Luces luces = new Luces(Version.LUCENE_36).mapping(TYPE, createMapping());
    luces.documentToJSONStringified(doc, true);
}

From source file:com.lithium.luces.LucesTest.java

License:Apache License

@Test(expected = NumberFormatException.class)
public void testErrorOnEmptyIntValue() {
    Document doc = createMockFlatUserDocument();
    doc.removeField(VIEWS);
    doc.add(new Field(VIEWS, "   ", Store.NO, Index.ANALYZED));
    Luces luces = new Luces(Version.LUCENE_36).mapping(TYPE, createMapping());
    luces.documentToJSONStringified(doc, true);
}

From source file:com.lithium.luces.LucesTest.java

License:Apache License

/**
 * for similar tests, this would throw a format error, but since empty strings get parsed to false, no error is
 * thrown//from ww w .j  a v  a 2 s .c  o m
 */
@Test
public void testEmptyBoolValue() {
    Document doc = createMockFlatUserDocument();
    doc.removeField(REGISTERED);
    doc.add(new Field(REGISTERED, "   ", Store.NO, Index.ANALYZED));
    Luces luces = new Luces(Version.LUCENE_36).mapping(TYPE, createMapping());
    JsonObject converted = luces.documentToJSON(doc).getAsJsonObject();
    Assert.assertEquals("false", converted.get(REGISTERED).getAsString());
}

From source file:com.lithium.luces.LucesTest.java

License:Apache License

@Test
public void testDefaultOnEmptyFloatValue() {
    Document doc = createMockFlatUserDocument();
    doc.removeField(RATING);
    doc.add(new Field(RATING, "   ", Store.NO, Index.ANALYZED));
    Luces luces = new Luces(Version.LUCENE_36).mapping(TYPE, createMapping()).useDefaultsForEmpty(true);
    JsonObject converted = luces.documentToJSON(doc).getAsJsonObject();
    Assert.assertEquals("0.0", converted.get(RATING).getAsString());
}

From source file:com.lithium.luces.LucesTest.java

License:Apache License

@Test
public void testDefaultOnEmptyIntValue() {
    Document doc = createMockFlatUserDocument();
    doc.removeField(VIEWS);
    doc.add(new Field(VIEWS, "   ", Store.NO, Index.ANALYZED));
    Luces luces = new Luces(Version.LUCENE_36).mapping(TYPE, createMapping()).useDefaultsForEmpty(true);
    JsonObject converted = luces.documentToJSON(doc).getAsJsonObject();
    Assert.assertEquals("0", converted.get(VIEWS).getAsString());
}

From source file:com.lithium.luces.LucesTest.java

License:Apache License

@Test
public void testDefaultOnEmptyBoolValue() {
    Document doc = createMockFlatUserDocument();
    doc.removeField(REGISTERED);
    doc.add(new Field(REGISTERED, "   ", Store.NO, Index.ANALYZED));
    Luces luces = new Luces(Version.LUCENE_36).mapping(TYPE, createMapping()).useDefaultsForEmpty(true);
    JsonObject converted = luces.documentToJSON(doc).getAsJsonObject();
    Assert.assertEquals("false", converted.get(REGISTERED).getAsString());
}

From source file:com.lithium.luces.LucesTest.java

License:Apache License

@Test
public void testWeirdBoolValue() {
    Document doc = createMockFlatUserDocument();
    doc.removeField(REGISTERED);
    doc.add(new Field(REGISTERED, "boolean", Store.NO, Index.ANALYZED));
    Luces luces = new Luces(Version.LUCENE_36).mapping(TYPE, createMapping()).useDefaultsForEmpty(true);
    JsonObject converted = luces.documentToJSON(doc).getAsJsonObject();
    Assert.assertEquals("false", converted.get(REGISTERED).getAsString());
}