You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by kl...@apache.org on 2007/10/18 01:55:01 UTC
svn commit: r585760 -
/lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java
Author: klaas
Date: Wed Oct 17 16:55:01 2007
New Revision: 585760
URL: http://svn.apache.org/viewvc?rev=585760&view=rev
Log:
honour onlyMorePopular flag SOLR-382
Modified:
lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java
Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java?rev=585760&r1=585759&r2=585760&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java Wed Oct 17 16:55:01 2007
@@ -64,8 +64,6 @@
* return only the words more frequent than this.
*
*/
- private static IndexReader nullReader = null;
- private String restrictToField = null;
private boolean onlyMorePopular = false;
private Directory spellcheckerIndexDir = new RAMDirectory();
@@ -73,7 +71,8 @@
private String termSourceField;
private static final float DEFAULT_ACCURACY = 0.5f;
private static final int DEFAULT_NUM_SUGGESTIONS = 1;
-
+ private static final boolean DEFAULT_MORE_POPULAR = false;
+
public void init(NamedList args) {
super.init(args);
SolrParams p = SolrParams.toSolrParams(args);
@@ -116,6 +115,8 @@
}
}
+ IndexReader indexReader = null;
+ String suggestionField = null;
Float accuracy;
int numSug;
try {
@@ -129,11 +130,24 @@
} catch (NumberFormatException e) {
throw new RuntimeException("Spelling suggestion count must be a valid positive integer", e);
}
+ try {
+ onlyMorePopular = p.getBool("onlyMorePopular", DEFAULT_MORE_POPULAR);
+ } catch (NumberFormatException e) {
+ throw new RuntimeException("'Only more popular' must be a valid boolean", e);
+ }
+
+ // when searching for more popular, a non null index-reader and
+ // restricted-field are required
+ if (onlyMorePopular) {
+ indexReader = req.getSearcher().getReader();
+ suggestionField = termSourceField;
+ }
+
if (null != words && !"".equals(words.trim())) {
String[] suggestions =
spellChecker.suggestSimilar(words, numSug,
- nullReader, restrictToField,
+ indexReader, suggestionField,
onlyMorePopular);
rsp.add("suggestions", Arrays.asList(suggestions));