diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 51b98ee1511..686cbfceeb1 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -6,6 +6,16 @@ http://s.apache.org/luceneversions ======================= Lucene 5.0.0 ======================= +Changes in backwards compatibility policy + +* LUCENE-3312: The API of oal.document was restructured to + differentiate between stored documents and indexed documents. + IndexReader.document(int) now returns StorableDocument + instead of Document. In most cases a simple replacement + of the return type is enough to upgrade (see MIGRATE.txt). + (Nikola Tanković, Uwe Schindler, Chris Male, Mike McCandless, + Robert Muir) + ======================= Lucene 4.0.0 ======================= New Features diff --git a/lucene/MIGRATE.txt b/lucene/MIGRATE.txt index a8120f38a75..88e74530d52 100644 --- a/lucene/MIGRATE.txt +++ b/lucene/MIGRATE.txt @@ -1,3 +1,8 @@ # Apache Lucene Migration Guide -TODO: Lucene 5.0 currently has no migration guide. \ No newline at end of file +## Separation of IndexDocument and StoredDocument (LUCENE-3312) + +The API of oal.document was restructured to differentiate between stored +documents and indexed documents. IndexReader.document(int) now returns +StorableDocument instead of Document. In most cases a simple replacement +of the return type is enough to upgrade. diff --git a/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java b/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java index 6961e15dbbc..e51e5af8080 100644 --- a/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java +++ b/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java @@ -25,6 +25,7 @@ import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.TopDocs; @@ -79,7 +80,7 @@ public class UIMABaseAnalyzerTest extends BaseTokenStreamTestCase { IndexSearcher indexSearcher = new IndexSearcher(directoryReader); TopDocs result = indexSearcher.search(new MatchAllDocsQuery(), 1); assertTrue(result.totalHits > 0); - Document d = indexSearcher.doc(result.scoreDocs[0].doc); + StoredDocument d = indexSearcher.doc(result.scoreDocs[0].doc); assertNotNull(d); assertNotNull(d.getField("title")); assertEquals(dummyTitle, d.getField("title").stringValue()); @@ -99,7 +100,7 @@ public class UIMABaseAnalyzerTest extends BaseTokenStreamTestCase { directoryReader = DirectoryReader.open(dir); indexSearcher = new IndexSearcher(directoryReader); result = indexSearcher.search(new MatchAllDocsQuery(), 2); - Document d1 = indexSearcher.doc(result.scoreDocs[1].doc); + StoredDocument d1 = indexSearcher.doc(result.scoreDocs[1].doc); assertNotNull(d1); assertNotNull(d1.getField("title")); assertEquals(dogmasTitle, d1.getField("title").stringValue()); diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java index 94014279243..5e471b18884 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java @@ -226,11 +226,12 @@ public class DocMaker implements Closeable { final DocState ds = getDocState(); final Document doc = reuseFields ? ds.doc : new Document(); - doc.getFields().clear(); + doc.clear(); // Set ID_FIELD FieldType ft = new FieldType(valType); ft.setIndexed(true); + ft.setStored(true); Field idField = ds.getField(ID_FIELD, ft); int id; diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java index fd229d08964..d1a3abf5d00 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java @@ -20,11 +20,12 @@ package org.apache.lucene.benchmark.byTask.tasks; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; /** * Abstract class for benchmarking highlighting performance */ public abstract class BenchmarkHighlighter { public abstract int doHighlight( IndexReader reader, int doc, String field, - Document document, Analyzer analyzer, String text ) throws Exception ; + StoredDocument document, Analyzer analyzer, String text ) throws Exception ; } diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java index f1cce8a8a37..c768b98789e 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java @@ -32,6 +32,8 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MultiFields; +import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.Collector; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.MultiTermQuery; @@ -96,7 +98,7 @@ public abstract class ReadTask extends PerfTask { // optionally warm and add num docs traversed to count if (withWarm()) { - Document doc = null; + StoredDocument doc = null; Bits liveDocs = MultiFields.getLiveDocs(reader); for (int m = 0; m < reader.maxDoc(); m++) { if (null == liveDocs || liveDocs.get(m)) { @@ -142,7 +144,7 @@ public abstract class ReadTask extends PerfTask { System.out.println("numDocs() = " + reader.numDocs()); for(int i=0;i0 && sufficientFields[i]; diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingHighlighterTestTask.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingHighlighterTestTask.java index a6e029398a6..3d5bb8a3116 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingHighlighterTestTask.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingHighlighterTestTask.java @@ -28,6 +28,7 @@ import org.apache.lucene.search.highlight.TokenSources; import org.apache.lucene.search.Query; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; import java.io.IOException; @@ -44,8 +45,8 @@ public class CountingHighlighterTestTask extends SearchTravRetHighlightTask { } @Override - protected Document retrieveDoc(IndexReader ir, int id) throws IOException { - Document document = ir.document(id); + protected StoredDocument retrieveDoc(IndexReader ir, int id) throws IOException { + StoredDocument document = ir.document(id); if (document != null) { numDocsRetrieved++; } @@ -57,7 +58,7 @@ public class CountingHighlighterTestTask extends SearchTravRetHighlightTask { highlighter = new Highlighter(new SimpleHTMLFormatter(), new QueryScorer(q)); return new BenchmarkHighlighter() { @Override - public int doHighlight(IndexReader reader, int doc, String field, Document document, Analyzer analyzer, String text) throws Exception { + public int doHighlight(IndexReader reader, int doc, String field, StoredDocument document, Analyzer analyzer, String text) throws Exception { TokenStream ts = TokenSources.getAnyTokenStream(reader, doc, field, document, analyzer); TextFragment[] frag = highlighter.getBestTextFragments(ts, text, mergeContiguous, maxFrags); numHighlightedResults += frag != null ? frag.length : 0; diff --git a/lucene/core/src/java/org/apache/lucene/analysis/package.html b/lucene/core/src/java/org/apache/lucene/analysis/package.html index b298263dd7f..b829f13492d 100644 --- a/lucene/core/src/java/org/apache/lucene/analysis/package.html +++ b/lucene/core/src/java/org/apache/lucene/analysis/package.html @@ -168,7 +168,7 @@ and proximity searches (though sentence identification is not provided by Lucene