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 + "]"); } }
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); }
@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); }