You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2016/04/20 15:15:19 UTC

[3/3] lucene-solr:branch_6_0: LUCENE-7232: Fixed InetAddressPoint.newPrefixQuery.

LUCENE-7232: Fixed InetAddressPoint.newPrefixQuery.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/2243e508
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2243e508
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2243e508

Branch: refs/heads/branch_6_0
Commit: 2243e5087b57a4ab812590f56d1daecb38a51578
Parents: cc43eaf
Author: Adrien Grand <jp...@gmail.com>
Authored: Wed Apr 20 15:13:20 2016 +0200
Committer: Adrien Grand <jp...@gmail.com>
Committed: Wed Apr 20 15:14:44 2016 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                                      |  3 +++
 .../org/apache/lucene/document/InetAddressPoint.java    |  5 +++--
 .../apache/lucene/document/TestInetAddressPoint.java    | 12 ++++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2243e508/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 639c0e1..1d8f032 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -12,6 +12,9 @@ Bug Fixes
 
 * LUCENE-7209: Fixed explanations of FunctionScoreQuery. (Adrien Grand)
 
+* LUCENE-7232: Fixed InetAddressPoint.newPrefixQuery, which was generating an
+  incorrect query when the prefix length was not a multiple of 8. (Adrien Grand)
+
 ======================= Lucene 6.0.0 =======================
 
 System Requirements

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2243e508/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java b/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java
index c0739a4..4d2cc7f 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/InetAddressPoint.java
@@ -174,8 +174,9 @@ public class InetAddressPoint extends Field {
     byte lower[] = value.getAddress();
     byte upper[] = value.getAddress();
     for (int i = prefixLength; i < 8 * lower.length; i++) {
-      lower[i >> 3] &= ~(1 << (i & 7));
-      upper[i >> 3] |= 1 << (i & 7);
+      int m = 1 << (7 - (i & 7));
+      lower[i >> 3] &= ~m;
+      upper[i >> 3] |= m;
     }
     try {
       return newRangeQuery(field, InetAddress.getByAddress(lower), InetAddress.getByAddress(upper));

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2243e508/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java
----------------------------------------------------------------------
diff --git a/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java b/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java
index 8523776..36c51a9 100644
--- a/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java
+++ b/lucene/sandbox/src/test/org/apache/lucene/document/TestInetAddressPoint.java
@@ -119,4 +119,16 @@ public class TestInetAddressPoint extends LuceneTestCase {
     assertEquals(q1.hashCode(), q2.hashCode());
     assertFalse(q1.equals(InetAddressPoint.newSetQuery("a", InetAddress.getByName("1.2.3.3"), InetAddress.getByName("1.2.3.7"))));
   }
+
+  public void testPrefixQuery() throws Exception {
+    assertEquals(
+        InetAddressPoint.newRangeQuery("a", InetAddress.getByName("1.2.3.0"), InetAddress.getByName("1.2.3.255")),
+        InetAddressPoint.newPrefixQuery("a", InetAddress.getByName("1.2.3.127"), 24));
+    assertEquals(
+        InetAddressPoint.newRangeQuery("a", InetAddress.getByName("1.2.3.128"), InetAddress.getByName("1.2.3.255")),
+        InetAddressPoint.newPrefixQuery("a", InetAddress.getByName("1.2.3.213"), 25));
+    assertEquals(
+        InetAddressPoint.newRangeQuery("a", InetAddress.getByName("2001::a000:0"), InetAddress.getByName("2001::afff:ffff")),
+        InetAddressPoint.newPrefixQuery("a", InetAddress.getByName("2001::a6bd:fc80"), 100));
+  }
 }