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/01/02 13:02:33 UTC

svn commit: r1649007 [5/10] - in /lucene/dev/branches/lucene6005/lucene: analysis/common/src/test/org/apache/lucene/analysis/core/ analysis/common/src/test/org/apache/lucene/collation/ benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ benchm...

Modified: lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/compressing/TestCompressingStoredFieldsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/compressing/TestCompressingStoredFieldsFormat.java?rev=1649007&r1=1649006&r2=1649007&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/compressing/TestCompressingStoredFieldsFormat.java (original)
+++ lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/compressing/TestCompressingStoredFieldsFormat.java Fri Jan  2 12:02:31 2015
@@ -22,7 +22,9 @@ import java.io.IOException;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.codecs.Codec;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.document.LowSchemaField;
 import org.apache.lucene.index.BaseStoredFieldsFormatTestCase;
+import org.apache.lucene.index.IndexOptions;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.store.AlreadyClosedException;
@@ -62,12 +64,20 @@ public class TestCompressingStoredFields
     
     // make sure that #writeField will fail to trigger an abort
     Document invalidDoc = iw.newDocument();
+    invalidDoc.add(new LowSchemaField(null, "invalid", "", IndexOptions.NONE, false) {
+        @Override
+        public String stringValue() {
+          // TODO: really bad & scary that this causes IW to
+          // abort the segment!!  We should fix this.
+          return null;
+        }
+      });
 
-    // nocommit this no longer aborts....
     try {
-      invalidDoc.addStored("invalid", (String) null);
+      iw.addDocument(invalidDoc);
+      iw.commit();
     } finally {
-      iw.close();
+      // Abort should have closed the deleter:
       dir.close();
     }
   }

Modified: lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestAutoPrefixTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestAutoPrefixTerms.java?rev=1649007&r1=1649006&r2=1649007&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestAutoPrefixTerms.java (original)
+++ lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestAutoPrefixTerms.java Fri Jan  2 12:02:31 2015
@@ -17,6 +17,7 @@ package org.apache.lucene.codecs.lucene5
  * limitations under the License.
  */
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -25,12 +26,14 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
 import org.apache.lucene.codecs.Codec;
 import org.apache.lucene.document.Document;
+import org.apache.lucene.document.FieldTypes;
 import org.apache.lucene.index.BinaryDocValues;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.DocValuesType;
@@ -45,13 +48,17 @@ import org.apache.lucene.index.SerialMer
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
+import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MultiTermQuery;
 import org.apache.lucene.search.PrefixQuery;
+import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.AttributeImpl;
+import org.apache.lucene.util.AttributeSource;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.FixedBitSet;
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.NumericUtils;
 import org.apache.lucene.util.StringHelper;
 import org.apache.lucene.util.TestUtil;
 import org.apache.lucene.util.automaton.CompiledAutomaton;
@@ -651,4 +658,81 @@ public class TestAutoPrefixTerms extends
     }
   }
 
+  public void testDisableAutoPrefix() throws Exception {
+    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+    iwc.setCodec(new Lucene50Codec());
+    IndexWriter w = new IndexWriter(dir, iwc);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.disableFastRanges("num");
+    for(int i=0;i<10000;i++) {
+      Document doc = w.newDocument();
+      doc.addInt("num", i);
+      w.addDocument(doc);
+    }
+    w.forceMerge(1);
+    IndexReader r = DirectoryReader.open(w);
+    shouldFail(() -> fieldTypes.newIntRangeFilter("num", 0, true, 100, true),
+               "field \"num\": cannot create range filter: this field was not indexed for fast ranges");
+
+    AtomicInteger termCount = new AtomicInteger();
+    TermRangeQuery q = new TermRangeQuery("num",
+                                          NumericUtils.intToBytes(0),
+                                          NumericUtils.intToBytes(9999),
+                                          true,
+                                          false) {
+
+        @Override
+        protected TermsEnum getTermsEnum(Terms terms, AttributeSource atts) throws IOException {
+          TermsEnum te = super.getTermsEnum(terms, atts);
+          while (te.next() != null) {
+            termCount.incrementAndGet();
+          }
+          return super.getTermsEnum(terms, atts);
+        }
+      };
+    
+    IndexSearcher s = newSearcher(r);
+    s.search(q, 1);
+    assertEquals(9999, termCount.get());
+    r.close();
+    w.close();
+  }
+
+  public void testEnableAutoPrefix() throws Exception {
+    IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
+    iwc.setCodec(new Lucene50Codec());
+    IndexWriter w = new IndexWriter(dir, iwc);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.enableFastRanges("num");
+    for(int i=0;i<10000;i++) {
+      Document doc = w.newDocument();
+      doc.addInt("num", i);
+      w.addDocument(doc);
+    }
+    w.forceMerge(1);
+    IndexReader r = DirectoryReader.open(w);
+
+    AtomicInteger termCount = new AtomicInteger();
+    TermRangeQuery q = new TermRangeQuery("num",
+                                          NumericUtils.intToBytes(0),
+                                          NumericUtils.intToBytes(9999),
+                                          true,
+                                          true) {
+
+        @Override
+        protected TermsEnum getTermsEnum(Terms terms, AttributeSource atts) throws IOException {
+          TermsEnum te = super.getTermsEnum(terms, atts);
+          while (te.next() != null) {
+            termCount.incrementAndGet();
+          }
+          return super.getTermsEnum(terms, atts);
+        }
+      };
+    
+    IndexSearcher s = newSearcher(r);
+    s.search(q, 1);
+    assertTrue(termCount.get() < 9999);
+    r.close();
+    w.close();
+  }
 }

Modified: lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java?rev=1649007&r1=1649006&r2=1649007&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java (original)
+++ lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/codecs/lucene50/TestLucene50StoredFieldsFormatHighCompression.java Fri Jan  2 12:02:31 2015
@@ -45,8 +45,8 @@ public class TestLucene50StoredFieldsFor
       iwc.setCodec(new Lucene50Codec(RandomPicks.randomFrom(random(), Mode.values())));
       IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig());
       Document doc = iw.newDocument();
-      doc.addStored("field1", "value1");
-      doc.addStored("field2", "value2");
+      doc.addStoredString("field1", "value1");
+      doc.addStoredString("field2", "value2");
       iw.addDocument(doc);
       if (random().nextInt(4) == 0) {
         iw.forceMerge(1);

Added: lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestAtomFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestAtomFields.java?rev=1649007&view=auto
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestAtomFields.java (added)
+++ lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestAtomFields.java Fri Jan  2 12:02:31 2015
@@ -0,0 +1,428 @@
+package org.apache.lucene.document;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.lucene.analysis.BaseTokenStreamTestCase;
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.search.FieldDoc;
+import org.apache.lucene.search.Filter;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortedSetSelector;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.HalfFloat;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.NumericUtils;
+import org.apache.lucene.util.TestUtil;
+
+public class TestAtomFields extends LuceneTestCase {
+
+  /** Make sure that if we index an ATOM field, at search time we get KeywordAnalyzer for it. */
+  public void testFieldUsesKeywordAnalyzer() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriterConfig iwc = newIndexWriterConfig();
+    IndexWriter w = new IndexWriter(dir, iwc);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    Document doc = w.newDocument();
+    doc.addAtom("id", "foo bar");
+    w.addDocument(doc);
+    BaseTokenStreamTestCase.assertTokenStreamContents(fieldTypes.getQueryAnalyzer().tokenStream("id", "foo bar"), new String[] {"foo bar"}, new int[1], new int[] {7});
+    w.close();
+    dir.close();
+  }
+
+  public void testBinaryAtomSort() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    w.commit();
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setSortMissingFirst("atom");
+
+    Document doc = w.newDocument();
+    doc.addAtom("atom", new BytesRef("z"));
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("atom", new BytesRef("a"));
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("id", "2");
+    w.addDocument(doc);
+    
+    DirectoryReader r = DirectoryReader.open(w, true);
+    fieldTypes = r.getFieldTypes();
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 3, fieldTypes.newSort("atom"));
+    assertEquals(3, hits.totalHits);
+    assertEquals("2", s.doc(hits.scoreDocs[0].doc).getString("id"));
+    assertEquals("1", s.doc(hits.scoreDocs[1].doc).getString("id"));
+    assertEquals("0", s.doc(hits.scoreDocs[2].doc).getString("id"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testSortMissingFirst() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    w.commit();
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setSortMissingFirst("atom");
+
+    Document doc = w.newDocument();
+    doc.addAtom("atom", "z");
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("atom", "a");
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("id", "2");
+    w.addDocument(doc);
+    
+    DirectoryReader r = DirectoryReader.open(w, true);
+    fieldTypes = r.getFieldTypes();
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 3, fieldTypes.newSort("atom"));
+    assertEquals(3, hits.totalHits);
+    assertEquals("2", s.doc(hits.scoreDocs[0].doc).getString("id"));
+    assertEquals("1", s.doc(hits.scoreDocs[1].doc).getString("id"));
+    assertEquals("0", s.doc(hits.scoreDocs[2].doc).getString("id"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testSortMissingFirstReversed() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    w.commit();
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.enableSorting("atom", true);
+    fieldTypes.setSortMissingFirst("atom");
+
+    Document doc = w.newDocument();
+    doc.addAtom("atom", "z");
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("atom", "a");
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("id", "2");
+    w.addDocument(doc);
+    
+    DirectoryReader r = DirectoryReader.open(w, true);
+    fieldTypes = r.getFieldTypes();
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 3, fieldTypes.newSort("atom"));
+    assertEquals(3, hits.totalHits);
+    assertEquals("2", s.doc(hits.scoreDocs[0].doc).getString("id"));
+    assertEquals("0", s.doc(hits.scoreDocs[1].doc).getString("id"));
+    assertEquals("1", s.doc(hits.scoreDocs[2].doc).getString("id"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testSortMissingLast() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    w.commit();
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.enableSorting("atom");
+    fieldTypes.setSortMissingLast("atom");
+
+    Document doc = w.newDocument();
+    doc.addAtom("atom", "z");
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("atom", "a");
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("id", "2");
+    w.addDocument(doc);
+    
+    DirectoryReader r = DirectoryReader.open(w, true);
+    fieldTypes = r.getFieldTypes();
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 3, fieldTypes.newSort("atom"));
+    assertEquals(3, hits.totalHits);
+    assertEquals("1", s.doc(hits.scoreDocs[0].doc).getString("id"));
+    assertEquals("0", s.doc(hits.scoreDocs[1].doc).getString("id"));
+    assertEquals("2", s.doc(hits.scoreDocs[2].doc).getString("id"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testSortMissingLastReversed() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    w.commit();
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.enableSorting("atom", true);
+    fieldTypes.setSortMissingLast("atom");
+
+    Document doc = w.newDocument();
+    doc.addAtom("atom", "z");
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("atom", "a");
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("id", "2");
+    w.addDocument(doc);
+    
+    DirectoryReader r = DirectoryReader.open(w, true);
+    fieldTypes = r.getFieldTypes();
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 3, fieldTypes.newSort("atom"));
+    assertEquals(3, hits.totalHits);
+    assertEquals("0", s.doc(hits.scoreDocs[0].doc).getString("id"));
+    assertEquals("1", s.doc(hits.scoreDocs[1].doc).getString("id"));
+    assertEquals("2", s.doc(hits.scoreDocs[2].doc).getString("id"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testSortMissingDefault() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    w.commit();
+
+    Document doc = w.newDocument();
+    doc.addAtom("atom", "z");
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("atom", "a");
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("id", "2");
+    w.addDocument(doc);
+    
+    DirectoryReader r = DirectoryReader.open(w, true);
+    FieldTypes fieldTypes = r.getFieldTypes();
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 3, fieldTypes.newSort("atom"));
+    assertEquals(3, hits.totalHits);
+    assertEquals("1", s.doc(hits.scoreDocs[0].doc).getString("id"));
+    assertEquals("0", s.doc(hits.scoreDocs[1].doc).getString("id"));
+    assertEquals("2", s.doc(hits.scoreDocs[2].doc).getString("id"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testSortMissingDefaultReversed() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    w.commit();
+
+    Document doc = w.newDocument();
+    doc.addAtom("atom", "z");
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("atom", "a");
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addAtom("id", "2");
+    w.addDocument(doc);
+    
+    DirectoryReader r = DirectoryReader.open(w, true);
+    FieldTypes fieldTypes = r.getFieldTypes();
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 3, fieldTypes.newSort("atom", true));
+    assertEquals(3, hits.totalHits);
+    assertEquals("0", s.doc(hits.scoreDocs[0].doc).getString("id"));
+    assertEquals("1", s.doc(hits.scoreDocs[1].doc).getString("id"));
+    assertEquals("2", s.doc(hits.scoreDocs[2].doc).getString("id"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testMinMaxAtom() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setMinMaxTokenLength("field", 2, 7);
+    fieldTypes.setMultiValued("field");
+    Document doc = w.newDocument();
+    doc.addAtom("field", "a");
+    doc.addAtom("field", "ab");
+    doc.addAtom("field", "goodbyeyou");
+    w.addDocument(doc);
+
+    DirectoryReader r = DirectoryReader.open(w, true);
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    assertEquals(0, hitCount(s, fieldTypes.newStringTermQuery("field", "a")));
+    assertEquals(1, hitCount(s, fieldTypes.newStringTermQuery("field", "ab")));
+    assertEquals(0, hitCount(s, fieldTypes.newStringTermQuery("field", "goodbyeyou")));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testMinMaxBinaryAtom() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setMinMaxTokenLength("field", 2, 7);
+    fieldTypes.setMultiValued("field");
+    Document doc = w.newDocument();
+    doc.addAtom("field", new BytesRef(new byte[1]));
+    doc.addAtom("field", new BytesRef(new byte[2]));
+    doc.addAtom("field", new BytesRef(new byte[10]));
+    w.addDocument(doc);
+
+    DirectoryReader r = DirectoryReader.open(w, true);
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    assertEquals(0, hitCount(s, fieldTypes.newBinaryTermQuery("field", new byte[1])));
+    assertEquals(1, hitCount(s, fieldTypes.newBinaryTermQuery("field", new byte[2])));
+    assertEquals(0, hitCount(s, fieldTypes.newBinaryTermQuery("field", new byte[10])));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testReversedStringAtom() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setReversedTerms("field");
+    Document doc = w.newDocument();
+    doc.addAtom("field", "Foobar");
+    w.addDocument(doc);
+
+    DirectoryReader r = DirectoryReader.open(w, true);
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    assertEquals(1, hitCount(s, fieldTypes.newStringTermQuery("field", "rabooF")));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testReversedBinaryAtom() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setReversedTerms("field");
+    Document doc = w.newDocument();
+    doc.addAtom("field", new BytesRef("Foobar"));
+    w.addDocument(doc);
+
+    DirectoryReader r = DirectoryReader.open(w, true);
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    assertEquals(1, hitCount(s, fieldTypes.newBinaryTermQuery("field", new BytesRef("rabooF"))));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testMultiValuedSort() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter w = newRandomIndexWriter(dir);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setMultiValued("field");
+
+    Document doc = w.newDocument();
+    doc.addUniqueInt("id", 0);
+    doc.addAtom("field", "zzz");
+    doc.addAtom("field", "a");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 1);
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 2);
+    doc.addAtom("field", "d");
+    doc.addAtom("field", "m");
+    w.addDocument(doc);
+
+    IndexReader r = w.getReader();
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 10, fieldTypes.newSort("field"));
+
+    // Default selector is MIN:
+    assertEquals(0, s.doc(hits.scoreDocs[0].doc).get("id"));
+    assertEquals(2, s.doc(hits.scoreDocs[1].doc).get("id"));
+    assertEquals(1, s.doc(hits.scoreDocs[2].doc).get("id"));
+
+    fieldTypes.setMultiValuedStringSortSelector("field", SortedSetSelector.Type.MAX);
+    hits = s.search(new MatchAllDocsQuery(), 10, fieldTypes.newSort("field"));
+    assertEquals(2, s.doc(hits.scoreDocs[0].doc).get("id"));
+    assertEquals(0, s.doc(hits.scoreDocs[1].doc).get("id"));
+    assertEquals(1, s.doc(hits.scoreDocs[2].doc).get("id"));
+
+    r.close();
+    w.close();
+    dir.close();
+  }
+}

Copied: lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBigIntegerFields.java (from r1644463, lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBigInteger.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBigIntegerFields.java?p2=lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBigIntegerFields.java&p1=lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBigInteger.java&r1=1644463&r2=1649007&rev=1649007&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBigInteger.java (original)
+++ lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBigIntegerFields.java Fri Jan  2 12:02:31 2015
@@ -20,45 +20,50 @@ package org.apache.lucene.document;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.search.FieldDoc;
+import org.apache.lucene.search.Filter;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortedSetSelector;
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.TestUtil;
 
-public class TestBigInteger extends LuceneTestCase {
-  // nocommit test multi-valued too
+public class TestBigIntegerFields extends LuceneTestCase {
   public void testRange1() throws Exception {
     Directory dir = newDirectory();
 
     IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
     FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setBigIntByteWidth("num", 30);
     //System.out.println("id type: " + fieldTypes.getFieldType("id"));
 
-    // nocommit need random test, across segments, with merging
     Document doc = w.newDocument();
-    doc.addBigInteger("big", new BigInteger("3000000000000000000"));
+    doc.addBigInteger("num", new BigInteger("3000000000000000000"));
     doc.addAtom("id", "one");
     w.addDocument(doc);
 
     doc = w.newDocument();
-    doc.addBigInteger("big", new BigInteger("2000000000000000000"));
+    doc.addBigInteger("num", new BigInteger("2000000000000000000"));
     doc.addAtom("id", "two");
     w.addDocument(doc);
 
     doc = w.newDocument();
-    doc.addBigInteger("big", new BigInteger("7000000000000000000"));
+    doc.addBigInteger("num", new BigInteger("7000000000000000000"));
     doc.addAtom("id", "three");
     w.addDocument(doc);
 
@@ -67,22 +72,22 @@ public class TestBigInteger extends Luce
 
     // Make sure range query hits the right number of hits
     assertEquals(2, s.search(new MatchAllDocsQuery(),
-                             fieldTypes.newBigIntRangeFilter("big",
+                             fieldTypes.newBigIntRangeFilter("num",
                                                              new BigInteger("0"), true,
                                                              new BigInteger("3000000000000000000"), true), 1).totalHits);
     assertEquals(3, s.search(new MatchAllDocsQuery(),
-                             fieldTypes.newBigIntRangeFilter("big",
+                             fieldTypes.newBigIntRangeFilter("num",
                                                              new BigInteger("0"), true,
                                                              new BigInteger("10000000000000000000"), true), 1).totalHits);
     TopDocs hits = s.search(new MatchAllDocsQuery(),
-                            fieldTypes.newBigIntRangeFilter("big",
+                            fieldTypes.newBigIntRangeFilter("num",
                                                             new BigInteger("1000000000000000000"), true,
                                                             new BigInteger("2500000000000000000"), true), 1);
     assertEquals(1, hits.totalHits);
-    assertEquals(new BigInteger("2000000000000000000"), s.doc(hits.scoreDocs[0].doc).getBigInteger("big"));
+    assertEquals(new BigInteger("2000000000000000000"), s.doc(hits.scoreDocs[0].doc).getBigInteger("num"));
 
     doc = w.newDocument();
-    doc.addBigInteger("big", new BigInteger("17"));
+    doc.addBigInteger("num", new BigInteger("17"));
     doc.addAtom("id", "four");
     w.addDocument(doc);
     w.forceMerge(1);
@@ -91,7 +96,7 @@ public class TestBigInteger extends Luce
     s = newSearcher(r);
 
     assertEquals(4, s.search(new MatchAllDocsQuery(),
-                             fieldTypes.newBigIntRangeFilter("big",
+                             fieldTypes.newBigIntRangeFilter("num",
                                                              new BigInteger("0"), true,
                                                              new BigInteger("10000000000000000000"), true), 1).totalHits);
     r.close();
@@ -99,84 +104,73 @@ public class TestBigInteger extends Luce
     dir.close();
   }
 
-  /*
-  public void testFoo() throws Exception {
-    for(int i=-257;i<=257;i++) {
-      byte[] bytes = BigInteger.valueOf(i).toByteArray();
-      if (bytes.length == 2) {
-        System.out.println(String.format(Locale.ROOT, "%d -> %x %x", i, bytes[0] & 0xff, bytes[1] & 0xff));
-      } else {
-        System.out.println(String.format(Locale.ROOT, "%d -> %x", i, bytes[0] & 0xff));
-      }
-    }
-  }
-  */
-
-  /*
   public void testBigIntRange2() throws Exception {
     Directory dir = newDirectory();
 
     IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
     FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setBigIntByteWidth("num", 3);
     //System.out.println("id type: " + fieldTypes.getFieldType("id"));
 
-    // nocommit need random test, across segments, with merging
     Document doc = w.newDocument();
-    doc.addBigInteger("big", new BigInteger("-100"));
+    doc.addBigInteger("num", new BigInteger("-100"));
     doc.addAtom("id", "one");
     w.addDocument(doc);
 
     doc = w.newDocument();
-    doc.addBigInteger("big", new BigInteger("200"));
+    doc.addBigInteger("num", new BigInteger("200"));
     doc.addAtom("id", "two");
     w.addDocument(doc);
 
     IndexReader r = DirectoryReader.open(w, true);
     IndexSearcher s = newSearcher(r);
 
-    // nocommit add & test TermQuery
-
     // Make sure range query hits the right number of hits
     assertEquals(1, s.search(new MatchAllDocsQuery(),
-                             fieldTypes.newRangeFilter("big",
-                                                       new BigInteger("-200"), true,
-                                                       new BigInteger("17"), true), 1).totalHits);
+                             fieldTypes.newBigIntRangeFilter("num",
+                                                             new BigInteger("-200"), true,
+                                                             new BigInteger("17"), true), 1).totalHits);
     r.close();
     w.close();
     dir.close();
   }
-  */
-
-  // nocommit sorting
 
   private BigInteger randomBigInt() {
     BigInteger big = new BigInteger(TestUtil.nextInt(random(), 4, 100), random()); 
-    // nocommit only positive for now
-    if (false && random().nextBoolean()) {
+    if (random().nextBoolean()) {
       big = big.negate();
     }
     return big;
   }
 
-  public void testRandom() throws Exception {
+  public void testRandomRangeAndSort() throws Exception {
     Directory dir = newDirectory();
     int numDocs = atLeast(100);
     RandomIndexWriter w = newRandomIndexWriter(dir);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setBigIntByteWidth("num", TestUtil.nextInt(random(), 20, 100));
     List<BigInteger> values = new ArrayList<>();
+    Map<BigInteger,Integer> valueCounts = new HashMap<>();
     for(int i=0;i<numDocs;i++) {
       Document doc = w.newDocument();
       doc.addUniqueInt("id", i);
       BigInteger big = randomBigInt();
       values.add(big);
-      doc.addBigInteger("big", big);
+      Integer cur = valueCounts.get(big);
+      if (cur == null) {
+        cur = 0;
+      }
+      cur++;
+      valueCounts.put(big, cur);
+      doc.addBigInteger("num", big);
       w.addDocument(doc);
       if (VERBOSE) {
-        System.out.println("id=" + i + " big=" + big);
+        System.out.println("TEST: id=" + i + " big=" + big);
       }
     }
 
     IndexReader r = w.getReader();
-    FieldTypes fieldTypes = r.getFieldTypes();
+    fieldTypes = r.getFieldTypes();
 
     IndexSearcher s = newSearcher(r);
     int iters = atLeast(1000);
@@ -200,22 +194,224 @@ public class TestBigInteger extends Luce
         }
       }
       if (VERBOSE) {
-        System.out.println("iter " + iter + " count=" + expected.size() + " min=" + min + " max=" + max);
+        System.out.println("TEST: iter " + iter + " count=" + expected.size() + " min=" + min + " max=" + max);
         for(int value : expected) {
           System.out.println("  " + value);
         }
       }
       
       Set<Integer> actual = new HashSet<>();
-      TopDocs hits = s.search(new MatchAllDocsQuery(), fieldTypes.newBigIntRangeFilter("big", min, true, max, true), numDocs);
+      Filter filter = fieldTypes.newBigIntRangeFilter("num", min, true, max, true);
+
+      boolean reversed = random().nextBoolean();
+      Sort sort = fieldTypes.newSort("num", reversed);
+      if (VERBOSE) {
+        System.out.println("TEST: filter=" + filter + " reversed=" + reversed + " sort=" + sort);
+      }
+      TopDocs hits = s.search(new MatchAllDocsQuery(), filter, numDocs, sort);
+      BigInteger last = null;
+      boolean wrongValues = false;
       for(ScoreDoc hit : hits.scoreDocs) {
-        actual.add(s.doc(hit.doc).getInt("id"));
+        Document doc = s.doc(hit.doc);
+        actual.add(doc.getInt("id"));
+        BigInteger v = doc.getBigInteger("num");
+        wrongValues |= v.equals(((FieldDoc) hit).fields[0]) == false;
+        if (last != null) {
+          int cmp = last.compareTo(v);
+          assertTrue((reversed && cmp >= 0) || (reversed == false && cmp <= 0));
+        }
+        last = v;
       }
       assertEquals(expected, actual);
+      assertFalse(wrongValues);
+    }
+
+    for (BigInteger value : values) {
+      assertEquals(valueCounts.get(value).intValue(), s.search(fieldTypes.newBigIntTermQuery("num", value), 1).totalHits);
     }
 
     r.close();
     w.close();
     dir.close();
   }
+
+  public void testSortMissingFirst() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter w = newRandomIndexWriter(dir);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setBigIntByteWidth("num", 20);
+    fieldTypes.setSortMissingFirst("num");
+    Document doc = w.newDocument();
+    doc.addUniqueInt("id", 0);
+    doc.addBigInteger("num", BigInteger.valueOf(45));
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 1);
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 2);
+    doc.addBigInteger("num", BigInteger.valueOf(-2));
+    w.addDocument(doc);
+
+    IndexReader r = w.getReader();
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 10, fieldTypes.newSort("num"));
+    assertEquals(1, s.doc(hits.scoreDocs[0].doc).get("id"));
+    assertEquals(2, s.doc(hits.scoreDocs[1].doc).get("id"));
+    assertEquals(0, s.doc(hits.scoreDocs[2].doc).get("id"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testSortMissingLast() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter w = newRandomIndexWriter(dir);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setBigIntByteWidth("num", 20);
+    fieldTypes.setSortMissingLast("num");
+    Document doc = w.newDocument();
+    doc.addUniqueInt("id", 0);
+    doc.addBigInteger("num", BigInteger.valueOf(45));
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 1);
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 2);
+    doc.addBigInteger("num", BigInteger.valueOf(-2));
+    w.addDocument(doc);
+
+    IndexReader r = w.getReader();
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 10, fieldTypes.newSort("num"));
+    assertEquals(2, s.doc(hits.scoreDocs[0].doc).get("id"));
+    assertEquals(0, s.doc(hits.scoreDocs[1].doc).get("id"));
+    assertEquals(1, s.doc(hits.scoreDocs[2].doc).get("id"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testMultiValuedSort() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter w = newRandomIndexWriter(dir);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setMultiValued("num");
+    fieldTypes.setBigIntByteWidth("num", 20);
+
+    Document doc = w.newDocument();
+    doc.addUniqueInt("id", 0);
+    doc.addBigInteger("num", BigInteger.valueOf(45));
+    doc.addBigInteger("num", BigInteger.valueOf(-22));
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 1);
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 2);
+    doc.addBigInteger("num", BigInteger.valueOf(-2));
+    doc.addBigInteger("num", BigInteger.valueOf(14));
+    w.addDocument(doc);
+
+    IndexReader r = w.getReader();
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 10, fieldTypes.newSort("num"));
+
+    // Default selector is MIN:
+    assertEquals(0, s.doc(hits.scoreDocs[0].doc).get("id"));
+    assertEquals(2, s.doc(hits.scoreDocs[1].doc).get("id"));
+    assertEquals(1, s.doc(hits.scoreDocs[2].doc).get("id"));
+
+    fieldTypes.setMultiValuedStringSortSelector("num", SortedSetSelector.Type.MAX);
+    hits = s.search(new MatchAllDocsQuery(), 10, fieldTypes.newSort("num"));
+    assertEquals(2, s.doc(hits.scoreDocs[0].doc).get("id"));
+    assertEquals(0, s.doc(hits.scoreDocs[1].doc).get("id"));
+    assertEquals(1, s.doc(hits.scoreDocs[2].doc).get("id"));
+
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testMultiValuedRange() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter w = newRandomIndexWriter(dir);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setMultiValued("num");
+    fieldTypes.setBigIntByteWidth("num", 20);
+
+    Document doc = w.newDocument();
+    doc.addUniqueInt("id", 0);
+    doc.addBigInteger("num", BigInteger.valueOf(45));
+    doc.addBigInteger("num", BigInteger.valueOf(-22));
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 1);
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 2);
+    doc.addBigInteger("num", BigInteger.valueOf(-2));
+    doc.addBigInteger("num", BigInteger.valueOf(14));
+    w.addDocument(doc);
+
+    IndexReader r = w.getReader();
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    assertEquals(2, s.search(new MatchAllDocsQuery(), fieldTypes.newBigIntRangeFilter("num", BigInteger.valueOf(-100), true, BigInteger.valueOf(100), true), 1).totalHits);
+    assertEquals(1, s.search(new MatchAllDocsQuery(), fieldTypes.newBigIntRangeFilter("num", BigInteger.valueOf(40), true, BigInteger.valueOf(45), true), 1).totalHits);
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testJustStored() throws Exception {
+    IndexWriter w = newIndexWriter(dir);
+    Document doc = w.newDocument();
+    doc.addStoredBigInteger("num", BigInteger.valueOf(100));
+    w.addDocument(doc);
+    DirectoryReader r = DirectoryReader.open(w, true);
+    IndexSearcher s = newSearcher(r);
+    doc = s.doc(0);
+    assertEquals(BigInteger.valueOf(100), doc.getBigInteger("num"));
+    r.close();
+    w.close();
+  }
+
+  public void testExcIndexedThenStored() throws Exception {
+    IndexWriter w = newIndexWriter(dir);
+    Document doc = w.newDocument();
+    doc.addDouble("num", 100.);
+    w.addDocument(doc);
+    final Document doc2 = w.newDocument();
+    shouldFail(() -> doc2.addStoredDouble("num", 200.),
+               "field \"num\": cannot addStored: field was already added non-stored");
+    w.close();
+  }
+
+  public void testExcStoredThenIndexed() throws Exception {
+    IndexWriter w = newIndexWriter(dir);
+    Document doc = w.newDocument();
+    doc.addStoredBigInteger("num", BigInteger.valueOf(100));
+    w.addDocument(doc);
+    final Document doc2 = w.newDocument();
+    shouldFail(() -> doc2.addBigInteger("num", BigInteger.valueOf(200)),
+               "field \"num\": this field is only stored; use addStoredXXX instead");
+    w.close();
+  }
 }

Modified: lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java?rev=1649007&r1=1649006&r2=1649007&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java (original)
+++ lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java Fri Jan  2 12:02:31 2015
@@ -41,8 +41,8 @@ public class TestBinaryDocument extends
 
     Document doc = writer.newDocument();
     
-    doc.addStored("binaryStored", binaryValStored.getBytes(StandardCharsets.UTF_8));
-    doc.addStored("stringStored", binaryValStored);
+    doc.addStoredBinary("binaryStored", binaryValStored.getBytes(StandardCharsets.UTF_8));
+    doc.addStoredString("stringStored", binaryValStored);
 
     /** test for field count */
     assertEquals(2, doc.getFields().size());
@@ -76,8 +76,8 @@ public class TestBinaryDocument extends
 
     Document doc = writer.newDocument();
     
-    doc.addStored("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes(StandardCharsets.UTF_8)));
-    doc.addStored("stringCompressed", CompressionTools.compressString(binaryValCompressed));
+    doc.addStoredBinary("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes(StandardCharsets.UTF_8)));
+    doc.addStoredBinary("stringCompressed", CompressionTools.compressString(binaryValCompressed));
     
     /** add the doc to a ram index */
     writer.addDocument(doc);

Added: lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestDateFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestDateFields.java?rev=1649007&view=auto
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestDateFields.java (added)
+++ lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestDateFields.java Fri Jan  2 12:02:31 2015
@@ -0,0 +1,213 @@
+package org.apache.lucene.document;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.lucene.index.DirectoryReader;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.SortedNumericSelector;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestDateFields extends LuceneTestCase {
+  static SimpleDateFormat parser = new SimpleDateFormat("MM/dd/yyyy", Locale.ROOT);
+  static {
+    parser.setTimeZone(TimeZone.getTimeZone("GMT"));
+  }
+
+  public void testDateSort() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+
+    Document doc = w.newDocument();
+    Date date0 = parser.parse("10/22/2014");
+    doc.addDate("date", date0);
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    Date date1 = parser.parse("10/21/2015");
+    doc.addDate("date", date1);
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    w.getFieldTypes().enableSorting("date", true);
+
+    DirectoryReader r = DirectoryReader.open(w, true);
+    FieldTypes fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 10, fieldTypes.newSort("date"));
+    assertEquals(2, hits.totalHits);
+    Document hit = s.doc(hits.scoreDocs[0].doc);
+    assertEquals("1", hit.getString("id"));
+    assertEquals(date1, hit.getDate("date"));
+    hit = s.doc(hits.scoreDocs[1].doc);
+    assertEquals("0", hit.getString("id"));
+    assertEquals(date0, hit.getDate("date"));
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testDateRangeFilter() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+
+    Document doc = w.newDocument();
+    Date date0 = parser.parse("10/22/2014");
+    doc.addDate("date", date0);
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    Date date1 = parser.parse("10/21/2015");
+    doc.addDate("date", date1);
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    DirectoryReader r = DirectoryReader.open(w, true);
+    FieldTypes fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    assertEquals(2, s.search(new MatchAllDocsQuery(), fieldTypes.newRangeFilter("date", date0, true, date1, true), 1).totalHits);
+    assertEquals(1, s.search(new MatchAllDocsQuery(), fieldTypes.newRangeFilter("date", date0, true, date1, false), 1).totalHits);
+    assertEquals(0, s.search(new MatchAllDocsQuery(), fieldTypes.newRangeFilter("date", date0, false, date1, false), 1).totalHits);
+    assertEquals(1, s.search(new MatchAllDocsQuery(), fieldTypes.newRangeFilter("date", parser.parse("10/21/2014"), false, parser.parse("10/23/2014"), false), 1).totalHits);
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testDateDocValuesRangeFilter() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+
+    Document doc = w.newDocument();
+    Date date0 = parser.parse("10/22/2014");
+    doc.addDate("date", date0);
+    doc.addAtom("id", "0");
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    Date date1 = parser.parse("10/21/2015");
+    doc.addDate("date", date1);
+    doc.addAtom("id", "1");
+    w.addDocument(doc);
+
+    DirectoryReader r = DirectoryReader.open(w, true);
+    FieldTypes fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    assertEquals(2, s.search(new MatchAllDocsQuery(), fieldTypes.newDocValuesRangeFilter("date", date0, true, date1, true), 1).totalHits);
+    assertEquals(1, s.search(new MatchAllDocsQuery(), fieldTypes.newDocValuesRangeFilter("date", date0, true, date1, false), 1).totalHits);
+    assertEquals(0, s.search(new MatchAllDocsQuery(), fieldTypes.newDocValuesRangeFilter("date", date0, false, date1, false), 1).totalHits);
+    assertEquals(1, s.search(new MatchAllDocsQuery(), fieldTypes.newDocValuesRangeFilter("date", parser.parse("10/21/2014"), false, parser.parse("10/23/2014"), false), 1).totalHits);
+    r.close();
+    w.close();
+    dir.close();
+  }
+
+  public void testMultiValuedSort() throws Exception {
+    RandomIndexWriter w = newRandomIndexWriter(dir);
+    FieldTypes fieldTypes = w.getFieldTypes();
+    fieldTypes.setMultiValued("num");
+
+    Document doc = w.newDocument();
+    doc.addUniqueInt("id", 0);
+    doc.addDate("num", parser.parse("10/25/2014"));
+    doc.addDate("num", parser.parse("10/2/2014"));
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 1);
+    w.addDocument(doc);
+
+    doc = w.newDocument();
+    doc.addUniqueInt("id", 2);
+    doc.addDate("num", parser.parse("10/10/2014"));
+    doc.addDate("num", parser.parse("10/20/2014"));
+    w.addDocument(doc);
+
+    IndexReader r = w.getReader();
+    fieldTypes = r.getFieldTypes();
+
+    IndexSearcher s = newSearcher(r);
+    TopDocs hits = s.search(new MatchAllDocsQuery(), 10, fieldTypes.newSort("num"));
+
+    // Default selector is MIN:
+    assertEquals(0, s.doc(hits.scoreDocs[0].doc).get("id"));
+    assertEquals(2, s.doc(hits.scoreDocs[1].doc).get("id"));
+    assertEquals(1, s.doc(hits.scoreDocs[2].doc).get("id"));
+
+    fieldTypes.setMultiValuedNumericSortSelector("num", SortedNumericSelector.Type.MAX);
+    hits = s.search(new MatchAllDocsQuery(), 10, fieldTypes.newSort("num"));
+    assertEquals(2, s.doc(hits.scoreDocs[0].doc).get("id"));
+    assertEquals(0, s.doc(hits.scoreDocs[1].doc).get("id"));
+    assertEquals(1, s.doc(hits.scoreDocs[2].doc).get("id"));
+
+    r.close();
+    w.close();
+  }
+
+  public void testJustStored() throws Exception {
+    Date date = parser.parse("10/22/2014");
+
+    IndexWriter w = newIndexWriter(dir);
+    Document doc = w.newDocument();
+    doc.addStoredDate("num", date);
+    w.addDocument(doc);
+    DirectoryReader r = DirectoryReader.open(w, true);
+    IndexSearcher s = newSearcher(r);
+    doc = s.doc(0);
+    assertEquals(date, doc.getDate("num"));
+    r.close();
+    w.close();
+  }
+
+  public void testExcIndexedThenStored() throws Exception {
+    IndexWriter w = newIndexWriter(dir);
+    Document doc = w.newDocument();
+    doc.addDate("num", parser.parse("10/22/2014"));
+    w.addDocument(doc);
+    final Document doc2 = w.newDocument();
+    shouldFail(() -> doc2.addStoredDate("num", parser.parse("10/27/2014")),
+               "field \"num\": cannot addStored: field was already added non-stored");
+    w.close();
+  }
+
+  public void testExcStoredThenIndexed() throws Exception {
+    IndexWriter w = newIndexWriter(dir);
+    Document doc = w.newDocument();
+    doc.addStoredDate("num", parser.parse("10/22/2014"));
+    w.addDocument(doc);
+    final Document doc2 = w.newDocument();
+    shouldFail(() -> doc2.addDate("num", parser.parse("10/27/2014")),
+               "field \"num\": this field is only stored; use addStoredXXX instead");
+    w.close();
+  }
+}

Modified: lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestDateTools.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestDateTools.java?rev=1649007&r1=1649006&r2=1649007&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestDateTools.java (original)
+++ lucene/dev/branches/lucene6005/lucene/core/src/test/org/apache/lucene/document/TestDateTools.java Fri Jan  2 12:02:31 2015
@@ -27,6 +27,7 @@ import com.carrotsearch.randomizedtestin
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 public class TestDateTools extends LuceneTestCase {
   @Rule
   public TestRule testRules =