Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

- Renamed some variables and made minScore private

Otis Gospodnetic895f763d2143
diff --git a/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java b/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
index 63fa39e0d17..e6f873a60b1 100755
--- a/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
+++ b/contrib/spellchecker/src/java/org/apache/lucene/search/spell/SpellChecker.java
@@ -74,7 +74,8 @@ public class SpellChecker {
private IndexReader reader;
private IndexSearcher searcher;
- float min = 0.5f;
+ // minimum score for hits generated by the spell checker query
+ private float minScore = 0.5f;
public SpellChecker(Directory spellIndex) throws IOException {
this.setSpellIndex(spellIndex);
@@ -86,27 +87,27 @@ public class SpellChecker {
}
/**
- * Sets the accuracy 0 < min < 1; default 0.5
+ * Sets the accuracy 0 < minScore < 1; default 0.5
*/
public void setAccuracy(float min) {
- this.min = min;
+ this.minScore = min;
}
/**
* Suggest similar words
* @param word String the word you want a spell check done on
- * @param num_sug int the number of suggest words
+ * @param numSug int the number of suggest words
* @throws IOException
* @return String[]
*/
- public String[] suggestSimilar(String word, int num_sug) throws IOException {
- return this.suggestSimilar(word, num_sug, null, null, false);
+ public String[] suggestSimilar(String word, int numSug) throws IOException {
+ return this.suggestSimilar(word, numSug, null, null, false);
}
/**
* Suggest similar words (restricted or not to a field of a user index)
* @param word String the word you want a spell check done on
- * @param num_sug int the number of suggest words
+ * @param numSug int the number of suggest words
* @param ir the indexReader of the user index (can be null see field param)
* @param field String the field of the user index: if field is not null, the suggested
* words are restricted to the words present in this field.
@@ -117,10 +118,10 @@ public class SpellChecker {
* first criteria: the edit distance, second criteria (only if restricted mode): the popularity
* of the suggest words in the field of the user index
*/
- public String[] suggestSimilar(String word, int num_sug, IndexReader ir,
+ public String[] suggestSimilar(String word, int numSug, IndexReader ir,
String field, boolean morePopular) throws IOException {
- float min = this.min;
+ float min = this.minScore;
final TRStringDistance sd = new TRStringDistance(word);
final int lengthWord = word.length();
@@ -159,46 +160,47 @@ public class SpellChecker {
// System.out.println("Q: " + query);
Hits hits = searcher.search(query);
- SuggestWordQueue sugqueue = new SuggestWordQueue(num_sug);
+// System.out.println("HITS: " + hits.length());
+ SuggestWordQueue sugQueue = new SuggestWordQueue(numSug);
// go thru more than 'maxr' matches in case the distance filter triggers
- int stop = Math.min(hits.length(), 10 * num_sug);
- SuggestWord sugword = new SuggestWord();
+ int stop = Math.min(hits.length(), 10 * numSug);
+ SuggestWord sugWord = new SuggestWord();
for (int i = 0; i < stop; i++) {
- sugword.string = hits.doc(i).get(F_WORD); // get orig word
+ sugWord.string = hits.doc(i).get(F_WORD); // get orig word
// don't suggest a word for itself, that would be silly
- if (sugword.string.equals(word)) {
+ if (sugWord.string.equals(word)) {
continue;
}
- // edit distance/normalize with the min word length
- sugword.score = 1.0f - ((float) sd.getDistance(sugword.string) / Math
- .min(sugword.string.length(), lengthWord));
- if (sugword.score < min) {
+ // edit distance/normalize with the minScore word length
+ sugWord.score = 1.0f - ((float) sd.getDistance(sugWord.string) / Math
+ .min(sugWord.string.length(), lengthWord));
+ if (sugWord.score < min) {
continue;
}
if (ir != null) { // use the user index
- sugword.freq = ir.docFreq(new Term(field, sugword.string)); // freq in the index
+ sugWord.freq = ir.docFreq(new Term(field, sugWord.string)); // freq in the index
// don't suggest a word that is not present in the field
- if ((morePopular && goalFreq > sugword.freq) || sugword.freq < 1) {
+ if ((morePopular && goalFreq > sugWord.freq) || sugWord.freq < 1) {
continue;
}
}
- sugqueue.insert(sugword);
- if (sugqueue.size() == num_sug) {
- // if queue full, maintain the min score
- min = ((SuggestWord) sugqueue.top()).score;
+ sugQueue.insert(sugWord);
+ if (sugQueue.size() == numSug) {
+ // if queue full, maintain the minScore score
+ min = ((SuggestWord) sugQueue.top()).score;
}
- sugword = new SuggestWord();
+ sugWord = new SuggestWord();
}
// convert to array string
- String[] list = new String[sugqueue.size()];
- for (int i = sugqueue.size() - 1; i >= 0; i--) {
- list[i] = ((SuggestWord) sugqueue.pop()).string;
+ String[] list = new String[sugQueue.size()];
+ for (int i = sugQueue.size() - 1; i >= 0; i--) {
+ list[i] = ((SuggestWord) sugQueue.pop()).string;
}
return list;