예제 #1
0
    @Override
    public Query rangeQuery(
        Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) {
      failIfNotIndexed();
      InetAddress lower;
      if (lowerTerm == null) {
        lower = XInetAddressPoint.MIN_VALUE;
      } else {
        lower = parse(lowerTerm);
        if (includeLower == false) {
          if (lower.equals(XInetAddressPoint.MAX_VALUE)) {
            return new MatchNoDocsQuery();
          }
          lower = XInetAddressPoint.nextUp(lower);
        }
      }

      InetAddress upper;
      if (upperTerm == null) {
        upper = XInetAddressPoint.MAX_VALUE;
      } else {
        upper = parse(upperTerm);
        if (includeUpper == false) {
          if (upper.equals(XInetAddressPoint.MIN_VALUE)) {
            return new MatchNoDocsQuery();
          }
          upper = XInetAddressPoint.nextDown(upper);
        }
      }

      return InetAddressPoint.newRangeQuery(name(), lower, upper);
    }
예제 #2
0
 @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);
 }
예제 #3
0
 @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);
   }
 }