| Index: lucene/CHANGES.txt |
| =================================================================== |
| --- lucene/CHANGES.txt (revision 1538369) |
| +++ lucene/CHANGES.txt (working copy) |
| @@ -208,6 +208,9 @@ |
| * LUCENE-5321: Remove Facet42DocValuesFormat. Use DirectDocValuesFormat if you |
| want to load the category list into memory. (Shai Erera, Mike McCandless) |
| |
| +* LUCENE-5324: AnalyzerWrapper.getPositionIncrementGap and getOffsetGap can now |
| + be overridden. (Adrien Grand) |
| + |
| Optimizations |
| |
| * LUCENE-5225: The ToParentBlockJoinQuery only keeps tracks of the the child |
| Index: lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java |
| =================================================================== |
| --- lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java (revision 1538369) |
| +++ lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java (working copy) |
| @@ -103,12 +103,12 @@ |
| } |
| |
| @Override |
| - public final int getPositionIncrementGap(String fieldName) { |
| + public int getPositionIncrementGap(String fieldName) { |
| return getWrappedAnalyzer(fieldName).getPositionIncrementGap(fieldName); |
| } |
| |
| @Override |
| - public final int getOffsetGap(String fieldName) { |
| + public int getOffsetGap(String fieldName) { |
| return getWrappedAnalyzer(fieldName).getOffsetGap(fieldName); |
| } |
| |
| Index: lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java |
| =================================================================== |
| --- lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java (revision 1538369) |
| +++ lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java (working copy) |
| @@ -5,6 +5,17 @@ |
| import java.util.Arrays; |
| import java.util.Random; |
| |
| +import org.apache.lucene.document.Document; |
| +import org.apache.lucene.document.Field; |
| +import org.apache.lucene.document.FieldType; |
| +import org.apache.lucene.index.AtomicReader; |
| +import org.apache.lucene.index.DocsAndPositionsEnum; |
| +import org.apache.lucene.index.FieldInfo.IndexOptions; |
| +import org.apache.lucene.index.Fields; |
| +import org.apache.lucene.index.RandomIndexWriter; |
| +import org.apache.lucene.index.Terms; |
| +import org.apache.lucene.index.TermsEnum; |
| +import org.apache.lucene.util.BytesRef; |
| import org.apache.lucene.util._TestUtil; |
| import org.apache.lucene.util.automaton.Automaton; |
| import org.apache.lucene.util.automaton.AutomatonTestUtil; |
| @@ -276,4 +287,53 @@ |
| |
| checkOneTerm(a, "abc", "aabc"); |
| } |
| + |
| + public void testChangeGaps() throws Exception { |
| + // LUCENE-5324: check that it is possible to change the wrapper's gaps |
| + final int positionGap = random().nextInt(1000); |
| + final int offsetGap = random().nextInt(1000); |
| + final Analyzer delegate = new MockAnalyzer(random()); |
| + final Analyzer a = new AnalyzerWrapper(delegate.getReuseStrategy()) { |
| + @Override |
| + protected Analyzer getWrappedAnalyzer(String fieldName) { |
| + return delegate; |
| + } |
| + @Override |
| + public int getPositionIncrementGap(String fieldName) { |
| + return positionGap; |
| + } |
| + @Override |
| + public int getOffsetGap(String fieldName) { |
| + return offsetGap; |
| + } |
| + }; |
| + |
| + final RandomIndexWriter writer = new RandomIndexWriter(random(), newDirectory()); |
| + final Document doc = new Document(); |
| + final FieldType ft = new FieldType(); |
| + ft.setIndexed(true); |
| + ft.setTokenized(true); |
| + ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); |
| + doc.add(new Field("f", "a", ft)); |
| + doc.add(new Field("f", "a", ft)); |
| + writer.addDocument(doc, a); |
| + final AtomicReader reader = getOnlySegmentReader(writer.getReader()); |
| + final Fields fields = reader.fields(); |
| + final Terms terms = fields.terms("f"); |
| + final TermsEnum te = terms.iterator(null); |
| + assertEquals(new BytesRef("a"), te.next()); |
| + final DocsAndPositionsEnum dpe = te.docsAndPositions(null, null); |
| + assertEquals(0, dpe.nextDoc()); |
| + assertEquals(2, dpe.freq()); |
| + assertEquals(0, dpe.nextPosition()); |
| + assertEquals(0, dpe.startOffset()); |
| + final int endOffset = dpe.endOffset(); |
| + assertEquals(1 + positionGap, dpe.nextPosition()); |
| + assertEquals(1 + endOffset + offsetGap, dpe.endOffset()); |
| + assertEquals(null, te.next()); |
| + reader.close(); |
| + writer.close(); |
| + writer.w.getDirectory().close(); |
| + } |
| + |
| } |