From 112935fcdb1f7762fab8964e63059ed6099497f5 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 9 Jun 2011 16:15:23 -0700 Subject: [PATCH] Allow fuzzy IP matches to accept a long min_similarity. --- .../elasticsearch/index/mapper/ip/IpFieldMapper.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java index 5332e064a89..0f7a525ccc5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java @@ -178,7 +178,16 @@ public class IpFieldMapper extends NumberFieldMapper { @Override public Query fuzzyQuery(String value, String minSim, int prefixLength, int maxExpansions) { long iValue = ipToLong(value); - long iSim = ipToLong(minSim); + long iSim; + try { + iSim = ipToLong(minSim); + } catch (ElasticSearchIllegalArgumentException e) { + try { + iSim = Long.parseLong(minSim); + } catch (NumberFormatException e1) { + iSim = (long) Double.parseDouble(minSim); + } + } return NumericRangeQuery.newLongRange(names.indexName(), precisionStep, iValue - iSim, iValue + iSim,