You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2013/11/04 12:24:42 UTC
svn commit: r1538561 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/CHANGES.txt lucene/core/
lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java
lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java
Author: jpountz
Date: Mon Nov 4 11:24:42 2013
New Revision: 1538561
URL: http://svn.apache.org/r1538561
Log:
LUCENE-5324: AnalyzerWrapper.get(PositionIncrement|Offset)Gap can now be overridden.
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/lucene/core/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java
Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1538561&r1=1538560&r2=1538561&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Mon Nov 4 11:24:42 2013
@@ -154,6 +154,9 @@ API Changes:
* 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
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java?rev=1538561&r1=1538560&r2=1538561&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/analysis/AnalyzerWrapper.java Mon Nov 4 11:24:42 2013
@@ -103,12 +103,12 @@ public abstract class AnalyzerWrapper ex
}
@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);
}
Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java?rev=1538561&r1=1538560&r2=1538561&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/analysis/TestMockAnalyzer.java Mon Nov 4 11:24:42 2013
@@ -1,19 +1,5 @@
package org.apache.lucene.analysis;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Arrays;
-import java.util.Random;
-
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util._TestUtil;
-import org.apache.lucene.util.automaton.Automaton;
-import org.apache.lucene.util.automaton.AutomatonTestUtil;
-import org.apache.lucene.util.automaton.BasicAutomata;
-import org.apache.lucene.util.automaton.BasicOperations;
-import org.apache.lucene.util.automaton.CharacterRunAutomaton;
-import org.apache.lucene.util.automaton.RegExp;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -31,6 +17,32 @@ import org.apache.lucene.util.automaton.
* limitations under the License.
*/
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.Random;
+
+import org.apache.lucene.util.IOUtils;
+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;
+import org.apache.lucene.util.automaton.BasicAutomata;
+import org.apache.lucene.util.automaton.BasicOperations;
+import org.apache.lucene.util.automaton.CharacterRunAutomaton;
+import org.apache.lucene.util.automaton.RegExp;
+
+
public class TestMockAnalyzer extends BaseTokenStreamTestCase {
/** Test a configuration that behaves a lot like WhitespaceAnalyzer */
@@ -289,4 +301,53 @@ public class TestMockAnalyzer extends Ba
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();
+ }
+
}