Index: . =================================================================== --- . (revision 1239059) +++ . (working copy) Property changes on: . ___________________________________________________________________ Modified: svn:mergeinfo Merged /lucene/dev/trunk:r1239052-1239056 Index: lucene =================================================================== --- lucene (revision 1239059) +++ lucene (working copy) Property changes on: lucene ___________________________________________________________________ Modified: svn:mergeinfo Merged /lucene/dev/trunk/lucene:r1239052-1239056 Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 1239059) +++ lucene/CHANGES.txt (working copy) @@ -89,6 +89,12 @@ In Lucene 4.0, SimilarityProvider will allow you to customize scoring using external norms, too. (Uwe Schindler, Robert Muir) +* LUCENE-3735: PayloadProcessorProvider was changed to return a + ReaderPayloadProcessor instead of DirPayloadProcessor. The selction + of the provider to return for the factory is now based on the IndexReader + to be merged. To mimic the old behaviour, just use IndexReader.directory() + for choosing the provider by Directory. (Uwe Schindler) + New Features * LUCENE-3593: Added a FieldValueFilter that accepts all documents that either Index: lucene/contrib/facet/src/java/org/apache/lucene/facet/index/FacetsPayloadProcessorProvider.java =================================================================== --- lucene/contrib/facet/src/java/org/apache/lucene/facet/index/FacetsPayloadProcessorProvider.java (revision 1239059) +++ lucene/contrib/facet/src/java/org/apache/lucene/facet/index/FacetsPayloadProcessorProvider.java (working copy) @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Map; +import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.PayloadProcessorProvider; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; @@ -93,7 +94,7 @@ private final Directory workDir; - private final DirPayloadProcessor dirProcessor; + private final ReaderPayloadProcessor dirProcessor; /** * Construct FacetsPayloadProcessorProvider with FacetIndexingParams @@ -109,14 +110,11 @@ } @Override - public DirPayloadProcessor getDirProcessor(Directory dir) throws IOException { - if (workDir != dir) { - return null; - } - return dirProcessor; + public ReaderPayloadProcessor getReaderProcessor(IndexReader reader) throws IOException { + return (workDir == reader.directory()) ? dirProcessor : null; } - public static class FacetsDirPayloadProcessor extends DirPayloadProcessor { + public static class FacetsDirPayloadProcessor extends ReaderPayloadProcessor { private final Map termMap = new HashMap(1); Index: lucene/src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/index/IndexWriter.java (revision 1239059) +++ lucene/src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -37,7 +37,6 @@ import org.apache.lucene.analysis.LimitTokenCountAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexWriterConfig.OpenMode; -import org.apache.lucene.index.PayloadProcessorProvider.DirPayloadProcessor; import org.apache.lucene.search.Query; import org.apache.lucene.search.Similarity; import org.apache.lucene.store.AlreadyClosedException; @@ -4778,7 +4777,7 @@ * is merged, not only external ones that are given through * {@link #addIndexes}. If you want only the payloads of the external segments * to be processed, you can return null whenever a - * {@link DirPayloadProcessor} is requested for the {@link Directory} of the + * {@link PayloadProcessorProvider.ReaderPayloadProcessor} is requested for the {@link Directory} of the * {@link IndexWriter}. *

* The default is null which means payloads are processed Index: lucene/src/java/org/apache/lucene/index/PayloadProcessorProvider.java =================================================================== --- lucene/src/java/org/apache/lucene/index/PayloadProcessorProvider.java (revision 1239059) +++ lucene/src/java/org/apache/lucene/index/PayloadProcessorProvider.java (working copy) @@ -22,20 +22,20 @@ import org.apache.lucene.store.Directory; /** - * Provides a {@link DirPayloadProcessor} to be used for a {@link Directory}. - * This allows using different {@link DirPayloadProcessor}s for different - * directories, for e.g. to perform different processing of payloads of + * Provides a {@link ReaderPayloadProcessor} to be used for a {@link Directory}. + * This allows using different {@link ReaderPayloadProcessor}s for different + * source {@link IndexReader}, for e.g. to perform different processing of payloads of * different directories. *

* NOTE: to avoid processing payloads of certain directories, you can - * return null in {@link #getDirProcessor}. + * return null in {@link #getReaderProcessor}. *

- * NOTE: it is possible that the same {@link DirPayloadProcessor} will be + * NOTE: it is possible that the same {@link ReaderPayloadProcessor} will be * requested for the same {@link Directory} concurrently. Therefore, to avoid * concurrency issues you should return different instances for different - * threads. Usually, if your {@link DirPayloadProcessor} does not maintain state + * threads. Usually, if your {@link ReaderPayloadProcessor} does not maintain state * this is not a problem. The merge code ensures that the - * {@link DirPayloadProcessor} instance you return will be accessed by one + * {@link ReaderPayloadProcessor} instance you return will be accessed by one * thread to obtain the {@link PayloadProcessor}s for different terms. * * @lucene.experimental @@ -47,11 +47,11 @@ * processing the payloads of different terms differently. If you intent to * process all your payloads the same way, then you can ignore the given term. *

- * NOTE: if you protect your {@link DirPayloadProcessor} from + * NOTE: if you protect your {@link ReaderPayloadProcessor} from * concurrency issues, then you shouldn't worry about any such issues when * {@link PayloadProcessor}s are requested for different terms. */ - public static abstract class DirPayloadProcessor { + public static abstract class ReaderPayloadProcessor { /** Returns a {@link PayloadProcessor} for the given term. */ public abstract PayloadProcessor getProcessor(Term term) throws IOException; @@ -59,6 +59,12 @@ } /** + * @deprecated Use {@link ReaderPayloadProcessor} instead. + */ + @Deprecated + public static abstract class DirPayloadProcessor extends ReaderPayloadProcessor {} + + /** * Processes the given payload. One should call {@link #payloadLength()} to * get the length of the processed payload. * @@ -80,10 +86,25 @@ } /** + * Returns a {@link ReaderPayloadProcessor} for the given {@link Directory}, + * through which {@link PayloadProcessor}s can be obtained for each + * {@link Term}, or null if none should be used. + * You should override this method, not {@link #getDirProcessor}. + */ + public ReaderPayloadProcessor getReaderProcessor(IndexReader reader) throws IOException { + return this.getDirProcessor(reader.directory()); + } + + /** * Returns a {@link DirPayloadProcessor} for the given {@link Directory}, * through which {@link PayloadProcessor}s can be obtained for each * {@link Term}, or null if none should be used. + * @deprecated Use {@link #getReaderProcessor} instead. You can still select by {@link Directory}, + * if you retrieve the underlying directory from {@link IndexReader#directory()}. */ - public abstract DirPayloadProcessor getDirProcessor(Directory dir) throws IOException; - + @Deprecated + public DirPayloadProcessor getDirProcessor(Directory dir) throws IOException { + throw new UnsupportedOperationException("You must either implement getReaderProcessor() or getDirProcessor()."); + } + } Index: lucene/src/java/org/apache/lucene/index/SegmentMergeInfo.java =================================================================== --- lucene/src/java/org/apache/lucene/index/SegmentMergeInfo.java (revision 1239059) +++ lucene/src/java/org/apache/lucene/index/SegmentMergeInfo.java (working copy) @@ -19,7 +19,7 @@ import java.io.IOException; -import org.apache.lucene.index.PayloadProcessorProvider.DirPayloadProcessor; +import org.apache.lucene.index.PayloadProcessorProvider.ReaderPayloadProcessor; final class SegmentMergeInfo { Term term; @@ -30,7 +30,7 @@ int delCount; private TermPositions postings; // use getPositions() private int[] docMap; // use getDocMap() - DirPayloadProcessor dirPayloadProcessor; + ReaderPayloadProcessor readerPayloadProcessor; SegmentMergeInfo(int b, TermEnum te, IndexReader r) throws IOException { Index: lucene/src/java/org/apache/lucene/index/SegmentMerger.java =================================================================== --- lucene/src/java/org/apache/lucene/index/SegmentMerger.java (revision 1239059) +++ lucene/src/java/org/apache/lucene/index/SegmentMerger.java (working copy) @@ -448,7 +448,7 @@ TermEnum termEnum = reader.terms(); SegmentMergeInfo smi = new SegmentMergeInfo(base, termEnum, reader); if (payloadProcessorProvider != null) { - smi.dirPayloadProcessor = payloadProcessorProvider.getDirProcessor(reader.directory()); + smi.readerPayloadProcessor = payloadProcessorProvider.getReaderProcessor(reader); } int[] docMap = smi.getDocMap(); if (docMap != null) { @@ -533,8 +533,8 @@ postings.seek(smi.termEnum); PayloadProcessor payloadProcessor = null; - if (smi.dirPayloadProcessor != null) { - payloadProcessor = smi.dirPayloadProcessor.getProcessor(smi.term); + if (smi.readerPayloadProcessor != null) { + payloadProcessor = smi.readerPayloadProcessor.getProcessor(smi.term); } while (postings.next()) { Index: lucene/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java (revision 1239059) +++ lucene/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java (working copy) @@ -32,7 +32,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.Field.Index; import org.apache.lucene.document.Field.Store; -import org.apache.lucene.index.PayloadProcessorProvider.DirPayloadProcessor; +import org.apache.lucene.index.PayloadProcessorProvider.ReaderPayloadProcessor; import org.apache.lucene.index.PayloadProcessorProvider.PayloadProcessor; import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; @@ -42,20 +42,20 @@ private static final class PerDirPayloadProcessor extends PayloadProcessorProvider { - private Map processors; + private final Map processors; - public PerDirPayloadProcessor(Map processors) { + public PerDirPayloadProcessor(Map processors) { this.processors = processors; } @Override - public DirPayloadProcessor getDirProcessor(Directory dir) throws IOException { - return processors.get(dir); + public ReaderPayloadProcessor getReaderProcessor(IndexReader reader) throws IOException { + return processors.get(reader.directory()); } } - private static final class PerTermPayloadProcessor extends DirPayloadProcessor { + private static final class PerTermPayloadProcessor extends ReaderPayloadProcessor { @Override public PayloadProcessor getProcessor(Term term) throws IOException { @@ -194,7 +194,7 @@ // Add two source dirs. By not adding the dest dir, we ensure its payloads // won't get processed. - Map processors = new HashMap(); + Map processors = new HashMap(); for (Directory d : dirs) { processors.put(d, new PerTermPayloadProcessor()); } @@ -250,7 +250,7 @@ // Add two source dirs. By not adding the dest dir, we ensure its payloads // won't get processed. - Map processors = new HashMap(); + Map processors = new HashMap(); processors.put(dir, new PerTermPayloadProcessor()); IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); writer.setPayloadProcessorProvider(new PerDirPayloadProcessor(processors)); Index: solr =================================================================== --- solr (revision 1239059) +++ solr (working copy) Property changes on: solr ___________________________________________________________________ Modified: svn:mergeinfo Merged /lucene/dev/trunk/solr:r1239052-1239056 Index: solr/core =================================================================== --- solr/core (revision 1239059) +++ solr/core (working copy) Property changes on: solr/core ___________________________________________________________________ Modified: svn:mergeinfo Merged /lucene/dev/trunk/solr/core:r1239052-1239056