From 28ae5a57632bf6f9bc7ef0b51826545c8c6a923c Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 16 Sep 2011 14:05:46 +0000 Subject: [PATCH] LUCENE-3436: remove deprecations from trunk / dont use deprecated methods git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1171570 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/search/spell/SpellChecker.java | 83 ------------------- .../spelling/AbstractLuceneSpellChecker.java | 4 +- 2 files changed, 3 insertions(+), 84 deletions(-) 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). - * - *

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. - * - *

I.e. if numSug == 1, don't count on that suggestion being the best one. - * Thus, you should set this value to at least 5 for a good suggestion. - * - *

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) - *

- */ - @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). - * - *

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. - * - *

I.e. if numSug == 1, don't count on that suggestion being the best one. - * Thus, you should set this value to at least 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) - *

- */ - @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;