Skip to content

Apache Lucene open-source search software

LUCENE-3436: remove deprecations from trunk / dont use deprecated methods

Robert Muir28ae5a57632b
diff --git a/modules/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java b/modules/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java
index 450d11bacac..c52c6948872 100755
--- a/modules/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java
+++ b/modules/suggest/src/java/org/apache/lucene/search/spell/SpellChecker.java
@@ -274,89 +274,6 @@ public class SpellChecker implements java.io.Closeable {
return this.suggestSimilar(word, numSug, null, null, SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX, accuracy);
}
- /**
- * Suggest similar words (optionally restricted to a field of an index).
- *
- * <p>As the Lucene similarity that is used to fetch the most relevant n-grammed terms
- * is not the same as the edit distance strategy used to calculate the best
- * matching spell-checked word from the hits that Lucene found, one usually has
- * to retrieve a couple of numSug's in order to get the true best match.
- *
- * <p>I.e. if numSug == 1, don't count on that suggestion being the best one.
- * Thus, you should set this value to <b>at least</b> 5 for a good suggestion.
- *
- * <p>Uses the {@link #getAccuracy()} value passed into the constructor as the accuracy.
- *
- * @param word the word you want a spell check done on
- * @param numSug the number of suggested words
- * @param ir the indexReader of the user index (can be null see field param)
- * @param field the field of the user index: if field is not null, the suggested
- * words are restricted to the words present in this field.
- * @param morePopular return only the suggest words that are as frequent or more frequent than the searched word
- * (only if restricted mode = (indexReader!=null and field!=null)
- * @throws IOException if the underlying index throws an {@link IOException}
- * @throws AlreadyClosedException if the Spellchecker is already closed
- * @return String[] the sorted list of the suggest words with these 2 criteria:
- * first criteria: the edit distance, second criteria (only if restricted mode): the popularity
- * of the suggest words in the field of the user index
- *
- * @see #suggestSimilar(String, int, IndexReader, String, SuggestMode, float)
- *
- * @deprecated
- * use suggestSimilar(String, int, IndexReader, String, SuggestMode)
- * <ul>
- * <li>SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX instead of morePopular=false</li>
- * <li>SuggestMode.SuGGEST_MORE_POPULAR instead of morePopular=true</li>
- * </ul>
- */
- @Deprecated
- public String[] suggestSimilar(String word, int numSug, IndexReader ir,
- String field, boolean morePopular) throws IOException {
- return suggestSimilar(word, numSug, ir, field, morePopular, accuracy);
- }
-
-
- /**
- * Suggest similar words (optionally restricted to a field of an index).
- *
- * <p>As the Lucene similarity that is used to fetch the most relevant n-grammed terms
- * is not the same as the edit distance strategy used to calculate the best
- * matching spell-checked word from the hits that Lucene found, one usually has
- * to retrieve a couple of numSug's in order to get the true best match.
- *
- * <p>I.e. if numSug == 1, don't count on that suggestion being the best one.
- * Thus, you should set this value to <b>at least</b> 5 for a good suggestion.
- *
- * @param word the word you want a spell check done on
- * @param numSug the number of suggested words
- * @param ir the indexReader of the user index (can be null see field param)
- * @param field the field of the user index: if field is not null, the suggested
- * words are restricted to the words present in this field.
- * @param morePopular return only the suggest words that are as frequent or more frequent than the searched word
- * (only if restricted mode = (indexReader!=null and field!=null)
- * @param accuracy The minimum score a suggestion must have in order to qualify for inclusion in the results
- * @throws IOException if the underlying index throws an {@link IOException}
- * @throws AlreadyClosedException if the Spellchecker is already closed
- * @return String[] the sorted list of the suggest words with these 2 criteria:
- * first criteria: the edit distance, second criteria (only if restricted mode): the popularity
- * of the suggest words in the field of the user index
- *
- * @see #suggestSimilar(String, int, IndexReader, String, SuggestMode, float)
- *
- * @deprecated
- * use suggestSimilar(String, int, IndexReader, String, SuggestMode, float)
- * <ul>
- * <li>SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX instead of morePopular=false</li>
- * <li>SuggestMode.SuGGEST_MORE_POPULAR instead of morePopular=true</li>
- * </ul>
- */
- @Deprecated
- public String[] suggestSimilar(String word, int numSug, IndexReader ir,
- String field, boolean morePopular, float accuracy) throws IOException {
- return suggestSimilar(word, numSug, ir, field, morePopular ? SuggestMode.SUGGEST_MORE_POPULAR :
- SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX, accuracy);
- }
-
/**
* Calls {@link #suggestSimilar(String, int, IndexReader, String, SuggestMode, float)
* suggestSimilar(word, numSug, ir, suggestMode, field, this.accuracy)}
diff --git a/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java b/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java
index 0c9f2c59bd8..d835acca2e0 100644
--- a/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java
+++ b/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java
@@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import org.apache.lucene.search.spell.SuggestMode;
import org.apache.lucene.search.spell.SuggestWord;
import org.apache.lucene.search.spell.SuggestWordFrequencyComparator;
import org.apache.lucene.search.spell.SuggestWordQueue;
@@ -168,13 +169,14 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {
float theAccuracy = (options.accuracy == Float.MIN_VALUE) ? spellChecker.getAccuracy() : options.accuracy;
int count = Math.max(options.count, AbstractLuceneSpellChecker.DEFAULT_SUGGESTION_COUNT);
+ SuggestMode mode = options.onlyMorePopular ? SuggestMode.SUGGEST_MORE_POPULAR : SuggestMode.SUGGEST_WHEN_NOT_IN_INDEX;
for (Token token : options.tokens) {
String tokenText = new String(token.buffer(), 0, token.length());
String[] suggestions = spellChecker.suggestSimilar(tokenText,
count,
field != null ? reader : null, //workaround LUCENE-1295
field,
- options.onlyMorePopular, theAccuracy);
+ mode, theAccuracy);
if (suggestions.length == 1 && suggestions[0].equals(tokenText)) {
//These are spelled the same, continue on
continue;