incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Fix to the termdocsiterable class, the test did not set the fieldtype correctly to be indexed.
Date Tue, 23 Oct 2012 21:12:56 GMT
Updated Branches:
  refs/heads/lucene-4.0.0 72395cfdb -> c7b7f6110


Fix to the termdocsiterable class, the test did not set the fieldtype correctly to be indexed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/c7b7f611
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/c7b7f611
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/c7b7f611

Branch: refs/heads/lucene-4.0.0
Commit: c7b7f6110210a801f54ce51472d0af9323ae8311
Parents: 72395cf
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Oct 23 17:12:05 2012 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Oct 23 17:12:05 2012 -0400

----------------------------------------------------------------------
 .../org/apache/blur/utils/TermDocIterable.java     |   11 ++-
 .../org/apache/blur/utils/TermDocIterableTest.java |   51 +++++----------
 2 files changed, 23 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c7b7f611/src/blur-core/src/main/java/org/apache/blur/utils/TermDocIterable.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/utils/TermDocIterable.java b/src/blur-core/src/main/java/org/apache/blur/utils/TermDocIterable.java
index 56d1f50..e47cba8 100644
--- a/src/blur-core/src/main/java/org/apache/blur/utils/TermDocIterable.java
+++ b/src/blur-core/src/main/java/org/apache/blur/utils/TermDocIterable.java
@@ -20,8 +20,8 @@ import java.io.IOException;
 import java.util.Iterator;
 
 import org.apache.lucene.document.Document;
+import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.MultiFields;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.util.Bits;
@@ -29,14 +29,17 @@ import org.apache.lucene.util.Bits;
 public class TermDocIterable implements Iterable<Document> {
 
   private DocsEnum docsEnum;
-  private IndexReader reader;
+  private AtomicReader reader;
   private ResetableDocumentStoredFieldVisitor fieldSelector;
 
-  public TermDocIterable(DocsEnum docsEnum, IndexReader reader) {
+  public TermDocIterable(DocsEnum docsEnum, AtomicReader reader) {
     this(docsEnum, reader, new ResetableDocumentStoredFieldVisitor());
   }
 
-  public TermDocIterable(DocsEnum docsEnum, IndexReader reader, ResetableDocumentStoredFieldVisitor
fieldSelector) {
+  public TermDocIterable(DocsEnum docsEnum, AtomicReader reader, ResetableDocumentStoredFieldVisitor
fieldSelector) {
+    if (docsEnum == null) {
+      throw new NullPointerException("docsEnum can not be null.");
+    }
     this.docsEnum = docsEnum;
     this.reader = reader;
     this.fieldSelector = fieldSelector;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c7b7f611/src/blur-core/src/test/java/org/apache/blur/utils/TermDocIterableTest.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/utils/TermDocIterableTest.java b/src/blur-core/src/test/java/org/apache/blur/utils/TermDocIterableTest.java
index 58e4ed8..3f5a412 100644
--- a/src/blur-core/src/test/java/org/apache/blur/utils/TermDocIterableTest.java
+++ b/src/blur-core/src/test/java/org/apache/blur/utils/TermDocIterableTest.java
@@ -20,7 +20,6 @@ package org.apache.blur.utils;
 import static org.apache.blur.lucene.LuceneVersionConstant.LUCENE_VERSION;
 import static org.junit.Assert.assertEquals;
 
-import java.io.File;
 import java.io.IOException;
 
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -30,21 +29,19 @@ import org.apache.lucene.document.FieldType;
 import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.SlowCompositeReaderWrapper;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.RAMDirectory;
 import org.junit.Before;
 import org.junit.Test;
 
-
 public class TermDocIterableTest {
 
   private static final int BLOCKS = 10;
   private static final int COUNT_PER_BLOCK = 100;
-  private IndexReader reader;
+  private AtomicReader reader;
 
   @Before
   public void setup() throws IOException {
@@ -53,12 +50,10 @@ public class TermDocIterableTest {
 
   @Test
   public void testTermDocIterable() throws IOException {
-    AtomicReader atomicReader = (AtomicReader)reader;
     for (int pass = 0; pass < 1; pass++) {
       for (int id = 0; id < BLOCKS; id++) {
-        
-        DocsEnum termDocs = atomicReader.termDocsEnum(new Term("id", Integer.toString(id)));
-        TermDocIterable iterable = new TermDocIterable(termDocs, atomicReader);
+        DocsEnum termDocs = reader.termDocsEnum(new Term("id", Integer.toString(id)));
+        TermDocIterable iterable = new TermDocIterable(termDocs, reader);
         int count = 0;
         int i = 0;
         long s = System.nanoTime();
@@ -74,41 +69,27 @@ public class TermDocIterableTest {
     }
   }
 
-  private IndexReader createIndexReader() throws IOException {
-    FSDirectory directory = FSDirectory.open(new File("./tmp/termdociterable"));
-    if (!DirectoryReader.indexExists(directory)) {
-      rm(new File("./tmp/termdociterable"));
-      IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION,
new StandardAnalyzer(LUCENE_VERSION)));
-      for (int i = 0; i < BLOCKS; i++) {
-        addDocumentBlock(i, COUNT_PER_BLOCK, writer);
-      }
-      writer.close();
+  private AtomicReader createIndexReader() throws IOException {
+    RAMDirectory directory = new RAMDirectory();
+    IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LUCENE_VERSION,
new StandardAnalyzer(LUCENE_VERSION)));
+    for (int i = 0; i < BLOCKS; i++) {
+      addDocumentBlock(i, COUNT_PER_BLOCK, writer);
     }
-    IndexReader indexReader = DirectoryReader.open(directory);
-    int numDocs = indexReader.numDocs();
-    System.out.println("numDocs " +numDocs);
+    writer.close();
     return SlowCompositeReaderWrapper.wrap(DirectoryReader.open(directory));
   }
 
-  private File rm(File file) {
-    if (file.isDirectory()) {
-      for (File f : file.listFiles()) {
-        rm(f);
-      }
-    }
-    file.delete();
-    return file;
-  }
-
   private void addDocumentBlock(int id, int count, IndexWriter writer) throws IOException
{
     FieldType fieldType = new FieldType();
-    fieldType.setStored(true);   
-    
+    fieldType.setIndexed(true);
+    fieldType.setOmitNorms(true);
+    fieldType.setTokenized(false);
+    fieldType.setStored(true);
+
     FieldType fieldTypeNoIndex = new FieldType();
     fieldTypeNoIndex.setStored(true);
     fieldTypeNoIndex.setIndexed(false);
-    
-    
+
     for (int i = 0; i < count; i++) {
       Document document = new Document();
       document.add(new Field("id", Integer.toString(id), fieldType));


Mime
View raw message