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.


git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@595184 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mike Klaas 2007-11-15 02:03:49 +00:00
parent c130be21ca
commit dd538e6312
3 changed files with 15 additions and 8 deletions

View File

@ -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;
@ -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();

View File

@ -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());

View File

@ -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]"