@Override public Query fuzzyQuery( Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) { failIfNotIndexed(); InetAddress base = parse(value); int mask = fuzziness.asInt(); return XInetAddressPoint.newPrefixQuery(name(), base, mask); }
@Override public Query termQuery(Object value, @Nullable QueryShardContext context) { failIfNotIndexed(); if (value instanceof InetAddress) { return InetAddressPoint.newExactQuery(name(), (InetAddress) value); } else { if (value instanceof BytesRef) { value = ((BytesRef) value).utf8ToString(); } String term = value.toString(); if (term.contains("/")) { String[] fields = term.split("/"); if (fields.length == 2) { InetAddress address = InetAddresses.forString(fields[0]); int prefixLength = Integer.parseInt(fields[1]); return XInetAddressPoint.newPrefixQuery(name(), address, prefixLength); } else { throw new IllegalArgumentException("Expected [ip/prefix] but was [" + term + "]"); } } InetAddress address = InetAddresses.forString(term); return InetAddressPoint.newExactQuery(name(), address); } }