Example usage for org.apache.lucene.document StoredField StoredField

List of usage examples for org.apache.lucene.document StoredField StoredField

Introduction

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

Prototype

public StoredField(String name, double value) 

Source Link

Document

Create a stored-only field with the given double value.

Usage

From source file:org.apache.blur.utils.ResetableDocumentStoredFieldVisitor.java

License:Apache License

@Override
public void floatField(FieldInfo fieldInfo, float value) {
    doc.add(new StoredField(fieldInfo.name, value));
    addSize(fieldInfo, _floatFieldSize);
}

From source file:org.apache.blur.utils.ResetableDocumentStoredFieldVisitor.java

License:Apache License

@Override
public void doubleField(FieldInfo fieldInfo, double value) {
    doc.add(new StoredField(fieldInfo.name, value));
    addSize(fieldInfo, _doubleFieldSize);
}

From source file:org.apache.carbondata.datamap.lucene.LuceneDataMapWriter.java

License:Apache License

private static void addField(Document doc, Object key, String fieldName, Field.Store store) {
    //get field name
    if (key instanceof Byte) {
        // byte type , use int range to deal with byte, lucene has no byte type
        byte value = (Byte) key;
        IntRangeField field = new IntRangeField(fieldName, new int[] { Byte.MIN_VALUE },
                new int[] { Byte.MAX_VALUE });
        field.setIntValue(value);/* w ww  . j  a v a 2  s.co m*/
        doc.add(field);

        // if need store it , add StoredField
        if (store == Field.Store.YES) {
            doc.add(new StoredField(fieldName, (int) value));
        }
    } else if (key instanceof Short) {
        // short type , use int range to deal with short type, lucene has no short type
        short value = (Short) key;
        IntRangeField field = new IntRangeField(fieldName, new int[] { Short.MIN_VALUE },
                new int[] { Short.MAX_VALUE });
        field.setShortValue(value);
        doc.add(field);

        // if need store it , add StoredField
        if (store == Field.Store.YES) {
            doc.add(new StoredField(fieldName, (int) value));
        }
    } else if (key instanceof Integer) {
        // int type , use int point to deal with int type
        int value = (Integer) key;
        doc.add(new IntPoint(fieldName, new int[] { value }));

        // if need store it , add StoredField
        if (store == Field.Store.YES) {
            doc.add(new StoredField(fieldName, value));
        }
    } else if (key instanceof Long) {
        // long type , use long point to deal with long type
        long value = (Long) key;
        doc.add(new LongPoint(fieldName, new long[] { value }));

        // if need store it , add StoredField
        if (store == Field.Store.YES) {
            doc.add(new StoredField(fieldName, value));
        }
    } else if (key instanceof Float) {
        float value = (Float) key;
        doc.add(new FloatPoint(fieldName, new float[] { value }));
        if (store == Field.Store.YES) {
            doc.add(new FloatPoint(fieldName, value));
        }
    } else if (key instanceof Double) {
        double value = (Double) key;
        doc.add(new DoublePoint(fieldName, new double[] { value }));
        if (store == Field.Store.YES) {
            doc.add(new DoublePoint(fieldName, value));
        }
    } else if (key instanceof String) {
        String strValue = (String) key;
        doc.add(new TextField(fieldName, strValue, store));
    } else if (key instanceof Boolean) {
        boolean value = (Boolean) key;
        IntRangeField field = new IntRangeField(fieldName, new int[] { 0 }, new int[] { 1 });
        field.setIntValue(value ? 1 : 0);
        doc.add(field);
        if (store == Field.Store.YES) {
            doc.add(new StoredField(fieldName, value ? 1 : 0));
        }
    }
}

From source file:org.apache.carbondata.datamap.lucene.LuceneDataMapWriter.java

License:Apache License

public static void addData(LuceneColumnKeys key, int rowId, int pageId, int blockletId, ByteBuffer intBuffer,
        IndexWriter indexWriter, List<CarbonColumn> indexCols, boolean storeBlockletWise) throws IOException {

    Document document = new Document();
    for (int i = 0; i < key.getColValues().length; i++) {
        addField(document, key.getColValues()[i], indexCols.get(i).getColName(), Field.Store.NO);
    }//w  w  w  . j  a  v a 2s  . c  o m
    intBuffer.clear();
    if (storeBlockletWise) {
        // No need to store blocklet id to it.
        intBuffer.putShort((short) pageId);
        intBuffer.putShort((short) rowId);
        intBuffer.rewind();
        document.add(new StoredField(ROWID_NAME, intBuffer.getInt()));
    } else {
        intBuffer.putShort((short) blockletId);
        intBuffer.putShort((short) pageId);
        intBuffer.rewind();
        document.add(new StoredField(PAGEID_NAME, intBuffer.getInt()));
        document.add(new StoredField(ROWID_NAME, (short) rowId));
    }
    indexWriter.addDocument(document);
}

From source file:org.apache.carbondata.datamap.lucene.LuceneDataMapWriter.java

License:Apache License

public static void flushCache(Map<LuceneColumnKeys, Map<Integer, RoaringBitmap>> cache,
        List<CarbonColumn> indexCols, IndexWriter indexWriter, boolean storeBlockletWise) throws IOException {
    for (Map.Entry<LuceneColumnKeys, Map<Integer, RoaringBitmap>> entry : cache.entrySet()) {
        Document document = new Document();
        LuceneColumnKeys key = entry.getKey();
        for (int i = 0; i < key.getColValues().length; i++) {
            addField(document, key.getColValues()[i], indexCols.get(i).getColName(), Field.Store.NO);
        }/*ww w  .ja v  a2 s  .  c  o m*/
        Map<Integer, RoaringBitmap> value = entry.getValue();
        int count = 0;
        for (Map.Entry<Integer, RoaringBitmap> pageData : value.entrySet()) {
            RoaringBitmap bitMap = pageData.getValue();
            int cardinality = bitMap.getCardinality();
            // Each row is short and pageid is stored in int
            ByteBuffer byteBuffer = ByteBuffer.allocate(cardinality * 2 + 4);
            if (!storeBlockletWise) {
                byteBuffer.putInt(pageData.getKey());
            } else {
                byteBuffer.putShort(pageData.getKey().shortValue());
            }
            IntIterator intIterator = bitMap.getIntIterator();
            while (intIterator.hasNext()) {
                byteBuffer.putShort((short) intIterator.next());
            }
            document.add(new StoredField(PAGEID_NAME + count, byteBuffer.array()));
            count++;
        }
        indexWriter.addDocument(document);
    }
    cache.clear();
}

From source file:org.apache.derby.optional.lucene.LuceneSupport.java

License:Apache License

/**
 * Get a float value to add to the document read by LuceneQueryVTI.
 */// ww w  .  j ava  2s .  c  o  m
private static IndexableField getFloatField(VTITemplate.ColumnDescriptor keyDescriptor, ResultSet rs,
        int columnIdx // 1-based
) throws SQLException {
    float value = rs.getFloat(columnIdx);
    if (rs.wasNull()) {
        return null;
    } else {
        return new StoredField(keyDescriptor.columnName, value);
    }
}

From source file:org.apache.derby.optional.lucene.LuceneSupport.java

License:Apache License

/**
 * Get a double value to add to the document read by LuceneQueryVTI.
 *//*from  www  . j  a  v a 2  s.  co  m*/
private static IndexableField getDoubleField(VTITemplate.ColumnDescriptor keyDescriptor, ResultSet rs,
        int columnIdx // 1-based
) throws SQLException {
    double value = rs.getDouble(columnIdx);
    if (rs.wasNull()) {
        return null;
    } else {
        return new StoredField(keyDescriptor.columnName, value);
    }
}

From source file:org.apache.derby.optional.lucene.LuceneSupport.java

License:Apache License

/**
 * Get an long value to add to the document read by LuceneQueryVTI.
 *//*from  w  ww  .  j ava 2  s .  c o m*/
private static IndexableField getLongField(VTITemplate.ColumnDescriptor keyDescriptor, ResultSet rs,
        int columnIdx // 1-based
) throws SQLException {
    long value = rs.getLong(columnIdx);
    if (rs.wasNull()) {
        return null;
    } else {
        return new StoredField(keyDescriptor.columnName, value);
    }
}

From source file:org.apache.derby.optional.lucene.LuceneSupport.java

License:Apache License

/**
 * Get a Date value to add to the document read by LuceneQueryVTI.
 *///from w  w w. j  a v  a2  s.  c  o m
private static IndexableField getDateField(VTITemplate.ColumnDescriptor keyDescriptor, ResultSet rs,
        int columnIdx // 1-based
) throws SQLException {
    Date value = rs.getDate(columnIdx);
    if (rs.wasNull()) {
        return null;
    } else {
        return new StoredField(keyDescriptor.columnName, value.getTime());
    }
}

From source file:org.apache.derby.optional.lucene.LuceneSupport.java

License:Apache License

/**
 * Get a Time value to add to the document read by LuceneQueryVTI.
 *//*w w  w .ja  v a  2s.c  o m*/
private static IndexableField getTimeField(VTITemplate.ColumnDescriptor keyDescriptor, ResultSet rs,
        int columnIdx // 1-based
) throws SQLException {
    Time value = rs.getTime(columnIdx);
    if (rs.wasNull()) {
        return null;
    } else {
        return new StoredField(keyDescriptor.columnName, value.getTime());
    }
}