Exemplo n.º 1
0
  public static Fuzziness parse(XContentParser parser) throws IOException {
    XContentParser.Token token = parser.currentToken();
    switch (token) {
      case VALUE_STRING:
      case VALUE_NUMBER:
        final String fuzziness = parser.text();
        if (AUTO.asString().equalsIgnoreCase(fuzziness)) {
          return AUTO;
        }
        try {
          final int minimumSimilarity = Integer.parseInt(fuzziness);
          switch (minimumSimilarity) {
            case 0:
              return ZERO;
            case 1:
              return ONE;
            case 2:
              return TWO;
            default:
              return build(fuzziness);
          }
        } catch (NumberFormatException ex) {
          return build(fuzziness);
        }

      default:
        throw new IllegalArgumentException("Can't parse fuzziness on token: [" + token + "]");
    }
  }
Exemplo n.º 2
0
 public static Fuzziness build(Object fuzziness) {
   if (fuzziness instanceof Fuzziness) {
     return (Fuzziness) fuzziness;
   }
   String string = fuzziness.toString();
   if (AUTO.asString().equalsIgnoreCase(string)) {
     return AUTO;
   }
   return new Fuzziness(string);
 }
Exemplo n.º 3
0
 @Override
 public Query fuzzyQuery(
     String value,
     Fuzziness fuzziness,
     int prefixLength,
     int maxExpansions,
     boolean transpositions) {
   long iValue = ipToLong(value);
   long iSim;
   try {
     iSim = ipToLong(fuzziness.asString());
   } catch (ElasticsearchIllegalArgumentException e) {
     iSim = fuzziness.asLong();
   }
   return NumericRangeQuery.newLongRange(
       names.indexName(), precisionStep, iValue - iSim, iValue + iSim, true, true);
 }