mirror of https://github.com/apache/lucene.git
LUCENE-4981: Remove deprecated classes.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1483412 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eefd3884b1
commit
c06fd47cba
|
@ -1,93 +0,0 @@
|
|||
package org.apache.lucene.analysis.position;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.analysis.TokenFilter;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
|
||||
import org.apache.lucene.queryparser.classic.QueryParser;
|
||||
|
||||
/** Set the positionIncrement of all tokens to the "positionIncrement",
|
||||
* except the first return token which retains its original positionIncrement value.
|
||||
* The default positionIncrement value is zero.
|
||||
* @deprecated (4.4) PositionFilter makes {@link TokenStream} graphs inconsistent
|
||||
* which can cause highlighting bugs. Its main use-case being to make
|
||||
* {@link QueryParser} generate boolean queries instead of phrase
|
||||
* queries, it is now advised to use
|
||||
* {@link QueryParser#setAutoGeneratePhraseQueries(boolean) QueryParser.setAutoGeneratePhraseQueries(false)}
|
||||
* (for simple cases) or to override {@link QueryParser#newFieldQuery}.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class PositionFilter extends TokenFilter {
|
||||
|
||||
/** Position increment to assign to all but the first token - default = 0 */
|
||||
private final int positionIncrement;
|
||||
|
||||
/** The first token must have non-zero positionIncrement **/
|
||||
private boolean firstTokenPositioned = false;
|
||||
|
||||
private PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class);
|
||||
|
||||
/**
|
||||
* Constructs a PositionFilter that assigns a position increment of zero to
|
||||
* all but the first token from the given input stream.
|
||||
*
|
||||
* @param input the input stream
|
||||
*/
|
||||
public PositionFilter(final TokenStream input) {
|
||||
this(input, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a PositionFilter that assigns the given position increment to
|
||||
* all but the first token from the given input stream.
|
||||
*
|
||||
* @param input the input stream
|
||||
* @param positionIncrement position increment to assign to all but the first
|
||||
* token from the input stream
|
||||
*/
|
||||
public PositionFilter(final TokenStream input, final int positionIncrement) {
|
||||
super(input);
|
||||
if (positionIncrement < 0) {
|
||||
throw new IllegalArgumentException("positionIncrement may not be negative");
|
||||
}
|
||||
this.positionIncrement = positionIncrement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean incrementToken() throws IOException {
|
||||
if (input.incrementToken()) {
|
||||
if (firstTokenPositioned) {
|
||||
posIncrAtt.setPositionIncrement(positionIncrement);
|
||||
} else {
|
||||
firstTokenPositioned = true;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() throws IOException {
|
||||
super.reset();
|
||||
firstTokenPositioned = false;
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package org.apache.lucene.analysis.position;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.analysis.position.PositionFilter;
|
||||
import org.apache.lucene.analysis.util.TokenFilterFactory;
|
||||
import org.apache.lucene.util.Version;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Factory for {@link PositionFilter}.
|
||||
* Set the positionIncrement of all tokens to the "positionIncrement", except the first return token which retains its
|
||||
* original positionIncrement value. The default positionIncrement value is zero.
|
||||
* <pre class="prettyprint">
|
||||
* <fieldType name="text_position" class="solr.TextField" positionIncrementGap="100">
|
||||
* <analyzer>
|
||||
* <tokenizer class="solr.WhitespaceTokenizerFactory"/>
|
||||
* <filter class="solr.PositionFilterFactory" positionIncrement="0"/>
|
||||
* </analyzer>
|
||||
* </fieldType></pre>
|
||||
*
|
||||
* @see org.apache.lucene.analysis.position.PositionFilter
|
||||
* @since solr 1.4
|
||||
* @deprecated (4.4)
|
||||
*/
|
||||
@Deprecated
|
||||
public class PositionFilterFactory extends TokenFilterFactory {
|
||||
private final int positionIncrement;
|
||||
|
||||
/** Creates a new PositionFilterFactory */
|
||||
public PositionFilterFactory(Map<String,String> args) {
|
||||
super(args);
|
||||
positionIncrement = getInt(args, "positionIncrement", 0);
|
||||
if (!args.isEmpty()) {
|
||||
throw new IllegalArgumentException("Unknown parameters: " + args);
|
||||
}
|
||||
if (luceneMatchVersion != null && luceneMatchVersion.onOrAfter(Version.LUCENE_44)) {
|
||||
throw new IllegalArgumentException("PositionFilter is deprecated as of Lucene 4.4. You should either fix your code to not use it or use Lucene 4.3 version compatibility");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionFilter create(TokenStream input) {
|
||||
return new PositionFilter(input, positionIncrement);
|
||||
}
|
||||
}
|
||||
|
|
@ -76,7 +76,6 @@ org.apache.lucene.analysis.payloads.DelimitedPayloadTokenFilterFactory
|
|||
org.apache.lucene.analysis.payloads.NumericPayloadTokenFilterFactory
|
||||
org.apache.lucene.analysis.payloads.TokenOffsetPayloadTokenFilterFactory
|
||||
org.apache.lucene.analysis.payloads.TypeAsPayloadTokenFilterFactory
|
||||
org.apache.lucene.analysis.position.PositionFilterFactory
|
||||
org.apache.lucene.analysis.pt.PortugueseLightStemFilterFactory
|
||||
org.apache.lucene.analysis.pt.PortugueseMinimalStemFilterFactory
|
||||
org.apache.lucene.analysis.pt.PortugueseStemFilterFactory
|
||||
|
|
|
@ -66,22 +66,15 @@ import org.apache.lucene.analysis.compound.hyphenation.HyphenationTree;
|
|||
import org.apache.lucene.analysis.hunspell.HunspellDictionary;
|
||||
import org.apache.lucene.analysis.hunspell.HunspellDictionaryTest;
|
||||
import org.apache.lucene.analysis.miscellaneous.HyphenatedWordsFilter;
|
||||
import org.apache.lucene.analysis.miscellaneous.KeepWordFilter;
|
||||
import org.apache.lucene.analysis.miscellaneous.LengthFilter;
|
||||
import org.apache.lucene.analysis.miscellaneous.LimitTokenCountFilter;
|
||||
import org.apache.lucene.analysis.miscellaneous.LimitTokenPositionFilter;
|
||||
import org.apache.lucene.analysis.miscellaneous.StemmerOverrideFilter;
|
||||
import org.apache.lucene.analysis.miscellaneous.StemmerOverrideFilter.StemmerOverrideMap;
|
||||
import org.apache.lucene.analysis.miscellaneous.TrimFilter;
|
||||
import org.apache.lucene.analysis.miscellaneous.WordDelimiterFilter;
|
||||
import org.apache.lucene.analysis.ngram.EdgeNGramTokenFilter;
|
||||
import org.apache.lucene.analysis.ngram.EdgeNGramTokenizer;
|
||||
import org.apache.lucene.analysis.ngram.Lucene43NGramTokenizer;
|
||||
import org.apache.lucene.analysis.path.PathHierarchyTokenizer;
|
||||
import org.apache.lucene.analysis.path.ReversePathHierarchyTokenizer;
|
||||
import org.apache.lucene.analysis.payloads.IdentityEncoder;
|
||||
import org.apache.lucene.analysis.payloads.PayloadEncoder;
|
||||
import org.apache.lucene.analysis.position.PositionFilter;
|
||||
import org.apache.lucene.analysis.snowball.TestSnowball;
|
||||
import org.apache.lucene.analysis.standard.StandardTokenizer;
|
||||
import org.apache.lucene.analysis.synonym.SynonymMap;
|
||||
|
|
|
@ -17,22 +17,21 @@ package org.apache.lucene.analysis.ngram;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.MockTokenizer;
|
||||
import org.apache.lucene.analysis.TokenFilter;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||
import org.apache.lucene.analysis.Tokenizer;
|
||||
import org.apache.lucene.analysis.core.KeywordTokenizer;
|
||||
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
|
||||
import org.apache.lucene.analysis.position.PositionFilter;
|
||||
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||
import org.apache.lucene.analysis.MockTokenizer;
|
||||
import org.apache.lucene.analysis.TokenFilter;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.analysis.Tokenizer;
|
||||
import org.apache.lucene.analysis.core.KeywordTokenizer;
|
||||
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
|
||||
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
|
||||
|
||||
/**
|
||||
* Tests {@link EdgeNGramTokenFilter} for correctness.
|
||||
*/
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
package org.apache.lucene.analysis.position;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.analysis.shingle.ShingleFilter;
|
||||
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
|
||||
|
||||
public class PositionFilterTest extends BaseTokenStreamTestCase {
|
||||
|
||||
public class TestTokenStream extends TokenStream {
|
||||
|
||||
protected int index = 0;
|
||||
protected String[] testToken;
|
||||
protected final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
|
||||
|
||||
public TestTokenStream(String[] testToken) {
|
||||
super();
|
||||
this.testToken = testToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean incrementToken() {
|
||||
clearAttributes();
|
||||
if (index < testToken.length) {
|
||||
termAtt.setEmpty().append(testToken[index++]);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void reset() {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String[] TEST_TOKEN = new String[]{
|
||||
"please",
|
||||
"divide",
|
||||
"this",
|
||||
"sentence",
|
||||
"into",
|
||||
"shingles",
|
||||
};
|
||||
public static final int[] TEST_TOKEN_POSITION_INCREMENTS = new int[]{
|
||||
1, 0, 0, 0, 0, 0
|
||||
};
|
||||
public static final int[] TEST_TOKEN_NON_ZERO_POSITION_INCREMENTS = new int[]{
|
||||
1, 5, 5, 5, 5, 5
|
||||
};
|
||||
|
||||
public static final String[] SIX_GRAM_NO_POSITIONS_TOKENS = new String[]{
|
||||
"please",
|
||||
"please divide",
|
||||
"please divide this",
|
||||
"please divide this sentence",
|
||||
"please divide this sentence into",
|
||||
"please divide this sentence into shingles",
|
||||
"divide",
|
||||
"divide this",
|
||||
"divide this sentence",
|
||||
"divide this sentence into",
|
||||
"divide this sentence into shingles",
|
||||
"this",
|
||||
"this sentence",
|
||||
"this sentence into",
|
||||
"this sentence into shingles",
|
||||
"sentence",
|
||||
"sentence into",
|
||||
"sentence into shingles",
|
||||
"into",
|
||||
"into shingles",
|
||||
"shingles",
|
||||
};
|
||||
public static final int[] SIX_GRAM_NO_POSITIONS_INCREMENTS = new int[]{
|
||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
public static final String[] SIX_GRAM_NO_POSITIONS_TYPES = new String[]{
|
||||
"word", "shingle", "shingle", "shingle", "shingle", "shingle",
|
||||
"word", "shingle", "shingle", "shingle", "shingle",
|
||||
"word", "shingle", "shingle", "shingle",
|
||||
"word", "shingle", "shingle",
|
||||
"word", "shingle",
|
||||
"word"
|
||||
};
|
||||
|
||||
public void testFilter() throws Exception {
|
||||
|
||||
assertTokenStreamContents(new PositionFilter(new TestTokenStream(TEST_TOKEN)),
|
||||
TEST_TOKEN,
|
||||
TEST_TOKEN_POSITION_INCREMENTS);
|
||||
}
|
||||
|
||||
public void testNonZeroPositionIncrement() throws Exception {
|
||||
|
||||
assertTokenStreamContents(new PositionFilter(new TestTokenStream(TEST_TOKEN), 5),
|
||||
TEST_TOKEN,
|
||||
TEST_TOKEN_NON_ZERO_POSITION_INCREMENTS);
|
||||
}
|
||||
|
||||
public void testReset() throws Exception {
|
||||
|
||||
PositionFilter filter = new PositionFilter(new TestTokenStream(TEST_TOKEN));
|
||||
assertTokenStreamContents(filter, TEST_TOKEN, TEST_TOKEN_POSITION_INCREMENTS);
|
||||
filter.reset();
|
||||
// Make sure that the reset filter provides correct position increments
|
||||
assertTokenStreamContents(filter, TEST_TOKEN, TEST_TOKEN_POSITION_INCREMENTS);
|
||||
}
|
||||
|
||||
/** Tests ShingleFilter up to six shingles against six terms.
|
||||
* Tests PositionFilter setting all but the first positionIncrement to zero.
|
||||
* @throws java.io.IOException @see Token#next(Token)
|
||||
*/
|
||||
public void test6GramFilterNoPositions() throws Exception {
|
||||
|
||||
ShingleFilter filter = new ShingleFilter(new TestTokenStream(TEST_TOKEN), 6);
|
||||
assertTokenStreamContents(new PositionFilter(filter),
|
||||
SIX_GRAM_NO_POSITIONS_TOKENS,
|
||||
SIX_GRAM_NO_POSITIONS_INCREMENTS);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue