Package org.apache.lucene.document
Class InetAddressPoint
- java.lang.Object
-
- org.apache.lucene.document.Field
-
- org.apache.lucene.document.InetAddressPoint
-
- All Implemented Interfaces:
IndexableField
public class InetAddressPoint extends Field
An indexed 128-bitInetAddress
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:
PointValues
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.document.Field
Field.Store
-
-
Field Summary
Fields Modifier and Type Field Description static int
BYTES
The number of bytes per dimension: 128 bitsstatic InetAddress
MAX_VALUE
The maximum value that an ip address can hold.static InetAddress
MIN_VALUE
The minimum value that an ip address can hold.-
Fields inherited from class org.apache.lucene.document.Field
fieldsData, name, tokenStream, type
-
-
Constructor Summary
Constructors Constructor Description InetAddressPoint(String name, InetAddress point)
Creates a new InetAddressPoint, indexing the provided address.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static InetAddress
decode(byte[] value)
Decodes InetAddress value from binary encodingstatic byte[]
encode(InetAddress value)
Encode InetAddress value into binary encodingstatic Query
newExactQuery(String field, InetAddress value)
Create a query for matching a network address.static Query
newPrefixQuery(String field, InetAddress value, int prefixLength)
Create a prefix query for matching a CIDR network range.static Query
newRangeQuery(String field, InetAddress lowerValue, InetAddress upperValue)
Create a range query for network addresses.static Query
newSetQuery(String field, InetAddress... values)
Create a query matching any of the specified 1D values.static InetAddress
nextDown(InetAddress address)
Return theInetAddress
that compares immediately less thanaddress
.static InetAddress
nextUp(InetAddress address)
Return theInetAddress
that compares immediately greater thanaddress
.void
setBytesValue(BytesRef bytes)
void
setInetAddressValue(InetAddress value)
Change the values of this fieldString
toString()
-
Methods inherited from class org.apache.lucene.document.Field
binaryValue, fieldType, getCharSequenceValue, name, numericValue, readerValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStream, tokenStreamValue
-
-
-
-
Field Detail
-
BYTES
public static final int BYTES
The number of bytes per dimension: 128 bits- See Also:
- Constant Field Values
-
MIN_VALUE
public static final InetAddress MIN_VALUE
The minimum value that an ip address can hold.
-
MAX_VALUE
public static final InetAddress MAX_VALUE
The maximum value that an ip address can hold.
-
-
Constructor Detail
-
InetAddressPoint
public InetAddressPoint(String name, InetAddress point)
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 Detail
-
nextUp
public static InetAddress nextUp(InetAddress address)
Return theInetAddress
that compares immediately greater thanaddress
.- Throws:
ArithmeticException
- if the provided address is themaximum ip address
-
nextDown
public static InetAddress nextDown(InetAddress address)
Return theInetAddress
that compares immediately less thanaddress
.- Throws:
ArithmeticException
- if the provided address is theminimum ip address
-
setInetAddressValue
public void setInetAddressValue(InetAddress value)
Change the values of this field
-
setBytesValue
public void setBytesValue(BytesRef bytes)
- Overrides:
setBytesValue
in classField
-
encode
public static byte[] encode(InetAddress value)
Encode InetAddress value into binary encoding
-
decode
public static InetAddress decode(byte[] value)
Decodes InetAddress value from binary encoding
-
newExactQuery
public static Query newExactQuery(String field, InetAddress value)
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
- iffield
is null.
-
newPrefixQuery
public static Query newPrefixQuery(String field, InetAddress value, int prefixLength)
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
- iffield
is null, or prefixLength is invalid.
-
newRangeQuery
public static Query newRangeQuery(String field, InetAddress lowerValue, InetAddress upperValue)
Create a range query for network addresses.You can have half-open ranges (which are in fact </≤ or >/≥ queries) by setting
lowerValue = InetAddressPoint.MIN_VALUE
orupperValue = 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
- iffield
is null,lowerValue
is null, orupperValue
is null
-
newSetQuery
public static Query newSetQuery(String field, InetAddress... values)
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
-
-