Author: kalle
Date: Sat Jun 13 21:54:07 2009
New Revision: 784481
URL: http://svn.apache.org/viewvc?rev=784481&view=rev
Log:
LUCENE-1578: Support for loading unoptimized readers to the
constructor of InstantiatedIndex. (Karl Wettin)
Added:
lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/
store/instantiated/TestUnoptimizedReaderOnConstructor.java
Modified:
lucene/java/trunk/contrib/CHANGES.txt
lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/
store/instantiated/InstantiatedIndex.java
lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/
store/instantiated/TestIndicesEquals.java
lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/
store/instantiated/TestRealTime.java
Modified: lucene/java/trunk/contrib/CHANGES.txt
URL:
http://svn.apache.org/viewvc/lucene/java/trunk/contrib/CHANGES.txt?rev=784481&r1=784480&r2=784481&view=diff
=
=
=
=
=
=
=
=
======================================================================
--- lucene/java/trunk/contrib/CHANGES.txt (original)
+++ lucene/java/trunk/contrib/CHANGES.txt Sat Jun 13 21:54:07 2009
@@ -62,8 +62,11 @@
(Xiaoping Gao via Mike McCandless)
-6. LUCENE-1676: Added DelimitedPayloadTokenFilter class for
automatically adding payloads "in-stream" (Grant Ingersoll)
-
+ 6. LUCENE-1676: Added DelimitedPayloadTokenFilter class for
automatically adding payloads "in-stream" (Grant Ingersoll)
+
+ 7. LUCENE-1578: Support for loading unoptimized readers to the
+ constructor of InstantiatedIndex. (Karl Wettin)
+
Optimizations
1. LUCENE-1643: Re-use the collation key (RawCollationKey) for
Modified: lucene/java/trunk/contrib/instantiated/src/java/org/apache/
lucene/store/instantiated/InstantiatedIndex.java
URL:
http://svn.apache.org/viewvc/lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedIndex.java?rev=784481&r1=784480&r2=784481&view=diff
=
=
=
=
=
=
=
=
======================================================================
--- lucene/java/trunk/contrib/instantiated/src/java/org/apache/
lucene/store/instantiated/InstantiatedIndex.java (original)
+++ lucene/java/trunk/contrib/instantiated/src/java/org/apache/
lucene/store/instantiated/InstantiatedIndex.java Sat Jun 13 21:54:07
2009
@@ -110,7 +110,8 @@
public InstantiatedIndex(IndexReader sourceIndexReader,
Set<String> fields) throws IOException {
if (!sourceIndexReader.isOptimized()) {
- throw new IOException("Source index is not optimized.");
+ System.out.println(("Source index is not optimized."));
+ //throw new IOException("Source index is not optimized.");
}
@@ -170,11 +171,14 @@
}
- documentsByNumber = new
InstantiatedDocument[sourceIndexReader.numDocs()];
+ documentsByNumber = new
InstantiatedDocument[sourceIndexReader.maxDoc()];
+
// create documents
- for (int i = 0; i < sourceIndexReader.numDocs(); i++) {
- if (!sourceIndexReader.isDeleted(i)) {
+ for (int i = 0; i < sourceIndexReader.maxDoc(); i++) {
+ if (sourceIndexReader.isDeleted(i)) {
+ deletedDocuments.add(i);
+ } else {
InstantiatedDocument document = new InstantiatedDocument();
// copy stored fields from source reader
Document sourceDocument = sourceIndexReader.document(i);
@@ -259,6 +263,9 @@
// load offsets to term-document informations
for (InstantiatedDocument document : getDocumentsByNumber()) {
+ if (document == null) {
+ continue; // deleted
+ }
for (Field field : (List<Field>)
document.getDocument().getFields()) {
if (field.isTermVectorStored() &&
field.isStoreOffsetWithTermVector()) {
TermPositionVector termPositionVector =
(TermPositionVector)
sourceIndexReader.getTermFreqVector(document.getDocumentNumber(),
field.name());
Modified: lucene/java/trunk/contrib/instantiated/src/test/org/apache/
lucene/store/instantiated/TestIndicesEquals.java
URL:
http://svn.apache.org/viewvc/lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java?rev=784481&r1=784480&r2=784481&view=diff
=
=
=
=
=
=
=
=
======================================================================
--- lucene/java/trunk/contrib/instantiated/src/test/org/apache/
lucene/store/instantiated/TestIndicesEquals.java (original)
+++ lucene/java/trunk/contrib/instantiated/src/test/org/apache/
lucene/store/instantiated/TestIndicesEquals.java Sat Jun 13 21:54:07
2009
@@ -40,6 +40,10 @@
import org.apache.lucene.index.TermPositions;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TopDocCollector;
+import org.apache.lucene.search.TopScoreDocCollector;
/**
* Asserts equality of content and behaviour of two index readers.
Modified: lucene/java/trunk/contrib/instantiated/src/test/org/apache/
lucene/store/instantiated/TestRealTime.java
URL:
http://svn.apache.org/viewvc/lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestRealTime.java?rev=784481&r1=784480&r2=784481&view=diff
=
=
=
=
=
=
=
=
======================================================================
--- lucene/java/trunk/contrib/instantiated/src/test/org/apache/
lucene/store/instantiated/TestRealTime.java (original)
+++ lucene/java/trunk/contrib/instantiated/src/test/org/apache/
lucene/store/instantiated/TestRealTime.java Sat Jun 13 21:54:07 2009
@@ -24,6 +24,12 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.index.Term;
+/**
+ * Assert that the content of an index
+ * is instantly available
+ * for all open searchers
+ * also after a commit.
+ */
public class TestRealTime extends TestCase {
public void test() throws Exception {
Added: lucene/java/trunk/contrib/instantiated/src/test/org/apache/
lucene/store/instantiated/TestUnoptimizedReaderOnConstructor.java
URL:
http://svn.apache.org/viewvc/lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestUnoptimizedReaderOnConstructor.java?rev=784481&view=auto
=
=
=
=
=
=
=
=
======================================================================
--- lucene/java/trunk/contrib/instantiated/src/test/org/apache/
lucene/store/instantiated/TestUnoptimizedReaderOnConstructor.java
(added)
+++ lucene/java/trunk/contrib/instantiated/src/test/org/apache/
lucene/store/instantiated/TestUnoptimizedReaderOnConstructor.java
Sat Jun 13 21:54:07 2009
@@ -0,0 +1,53 @@
+package org.apache.lucene.store.instantiated;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.analysis.WhitespaceAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+
+/**
+ * @author kalle
+ * @since 2009-mar-30 13:15:49
+ */
+public class TestUnoptimizedReaderOnConstructor extends TestCase {
+
+ public void test() throws Exception {
+ Directory dir = new RAMDirectory();
+ IndexWriter iw = new IndexWriter(dir, new WhitespaceAnalyzer(),
true, IndexWriter.MaxFieldLength.UNLIMITED);
+ addDocument(iw, "Hello, world!");
+ addDocument(iw, "All work and no play makes jack a dull boy");
+ iw.commit("a");
+ iw.close();
+
+ iw = new IndexWriter(dir, new WhitespaceAnalyzer(), false,
IndexWriter.MaxFieldLength.UNLIMITED);
+ addDocument(iw, "Hello, tellus!");
+ addDocument(iw, "All work and no play makes danny a dull boy");
+ iw.commit("b");
+ iw.close();
+
+ iw = new IndexWriter(dir, new WhitespaceAnalyzer(), false,
IndexWriter.MaxFieldLength.UNLIMITED);
+ addDocument(iw, "Hello, earth!");
+ addDocument(iw, "All work and no play makes wendy a dull girl");
+ iw.commit("c");
+ iw.close();
+
+ IndexReader unoptimizedReader = IndexReader.open(dir);
+ unoptimizedReader.deleteDocument(2);
+
+ InstantiatedIndex ii = new InstantiatedIndex(unoptimizedReader);
+
+ }
+
+ private void addDocument(IndexWriter iw, String text) throws
IOException {
+ Document doc = new Document();
+ doc.add(new Field("field", text, Field.Store.NO,
Field.Index.ANALYZED));
+ iw.addDocument(doc);
+ }
+}