Skip to content

Apache Lucene open-source search software

rename HiFrequencyDictionary to HighFrequencyDictionary, and add numDocs to spellcheck handler response so that docfreqs can be converted from counts to frequencies, should the client be so inclined.

Mike Klaasdd538e63128d
diff --git a/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java b/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java
index 6efcde5a6c3..fb9c4a138b0 100644
--- a/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java
+++ b/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java
@@ -33,7 +33,7 @@ import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.util.HiFrequencyDictionary;
+import org.apache.solr.util.HighFrequencyDictionary;
import java.io.File;
import java.io.IOException;
@@ -305,7 +305,7 @@ public class SpellCheckerRequestHandler extends RequestHandlerBase {
throw new RuntimeException("'Extended results' must be a valid boolean", e);
}
- // when searching for more popular, a non null index-reader and
+ // when searching for more popular, a non null index-reader and
// restricted-field are required
if (onlyMorePopular || extendedResults) {
indexReader = req.getSearcher().getReader();
@@ -314,6 +314,8 @@ public class SpellCheckerRequestHandler extends RequestHandlerBase {
if (extendedResults) {
+ rsp.add("numDocs", indexReader.numDocs());
+
SimpleOrderedMap<Object> results = new SimpleOrderedMap<Object>();
String[] wordz = words.split(" ");
for (String word : wordz)
@@ -371,7 +373,7 @@ public class SpellCheckerRequestHandler extends RequestHandlerBase {
}
IndexReader indexReader = req.getSearcher().getReader();
- Dictionary dictionary = new HiFrequencyDictionary(indexReader, termSourceField, threshold);
+ Dictionary dictionary = new HighFrequencyDictionary(indexReader, termSourceField, threshold);
spellChecker.clearIndex();
spellChecker.indexDictionary(dictionary);
reopen();
diff --git a/src/java/org/apache/solr/util/HiFrequencyDictionary.java b/src/java/org/apache/solr/util/HighFrequencyDictionary.java
similarity index 93%
rename from src/java/org/apache/solr/util/HiFrequencyDictionary.java
rename to src/java/org/apache/solr/util/HighFrequencyDictionary.java
index e473d673946..838fc5c6cb6 100644
--- a/src/java/org/apache/solr/util/HiFrequencyDictionary.java
+++ b/src/java/org/apache/solr/util/HighFrequencyDictionary.java
@@ -42,29 +42,29 @@ import org.apache.lucene.search.spell.Dictionary;
* @author Nicolas Maisonneuve
* @author Christian Mallwitz
*/
-public class HiFrequencyDictionary implements Dictionary {
+public class HighFrequencyDictionary implements Dictionary {
private IndexReader reader;
private String field;
private float thresh;
- public HiFrequencyDictionary(IndexReader reader, String field, float thresh) {
+ public HighFrequencyDictionary(IndexReader reader, String field, float thresh) {
this.reader = reader;
this.field = field.intern();
this.thresh = thresh;
}
public final Iterator getWordsIterator() {
- return new HiFrequencyIterator();
+ return new HighFrequencyIterator();
}
- final class HiFrequencyIterator implements Iterator {
+ final class HighFrequencyIterator implements Iterator {
private TermEnum termEnum;
private Term actualTerm;
private boolean hasNextCalled;
private int minNumDocs;
- HiFrequencyIterator() {
+ HighFrequencyIterator() {
try {
termEnum = reader.terms(new Term(field, ""));
minNumDocs = (int)(thresh * (float)reader.numDocs());
diff --git a/src/test/org/apache/solr/handler/SpellCheckerRequestHandlerTest.java b/src/test/org/apache/solr/handler/SpellCheckerRequestHandlerTest.java
index cf53e68efee..3fc793ca08f 100644
--- a/src/test/org/apache/solr/handler/SpellCheckerRequestHandlerTest.java
+++ b/src/test/org/apache/solr/handler/SpellCheckerRequestHandlerTest.java
@@ -228,6 +228,7 @@ public class SpellCheckerRequestHandlerTest
assertQ("Failed to spell check",
req("cat")
+ ,"//int[@name='numDocs'][.=10]"
,"//lst[@name='cat']"
,"//lst[@name='cat']/int[@name='frequency'][.>0]"
,"//lst[@name='cat']/lst[@name='suggestions' and count(lst)=0]"
@@ -256,6 +257,7 @@ public class SpellCheckerRequestHandlerTest
lrf.args.put("sp.query.accuracy",".2");
assertQ("Failed to spell check",
req("cat")
+ ,"//int[@name='numDocs'][.=10]"
,"//lst[@name='cat']"
,"//lst[@name='cat']/int[@name='frequency'][.>0]"
,"//lst[@name='cat']/lst[@name='suggestions']/lst[@name='cart']/int[@name='frequency'][.>0]"
@@ -277,6 +279,7 @@ public class SpellCheckerRequestHandlerTest
/* The following is the generated XML response for the next query with three words:
<response>
<responseHeader><status>0</status><QTime>0</QTime></responseHeader>
+ <int name="numDocs">10</int>
<lst name="result">
<lst name="cat">
<int name="frequency">1</int>
@@ -351,6 +354,7 @@ public class SpellCheckerRequestHandlerTest
assertQ("Failed to spell check",
req("coat")
+ ,"//int[@name='numDocs'][.=10]"
,"//lst[@name='coat']"
,"//lst[@name='coat']/int[@name='frequency'][.=0]"
,"//lst[@name='coat']/lst[@name='suggestions' and count(lst)=0]"
@@ -383,6 +387,7 @@ public class SpellCheckerRequestHandlerTest
lrf.args.put("sp.query.accuracy",".2");
assertQ("Failed to spell check",
req("cet cert corp")
+ ,"//int[@name='numDocs'][.=10]"
,"//lst[@name='cet']"
,"//lst[@name='cet']/int[@name='frequency'][.=0]"
,"//lst[@name='cet']/lst[@name='suggestions']/lst[1]"