Apache Lucene open-source search software
SOLR-822: rename correctPosition() to correct() in CharFilter because it is for correcting token offset, not for token position
Koji Sekiguchib46fca3934da
diff --git a/src/java/org/apache/solr/analysis/BaseCharFilter.java b/src/java/org/apache/solr/analysis/BaseCharFilter.javaindex f7457a473ea..54008cce1ec 100644--- a/src/java/org/apache/solr/analysis/BaseCharFilter.java+++ b/src/java/org/apache/solr/analysis/BaseCharFilter.java@@ -28,44 +28,44 @@ import java.util.List;*/public abstract class BaseCharFilter extends CharFilter {- private List<PosCorrectMap> pcmList;+ private List<OffCorrectMap> pcmList;public BaseCharFilter( CharStream in ){super(in);}- protected int correctPosition( int currentPos ){- if( pcmList == null || pcmList.isEmpty() ) return currentPos;+ protected int correct( int currentOff ){+ if( pcmList == null || pcmList.isEmpty() ) return currentOff;for( int i = pcmList.size() - 1; i >= 0; i-- ){- if( currentPos >= pcmList.get( i ).pos )- return currentPos + pcmList.get( i ).cumulativeDiff;+ if( currentOff >= pcmList.get( i ).off )+ return currentOff + pcmList.get( i ).cumulativeDiff;}- return currentPos;+ return currentOff;}protected int getLastCumulativeDiff(){return pcmList == null || pcmList.isEmpty() ? 0 : pcmList.get( pcmList.size() - 1 ).cumulativeDiff;}- protected void addPosCorrectMap( int pos, int cumulativeDiff ){- if( pcmList == null ) pcmList = new ArrayList<PosCorrectMap>();- pcmList.add( new PosCorrectMap( pos, cumulativeDiff ) );+ protected void addOffCorrectMap( int off, int cumulativeDiff ){+ if( pcmList == null ) pcmList = new ArrayList<OffCorrectMap>();+ pcmList.add( new OffCorrectMap( off, cumulativeDiff ) );}- static class PosCorrectMap {+ static class OffCorrectMap {- int pos;+ int off;int cumulativeDiff;- PosCorrectMap( int pos, int cumulativeDiff ){- this.pos = pos;+ OffCorrectMap( int off, int cumulativeDiff ){+ this.off = off;this.cumulativeDiff = cumulativeDiff;}public String toString(){StringBuilder sb = new StringBuilder();sb.append('(');- sb.append(pos);+ sb.append(off);sb.append(',');sb.append(cumulativeDiff);sb.append(')');diff --git a/src/java/org/apache/solr/analysis/CharFilter.java b/src/java/org/apache/solr/analysis/CharFilter.javaindex 60960d30f03..9616bcf9a9f 100644--- a/src/java/org/apache/solr/analysis/CharFilter.java+++ b/src/java/org/apache/solr/analysis/CharFilter.java@@ -37,18 +37,18 @@ public abstract class CharFilter extends CharStream {/***- * Subclass may want to override to correct the current position.+ * Subclass may want to override to correct the current offset.*- * @param pos current position- * @return corrected position+ * @param currentOff current offset+ * @return corrected offset*/- protected int correctPosition( int pos ){- return pos;+ protected int correct( int currentOff ){+ return currentOff;}@Overridepublic final int correctOffset(int currentOff) {- return input.correctOffset( correctPosition( currentOff ) );+ return input.correctOffset( correct( currentOff ) );}@Overridediff --git a/src/java/org/apache/solr/analysis/MappingCharFilter.java b/src/java/org/apache/solr/analysis/MappingCharFilter.javaindex 78997e13383..bf8e54f3e81 100644--- a/src/java/org/apache/solr/analysis/MappingCharFilter.java+++ b/src/java/org/apache/solr/analysis/MappingCharFilter.java@@ -57,10 +57,10 @@ public class MappingCharFilter extends BaseCharFilter {int prevCumulativeDiff = getLastCumulativeDiff();if( result.diff < 0 ){for( int i = 0; i < -result.diff ; i++ )- addPosCorrectMap( nextCharCounter + i - prevCumulativeDiff, prevCumulativeDiff - 1 - i );+ addOffCorrectMap( nextCharCounter + i - prevCumulativeDiff, prevCumulativeDiff - 1 - i );}else{- addPosCorrectMap( nextCharCounter - result.diff - prevCumulativeDiff, prevCumulativeDiff + result.diff ) ;+ addOffCorrectMap( nextCharCounter - result.diff - prevCumulativeDiff, prevCumulativeDiff + result.diff ) ;}}}diff --git a/src/test/org/apache/solr/analysis/TestCharFilter.java b/src/test/org/apache/solr/analysis/TestCharFilter.javaindex cb64e84be77..c537e7b9e59 100644--- a/src/test/org/apache/solr/analysis/TestCharFilter.java+++ b/src/test/org/apache/solr/analysis/TestCharFilter.java@@ -1,3 +1,20 @@+/**+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package org.apache.solr.analysis;import java.io.StringReader;@@ -8,22 +25,22 @@ public class TestCharFilter extends TestCase {public void testCharFilter1() throws Exception {CharStream cs = new CharFilter1( new CharReader( new StringReader("") ) );- assertEquals( "corrected position is invalid", 1, cs.correctOffset( 0 ) );+ assertEquals( "corrected offset is invalid", 1, cs.correctOffset( 0 ) );}public void testCharFilter2() throws Exception {CharStream cs = new CharFilter2( new CharReader( new StringReader("") ) );- assertEquals( "corrected position is invalid", 2, cs.correctOffset( 0 ) );+ assertEquals( "corrected offset is invalid", 2, cs.correctOffset( 0 ) );}public void testCharFilter12() throws Exception {CharStream cs = new CharFilter2( new CharFilter1( new CharReader( new StringReader("") ) ) );- assertEquals( "corrected position is invalid", 3, cs.correctOffset( 0 ) );+ assertEquals( "corrected offset is invalid", 3, cs.correctOffset( 0 ) );}public void testCharFilter11() throws Exception {CharStream cs = new CharFilter1( new CharFilter1( new CharReader( new StringReader("") ) ) );- assertEquals( "corrected position is invalid", 2, cs.correctOffset( 0 ) );+ assertEquals( "corrected offset is invalid", 2, cs.correctOffset( 0 ) );}static class CharFilter1 extends CharFilter {@@ -33,8 +50,8 @@ public class TestCharFilter extends TestCase {}@Override- protected int correctPosition(int currentPos) {- return currentPos + 1;+ protected int correct(int currentOff) {+ return currentOff + 1;}}@@ -45,8 +62,8 @@ public class TestCharFilter extends TestCase {}@Override- protected int correctPosition(int currentPos) {- return currentPos + 2;+ protected int correct(int currentOff) {+ return currentOff + 2;}}}