You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2015/12/21 12:40:14 UTC

svn commit: r1721134 [15/48] - in /lucene/dev/branches/lucene6835: ./ dev-tools/ dev-tools/eclipse/dot.settings/ dev-tools/idea/.idea/libraries/ dev-tools/maven/ dev-tools/maven/lucene/analysis/morfologik/ dev-tools/scripts/ lucene/ lucene/analysis/ lu...

Modified: lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java (original)
+++ lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CoreParser.java Mon Dec 21 11:39:57 2015
@@ -37,8 +37,6 @@ public class CoreParser implements Query
   protected Analyzer analyzer;
   protected QueryParser parser;
   protected QueryBuilderFactory queryFactory;
-  //Controls the max size of the LRU cache used for QueryFilter objects parsed.
-  public static int maxNumCachedQueries = 20;
 
 
   /**
@@ -69,7 +67,7 @@ public class CoreParser implements Query
     queryFactory.addBuilder("TermsQuery", new TermsQueryBuilder(analyzer));
     queryFactory.addBuilder("MatchAllDocsQuery", new MatchAllDocsQueryBuilder());
     queryFactory.addBuilder("BooleanQuery", new BooleanQueryBuilder(queryFactory));
-    queryFactory.addBuilder("NumericRangeQuery", new NumericRangeQueryBuilder());
+    queryFactory.addBuilder("LegacyNumericRangeQuery", new LegacyNumericRangeQueryBuilder());
     queryFactory.addBuilder("RangeQuery", new RangeQueryBuilder());
     queryFactory.addBuilder("DisjunctionMaxQuery", new DisjunctionMaxQueryBuilder(queryFactory));
     if (parser != null) {
@@ -78,7 +76,6 @@ public class CoreParser implements Query
       queryFactory.addBuilder("UserQuery", new UserInputQueryBuilder(defaultField, analyzer));
     }
     queryFactory.addBuilder("ConstantScoreQuery", new ConstantScoreQueryBuilder(queryFactory));
-    queryFactory.addBuilder("CachedQuery", new CachedQueryBuilder(queryFactory, maxNumCachedQueries));
 
     SpanQueryBuilderFactory sqof = new SpanQueryBuilderFactory();
 

Modified: lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CorePlusExtensionsParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CorePlusExtensionsParser.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CorePlusExtensionsParser.java (original)
+++ lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/CorePlusExtensionsParser.java Mon Dec 21 11:39:57 2015
@@ -2,7 +2,7 @@ package org.apache.lucene.queryparser.xm
 
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.queryparser.classic.QueryParser;
-import org.apache.lucene.queryparser.xml.builders.*;
+import org.apache.lucene.queryparser.xml.builders.FuzzyLikeThisQueryBuilder;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -26,7 +26,7 @@ import org.apache.lucene.queryparser.xml
  * Lucene's <code>sandbox</code> and <code>queries</code>
  * modules in addition to core queries.
  */
-public class CorePlusExtensionsParser extends CoreParser {
+public class CorePlusExtensionsParser extends CorePlusQueriesParser {
 
   /**
    * Construct an XML parser that uses a single instance QueryParser for handling
@@ -49,9 +49,6 @@ public class CorePlusExtensionsParser ex
 
   private CorePlusExtensionsParser(String defaultField, Analyzer analyzer, QueryParser parser) {
     super(defaultField, analyzer, parser);
-    String fields[] = {"contents"};
-    queryFactory.addBuilder("LikeThisQuery", new LikeThisQueryBuilder(analyzer, fields));
-    queryFactory.addBuilder("BoostingQuery", new BoostingQueryBuilder(queryFactory));
     queryFactory.addBuilder("FuzzyLikeThisQuery", new FuzzyLikeThisQueryBuilder(analyzer));
 
   }

Modified: lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java (original)
+++ lucene/dev/branches/lucene6835/lucene/queryparser/src/java/org/apache/lucene/queryparser/xml/builders/DisjunctionMaxQueryBuilder.java Mon Dec 21 11:39:57 2015
@@ -16,6 +16,9 @@ package org.apache.lucene.queryparser.xm
  * limitations under the License.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.lucene.queryparser.xml.DOMUtils;
 import org.apache.lucene.queryparser.xml.ParserException;
 import org.apache.lucene.queryparser.xml.QueryBuilder;
@@ -44,22 +47,22 @@ public class DisjunctionMaxQueryBuilder
   @Override
   public Query getQuery(Element e) throws ParserException {
     float tieBreaker = DOMUtils.getAttribute(e, "tieBreaker", 0.0f); 
-    DisjunctionMaxQuery dq = new DisjunctionMaxQuery(tieBreaker);
 
+    List<Query> disjuncts = new ArrayList<>();
     NodeList nl = e.getChildNodes();
     for (int i = 0; i < nl.getLength(); i++) {
       Node node = nl.item(i);
       if (node instanceof Element) { // all elements are disjuncts.
         Element queryElem = (Element) node;
         Query q = factory.getQuery(queryElem);
-        dq.add(q);
+        disjuncts.add(q);
       }
     }
 
-    Query q = dq;
+    Query q = new DisjunctionMaxQuery(disjuncts, tieBreaker);
     float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
     if (boost != 1f) {
-      q = new BoostQuery(dq, boost);
+      q = new BoostQuery(q, boost);
     }
     return q;
   }

Modified: lucene/dev/branches/lucene6835/lucene/queryparser/src/resources/org/apache/lucene/queryparser/xml/LuceneCoreQuery.dtd
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/queryparser/src/resources/org/apache/lucene/queryparser/xml/LuceneCoreQuery.dtd?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/queryparser/src/resources/org/apache/lucene/queryparser/xml/LuceneCoreQuery.dtd (original)
+++ lucene/dev/branches/lucene6835/lucene/queryparser/src/resources/org/apache/lucene/queryparser/xml/LuceneCoreQuery.dtd Mon Dec 21 11:39:57 2015
@@ -288,7 +288,7 @@ Passes content directly through to the s
 	@example 
 	        <em>Search for documents about people who are aged 20-25</em>
 	        %	          
-            <NumericRangeQuery fieldName="age" lowerTerm="20" upperTerm="25" />
+            <LegacyNumericRangeQuery fieldName="age" lowerTerm="20" upperTerm="25" />
 	         %
 	-->
 <!ELEMENT NumericRangeQuery EMPTY>

Modified: lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestNumericQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestNumericQueryParser.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestNumericQueryParser.java (original)
+++ lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestNumericQueryParser.java Mon Dec 21 11:39:57 2015
@@ -33,13 +33,13 @@ import java.util.TimeZone;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
-import org.apache.lucene.document.DoubleField;
+import org.apache.lucene.document.LegacyDoubleField;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.document.FieldType.NumericType;
+import org.apache.lucene.document.FieldType.LegacyNumericType;
 import org.apache.lucene.document.FieldType;
-import org.apache.lucene.document.FloatField;
-import org.apache.lucene.document.IntField;
-import org.apache.lucene.document.LongField;
+import org.apache.lucene.document.LegacyFloatField;
+import org.apache.lucene.document.LegacyIntField;
+import org.apache.lucene.document.LegacyLongField;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.queryparser.flexible.core.QueryNodeException;
@@ -179,10 +179,10 @@ public class TestNumericQueryParser exte
     while ((randomInt = normalizeNumber(Math.abs(random().nextInt())).intValue()) == 0)
       ;
     
-    randomNumberMap.put(NumericType.LONG.name(), randomLong);
-    randomNumberMap.put(NumericType.INT.name(), randomInt);
-    randomNumberMap.put(NumericType.FLOAT.name(), randomFloat);
-    randomNumberMap.put(NumericType.DOUBLE.name(), randomDouble);
+    randomNumberMap.put(LegacyNumericType.LONG.name(), randomLong);
+    randomNumberMap.put(FieldType.LegacyNumericType.INT.name(), randomInt);
+    randomNumberMap.put(LegacyNumericType.FLOAT.name(), randomFloat);
+    randomNumberMap.put(LegacyNumericType.DOUBLE.name(), randomDouble);
     randomNumberMap.put(DATE_FIELD_NAME, randomDate);
     
     RANDOM_NUMBER_MAP = Collections.unmodifiableMap(randomNumberMap);
@@ -198,11 +198,11 @@ public class TestNumericQueryParser exte
     HashMap<String,Field> numericFieldMap = new HashMap<>();
     qp.setNumericConfigMap(numericConfigMap);
     
-    for (NumericType type : NumericType.values()) {
+    for (LegacyNumericType type : LegacyNumericType.values()) {
       numericConfigMap.put(type.name(), new NumericConfig(PRECISION_STEP,
           NUMBER_FORMAT, type));
 
-      FieldType ft = new FieldType(IntField.TYPE_NOT_STORED);
+      FieldType ft = new FieldType(LegacyIntField.TYPE_NOT_STORED);
       ft.setNumericType(type);
       ft.setStored(true);
       ft.setNumericPrecisionStep(PRECISION_STEP);
@@ -211,16 +211,16 @@ public class TestNumericQueryParser exte
 
       switch(type) {
       case INT:
-        field = new IntField(type.name(), 0, ft);
+        field = new LegacyIntField(type.name(), 0, ft);
         break;
       case FLOAT:
-        field = new FloatField(type.name(), 0.0f, ft);
+        field = new LegacyFloatField(type.name(), 0.0f, ft);
         break;
       case LONG:
-        field = new LongField(type.name(), 0l, ft);
+        field = new LegacyLongField(type.name(), 0l, ft);
         break;
       case DOUBLE:
-        field = new DoubleField(type.name(), 0.0, ft);
+        field = new LegacyDoubleField(type.name(), 0.0, ft);
         break;
       default:
         fail();
@@ -231,11 +231,11 @@ public class TestNumericQueryParser exte
     }
     
     numericConfigMap.put(DATE_FIELD_NAME, new NumericConfig(PRECISION_STEP,
-        DATE_FORMAT, NumericType.LONG));
-    FieldType ft = new FieldType(LongField.TYPE_NOT_STORED);
+        DATE_FORMAT, LegacyNumericType.LONG));
+    FieldType ft = new FieldType(LegacyLongField.TYPE_NOT_STORED);
     ft.setStored(true);
     ft.setNumericPrecisionStep(PRECISION_STEP);
-    LongField dateField = new LongField(DATE_FIELD_NAME, 0l, ft);
+    LegacyLongField dateField = new LegacyLongField(DATE_FIELD_NAME, 0l, ft);
     numericFieldMap.put(DATE_FIELD_NAME, dateField);
     doc.add(dateField);
     
@@ -265,17 +265,17 @@ public class TestNumericQueryParser exte
       case NEGATIVE:
         Number number = RANDOM_NUMBER_MAP.get(fieldName);
         
-        if (NumericType.LONG.name().equals(fieldName)
+        if (LegacyNumericType.LONG.name().equals(fieldName)
             || DATE_FIELD_NAME.equals(fieldName)) {
           number = -number.longValue();
           
-        } else if (NumericType.DOUBLE.name().equals(fieldName)) {
+        } else if (FieldType.LegacyNumericType.DOUBLE.name().equals(fieldName)) {
           number = -number.doubleValue();
           
-        } else if (NumericType.FLOAT.name().equals(fieldName)) {
+        } else if (FieldType.LegacyNumericType.FLOAT.name().equals(fieldName)) {
           number = -number.floatValue();
           
-        } else if (NumericType.INT.name().equals(fieldName)) {
+        } else if (LegacyNumericType.INT.name().equals(fieldName)) {
           number = -number.intValue();
           
         } else {
@@ -295,21 +295,21 @@ public class TestNumericQueryParser exte
   private static void setFieldValues(NumberType numberType,
       HashMap<String,Field> numericFieldMap) {
     
-    Number number = getNumberType(numberType, NumericType.DOUBLE
+    Number number = getNumberType(numberType, LegacyNumericType.DOUBLE
         .name());
-    numericFieldMap.get(NumericType.DOUBLE.name()).setDoubleValue(
+    numericFieldMap.get(LegacyNumericType.DOUBLE.name()).setDoubleValue(
         number.doubleValue());
     
-    number = getNumberType(numberType, NumericType.INT.name());
-    numericFieldMap.get(NumericType.INT.name()).setIntValue(
+    number = getNumberType(numberType, FieldType.LegacyNumericType.INT.name());
+    numericFieldMap.get(FieldType.LegacyNumericType.INT.name()).setIntValue(
         number.intValue());
     
-    number = getNumberType(numberType, NumericType.LONG.name());
-    numericFieldMap.get(NumericType.LONG.name()).setLongValue(
+    number = getNumberType(numberType, LegacyNumericType.LONG.name());
+    numericFieldMap.get(FieldType.LegacyNumericType.LONG.name()).setLongValue(
         number.longValue());
     
-    number = getNumberType(numberType, NumericType.FLOAT.name());
-    numericFieldMap.get(NumericType.FLOAT.name()).setFloatValue(
+    number = getNumberType(numberType, FieldType.LegacyNumericType.FLOAT.name());
+    numericFieldMap.get(FieldType.LegacyNumericType.FLOAT.name()).setFloatValue(
         number.floatValue());
     
     number = getNumberType(numberType, DATE_FIELD_NAME);
@@ -411,7 +411,7 @@ public class TestNumericQueryParser exte
     String lowerInclusiveStr = (lowerInclusive ? "[" : "{");
     String upperInclusiveStr = (upperInclusive ? "]" : "}");
     
-    for (NumericType type : NumericType.values()) {
+    for (LegacyNumericType type : LegacyNumericType.values()) {
       String lowerStr = numberToString(getNumberType(lowerType, type.name()));
       String upperStr = numberToString(getNumberType(upperType, type.name()));
       
@@ -457,7 +457,7 @@ public class TestNumericQueryParser exte
 
     StringBuilder sb = new StringBuilder();
     
-    for (NumericType type : NumericType.values()) {
+    for (LegacyNumericType type : FieldType.LegacyNumericType.values()) {
       String boundStr = numberToString(getNumberType(boundType, type.name()));
       
       sb.append("+").append(type.name()).append(operator).append('"').append(boundStr).append('"').append(' ');
@@ -476,7 +476,7 @@ public class TestNumericQueryParser exte
       throws QueryNodeException, IOException {
     StringBuilder sb = new StringBuilder();
     
-    for (NumericType type : NumericType.values()) {
+    for (LegacyNumericType type : LegacyNumericType.values()) {
       String numberStr = numberToString(getNumberType(numberType, type.name()));
       sb.append('+').append(type.name()).append(":\"").append(numberStr)
           .append("\" ");

Modified: lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java (original)
+++ lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java Mon Dec 21 11:39:57 2015
@@ -538,7 +538,18 @@ public class TestQPHelper extends Lucene
     assertQueryEquals("!term", null, "-term");
     assertQueryEquals("NOT term", null, "-term");
   }
-
+  
+  public void testNegationInParentheses() throws Exception {
+   assertQueryEquals("(-a)", null, "-a");
+   assertQueryEquals("(!a)", null, "-a");
+   assertQueryEquals("(NOT a)", null, "-a");
+   assertQueryEquals("a (!b)", null, "a (-b)");
+   assertQueryEquals("+a +(!b)", null, "+a +(-b)");
+   assertQueryEquals("a AND (!b)", null, "+a +(-b)");
+   assertQueryEquals("a (NOT b)", null, "a (-b)");
+   assertQueryEquals("a AND (NOT b)", null, "+a +(-b)");
+  }
+  
   public void testWildcard() throws Exception {
     assertQueryEquals("term*", null, "term*");
     assertQueryEquals("term*^2", null, "(term*)^2.0");

Modified: lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java (original)
+++ lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java Mon Dec 21 11:39:57 2015
@@ -23,8 +23,7 @@ import org.apache.lucene.analysis.MockTo
 import org.apache.lucene.analysis.MockTokenizer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.document.IntField;
-import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.document.LegacyIntField;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
@@ -37,7 +36,6 @@ import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.junit.AfterClass;
-import org.junit.Assume;
 import org.junit.BeforeClass;
 
 import java.io.BufferedReader;
@@ -45,12 +43,12 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
-import java.util.List;
 
 
 public class TestParser extends LuceneTestCase {
 
-  private static CoreParser builder;
+  private static Analyzer analyzer;
+  private static CoreParser coreParser;
   private static Directory dir;
   private static IndexReader reader;
   private static IndexSearcher searcher;
@@ -58,9 +56,9 @@ public class TestParser extends LuceneTe
   @BeforeClass
   public static void beforeClass() throws Exception {
     // TODO: rewrite test (this needs to set QueryParser.enablePositionIncrements, too, for work with CURRENT):
-    Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET);
+    analyzer = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, true, MockTokenFilter.ENGLISH_STOPSET);
     //initialize the parser
-    builder = new CorePlusExtensionsParser("contents", analyzer);
+    coreParser = new CorePlusExtensionsParser("contents", analyzer);
 
     BufferedReader d = new BufferedReader(new InputStreamReader(
         TestParser.class.getResourceAsStream("reuters21578.txt"), StandardCharsets.US_ASCII));
@@ -74,7 +72,7 @@ public class TestParser extends LuceneTe
       Document doc = new Document();
       doc.add(newTextField("date", date, Field.Store.YES));
       doc.add(newTextField("contents", content, Field.Store.YES));
-      doc.add(new IntField("date2", Integer.valueOf(date), Field.Store.NO));
+      doc.add(new LegacyIntField("date2", Integer.valueOf(date), Field.Store.NO));
       writer.addDocument(doc);
       line = d.readLine();
     }
@@ -92,7 +90,8 @@ public class TestParser extends LuceneTe
     reader = null;
     searcher = null;
     dir = null;
-    builder = null;
+    coreParser = null;
+    analyzer = null;
   }
 
   public void testSimpleXML() throws ParserException, IOException {
@@ -181,21 +180,24 @@ public class TestParser extends LuceneTe
     dumpResults("Nested Boolean query", q, 5);
   }
 
-  public void testCachedFilterXML() throws ParserException, IOException {
-    Query q = parse("CachedQuery.xml");
-    dumpResults("Cached filter", q, 5);
+  public void testNumericRangeQueryXML() throws ParserException, IOException {
+    Query q = parse("LegacyNumericRangeQuery.xml");
+    dumpResults("LegacyNumericRangeQuery", q, 5);
   }
 
-  public void testNumericRangeQueryQueryXML() throws ParserException, IOException {
-    Query q = parse("NumericRangeQueryQuery.xml");
-    dumpResults("NumericRangeQuery", q, 5);
+  //================= Helper methods ===================================
+
+  protected Analyzer analyzer() {
+    return analyzer;
   }
 
-  //================= Helper methods ===================================
+  protected CoreParser coreParser() {
+    return coreParser;
+  }
 
   private Query parse(String xmlFileName) throws ParserException, IOException {
     InputStream xmlStream = TestParser.class.getResourceAsStream(xmlFileName);
-    Query result = builder.parse(xmlStream);
+    Query result = coreParser().parse(xmlStream);
     xmlStream.close();
     return result;
   }

Modified: lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeQueryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeQueryBuilder.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeQueryBuilder.java (original)
+++ lucene/dev/branches/lucene6835/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/builders/TestNumericRangeQueryBuilder.java Mon Dec 21 11:39:57 2015
@@ -17,7 +17,7 @@ package org.apache.lucene.queryparser.xm
  * limitations under the License.
  */
 
-import org.apache.lucene.search.NumericRangeQuery;
+import org.apache.lucene.search.LegacyNumericRangeQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.queryparser.xml.ParserException;
@@ -36,9 +36,9 @@ import java.nio.charset.StandardCharsets
 public class TestNumericRangeQueryBuilder extends LuceneTestCase {
 
   public void testGetFilterHandleNumericParseErrorStrict() throws Exception {
-    NumericRangeQueryBuilder filterBuilder = new NumericRangeQueryBuilder();
+    LegacyNumericRangeQueryBuilder filterBuilder = new LegacyNumericRangeQueryBuilder();
 
-    String xml = "<NumericRangeQuery fieldName='AGE' type='int' lowerTerm='-1' upperTerm='NaN'/>";
+    String xml = "<LegacyNumericRangeQuery fieldName='AGE' type='int' lowerTerm='-1' upperTerm='NaN'/>";
     Document doc = getDocumentFromString(xml);
     try {
       filterBuilder.getQuery(doc.getDocumentElement());
@@ -50,26 +50,26 @@ public class TestNumericRangeQueryBuilde
 
   @SuppressWarnings({"unchecked","rawtypes"})
   public void testGetFilterInt() throws Exception {
-    NumericRangeQueryBuilder filterBuilder = new NumericRangeQueryBuilder();
+    LegacyNumericRangeQueryBuilder filterBuilder = new LegacyNumericRangeQueryBuilder();
 
-    String xml = "<NumericRangeQuery fieldName='AGE' type='int' lowerTerm='-1' upperTerm='10'/>";
+    String xml = "<LegacyNumericRangeQuery fieldName='AGE' type='int' lowerTerm='-1' upperTerm='10'/>";
     Document doc = getDocumentFromString(xml);
     Query filter = filterBuilder.getQuery(doc.getDocumentElement());
-    assertTrue(filter instanceof NumericRangeQuery<?>);
+    assertTrue(filter instanceof LegacyNumericRangeQuery<?>);
 
-    NumericRangeQuery<Integer> numRangeFilter = (NumericRangeQuery<Integer>) filter;
+    LegacyNumericRangeQuery<Integer> numRangeFilter = (LegacyNumericRangeQuery<Integer>) filter;
     assertEquals(Integer.valueOf(-1), numRangeFilter.getMin());
     assertEquals(Integer.valueOf(10), numRangeFilter.getMax());
     assertEquals("AGE", numRangeFilter.getField());
     assertTrue(numRangeFilter.includesMin());
     assertTrue(numRangeFilter.includesMax());
 
-    String xml2 = "<NumericRangeQuery fieldName='AGE' type='int' lowerTerm='-1' upperTerm='10' includeUpper='false'/>";
+    String xml2 = "<LegacyNumericRangeQuery fieldName='AGE' type='int' lowerTerm='-1' upperTerm='10' includeUpper='false'/>";
     Document doc2 = getDocumentFromString(xml2);
     Query filter2 = filterBuilder.getQuery(doc2.getDocumentElement());
-    assertTrue(filter2 instanceof NumericRangeQuery<?>);
+    assertTrue(filter2 instanceof LegacyNumericRangeQuery<?>);
 
-    NumericRangeQuery<Integer> numRangeFilter2 = (NumericRangeQuery) filter2;
+    LegacyNumericRangeQuery<Integer> numRangeFilter2 = (LegacyNumericRangeQuery) filter2;
     assertEquals(Integer.valueOf(-1), numRangeFilter2.getMin());
     assertEquals(Integer.valueOf(10), numRangeFilter2.getMax());
     assertEquals("AGE", numRangeFilter2.getField());
@@ -79,25 +79,25 @@ public class TestNumericRangeQueryBuilde
 
   @SuppressWarnings({"unchecked","rawtypes"})
   public void testGetFilterLong() throws Exception {
-    NumericRangeQueryBuilder filterBuilder = new NumericRangeQueryBuilder();
+    LegacyNumericRangeQueryBuilder filterBuilder = new LegacyNumericRangeQueryBuilder();
 
-    String xml = "<NumericRangeQuery fieldName='AGE' type='LoNg' lowerTerm='-2321' upperTerm='60000000'/>";
+    String xml = "<LegacyNumericRangeQuery fieldName='AGE' type='LoNg' lowerTerm='-2321' upperTerm='60000000'/>";
     Document doc = getDocumentFromString(xml);
     Query filter = filterBuilder.getQuery(doc.getDocumentElement());
-    assertTrue(filter instanceof NumericRangeQuery<?>);
-    NumericRangeQuery<Long> numRangeFilter = (NumericRangeQuery) filter;
+    assertTrue(filter instanceof LegacyNumericRangeQuery<?>);
+    LegacyNumericRangeQuery<Long> numRangeFilter = (LegacyNumericRangeQuery) filter;
     assertEquals(Long.valueOf(-2321L), numRangeFilter.getMin());
     assertEquals(Long.valueOf(60000000L), numRangeFilter.getMax());
     assertEquals("AGE", numRangeFilter.getField());
     assertTrue(numRangeFilter.includesMin());
     assertTrue(numRangeFilter.includesMax());
 
-    String xml2 = "<NumericRangeQuery fieldName='AGE' type='LoNg' lowerTerm='-2321' upperTerm='60000000' includeUpper='false'/>";
+    String xml2 = "<LegacyNumericRangeQuery fieldName='AGE' type='LoNg' lowerTerm='-2321' upperTerm='60000000' includeUpper='false'/>";
     Document doc2 = getDocumentFromString(xml2);
     Query filter2 = filterBuilder.getQuery(doc2.getDocumentElement());
-    assertTrue(filter2 instanceof NumericRangeQuery<?>);
+    assertTrue(filter2 instanceof LegacyNumericRangeQuery<?>);
 
-    NumericRangeQuery<Long> numRangeFilter2 = (NumericRangeQuery) filter2;
+    LegacyNumericRangeQuery<Long> numRangeFilter2 = (LegacyNumericRangeQuery) filter2;
     assertEquals(Long.valueOf(-2321L), numRangeFilter2.getMin());
     assertEquals(Long.valueOf(60000000L), numRangeFilter2.getMax());
     assertEquals("AGE", numRangeFilter2.getField());
@@ -107,27 +107,27 @@ public class TestNumericRangeQueryBuilde
 
   @SuppressWarnings({"unchecked","rawtypes"})
   public void testGetFilterDouble() throws Exception {
-    NumericRangeQueryBuilder filterBuilder = new NumericRangeQueryBuilder();
+    LegacyNumericRangeQueryBuilder filterBuilder = new LegacyNumericRangeQueryBuilder();
 
-    String xml = "<NumericRangeQuery fieldName='AGE' type='doubLe' lowerTerm='-23.21' upperTerm='60000.00023'/>";
+    String xml = "<LegacyNumericRangeQuery fieldName='AGE' type='doubLe' lowerTerm='-23.21' upperTerm='60000.00023'/>";
     Document doc = getDocumentFromString(xml);
 
     Query filter = filterBuilder.getQuery(doc.getDocumentElement());
-    assertTrue(filter instanceof NumericRangeQuery<?>);
+    assertTrue(filter instanceof LegacyNumericRangeQuery<?>);
 
-    NumericRangeQuery<Double> numRangeFilter = (NumericRangeQuery) filter;
+    LegacyNumericRangeQuery<Double> numRangeFilter = (LegacyNumericRangeQuery) filter;
     assertEquals(Double.valueOf(-23.21d), numRangeFilter.getMin());
     assertEquals(Double.valueOf(60000.00023d), numRangeFilter.getMax());
     assertEquals("AGE", numRangeFilter.getField());
     assertTrue(numRangeFilter.includesMin());
     assertTrue(numRangeFilter.includesMax());
 
-    String xml2 = "<NumericRangeQuery fieldName='AGE' type='doubLe' lowerTerm='-23.21' upperTerm='60000.00023' includeUpper='false'/>";
+    String xml2 = "<LegacyNumericRangeQuery fieldName='AGE' type='doubLe' lowerTerm='-23.21' upperTerm='60000.00023' includeUpper='false'/>";
     Document doc2 = getDocumentFromString(xml2);
     Query filter2 = filterBuilder.getQuery(doc2.getDocumentElement());
-    assertTrue(filter2 instanceof NumericRangeQuery<?>);
+    assertTrue(filter2 instanceof LegacyNumericRangeQuery<?>);
 
-    NumericRangeQuery<Double> numRangeFilter2 = (NumericRangeQuery) filter2;
+    LegacyNumericRangeQuery<Double> numRangeFilter2 = (LegacyNumericRangeQuery) filter2;
     assertEquals(Double.valueOf(-23.21d), numRangeFilter2.getMin());
     assertEquals(Double.valueOf(60000.00023d), numRangeFilter2.getMax());
     assertEquals("AGE", numRangeFilter2.getField());
@@ -137,28 +137,28 @@ public class TestNumericRangeQueryBuilde
 
   @SuppressWarnings({"unchecked","rawtypes"})
   public void testGetFilterFloat() throws Exception {
-    NumericRangeQueryBuilder filterBuilder = new NumericRangeQueryBuilder();
+    LegacyNumericRangeQueryBuilder filterBuilder = new LegacyNumericRangeQueryBuilder();
 
-    String xml = "<NumericRangeQuery fieldName='AGE' type='FLOAT' lowerTerm='-2.321432' upperTerm='32432.23'/>";
+    String xml = "<LegacyNumericRangeQuery fieldName='AGE' type='FLOAT' lowerTerm='-2.321432' upperTerm='32432.23'/>";
     Document doc = getDocumentFromString(xml);
 
     Query filter = filterBuilder.getQuery(doc.getDocumentElement());
-    assertTrue(filter instanceof NumericRangeQuery<?>);
+    assertTrue(filter instanceof LegacyNumericRangeQuery<?>);
 
-    NumericRangeQuery<Float> numRangeFilter = (NumericRangeQuery) filter;
+    LegacyNumericRangeQuery<Float> numRangeFilter = (LegacyNumericRangeQuery) filter;
     assertEquals(Float.valueOf(-2.321432f), numRangeFilter.getMin());
     assertEquals(Float.valueOf(32432.23f), numRangeFilter.getMax());
     assertEquals("AGE", numRangeFilter.getField());
     assertTrue(numRangeFilter.includesMin());
     assertTrue(numRangeFilter.includesMax());
 
-    String xml2 = "<NumericRangeQuery fieldName='AGE' type='FLOAT' lowerTerm='-2.321432' upperTerm='32432.23' includeUpper='false' precisionStep='2' />";
+    String xml2 = "<LegacyNumericRangeQuery fieldName='AGE' type='FLOAT' lowerTerm='-2.321432' upperTerm='32432.23' includeUpper='false' precisionStep='2' />";
     Document doc2 = getDocumentFromString(xml2);
 
     Query filter2 = filterBuilder.getQuery(doc2.getDocumentElement());
-    assertTrue(filter2 instanceof NumericRangeQuery<?>);
+    assertTrue(filter2 instanceof LegacyNumericRangeQuery<?>);
 
-    NumericRangeQuery<Float> numRangeFilter2 = (NumericRangeQuery) filter2;
+    LegacyNumericRangeQuery<Float> numRangeFilter2 = (LegacyNumericRangeQuery) filter2;
     assertEquals(Float.valueOf(-2.321432f), numRangeFilter2.getMin());
     assertEquals(Float.valueOf(32432.23f), numRangeFilter2.getMax());
     assertEquals("AGE", numRangeFilter2.getField());

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/document/GeoPointField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/document/GeoPointField.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/document/GeoPointField.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/document/GeoPointField.java Mon Dec 21 11:39:57 2015
@@ -54,7 +54,7 @@ public final class GeoPointField extends
     TYPE_NOT_STORED.setOmitNorms(true);
     TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS);
     TYPE_NOT_STORED.setDocValuesType(DocValuesType.SORTED_NUMERIC);
-    TYPE_NOT_STORED.setNumericType(FieldType.NumericType.LONG);
+    TYPE_NOT_STORED.setNumericType(FieldType.LegacyNumericType.LONG);
     TYPE_NOT_STORED.setNumericPrecisionStep(PRECISION_STEP);
     TYPE_NOT_STORED.freeze();
   }
@@ -69,7 +69,7 @@ public final class GeoPointField extends
     TYPE_STORED.setOmitNorms(true);
     TYPE_STORED.setIndexOptions(IndexOptions.DOCS);
     TYPE_STORED.setDocValuesType(DocValuesType.SORTED_NUMERIC);
-    TYPE_STORED.setNumericType(FieldType.NumericType.LONG);
+    TYPE_STORED.setNumericType(FieldType.LegacyNumericType.LONG);
     TYPE_STORED.setNumericPrecisionStep(PRECISION_STEP);
     TYPE_STORED.setStored(true);
     TYPE_STORED.freeze();
@@ -95,15 +95,38 @@ public final class GeoPointField extends
    *  @param lon longitude double value [-180.0 : 180.0]
    *  @param lat latitude double value [-90.0 : 90.0]
    *  @param type customized field type: must have {@link FieldType#numericType()}
-   *         of {@link FieldType.NumericType#LONG}.
+   *         of {@link org.apache.lucene.document.FieldType.LegacyNumericType#LONG}.
    *  @throws IllegalArgumentException if the field name or type is null, or
    *          if the field type does not have a LONG numericType()
    */
   public GeoPointField(String name, double lon, double lat, FieldType type) {
     super(name, type);
-    if (type.numericType() != FieldType.NumericType.LONG) {
+    if (type.numericType() != FieldType.LegacyNumericType.LONG) {
       throw new IllegalArgumentException("type.numericType() must be LONG but got " + type.numericType());
     }
+    if (type.docValuesType() != DocValuesType.SORTED_NUMERIC) {
+      throw new IllegalArgumentException("type.docValuesType() must be SORTED_NUMERIC but got " + type.docValuesType());
+    }
     fieldsData = GeoUtils.mortonHash(lon, lat);
   }
+
+  public double getLon() {
+    return GeoUtils.mortonUnhashLon((long) fieldsData);
+  }
+
+  public double getLat() {
+    return GeoUtils.mortonUnhashLat((long) fieldsData);
+  }
+
+  @Override
+  public String toString() {
+    if (fieldsData == null) {
+      return null;
+    }
+    StringBuilder sb = new StringBuilder();
+    sb.append(GeoUtils.mortonUnhashLon((long) fieldsData));
+    sb.append(',');
+    sb.append(GeoUtils.mortonUnhashLat((long) fieldsData));
+    return sb.toString();
+  }
 }

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/payloads/PayloadSpanUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/payloads/PayloadSpanUtil.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/payloads/PayloadSpanUtil.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/payloads/PayloadSpanUtil.java Mon Dec 21 11:39:57 2015
@@ -38,9 +38,9 @@ import org.apache.lucene.search.TermQuer
 import org.apache.lucene.search.spans.SpanNearQuery;
 import org.apache.lucene.search.spans.SpanOrQuery;
 import org.apache.lucene.search.spans.SpanQuery;
+import org.apache.lucene.search.spans.Spans;
 import org.apache.lucene.search.spans.SpanTermQuery;
 import org.apache.lucene.search.spans.SpanWeight;
-import org.apache.lucene.search.spans.Spans;
 
 /**
  * Experimental class to get set of payloads for most standard Lucene queries.

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/DocValuesRangeQuery.java Mon Dec 21 11:39:57 2015
@@ -33,7 +33,7 @@ import org.apache.lucene.util.BytesRef;
  * A range query that works on top of the doc values APIs. Such queries are
  * usually slow since they do not use an inverted index. However, in the
  * dense case where most documents match this query, it <b>might</b> be as
- * fast or faster than a regular {@link NumericRangeQuery}.
+ * fast or faster than a regular {@link DimensionalRangeQuery}.
  *
  * <p>
  * <b>NOTE</b>: be very careful using this query: it is

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQuery.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQuery.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQuery.java Mon Dec 21 11:39:57 2015
@@ -18,40 +18,47 @@ package org.apache.lucene.search;
  */
 
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.util.GeoProjectionUtils;
+import org.apache.lucene.util.GeoDistanceUtils;
+import org.apache.lucene.util.GeoRect;
 import org.apache.lucene.util.GeoUtils;
 
 /** Implements a simple point distance query on a GeoPoint field. This is based on
  * {@link org.apache.lucene.search.GeoPointInBBoxQuery} and is implemented using a two phase approach. First,
  * like {@code GeoPointInBBoxQueryImpl} candidate terms are queried using the numeric ranges based on
  * the morton codes of the min and max lat/lon pairs that intersect the boundary of the point-radius
- * circle (see {@link org.apache.lucene.util.GeoUtils#lineCrossesSphere}. Terms
+ * circle. Terms
  * passing this initial filter are then passed to a secondary {@code postFilter} method that verifies whether the
  * decoded lat/lon point fall within the specified query distance (see {@link org.apache.lucene.util.SloppyMath#haversin}.
  * All morton value comparisons are subject to the same precision tolerance defined in
  * {@value org.apache.lucene.util.GeoUtils#TOLERANCE} and distance comparisons are subject to the accuracy of the
  * haversine formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159)
  *
- *
- * Note: This query currently uses haversine which is a sloppy distance calculation (see above reference). For large
+ * <p>Note: This query currently uses haversine which is a sloppy distance calculation (see above reference). For large
  * queries one can expect upwards of 400m error. Vincenty shrinks this to ~40m error but pays a penalty for computing
  * using the spheroid
  *
- *    @lucene.experimental
- */
-public final class GeoPointDistanceQuery extends GeoPointInBBoxQuery {
+ * @lucene.experimental */
+public class GeoPointDistanceQuery extends GeoPointInBBoxQuery {
   protected final double centerLon;
   protected final double centerLat;
-  protected final double radius;
+  protected final double radiusMeters;
 
   /** NOTE: radius is in meters. */
-  public GeoPointDistanceQuery(final String field, final double centerLon, final double centerLat, final double radius) {
-    this(field, computeBBox(centerLon, centerLat, radius), centerLon, centerLat, radius);
+  public GeoPointDistanceQuery(final String field, final double centerLon, final double centerLat, final double radiusMeters) {
+    this(field, GeoUtils.circleToBBox(centerLon, centerLat, radiusMeters), centerLon, centerLat, radiusMeters);
   }
 
-  private GeoPointDistanceQuery(final String field, GeoBoundingBox bbox, final double centerLon,
-                                final double centerLat, final double radius) {
+  private GeoPointDistanceQuery(final String field, GeoRect bbox, final double centerLon,
+                                final double centerLat, final double radiusMeters) {
     super(field, bbox.minLon, bbox.minLat, bbox.maxLon, bbox.maxLat);
+    {
+      // check longitudinal overlap (limits radius)
+      final double maxRadius = GeoDistanceUtils.maxRadialDistanceMeters(centerLon, centerLat);
+      if (radiusMeters > maxRadius) {
+        throw new IllegalArgumentException("radiusMeters " + radiusMeters + " exceeds maxRadius [" + maxRadius
+            + "] at location [" + centerLon + " " + centerLat + "]");
+      }
+    }
 
     if (GeoUtils.isValidLon(centerLon) == false) {
       throw new IllegalArgumentException("invalid centerLon " + centerLon);
@@ -61,35 +68,43 @@ public final class GeoPointDistanceQuery
       throw new IllegalArgumentException("invalid centerLat " + centerLat);
     }
 
+    if (radiusMeters <= 0.0) {
+      throw new IllegalArgumentException("invalid radiusMeters " + radiusMeters);
+    }
+
     this.centerLon = centerLon;
     this.centerLat = centerLat;
-    this.radius = radius;
+    this.radiusMeters = radiusMeters;
   }
 
   @Override
   public Query rewrite(IndexReader reader) {
+    // query crosses dateline; split into left and right queries
     if (maxLon < minLon) {
       BooleanQuery.Builder bqb = new BooleanQuery.Builder();
 
-      GeoPointDistanceQueryImpl left = new GeoPointDistanceQueryImpl(field, this, new GeoBoundingBox(-180.0D, maxLon,
-          minLat, maxLat));
+      // unwrap the longitude iff outside the specified min/max lon range
+      double unwrappedLon = centerLon;
+      if (unwrappedLon > maxLon) {
+        // unwrap left
+        unwrappedLon += -360.0D;
+      }
+      GeoPointDistanceQueryImpl left = new GeoPointDistanceQueryImpl(field, this, unwrappedLon,
+          new GeoRect(GeoUtils.MIN_LON_INCL, maxLon, minLat, maxLat));
       bqb.add(new BooleanClause(left, BooleanClause.Occur.SHOULD));
-      GeoPointDistanceQueryImpl right = new GeoPointDistanceQueryImpl(field, this, new GeoBoundingBox(minLon, 180.0D,
-          minLat, maxLat));
+
+      if (unwrappedLon < maxLon) {
+        // unwrap right
+        unwrappedLon += 360.0D;
+      }
+      GeoPointDistanceQueryImpl right = new GeoPointDistanceQueryImpl(field, this, unwrappedLon,
+          new GeoRect(minLon, GeoUtils.MAX_LON_INCL, minLat, maxLat));
       bqb.add(new BooleanClause(right, BooleanClause.Occur.SHOULD));
+
       return bqb.build();
     }
-    return new GeoPointDistanceQueryImpl(field, this, new GeoBoundingBox(this.minLon, this.maxLon, this.minLat, this.maxLat));
-  }
-
-  static GeoBoundingBox computeBBox(final double centerLon, final double centerLat, final double radius) {
-    double[] t = GeoProjectionUtils.pointFromLonLatBearing(centerLon, centerLat, 0, radius, null);
-    double[] r = GeoProjectionUtils.pointFromLonLatBearing(centerLon, centerLat, 90, radius, null);
-    double[] b = GeoProjectionUtils.pointFromLonLatBearing(centerLon, centerLat, 180, radius, null);
-    double[] l = GeoProjectionUtils.pointFromLonLatBearing(centerLon, centerLat, 270, radius, null);
-
-    return new GeoBoundingBox(GeoUtils.normalizeLon(l[0]), GeoUtils.normalizeLon(r[0]), GeoUtils.normalizeLat(b[1]),
-        GeoUtils.normalizeLat(t[1]));
+    return new GeoPointDistanceQueryImpl(field, this, centerLon,
+        new GeoRect(this.minLon, this.maxLon, this.minLat, this.maxLat));
   }
 
   @Override
@@ -102,7 +117,7 @@ public final class GeoPointDistanceQuery
 
     if (Double.compare(that.centerLat, centerLat) != 0) return false;
     if (Double.compare(that.centerLon, centerLon) != 0) return false;
-    if (Double.compare(that.radius, radius) != 0) return false;
+    if (Double.compare(that.radiusMeters, radiusMeters) != 0) return false;
 
     return true;
   }
@@ -115,7 +130,7 @@ public final class GeoPointDistanceQuery
     result = 31 * result + (int) (temp ^ (temp >>> 32));
     temp = Double.doubleToLongBits(centerLat);
     result = 31 * result + (int) (temp ^ (temp >>> 32));
-    temp = Double.doubleToLongBits(radius);
+    temp = Double.doubleToLongBits(radiusMeters);
     result = 31 * result + (int) (temp ^ (temp >>> 32));
     return result;
   }
@@ -136,17 +151,8 @@ public final class GeoPointDistanceQuery
         .append(centerLat)
         .append(']')
         .append(" Distance: ")
-        .append(radius)
-        .append(" m")
-        .append(" Lower Left: [")
-        .append(minLon)
-        .append(',')
-        .append(minLat)
-        .append(']')
-        .append(" Upper Right: [")
-        .append(maxLon)
-        .append(',')
-        .append(maxLat)
+        .append(radiusMeters)
+        .append(" meters")
         .append("]")
         .toString();
   }
@@ -159,7 +165,7 @@ public final class GeoPointDistanceQuery
     return this.centerLat;
   }
 
-  public double getRadius() {
-    return this.radius;
+  public double getRadiusMeters() {
+    return this.radiusMeters;
   }
 }

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQueryImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQueryImpl.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQueryImpl.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointDistanceQueryImpl.java Mon Dec 21 11:39:57 2015
@@ -19,9 +19,12 @@ package org.apache.lucene.search;
 
 import java.io.IOException;
 
+import org.apache.lucene.document.GeoPointField;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.util.AttributeSource;
+import org.apache.lucene.util.GeoRect;
+import org.apache.lucene.util.GeoRelationUtils;
 import org.apache.lucene.util.GeoUtils;
 import org.apache.lucene.util.SloppyMath;
 
@@ -31,10 +34,13 @@ import org.apache.lucene.util.SloppyMath
  */
 final class GeoPointDistanceQueryImpl extends GeoPointInBBoxQueryImpl {
   private final GeoPointDistanceQuery query;
+  private final double centerLon;
 
-  GeoPointDistanceQueryImpl(final String field, final GeoPointDistanceQuery q, final GeoBoundingBox bbox) {
+  GeoPointDistanceQueryImpl(final String field, final GeoPointDistanceQuery q, final double centerLonUnwrapped,
+                            final GeoRect bbox) {
     super(field, bbox.minLon, bbox.minLat, bbox.maxLon, bbox.maxLat);
     query = q;
+    centerLon = centerLonUnwrapped;
   }
 
   @Override @SuppressWarnings("unchecked")
@@ -53,14 +59,33 @@ final class GeoPointDistanceQueryImpl ex
       super(tenum, minLon, minLat, maxLon, maxLat);
     }
 
+    /**
+     * Computes the maximum shift for the given pointDistanceQuery. This prevents unnecessary depth traversal
+     * given the size of the distance query.
+     */
+    @Override
+    protected short computeMaxShift() {
+      final short shiftFactor;
+
+      if (query.radiusMeters > 1000000) {
+        shiftFactor = 5;
+      } else {
+        shiftFactor = 4;
+      }
+
+      return (short)(GeoPointField.PRECISION_STEP * shiftFactor);
+    }
+
     @Override
     protected boolean cellCrosses(final double minLon, final double minLat, final double maxLon, final double maxLat) {
-      return GeoUtils.rectCrossesCircle(minLon, minLat, maxLon, maxLat, query.centerLon, query.centerLat, query.radius);
+      return GeoRelationUtils.rectCrossesCircle(minLon, minLat, maxLon, maxLat,
+          centerLon, query.centerLat, query.radiusMeters, true);
     }
 
     @Override
     protected boolean cellWithin(final double minLon, final double minLat, final double maxLon, final double maxLat) {
-      return GeoUtils.rectWithinCircle(minLon, minLat, maxLon, maxLat, query.centerLon, query.centerLat, query.radius);
+      return GeoRelationUtils.rectWithinCircle(minLon, minLat, maxLon, maxLat,
+          centerLon, query.centerLat, query.radiusMeters, true);
     }
 
     @Override
@@ -77,7 +102,7 @@ final class GeoPointDistanceQueryImpl ex
      */
     @Override
     protected boolean postFilter(final double lon, final double lat) {
-      return (SloppyMath.haversin(query.centerLat, query.centerLon, lat, lon) * 1000.0 <= query.radius);
+      return (SloppyMath.haversin(query.centerLat, centerLon, lat, lon) * 1000.0 <= query.radiusMeters);
     }
   }
 
@@ -100,4 +125,8 @@ final class GeoPointDistanceQueryImpl ex
     result = 31 * result + query.hashCode();
     return result;
   }
+
+  public double getRadiusMeters() {
+    return query.getRadiusMeters();
+  }
 }

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQuery.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQuery.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQuery.java Mon Dec 21 11:39:57 2015
@@ -18,9 +18,10 @@ package org.apache.lucene.search;
  */
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.util.GeoUtils;
 
 /** Implements a simple bounding box query on a GeoPoint field. This is inspired by
- * {@link org.apache.lucene.search.NumericRangeQuery} and is implemented using a
+ * {@link LegacyNumericRangeQuery} and is implemented using a
  * two phase approach. First, candidate terms are queried using a numeric
  * range based on the morton codes of the min and max lat/lon pairs. Terms
  * passing this initial filter are passed to a final check that verifies whether
@@ -55,6 +56,13 @@ public class GeoPointInBBoxQuery extends
 
   @Override
   public Query rewrite(IndexReader reader) {
+    // short-circuit to match all if specifying the whole map
+    if (minLon == GeoUtils.MIN_LON_INCL && maxLon == GeoUtils.MAX_LON_INCL
+        && minLat == GeoUtils.MIN_LAT_INCL && maxLat == GeoUtils.MAX_LAT_INCL) {
+      // FieldValueQuery is valid since DocValues are *required* for GeoPointField
+      return new FieldValueQuery(field);
+    }
+
     if (maxLon < minLon) {
       BooleanQuery.Builder bqb = new BooleanQuery.Builder();
 

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQueryImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQueryImpl.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQueryImpl.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInBBoxQueryImpl.java Mon Dec 21 11:39:57 2015
@@ -19,10 +19,13 @@ package org.apache.lucene.search;
 
 import java.io.IOException;
 
+import org.apache.lucene.document.GeoPointField;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.util.AttributeSource;
+import org.apache.lucene.util.GeoRelationUtils;
 import org.apache.lucene.util.GeoUtils;
+import org.apache.lucene.util.SloppyMath;
 import org.apache.lucene.util.ToStringUtils;
 
 /** Package private implementation for the public facing GeoPointInBBoxQuery delegate class.
@@ -59,12 +62,29 @@ class GeoPointInBBoxQueryImpl extends Ge
       super(tenum, minLon, minLat, maxLon, maxLat);
     }
 
+    @Override
+    protected short computeMaxShift() {
+      final short shiftFactor;
+
+      // compute diagonal radius
+      double midLon = (minLon + maxLon) * 0.5;
+      double midLat = (minLat + maxLat) * 0.5;
+
+      if (SloppyMath.haversin(minLat, minLon, midLat, midLon)*1000 > 1000000) {
+        shiftFactor = 5;
+      } else {
+        shiftFactor = 4;
+      }
+
+      return (short)(GeoPointField.PRECISION_STEP * shiftFactor);
+    }
+
     /**
      * Determine whether the quad-cell crosses the shape
      */
     @Override
     protected boolean cellCrosses(final double minLon, final double minLat, final double maxLon, final double maxLat) {
-      return GeoUtils.rectCrosses(minLon, minLat, maxLon, maxLat, this.minLon, this.minLat, this.maxLon, this.maxLat);
+      return GeoRelationUtils.rectCrosses(minLon, minLat, maxLon, maxLat, this.minLon, this.minLat, this.maxLon, this.maxLat);
     }
 
     /**
@@ -72,7 +92,7 @@ class GeoPointInBBoxQueryImpl extends Ge
      */
     @Override
     protected boolean cellWithin(final double minLon, final double minLat, final double maxLon, final double maxLat) {
-      return GeoUtils.rectWithin(minLon, minLat, maxLon, maxLat, this.minLon, this.minLat, this.maxLon, this.maxLat);
+      return GeoRelationUtils.rectWithin(minLon, minLat, maxLon, maxLat, this.minLon, this.minLat, this.maxLon, this.maxLat);
     }
 
     @Override
@@ -82,7 +102,7 @@ class GeoPointInBBoxQueryImpl extends Ge
 
     @Override
     protected boolean postFilter(final double lon, final double lat) {
-      return GeoUtils.bboxContains(lon, lat, minLon, minLat, maxLon, maxLat);
+      return GeoRelationUtils.pointInRect(lon, lat, minLon, minLat, maxLon, maxLat);
     }
   }
 

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInPolygonQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInPolygonQuery.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInPolygonQuery.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointInPolygonQuery.java Mon Dec 21 11:39:57 2015
@@ -17,14 +17,15 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import java.io.IOException;
+import java.util.Arrays;
+
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.util.AttributeSource;
+import org.apache.lucene.util.GeoRect;
+import org.apache.lucene.util.GeoRelationUtils;
 import org.apache.lucene.util.GeoUtils;
-import org.apache.lucene.util.ToStringUtils;
-
-import java.io.IOException;
-import java.util.Arrays;
 
 /** Implements a simple point in polygon query on a GeoPoint field. This is based on
  * {@code GeoPointInBBoxQueryImpl} and is implemented using a
@@ -36,14 +37,14 @@ import java.util.Arrays;
  * term is passed to the final point in polygon check. All value comparisons are subject
  * to the same precision tolerance defined in {@value org.apache.lucene.util.GeoUtils#TOLERANCE}
  *
- * NOTES:
+ * <p>NOTES:
  *    1.  The polygon coordinates need to be in either clockwise or counter-clockwise order.
  *    2.  The polygon must not be self-crossing, otherwise the query may result in unexpected behavior
  *    3.  All latitude/longitude values must be in decimal degrees.
  *    4.  Complex computational geometry (e.g., dateline wrapping, polygon with holes) is not supported
  *    5.  For more advanced GeoSpatial indexing and query operations see spatial module
  *
- *    @lucene.experimental
+ * @lucene.experimental
  */
 public final class GeoPointInPolygonQuery extends GeoPointInBBoxQueryImpl {
   // polygon position arrays - this avoids the use of any objects or
@@ -56,11 +57,11 @@ public final class GeoPointInPolygonQuer
    * that fall within or on the boundary of the polygon defined by the input parameters.
    */
   public GeoPointInPolygonQuery(final String field, final double[] polyLons, final double[] polyLats) {
-    this(field, computeBBox(polyLons, polyLats), polyLons, polyLats);
+    this(field, GeoUtils.polyToBBox(polyLons, polyLats), polyLons, polyLats);
   }
 
   /** Common constructor, used only internally. */
-  private GeoPointInPolygonQuery(final String field, GeoBoundingBox bbox, final double[] polyLons, final double[] polyLats) {
+  private GeoPointInPolygonQuery(final String field, GeoRect bbox, final double[] polyLons, final double[] polyLats) {
     super(field, bbox.minLon, bbox.minLat, bbox.maxLon, bbox.maxLat);
     if (polyLats.length != polyLons.length) {
       throw new IllegalArgumentException("polyLats and polyLons must be equal length");
@@ -75,16 +76,8 @@ public final class GeoPointInPolygonQuer
       throw new IllegalArgumentException("first and last points of the polygon must be the same (it must close itself): polyLons[0]=" + polyLons[0] + " polyLons[" + (polyLons.length-1) + "]=" + polyLons[polyLons.length-1]);
     }
 
-    // convert polygon vertices to coordinates within tolerance
-    this.x = toleranceConversion(polyLons);
-    this.y = toleranceConversion(polyLats);
-  }
-
-  private double[] toleranceConversion(double[] vals) {
-    for (int i=0; i<vals.length; ++i) {
-      vals[i] = ((int)(vals[i]/GeoUtils.TOLERANCE))*GeoUtils.TOLERANCE;
-    }
-    return vals;
+    this.x = polyLons;
+    this.y = polyLats;
   }
 
   @Override @SuppressWarnings("unchecked")
@@ -155,19 +148,20 @@ public final class GeoPointInPolygonQuer
 
     @Override
     protected boolean cellCrosses(final double minLon, final double minLat, final double maxLon, final double maxLat) {
-      return GeoUtils.rectCrossesPoly(minLon, minLat, maxLon, maxLat, x, y, GeoPointInPolygonQuery.this.minLon,
+      return GeoRelationUtils.rectCrossesPoly(minLon, minLat, maxLon, maxLat, x, y, GeoPointInPolygonQuery.this.minLon,
           GeoPointInPolygonQuery.this.minLat, GeoPointInPolygonQuery.this.maxLon, GeoPointInPolygonQuery.this.maxLat);
     }
 
     @Override
     protected boolean cellWithin(final double minLon, final double minLat, final double maxLon, final double maxLat) {
-      return GeoUtils.rectWithinPoly(minLon, minLat, maxLon, maxLat, x, y, GeoPointInPolygonQuery.this.minLon,
+      return GeoRelationUtils.rectWithinPoly(minLon, minLat, maxLon, maxLat, x, y, GeoPointInPolygonQuery.this.minLon,
           GeoPointInPolygonQuery.this.minLat, GeoPointInPolygonQuery.this.maxLon, GeoPointInPolygonQuery.this.maxLat);
     }
 
     @Override
     protected boolean cellIntersectsShape(final double minLon, final double minLat, final double maxLon, final double maxLat) {
-      return cellWithin(minLon, minLat, maxLon, maxLat) || cellCrosses(minLon, minLat, maxLon, maxLat);
+      return cellContains(minLon, minLat, maxLon, maxLat) || cellWithin(minLon, minLat, maxLon, maxLat)
+          || cellCrosses(minLon, minLat, maxLon, maxLat);
     }
 
     /**
@@ -175,38 +169,12 @@ public final class GeoPointInPolygonQuer
      * {@link org.apache.lucene.search.GeoPointTermsEnum#accept} method is called to match
      * encoded terms that fall within the bounding box of the polygon. Those documents that pass the initial
      * bounding box filter are then compared to the provided polygon using the
-     * {@link org.apache.lucene.util.GeoUtils#pointInPolygon} method.
+     * {@link org.apache.lucene.util.GeoRelationUtils#pointInPolygon} method.
      */
     @Override
     protected boolean postFilter(final double lon, final double lat) {
-      return GeoUtils.pointInPolygon(x, y, lat, lon);
-    }
-  }
-
-  private static GeoBoundingBox computeBBox(double[] polyLons, double[] polyLats) {
-    if (polyLons.length != polyLats.length) {
-      throw new IllegalArgumentException("polyLons and polyLats must be equal length");
+      return GeoRelationUtils.pointInPolygon(x, y, lat, lon);
     }
-
-    double minLon = Double.POSITIVE_INFINITY;
-    double maxLon = Double.NEGATIVE_INFINITY;
-    double minLat = Double.POSITIVE_INFINITY;
-    double maxLat = Double.NEGATIVE_INFINITY;
-
-    for (int i=0;i<polyLats.length;i++) {
-      if (GeoUtils.isValidLon(polyLons[i]) == false) {
-        throw new IllegalArgumentException("invalid polyLons[" + i + "]=" + polyLons[i]);
-      }
-      if (GeoUtils.isValidLat(polyLats[i]) == false) {
-        throw new IllegalArgumentException("invalid polyLats[" + i + "]=" + polyLats[i]);
-      }
-      minLon = Math.min(polyLons[i], minLon);
-      maxLon = Math.max(polyLons[i], maxLon);
-      minLat = Math.min(polyLats[i], minLat);
-      maxLat = Math.max(polyLats[i], maxLat);
-    }
-
-    return new GeoBoundingBox(minLon, maxLon, minLat, maxLat);
   }
 
   /**

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointTermsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointTermsEnum.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointTermsEnum.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/GeoPointTermsEnum.java Mon Dec 21 11:39:57 2015
@@ -26,8 +26,9 @@ import org.apache.lucene.index.FilteredT
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefBuilder;
+import org.apache.lucene.util.GeoRelationUtils;
 import org.apache.lucene.util.GeoUtils;
-import org.apache.lucene.util.NumericUtils;
+import org.apache.lucene.util.LegacyNumericUtils;
 
 /**
  * computes all ranges along a space-filling curve that represents
@@ -48,9 +49,7 @@ abstract class GeoPointTermsEnum extends
   private final List<Range> rangeBounds = new LinkedList<>();
 
   // detail level should be a factor of PRECISION_STEP limiting the depth of recursion (and number of ranges)
-  // in this case a factor of 4 brings the detail level to ~0.002/0.001 degrees lon/lat respectively (or ~222m/111m)
-  private static final short MAX_SHIFT = GeoPointField.PRECISION_STEP * 4;
-  protected static final short DETAIL_LEVEL = ((GeoUtils.BITS<<1)-MAX_SHIFT)/2;
+  protected final short DETAIL_LEVEL;
 
   GeoPointTermsEnum(final TermsEnum tenum, final double minLon, final double minLat,
                     final double maxLon, final double maxLat) {
@@ -61,8 +60,10 @@ abstract class GeoPointTermsEnum extends
     this.minLat = GeoUtils.mortonUnhashLat(rectMinHash);
     this.maxLon = GeoUtils.mortonUnhashLon(rectMaxHash);
     this.maxLat = GeoUtils.mortonUnhashLat(rectMaxHash);
+    DETAIL_LEVEL = (short)(((GeoUtils.BITS<<1)-computeMaxShift())/2);
 
     computeRange(0L, (short) (((GeoUtils.BITS) << 1) - 1));
+    assert rangeBounds.isEmpty() == false;
     Collections.sort(rangeBounds);
   }
 
@@ -103,12 +104,23 @@ abstract class GeoPointTermsEnum extends
     // if cell is within and a factor of the precision step, or it crosses the edge of the shape add the range
     final boolean within = res % GeoPointField.PRECISION_STEP == 0 && cellWithin(minLon, minLat, maxLon, maxLat);
     if (within || (level == DETAIL_LEVEL && cellIntersectsShape(minLon, minLat, maxLon, maxLat))) {
-      rangeBounds.add(new Range(start, res, !within));
+      final short nextRes = (short)(res-1);
+      if (nextRes % GeoPointField.PRECISION_STEP == 0) {
+        rangeBounds.add(new Range(start, nextRes, !within));
+        rangeBounds.add(new Range(start|(1L<<nextRes), nextRes, !within));
+      } else {
+        rangeBounds.add(new Range(start, res, !within));
+      }
     } else if (level < DETAIL_LEVEL && cellIntersectsMBR(minLon, minLat, maxLon, maxLat)) {
       computeRange(start, (short) (res - 1));
     }
   }
 
+  protected short computeMaxShift() {
+    // in this case a factor of 4 brings the detail level to ~0.002/0.001 degrees lon/lat respectively (or ~222m/111m)
+    return GeoPointField.PRECISION_STEP * 4;
+  }
+
   /**
    * Determine whether the quad-cell crosses the shape
    */
@@ -128,14 +140,14 @@ abstract class GeoPointTermsEnum extends
    * Primary driver for cells intersecting shape boundaries
    */
   protected boolean cellIntersectsMBR(final double minLon, final double minLat, final double maxLon, final double maxLat) {
-    return GeoUtils.rectIntersects(minLon, minLat, maxLon, maxLat, this.minLon, this.minLat, this.maxLon, this.maxLat);
+    return GeoRelationUtils.rectIntersects(minLon, minLat, maxLon, maxLat, this.minLon, this.minLat, this.maxLon, this.maxLat);
   }
 
   /**
    * Return whether quad-cell contains the bounding box of this shape
    */
   protected boolean cellContains(final double minLon, final double minLat, final double maxLon, final double maxLat) {
-    return GeoUtils.rectWithin(this.minLon, this.minLat, this.maxLon, this.maxLat, minLon, minLat, maxLon, maxLat);
+    return GeoRelationUtils.rectWithin(this.minLon, this.minLat, this.maxLon, this.maxLat, minLon, minLat, maxLon, maxLat);
   }
 
   public boolean boundaryTerm() {
@@ -223,7 +235,7 @@ abstract class GeoPointTermsEnum extends
      */
     private void fillBytesRef(BytesRefBuilder result) {
       assert result != null;
-      NumericUtils.longToPrefixCoded(start, shift, result);
+      LegacyNumericUtils.longToPrefixCoded(start, shift, result);
     }
 
     @Override

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonScorer.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonScorer.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonScorer.java Mon Dec 21 11:39:57 2015
@@ -130,71 +130,86 @@ class TermAutomatonScorer extends Scorer
   }
 
   @Override
-  public int nextDoc() throws IOException {
-    // we only need to advance docs that are positioned since all docs in the
-    // pq are guaranteed to be beyond the current doc already
-    for(int i=0;i<numSubsOnDoc;i++) {
-      EnumAndScorer sub = subsOnDoc[i];
-      if (sub.posEnum.nextDoc() != NO_MORE_DOCS) {
-        sub.posLeft = sub.posEnum.freq()-1;
-        sub.pos = sub.posEnum.nextPosition();
+  public DocIdSetIterator iterator() {
+    return new DocIdSetIterator() {
+      @Override
+      public int docID() {
+        return docID;
       }
-    }
-    pushCurrentDoc();
-    return doNext();
-  }
 
-  @Override
-  public int advance(int target) throws IOException {
-    // Both positioned docs and docs in the pq might be behind target
+      @Override
+      public long cost() {
+        return cost;
+      }
 
-    // 1. Advance the PQ
-    if (docIDQueue.size() > 0) {
-      EnumAndScorer top = docIDQueue.top();
-      while (top.posEnum.docID() < target) {
-        if (top.posEnum.advance(target) != NO_MORE_DOCS) {
-          top.posLeft = top.posEnum.freq()-1;
-          top.pos = top.posEnum.nextPosition();
+      @Override
+      public int nextDoc() throws IOException {
+        // we only need to advance docs that are positioned since all docs in the
+        // pq are guaranteed to be beyond the current doc already
+        for(int i=0;i<numSubsOnDoc;i++) {
+          EnumAndScorer sub = subsOnDoc[i];
+          if (sub.posEnum.nextDoc() != NO_MORE_DOCS) {
+            sub.posLeft = sub.posEnum.freq()-1;
+            sub.pos = sub.posEnum.nextPosition();
+          }
         }
-        top = docIDQueue.updateTop();
+        pushCurrentDoc();
+        return doNext();
       }
-    }
 
-    // 2. Advance subsOnDoc
-    for(int i=0;i<numSubsOnDoc;i++) {
-      EnumAndScorer sub = subsOnDoc[i];
-      if (sub.posEnum.advance(target) != NO_MORE_DOCS) {
-        sub.posLeft = sub.posEnum.freq()-1;
-        sub.pos = sub.posEnum.nextPosition();
-      }
-    }
-    pushCurrentDoc();
-    return doNext();
-  }
+      @Override
+      public int advance(int target) throws IOException {
+        // Both positioned docs and docs in the pq might be behind target
+
+        // 1. Advance the PQ
+        if (docIDQueue.size() > 0) {
+          EnumAndScorer top = docIDQueue.top();
+          while (top.posEnum.docID() < target) {
+            if (top.posEnum.advance(target) != NO_MORE_DOCS) {
+              top.posLeft = top.posEnum.freq()-1;
+              top.pos = top.posEnum.nextPosition();
+            }
+            top = docIDQueue.updateTop();
+          }
+        }
 
-  private int doNext() throws IOException {
-    assert numSubsOnDoc == 0;
-    assert docIDQueue.top().posEnum.docID() > docID;
-    while (true) {
-      //System.out.println("  doNext: cycle");
-      popCurrentDoc();
-      //System.out.println("    docID=" + docID);
-      if (docID == NO_MORE_DOCS) {
-        return docID;
-      }
-      countMatches();
-      if (freq > 0) {
-        return docID;
+        // 2. Advance subsOnDoc
+        for(int i=0;i<numSubsOnDoc;i++) {
+          EnumAndScorer sub = subsOnDoc[i];
+          if (sub.posEnum.advance(target) != NO_MORE_DOCS) {
+            sub.posLeft = sub.posEnum.freq()-1;
+            sub.pos = sub.posEnum.nextPosition();
+          }
+        }
+        pushCurrentDoc();
+        return doNext();
       }
-      for(int i=0;i<numSubsOnDoc;i++) {
-        EnumAndScorer sub = subsOnDoc[i];
-        if (sub.posEnum.nextDoc() != NO_MORE_DOCS) {
-          sub.posLeft = sub.posEnum.freq()-1;
-          sub.pos = sub.posEnum.nextPosition();
+
+      private int doNext() throws IOException {
+        assert numSubsOnDoc == 0;
+        assert docIDQueue.top().posEnum.docID() > docID;
+        while (true) {
+          //System.out.println("  doNext: cycle");
+          popCurrentDoc();
+          //System.out.println("    docID=" + docID);
+          if (docID == NO_MORE_DOCS) {
+            return docID;
+          }
+          countMatches();
+          if (freq > 0) {
+            return docID;
+          }
+          for(int i=0;i<numSubsOnDoc;i++) {
+            EnumAndScorer sub = subsOnDoc[i];
+            if (sub.posEnum.nextDoc() != NO_MORE_DOCS) {
+              sub.posLeft = sub.posEnum.freq()-1;
+              sub.pos = sub.posEnum.nextPosition();
+            }
+          }
+          pushCurrentDoc();
         }
       }
-      pushCurrentDoc();
-    }
+    };
   }
 
   private PosState getPosition(int pos) {
@@ -351,11 +366,6 @@ class TermAutomatonScorer extends Scorer
     return docScorer.score(docID, freq);
   }
 
-  @Override
-  public long cost() {
-    return cost;
-  }
-
   static class TermRunAutomaton extends RunAutomaton {
     public TermRunAutomaton(Automaton a, int termCount) {
       super(a, termCount, true);

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/util/GeoDistanceUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/util/GeoDistanceUtils.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/util/GeoDistanceUtils.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/util/GeoDistanceUtils.java Mon Dec 21 11:39:57 2015
@@ -17,6 +17,8 @@ package org.apache.lucene.util;
  * limitations under the License.
  */
 
+import static org.apache.lucene.util.SloppyMath.TO_RADIANS;
+
 /**
  * Reusable geo-spatial distance utility methods.
  *
@@ -25,6 +27,28 @@ package org.apache.lucene.util;
 public class GeoDistanceUtils {
 
   /**
+   * Compute the great-circle distance using original haversine implementation published by Sinnot in:
+   * R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159
+   *
+   * NOTE: this differs from {@link org.apache.lucene.util.SloppyMath#haversin} in that it uses the semi-major axis
+   * of the earth instead of an approximation based on the average latitude of the two points (which can introduce an
+   * additional error up to .337%, or ~67.6 km at the equator)
+   */
+  public static double haversin(double lat1, double lon1, double lat2, double lon2) {
+    double dLat = TO_RADIANS * (lat2 - lat1);
+    double dLon = TO_RADIANS * (lon2 - lon1);
+    lat1 = TO_RADIANS * (lat1);
+    lat2 = TO_RADIANS * (lat2);
+
+    final double sinDLatO2 = SloppyMath.sin(dLat / 2);
+    final double sinDLonO2 = SloppyMath.sin(dLon / 2);
+
+    double a = sinDLatO2*sinDLatO2 + sinDLonO2 * sinDLonO2 * SloppyMath.cos(lat1) * SloppyMath.cos(lat2);
+    double c = 2 * SloppyMath.asin(Math.sqrt(a));
+    return (GeoProjectionUtils.SEMIMAJOR_AXIS * c);
+  }
+
+  /**
    * Compute the distance between two geo-points using vincenty distance formula
    * Vincenty uses the oblate spheroid whereas haversine uses unit sphere, this will give roughly
    * 22m better accuracy (in worst case) than haversine
@@ -87,6 +111,20 @@ public class GeoDistanceUtils {
   }
 
   /**
+   * Computes distance between two points in a cartesian (x, y, {z - optional}) coordinate system
+   */
+  public static double linearDistance(double[] pt1, double[] pt2) {
+    assert pt1 != null && pt2 != null && pt1.length == pt2.length && pt1.length > 1;
+    final double d0 = pt1[0] - pt2[0];
+    final double d1 = pt1[1] - pt2[1];
+    if (pt1.length == 3) {
+      final double d2 = pt1[2] - pt2[2];
+      return Math.sqrt(d0*d0 + d1*d1 + d2*d2);
+    }
+    return Math.sqrt(d0*d0 + d1*d1);
+  }
+
+  /**
    * Compute the inverse haversine to determine distance in degrees longitude for provided distance in meters
    * @param lat latitude to compute delta degrees lon
    * @param distance distance in meters to convert to degrees lon
@@ -110,6 +148,54 @@ public class GeoDistanceUtils {
   }
 
   /**
+   *  Finds the closest point within a rectangle (defined by rMinX, rMinY, rMaxX, rMaxY) to the given (lon, lat) point
+   *  the result is provided in closestPt.  When the point is outside the rectangle, the closest point is on an edge
+   *  or corner of the rectangle; else, the closest point is the point itself.
+   */
+  public static void closestPointOnBBox(final double rMinX, final double rMinY, final double rMaxX, final double rMaxY,
+                                        final double lon, final double lat, double[] closestPt) {
+    assert closestPt != null && closestPt.length == 2;
+
+    closestPt[0] = 0;
+    closestPt[1] = 0;
+
+    boolean xSet = true;
+    boolean ySet = true;
+
+    if (lon > rMaxX) {
+      closestPt[0] = rMaxX;
+    } else if (lon < rMinX) {
+      closestPt[0] = rMinX;
+    } else {
+      xSet = false;
+    }
+
+    if (lat > rMaxY) {
+      closestPt[1] = rMaxY;
+    } else if (lat < rMinY) {
+      closestPt[1] = rMinY;
+    } else {
+      ySet = false;
+    }
+
+    if (closestPt[0] == 0 && xSet == false) {
+      closestPt[0] = lon;
+    }
+
+    if (closestPt[1] == 0 && ySet == false) {
+      closestPt[1] = lat;
+    }
+  }
+
+  /** Returns the maximum distance/radius (in meters) from the point 'center' before overlapping */
+  public static double maxRadialDistanceMeters(final double centerLon, final double centerLat) {
+    if (Math.abs(centerLat) == GeoUtils.MAX_LAT_INCL) {
+      return GeoDistanceUtils.haversin(centerLat, centerLon, 0, centerLon);
+    }
+    return GeoDistanceUtils.haversin(centerLat, centerLon, centerLat, (GeoUtils.MAX_LON_INCL + centerLon) % 360);
+  }
+
+  /**
    * Compute the inverse haversine to determine distance in degrees longitude for provided distance in meters
    * @param lat latitude to compute delta degrees lon
    * @param distance distance in meters to convert to degrees lon

Modified: lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/util/GeoHashUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/util/GeoHashUtils.java?rev=1721134&r1=1721133&r2=1721134&view=diff
==============================================================================
--- lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/util/GeoHashUtils.java (original)
+++ lucene/dev/branches/lucene6835/lucene/sandbox/src/java/org/apache/lucene/util/GeoHashUtils.java Mon Dec 21 11:39:57 2015
@@ -64,6 +64,25 @@ public class GeoHashUtils {
   }
 
   /**
+   * Encode an existing geohash long to the provided precision
+   */
+  public static long longEncode(long geohash, int level) {
+    final short precision = (short)(geohash & 15);
+    if (precision == level) {
+      return geohash;
+    } else if (precision > level) {
+      return ((geohash >>> (((precision - level) * 5) + 4)) << 4) | level;
+    }
+    return ((geohash >>> 4) << (((level - precision) * 5) + 4) | level);
+  }
+
+  public static long fromMorton(long morton, int level) {
+    long mFlipped = BitUtil.flipFlop(morton);
+    mFlipped >>>= (((GeoHashUtils.PRECISION - level) * 5) + MORTON_OFFSET);
+    return (mFlipped << 4) | level;
+  }
+
+  /**
    * Encode to a geohash string from the geohash based long format
    */
   public static final String stringEncode(long geoHashLong) {
@@ -71,7 +90,7 @@ public class GeoHashUtils {
     geoHashLong >>>= 4;
     char[] chars = new char[level];
     do {
-      chars[--level] = BASE_32[(int)(geoHashLong&31L)];
+      chars[--level] = BASE_32[(int) (geoHashLong&31L)];
       geoHashLong>>>=5;
     } while(level > 0);
 
@@ -89,19 +108,10 @@ public class GeoHashUtils {
    * Encode to a level specific geohash string from full resolution longitude, latitude
    */
   public static final String stringEncode(final double lon, final double lat, final int level) {
-    // bit twiddle to geohash (since geohash is a swapped (lon/lat) encoding)
-    final long hashedVal = BitUtil.flipFlop(GeoUtils.mortonHash(lon, lat));
+    // convert to geohashlong
+    final long ghLong = fromMorton(GeoUtils.mortonHash(lon, lat), level);
+    return stringEncode(ghLong);
 
-    StringBuilder geoHash = new StringBuilder();
-    short precision = 0;
-    final short msf = (GeoUtils.BITS<<1)-5;
-    long mask = 31L<<msf;
-    do {
-      geoHash.append(BASE_32[(int)((mask & hashedVal)>>>(msf-(precision*5)))]);
-      // next 5 bits
-      mask >>>= 5;
-    } while (++precision < level);
-    return geoHash.toString();
   }
 
   /**
@@ -151,7 +161,7 @@ public class GeoHashUtils {
     final int level = (int)(geoHashLong&15);
     final short odd = (short)(level & 1);
 
-    return BitUtil.flipFlop((geoHashLong >>> 4) << odd) << (((12 - level) * 5) + (MORTON_OFFSET - odd));
+    return BitUtil.flipFlop(((geoHashLong >>> 4) << odd) << (((12 - level) * 5) + (MORTON_OFFSET - odd)));
   }
 
   private static final char encode(int x, int y) {