- All Implemented Interfaces:
IndexableField
InetAddress field.
Finding all documents within a range at search time is efficient. Multiple values for the same field in one document is allowed.
This field defines static factory methods for creating common queries:
newExactQuery(String, InetAddress)for matching an exact network address.newPrefixQuery(String, InetAddress, int)for matching a network based on CIDR prefix.newRangeQuery(String, InetAddress, InetAddress)for matching arbitrary network address ranges.newSetQuery(String, InetAddress...)for matching a set of network addresses.
This field supports both IPv4 and IPv6 addresses: IPv4 addresses are converted to IPv4-Mapped IPv6 Addresses: indexing
1.2.3.4 is the same as indexing ::FFFF:1.2.3.4.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.document.Field
Field.Store -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe number of bytes per dimension: 128 bits(package private) static final byte[]static final InetAddressThe maximum value that an ip address can hold.static final InetAddressThe minimum value that an ip address can hold.private static final FieldTypeFields inherited from class org.apache.lucene.document.Field
fieldsData, name, tokenStream, type -
Constructor Summary
ConstructorsConstructorDescriptionInetAddressPoint(String name, InetAddress point) Creates a new InetAddressPoint, indexing the provided address. -
Method Summary
Modifier and TypeMethodDescriptionstatic InetAddressdecode(byte[] value) Decodes InetAddress value from binary encodingstatic byte[]encode(InetAddress value) Encode InetAddress value into binary encodingstatic QuerynewExactQuery(String field, InetAddress value) Create a query for matching a network address.static QuerynewPrefixQuery(String field, InetAddress value, int prefixLength) Create a prefix query for matching a CIDR network range.static QuerynewRangeQuery(String field, InetAddress lowerValue, InetAddress upperValue) Create a range query for network addresses.static QuerynewSetQuery(String field, InetAddress... values) Create a query matching any of the specified 1D values.static InetAddressnextDown(InetAddress address) Return theInetAddressthat compares immediately less thanaddress.static InetAddressnextUp(InetAddress address) Return theInetAddressthat compares immediately greater thanaddress.voidsetBytesValue(BytesRef bytes) Expert: change the value of this field.voidsetInetAddressValue(InetAddress value) Change the values of this fieldtoString()Prints a Field for human consumption.Methods inherited from class org.apache.lucene.document.Field
binaryValue, fieldType, getCharSequenceValue, invertableType, name, numericValue, readerValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, storedValue, stringValue, tokenStream, tokenStreamValue
-
Field Details
-
BYTES
public static final int BYTESThe number of bytes per dimension: 128 bits- See Also:
-
IPV4_PREFIX
static final byte[] IPV4_PREFIX -
TYPE
-
MIN_VALUE
The minimum value that an ip address can hold. -
MAX_VALUE
The maximum value that an ip address can hold.
-
-
Constructor Details
-
InetAddressPoint
Creates a new InetAddressPoint, indexing the provided address.- Parameters:
name- field namepoint- InetAddress value- Throws:
IllegalArgumentException- if the field name or value is null.
-
-
Method Details
-
nextUp
Return theInetAddressthat compares immediately greater thanaddress.- Throws:
ArithmeticException- if the provided address is themaximum ip address
-
nextDown
Return theInetAddressthat compares immediately less thanaddress.- Throws:
ArithmeticException- if the provided address is theminimum ip address
-
setInetAddressValue
Change the values of this field -
setBytesValue
Description copied from class:FieldExpert: change the value of this field. SeeField.setStringValue(String).NOTE: the provided BytesRef is not copied so be sure not to change it until you're done with this field.
- Overrides:
setBytesValuein classField
-
toString
Description copied from class:FieldPrints a Field for human consumption. -
encode
Encode InetAddress value into binary encoding -
decode
Decodes InetAddress value from binary encoding -
newExactQuery
Create a query for matching a network address.- Parameters:
field- field name. must not benull.value- exact value- Returns:
- a query matching documents with this exact value
- Throws:
IllegalArgumentException- iffieldis null.
-
newPrefixQuery
Create a prefix query for matching a CIDR network range.- Parameters:
field- field name. must not benull.value- any host addressprefixLength- the network prefix length for this address. This is also known as the subnet mask in the context of IPv4 addresses.- Returns:
- a query matching documents with addresses contained within this network
- Throws:
IllegalArgumentException- iffieldis null, or prefixLength is invalid.
-
newRangeQuery
Create a range query for network addresses.You can have half-open ranges (which are in fact </≤ or >/≥ queries) by setting
lowerValue = InetAddressPoint.MIN_VALUEorupperValue = InetAddressPoint.MAX_VALUE.Ranges are inclusive. For exclusive ranges, pass
InetAddressPoint#nextUp(lowerValue)orInetAddressPoint#nexDown(upperValue).- Parameters:
field- field name. must not benull.lowerValue- lower portion of the range (inclusive). must not be null.upperValue- upper portion of the range (inclusive). must not be null.- Returns:
- a query matching documents within this range.
- Throws:
IllegalArgumentException- iffieldis null,lowerValueis null, orupperValueis null
-
newSetQuery
Create a query matching any of the specified 1D values. This is the points equivalent ofTermsQuery.- Parameters:
field- field name. must not benull.values- all values to match
-