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.derby.optional.lucene.LuceneSupport.java

License:Apache License

/**
 * Get a Timestamp value to add to the document read by LuceneQueryVTI.
 *//*w  w w  .j a v a2  s.c o  m*/
private static IndexableField getTimestampField(VTITemplate.ColumnDescriptor keyDescriptor, ResultSet rs,
        int columnIdx // 1-based
) throws SQLException {
    Timestamp value = rs.getTimestamp(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 an integer value to add to the document read by LuceneQueryVTI.
 *///from w  w w .ja  va2  s  .com
private static IndexableField getIntField(VTITemplate.ColumnDescriptor keyDescriptor, ResultSet rs,
        int columnIdx // 1-based
) throws SQLException {
    int value = rs.getInt(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 binary value to add to the document read by LuceneQueryVTI.
 *//*  ww w .java  2 s  .  co  m*/
private static IndexableField getBinaryField(VTITemplate.ColumnDescriptor keyDescriptor, ResultSet rs,
        int columnIdx // 1-based
) throws SQLException {
    byte[] value = rs.getBytes(columnIdx);
    if (value != null) {
        BytesRef ref = new BytesRef(value);
        return new StoredField(keyDescriptor.columnName, ref);
    } else {
        return null;
    }
}

From source file:org.apache.gora.lucene.store.LuceneStore.java

License:Apache License

private IndexableField convertToIndexableField(String sf, Schema fieldSchema, Object o) {
    IndexableField result = null;/*from   w w w.  j ava 2  s .  c  om*/
    switch (fieldSchema.getType()) {
    case MAP: //TODO: These should be handled better
    case ARRAY:
    case RECORD:
        // For now we'll just store the bytes
        byte[] data = new byte[0];
        try {
            SpecificDatumWriter writer = getDatumWriter(fieldSchema);
            data = IOUtils.serialize(writer, o);
        } catch (IOException e) {
            LOG.error("Error occurred while serializing record", e);
        }
        result = new StoredField(sf, data);
        break;
    case UNION:
        result = convertAvroUnionToDocumentField(sf, fieldSchema, o);
        break;
    case BYTES:
        result = new StoredField(sf, ((ByteBuffer) o).array());
        break;
    case ENUM:
    case STRING:
        //TODO make this Text based on a mapping.xml attribute
        result = new StringField(sf, o.toString(), Store.YES);
        break;
    case BOOLEAN:
        result = new StringField(sf, o.toString(), Store.YES);
        break;
    case DOUBLE:
        result = new StoredField(sf, (Double) o);
        break;
    case FLOAT:
        result = new StoredField(sf, (Float) o);
        break;
    case INT:
        result = new StoredField(sf, (Integer) o);
        break;
    case LONG:
        result = new StoredField(sf, (Long) o);
        break;
    default:
        LOG.error("Unknown field type: {}", fieldSchema.getType());
    }
    return result;
}

From source file:org.apache.solr.legacy.BBoxStrategy.java

License:Apache License

private Field[] createIndexableFields(Rectangle bbox) {
    Field[] fields = new Field[fieldsLen];
    int idx = -1;
    if (hasStored) {
        fields[++idx] = new StoredField(field_minX, bbox.getMinX());
        fields[++idx] = new StoredField(field_minY, bbox.getMinY());
        fields[++idx] = new StoredField(field_maxX, bbox.getMaxX());
        fields[++idx] = new StoredField(field_maxY, bbox.getMaxY());
    }//from  w w w  . j  a  va  2 s.  co m
    if (hasDocVals) {
        fields[++idx] = new DoubleDocValuesField(field_minX, bbox.getMinX());
        fields[++idx] = new DoubleDocValuesField(field_minY, bbox.getMinY());
        fields[++idx] = new DoubleDocValuesField(field_maxX, bbox.getMaxX());
        fields[++idx] = new DoubleDocValuesField(field_maxY, bbox.getMaxY());
    }
    if (hasPointVals) {
        fields[++idx] = new DoublePoint(field_minX, bbox.getMinX());
        fields[++idx] = new DoublePoint(field_minY, bbox.getMinY());
        fields[++idx] = new DoublePoint(field_maxX, bbox.getMaxX());
        fields[++idx] = new DoublePoint(field_maxY, bbox.getMaxY());
    }
    if (legacyNumericFieldType != null) {
        fields[++idx] = new LegacyDoubleField(field_minX, bbox.getMinX(), legacyNumericFieldType);
        fields[++idx] = new LegacyDoubleField(field_minY, bbox.getMinY(), legacyNumericFieldType);
        fields[++idx] = new LegacyDoubleField(field_maxX, bbox.getMaxX(), legacyNumericFieldType);
        fields[++idx] = new LegacyDoubleField(field_maxY, bbox.getMaxY(), legacyNumericFieldType);
    }
    if (xdlFieldType != null) {
        fields[++idx] = new Field(field_xdl, bbox.getCrossesDateLine() ? "T" : "F", xdlFieldType);
    }
    assert idx == fields.length - 1;
    return fields;
}

From source file:org.apache.solr.legacy.PointVectorStrategy.java

License:Apache License

/** @see #createIndexableFields(org.locationtech.spatial4j.shape.Shape) */
public Field[] createIndexableFields(Point point) {
    Field[] fields = new Field[fieldsLen];
    int idx = -1;
    if (hasStored) {
        fields[++idx] = new StoredField(fieldNameX, point.getX());
        fields[++idx] = new StoredField(fieldNameY, point.getY());
    }/*from  w w w .  ja  va  2s .c  o m*/
    if (hasDocVals) {
        fields[++idx] = new DoubleDocValuesField(fieldNameX, point.getX());
        fields[++idx] = new DoubleDocValuesField(fieldNameY, point.getY());
    }
    if (hasPointVals) {
        fields[++idx] = new DoublePoint(fieldNameX, point.getX());
        fields[++idx] = new DoublePoint(fieldNameY, point.getY());
    }
    if (legacyNumericFieldType != null) {
        fields[++idx] = new LegacyDoubleField(fieldNameX, point.getX(), legacyNumericFieldType);
        fields[++idx] = new LegacyDoubleField(fieldNameY, point.getY(), legacyNumericFieldType);
    }
    assert idx == fields.length - 1;
    return fields;
}

From source file:org.apache.solr.schema.AbstractSpatialFieldType.java

License:Apache License

@Override
public List<IndexableField> createFields(SchemaField field, Object val, float boost) {
    String shapeStr = null;//from  w  w  w.j  ava  2 s  . c o m
    Shape shape = null;
    if (val instanceof Shape) {
        shape = ((Shape) val);
    } else {
        shapeStr = val.toString();
        shape = parseShape(shapeStr);
    }
    if (shape == null) {
        log.debug("Field {}: null shape for input: {}", field, val);
        return Collections.emptyList();
    }

    List<IndexableField> result = new ArrayList<IndexableField>();
    if (field.indexed()) {
        T strategy = getStrategy(field.getName());
        result.addAll(Arrays.asList(strategy.createIndexableFields(shape)));
    }

    if (field.stored()) {
        if (shapeStr == null)
            shapeStr = shapeToString(shape);
        result.add(new StoredField(field.getName(), shapeStr));
    }

    return result;
}

From source file:org.apache.solr.schema.DatePointField.java

License:Apache License

@Override
protected StoredField getStoredField(SchemaField sf, Object value) {
    return new StoredField(sf.getName(), ((Date) this.toNativeType(value)).getTime());
}

From source file:org.apache.solr.schema.DoublePointField.java

License:Apache License

@Override
protected StoredField getStoredField(SchemaField sf, Object value) {
    return new StoredField(sf.getName(), (Double) this.toNativeType(value));
}

From source file:org.apache.solr.schema.FloatPointField.java

License:Apache License

@Override
protected StoredField getStoredField(SchemaField sf, Object value) {
    return new StoredField(sf.getName(), (Float) this.toNativeType(value));
}