Search in sources :

Example 1 with InetAddressPoint

use of org.apache.lucene.document.InetAddressPoint in project elasticsearch by elastic.

the class IpFieldMapper method parseCreateField.

@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    Object addressAsObject;
    if (context.externalValueSet()) {
        addressAsObject = context.externalValue();
    } else {
        addressAsObject = context.parser().textOrNull();
    }
    if (addressAsObject == null) {
        addressAsObject = fieldType().nullValue();
    }
    if (addressAsObject == null) {
        return;
    }
    String addressAsString = addressAsObject.toString();
    InetAddress address;
    if (addressAsObject instanceof InetAddress) {
        address = (InetAddress) addressAsObject;
    } else {
        try {
            address = InetAddresses.forString(addressAsString);
        } catch (IllegalArgumentException e) {
            if (ignoreMalformed.value()) {
                return;
            } else {
                throw e;
            }
        }
    }
    if (context.includeInAll(includeInAll, this)) {
        context.allEntries().addText(fieldType().name(), addressAsString, fieldType().boost());
    }
    if (fieldType().indexOptions() != IndexOptions.NONE) {
        fields.add(new InetAddressPoint(fieldType().name(), address));
    }
    if (fieldType().hasDocValues()) {
        fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address))));
    }
    if (fieldType().stored()) {
        fields.add(new StoredField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address))));
    }
}
Also used : StoredField(org.apache.lucene.document.StoredField) InetAddressPoint(org.apache.lucene.document.InetAddressPoint) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) InetAddress(java.net.InetAddress) BytesRef(org.apache.lucene.util.BytesRef)

Example 2 with InetAddressPoint

use of org.apache.lucene.document.InetAddressPoint in project crate by crate.

the class IpFieldMapper method parseCreateField.

@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    Object addressAsObject;
    if (context.externalValueSet()) {
        addressAsObject = context.externalValue();
    } else {
        addressAsObject = context.parser().textOrNull();
    }
    if (addressAsObject == null) {
        addressAsObject = nullValue;
        ;
    }
    if (addressAsObject == null) {
        return;
    }
    String addressAsString = addressAsObject.toString();
    InetAddress address;
    if (addressAsObject instanceof InetAddress) {
        address = (InetAddress) addressAsObject;
    } else {
        address = InetAddresses.forString(addressAsString);
    }
    if (fieldType().isSearchable()) {
        fields.add(new InetAddressPoint(fieldType().name(), address));
    }
    if (fieldType().hasDocValues()) {
        fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address))));
    } else if (fieldType.stored() || fieldType().isSearchable()) {
        createFieldNamesField(context, fields);
    }
    if (fieldType.stored()) {
        fields.add(new StoredField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address))));
    }
}
Also used : StoredField(org.apache.lucene.document.StoredField) InetAddressPoint(org.apache.lucene.document.InetAddressPoint) SortedSetDocValuesField(org.apache.lucene.document.SortedSetDocValuesField) InetAddress(java.net.InetAddress) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

InetAddress (java.net.InetAddress)2 InetAddressPoint (org.apache.lucene.document.InetAddressPoint)2 SortedSetDocValuesField (org.apache.lucene.document.SortedSetDocValuesField)2 StoredField (org.apache.lucene.document.StoredField)2 BytesRef (org.apache.lucene.util.BytesRef)2