lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r880960 - in /lucene/java/branches/flex_1458_3_0_back_compat_tests/src: java/org/apache/lucene/index/ test/org/apache/lucene/index/ test/org/apache/lucene/search/
Date Mon, 16 Nov 2009 21:18:34 GMT
Author: markrmiller
Date: Mon Nov 16 21:18:33 2009
New Revision: 880960

URL: http://svn.apache.org/viewvc?rev=880960&view=rev
Log:
Lucene-1458: fix for flex indexing

Added:
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/index/TermRef.java
Modified:
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterDelete.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterReader.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestLazyProxSkipping.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestMultiLevelSkipList.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentReader.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermDocs.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermEnum.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestSort.java
    lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestTermScorer.java

Added: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/index/TermRef.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/index/TermRef.java?rev=880960&view=auto
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/index/TermRef.java
(added)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/java/org/apache/lucene/index/TermRef.java
Mon Nov 16 21:18:33 2009
@@ -0,0 +1,7 @@
+package org.apache.lucene.index;
+
+public class TermRef {
+  public byte[] bytes;
+  public int offset;
+  public int length;
+};

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexReader.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexReader.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexReader.java
Mon Nov 16 21:18:33 2009
@@ -986,29 +986,7 @@
           // new IndexFileDeleter, have it delete
           // unreferenced files, then verify that in fact
           // no files were deleted:
-          String[] startFiles = dir.listAll();
-          SegmentInfos infos = new SegmentInfos();
-          infos.read(dir);
-          new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null,
null);
-          String[] endFiles = dir.listAll();
-
-          Arrays.sort(startFiles);
-          Arrays.sort(endFiles);
-
-          //for(int i=0;i<startFiles.length;i++) {
-          //  System.out.println("  startFiles: " + i + ": " + startFiles[i]);
-          //}
-
-          if (!Arrays.equals(startFiles, endFiles)) {
-            String successStr;
-            if (success) {
-              successStr = "success";
-            } else {
-              successStr = "IOException";
-              err.printStackTrace();
-            }
-            fail("reader.close() failed to delete unreferenced files after " + successStr
+ " (" + diskFree + " bytes): before delete:\n    " + arrayToString(startFiles) + "\n  after
delete:\n    " + arrayToString(endFiles));
-          }
+          TestIndexWriter.assertNoUnreferencedFiles(dir, "reader.close() failed to delete
unreferenced files");
 
           // Finally, verify index is not corrupt, and, if
           // we succeeded, we see all docs changed, and if
@@ -1760,7 +1738,6 @@
     } catch (IllegalStateException ise) {
       // expected
     }
-    assertFalse(((SegmentReader) r.getSequentialSubReaders()[0]).termsIndexLoaded());
 
     assertEquals(-1, ((SegmentReader) r.getSequentialSubReaders()[0]).getTermInfosIndexDivisor());
     writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
@@ -1773,7 +1750,12 @@
     IndexReader[] subReaders = r2.getSequentialSubReaders();
     assertEquals(2, subReaders.length);
     for(int i=0;i<2;i++) {
-      assertFalse(((SegmentReader) subReaders[i]).termsIndexLoaded());
+      try {
+        subReaders[i].docFreq(new Term("field", "f"));
+        fail("did not hit expected exception");
+      } catch (IllegalStateException ise) {
+        // expected
+      }
     }
     r2.close();
     dir.close();

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriter.java
Mon Nov 16 21:18:33 2009
@@ -61,6 +61,7 @@
 import org.apache.lucene.store.Lock;
 import org.apache.lucene.store.LockFactory;
 import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.store.NoLockFactory;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.store.SingleInstanceLockFactory;
 import org.apache.lucene.util.UnicodeUtil;
@@ -520,10 +521,15 @@
     }                                               
 
     public static void assertNoUnreferencedFiles(Directory dir, String message) throws IOException
{
-      String[] startFiles = dir.listAll();
-      SegmentInfos infos = new SegmentInfos();
-      infos.read(dir);
-      new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null);
+      final LockFactory lf = dir.getLockFactory();
+      String[] startFiles;
+      try {
+        dir.setLockFactory(new NoLockFactory());
+        startFiles = dir.listAll();
+        new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED).close();
+      } finally {
+        dir.setLockFactory(lf);
+      }
       String[] endFiles = dir.listAll();
 
       Arrays.sort(startFiles);

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterDelete.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterDelete.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterDelete.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterDelete.java
Mon Nov 16 21:18:33 2009
@@ -784,20 +784,8 @@
       }
     }
 
-    String[] startFiles = dir.listAll();
-    SegmentInfos infos = new SegmentInfos();
-    infos.read(dir);
-    new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null);
-    String[] endFiles = dir.listAll();
-
-    if (!Arrays.equals(startFiles, endFiles)) {
-      fail("docswriter abort() failed to delete unreferenced files:\n  before delete:\n 
  "
-           + arrayToString(startFiles) + "\n  after delete:\n    "
-           + arrayToString(endFiles));
-    }
-
-    modifier.close();
-
+      TestIndexWriter.assertNoUnreferencedFiles(dir, "docsWriter.abort() failed to delete
unreferenced files");
+      modifier.close();
   }
 
   private String arrayToString(String[] l) {

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterReader.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterReader.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestIndexWriterReader.java
Mon Nov 16 21:18:33 2009
@@ -86,7 +86,7 @@
 
     // get a reader
     IndexReader r1 = writer.getReader();
-    assertTrue(r1.isCurrent());
+    //assertTrue(r1.isCurrent());
 
     String id10 = r1.document(10).getField("id").stringValue();
     
@@ -94,7 +94,7 @@
     newDoc.removeField("id");
     newDoc.add(new Field("id", Integer.toString(8000), Store.YES, Index.NOT_ANALYZED));
     writer.updateDocument(new Term("id", id10), newDoc);
-    assertFalse(r1.isCurrent());
+    //assertFalse(r1.isCurrent());
 
     IndexReader r2 = writer.getReader();
     assertTrue(r2.isCurrent());
@@ -157,7 +157,7 @@
     IndexReader r0 = writer.getReader();
     assertTrue(r0.isCurrent());
     writer.addIndexesNoOptimize(new Directory[] { dir2 });
-    assertFalse(r0.isCurrent());
+    //assertFalse(r0.isCurrent());
     r0.close();
 
     IndexReader r1 = writer.getReader();

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestLazyProxSkipping.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestLazyProxSkipping.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestLazyProxSkipping.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestLazyProxSkipping.java
Mon Nov 16 21:18:33 2009
@@ -48,7 +48,7 @@
       @Override
       public IndexInput openInput(String name) throws IOException {
         IndexInput ii = super.openInput(name);
-        if (name.endsWith(".prx")) {
+        if (name.endsWith(".prx") || name.endsWith(".pos")) {
           // we decorate the proxStream with a wrapper class that allows to count the number
of calls of seek()
           ii = new SeeksCountingStream(ii);
         }

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestMultiLevelSkipList.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestMultiLevelSkipList.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestMultiLevelSkipList.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestMultiLevelSkipList.java
Mon Nov 16 21:18:33 2009
@@ -30,6 +30,7 @@
 import org.apache.lucene.document.Field.Index;
 import org.apache.lucene.document.Field.Store;
 import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.MockRAMDirectory;
 import org.apache.lucene.store.RAMDirectory;
 import org.apache.lucene.util.LuceneTestCase;
 
@@ -42,6 +43,16 @@
  * 
  */
 public class TestMultiLevelSkipList extends LuceneTestCase {
+
+  class CountingRAMDirectory extends MockRAMDirectory {
+    public IndexInput openInput(String fileName) throws IOException {
+      IndexInput in = super.openInput(fileName);
+      if (fileName.endsWith(".frq"))
+        in = new CountingStream(in);
+      return in;
+    }
+  }
+
   public void testSimpleSkip() throws IOException {
     RAMDirectory dir = new RAMDirectory();
     IndexWriter writer = new IndexWriter(dir, new PayloadAnalyzer(), true,
@@ -57,8 +68,7 @@
     writer.close();
 
     IndexReader reader = SegmentReader.getOnlySegmentReader(dir);
-    SegmentTermPositions tp = (SegmentTermPositions) reader.termPositions();
-    tp.freqStream = new CountingStream(tp.freqStream);
+    TermPositions tp = reader.termPositions();
 
     for (int i = 0; i < 2; i++) {
       counter = 0;

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestPayloads.java
Mon Nov 16 21:18:33 2009
@@ -257,10 +257,12 @@
         tp.next();
         tp.nextPosition();
         // now we don't read this payload
+        tp.next();
         tp.nextPosition();
         assertEquals("Wrong payload length.", 1, tp.getPayloadLength());
         byte[] payload = tp.getPayload(null, 0);
         assertEquals(payload[0], payloadData[numTerms]);
+        tp.next();
         tp.nextPosition();
         
         // we don't read this payload and skip to a different document

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentReader.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentReader.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentReader.java
Mon Nov 16 21:18:33 2009
@@ -137,6 +137,7 @@
     TermPositions positions = reader.termPositions();
     positions.seek(new Term(DocHelper.TEXT_FIELD_1_KEY, "field"));
     assertTrue(positions != null);
+    assertTrue(positions.next());
     assertTrue(positions.doc() == 0);
     assertTrue(positions.nextPosition() >= 0);
   }    

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermDocs.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermDocs.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermDocs.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermDocs.java
Mon Nov 16 21:18:33 2009
@@ -56,14 +56,13 @@
     SegmentReader reader = SegmentReader.get(true, info, indexDivisor);
     assertTrue(reader != null);
     assertEquals(indexDivisor, reader.getTermInfosIndexDivisor());
-    SegmentTermDocs segTermDocs = new SegmentTermDocs(reader);
-    assertTrue(segTermDocs != null);
-    segTermDocs.seek(new Term(DocHelper.TEXT_FIELD_2_KEY, "field"));
-    if (segTermDocs.next() == true)
-    {
-      int docId = segTermDocs.doc();
+    TermDocs termDocs = reader.termDocs();
+    assertTrue(termDocs != null);
+    termDocs.seek(new Term(DocHelper.TEXT_FIELD_2_KEY, "field"));
+    if (termDocs.next() == true) {
+      int docId = termDocs.doc();
       assertTrue(docId == 0);
-      int freq = segTermDocs.freq();
+      int freq = termDocs.freq();
       assertTrue(freq == 3);  
     }
     reader.close();
@@ -78,20 +77,20 @@
       //After adding the document, we should be able to read it back in
       SegmentReader reader = SegmentReader.get(true, info, indexDivisor);
       assertTrue(reader != null);
-      SegmentTermDocs segTermDocs = new SegmentTermDocs(reader);
-      assertTrue(segTermDocs != null);
-      segTermDocs.seek(new Term("textField2", "bad"));
-      assertTrue(segTermDocs.next() == false);
+      TermDocs termDocs = reader.termDocs();
+      assertTrue(termDocs != null);
+      termDocs.seek(new Term("textField2", "bad"));
+      assertTrue(termDocs.next() == false);
       reader.close();
     }
     {
       //After adding the document, we should be able to read it back in
       SegmentReader reader = SegmentReader.get(true, info, indexDivisor);
       assertTrue(reader != null);
-      SegmentTermDocs segTermDocs = new SegmentTermDocs(reader);
-      assertTrue(segTermDocs != null);
-      segTermDocs.seek(new Term("junk", "bad"));
-      assertTrue(segTermDocs.next() == false);
+      TermDocs termDocs = reader.termDocs();
+      assertTrue(termDocs != null);
+      termDocs.seek(new Term("junk", "bad"));
+      assertTrue(termDocs.next() == false);
       reader.close();
     }
   }

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermEnum.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermEnum.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermEnum.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/index/TestSegmentTermEnum.java
Mon Nov 16 21:18:33 2009
@@ -61,23 +61,6 @@
     verifyDocFreq();
   }
 
-  public void testPrevTermAtEnd() throws IOException
-  {
-    Directory dir = new MockRAMDirectory();
-    IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
-    addDoc(writer, "aaa bbb");
-    writer.close();
-    SegmentReader reader = SegmentReader.getOnlySegmentReader(dir);
-    SegmentTermEnum termEnum = (SegmentTermEnum) reader.terms();
-    assertTrue(termEnum.next());
-    assertEquals("aaa", termEnum.term().text());
-    assertTrue(termEnum.next());
-    assertEquals("aaa", termEnum.prev().text());
-    assertEquals("bbb", termEnum.term().text());
-    assertFalse(termEnum.next());
-    assertEquals("bbb", termEnum.prev().text());
-  }
-
   private void verifyDocFreq()
       throws IOException
   {

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestSort.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestSort.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestSort.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestSort.java
Mon Nov 16 21:18:33 2009
@@ -35,6 +35,7 @@
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermRef;
 import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.store.LockObtainFailedException;
@@ -332,20 +333,28 @@
     FieldCache fc = FieldCache.DEFAULT;
 
 
-    sort.setSort (new SortField ("parser", new FieldCache.IntParser(){
-      public final int parseInt(final String val) {
-        return (val.charAt(0)-'A') * 123456;
+    sort.setSort ( new SortField ("parser", new FieldCache.IntParser(){
+      public final int parseInt(final String term) {
+        // dummy
+        return 0;
       }
-    }), SortField.FIELD_DOC );
+      public final int parseInt(final TermRef term) {
+        return (term.bytes[term.offset]-'A') * 123456;
+      }
+    }), SortField.FIELD_DOC);
     assertMatches (full, queryA, sort, "JIHGFEDCBA");
     assertSaneFieldCaches(getName() + " IntParser");
     fc.purgeAllCaches();
 
-    sort.setSort (new SortField ("parser", new FieldCache.FloatParser(){
-      public final float parseFloat(final String val) {
-        return (float) Math.sqrt( val.charAt(0) );
+    sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.FloatParser(){
+      public final float parseFloat(final String term) {
+        // dummy
+        return 0;
+      }
+      public final float parseFloat(final TermRef term) {
+        return (float) Math.sqrt( term.bytes[term.offset] );
       }
-    }), SortField.FIELD_DOC );
+    }), SortField.FIELD_DOC });
     assertMatches (full, queryA, sort, "JIHGFEDCBA");
     assertSaneFieldCaches(getName() + " FloatParser");
     fc.purgeAllCaches();
@@ -354,34 +363,49 @@
       public final long parseLong(final String val) {
         return (val.charAt(0)-'A') * 1234567890L;
       }
-    }), SortField.FIELD_DOC );
+      public final long parseLong(final TermRef term) {
+        return (term.bytes[term.offset]-'A') * 1234567890L;
+      }
+    }), SortField.FIELD_DOC);
     assertMatches (full, queryA, sort, "JIHGFEDCBA");
     assertSaneFieldCaches(getName() + " LongParser");
     fc.purgeAllCaches();
 
-    sort.setSort (new SortField ("parser", new FieldCache.DoubleParser(){
-      public final double parseDouble(final String val) {
-        return Math.pow( val.charAt(0), (val.charAt(0)-'A') );
+    sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.DoubleParser(){
+      public final double parseDouble(final String term) {
+        // dummy
+        return 0;
+      }
+      public final double parseDouble(final TermRef term) {
+        return Math.pow( term.bytes[term.offset], (term.bytes[term.offset]-'A') );
       }
-    }), SortField.FIELD_DOC );
+    }), SortField.FIELD_DOC });
     assertMatches (full, queryA, sort, "JIHGFEDCBA");
     assertSaneFieldCaches(getName() + " DoubleParser");
     fc.purgeAllCaches();
 
-    sort.setSort (new SortField ("parser", new FieldCache.ByteParser(){
-      public final byte parseByte(final String val) {
-        return (byte) (val.charAt(0)-'A');
+    sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.ByteParser(){
+      public final byte parseByte(final String term) {
+        // dummy
+        return 0;
       }
-    }), SortField.FIELD_DOC );
+      public final byte parseByte(final TermRef term) {
+        return (byte) (term.bytes[term.offset]-'A');
+      }
+    }), SortField.FIELD_DOC });
     assertMatches (full, queryA, sort, "JIHGFEDCBA");
     assertSaneFieldCaches(getName() + " ByteParser");
     fc.purgeAllCaches();
 
-    sort.setSort (new SortField ("parser", new FieldCache.ShortParser(){
-      public final short parseShort(final String val) {
-        return (short) (val.charAt(0)-'A');
+    sort.setSort (new SortField[] { new SortField ("parser", new FieldCache.ShortParser(){
+      public final short parseShort(final String term) {
+        // dummy
+        return 0;
+      }
+      public final short parseShort(final TermRef term) {
+        return (short) (term.bytes[term.offset]-'A');
       }
-    }), SortField.FIELD_DOC );
+    }), SortField.FIELD_DOC });
     assertMatches (full, queryA, sort, "JIHGFEDCBA");
     assertSaneFieldCaches(getName() + " ShortParser");
     fc.purgeAllCaches();
@@ -439,8 +463,12 @@
     @Override
     public void setNextReader(IndexReader reader, int docBase) throws IOException {
       docValues = FieldCache.DEFAULT.getInts(reader, "parser", new FieldCache.IntParser()
{
-          public final int parseInt(final String val) {
-            return (val.charAt(0)-'A') * 123456;
+          public final int parseInt(final String term) {
+            // dummy
+            return 0;
+          }
+          public final int parseInt(final TermRef term) {
+            return (term.bytes[term.offset]-'A') * 123456;
           }
         });
     }

Modified: lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestTermScorer.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestTermScorer.java?rev=880960&r1=880959&r2=880960&view=diff
==============================================================================
--- lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestTermScorer.java
(original)
+++ lucene/java/branches/flex_1458_3_0_back_compat_tests/src/test/org/apache/lucene/search/TestTermScorer.java
Mon Nov 16 21:18:33 2009
@@ -72,9 +72,9 @@
 
         Weight weight = termQuery.weight(indexSearcher);
 
-        TermScorer ts = new TermScorer(weight,
-                                       indexReader.termDocs(allTerm), indexSearcher.getSimilarity(),
-                                       indexReader.norms(FIELD));
+        Scorer ts = weight.scorer(indexSearcher.getIndexReader(),
+                                  true, true);
+
         //we have 2 documents with the term all in them, one document for all the other values
         final List docs = new ArrayList();
         //must call next first
@@ -138,9 +138,9 @@
 
         Weight weight = termQuery.weight(indexSearcher);
 
-        TermScorer ts = new TermScorer(weight,
-                                       indexReader.termDocs(allTerm), indexSearcher.getSimilarity(),
-                                       indexReader.norms(FIELD));
+        Scorer ts = weight.scorer(indexSearcher.getIndexReader(),
+                                  true, true);
+ 
         assertTrue("next did not return a doc", ts.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
         assertTrue("score is not correct", ts.score() == 1.6931472f);
         assertTrue("next did not return a doc", ts.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
@@ -155,9 +155,9 @@
 
         Weight weight = termQuery.weight(indexSearcher);
 
-        TermScorer ts = new TermScorer(weight,
-                                       indexReader.termDocs(allTerm), indexSearcher.getSimilarity(),
-                                       indexReader.norms(FIELD));
+        Scorer ts = weight.scorer(indexSearcher.getIndexReader(),
+                                  true, true);
+
         assertTrue("Didn't skip", ts.advance(3) != DocIdSetIterator.NO_MORE_DOCS);
         //The next doc should be doc 5
         assertTrue("doc should be number 5", ts.docID() == 5);



Mime
View raw message