mirror of https://github.com/apache/lucene.git
SOLR-2726: Fixed NullPointerException when using spellcheck.q with Suggester
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1171597 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
edd8822929
commit
72106bb37b
|
@ -342,6 +342,8 @@ Bug Fixes
|
||||||
could commit too frequently and could block adds until a new seaercher was
|
could commit too frequently and could block adds until a new seaercher was
|
||||||
registered. (yonik)
|
registered. (yonik)
|
||||||
|
|
||||||
|
* SOLR-2726: Fixed NullPointerException when using spellcheck.q with Suggester.
|
||||||
|
(Bernd Fehling, valentin via rmuir)
|
||||||
|
|
||||||
Other Changes
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
|
@ -68,14 +68,11 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {
|
||||||
public static final String INDEX_DIR = "spellcheckIndexDir";
|
public static final String INDEX_DIR = "spellcheckIndexDir";
|
||||||
public static final String ACCURACY = "accuracy";
|
public static final String ACCURACY = "accuracy";
|
||||||
public static final String STRING_DISTANCE = "distanceMeasure";
|
public static final String STRING_DISTANCE = "distanceMeasure";
|
||||||
public static final String FIELD_TYPE = "fieldType";
|
|
||||||
public static final String COMPARATOR_CLASS = "comparatorClass";
|
public static final String COMPARATOR_CLASS = "comparatorClass";
|
||||||
|
|
||||||
public static final String SCORE_COMP = "score";
|
public static final String SCORE_COMP = "score";
|
||||||
public static final String FREQ_COMP = "freq";
|
public static final String FREQ_COMP = "freq";
|
||||||
|
|
||||||
protected String field;
|
|
||||||
protected String fieldTypeName;
|
|
||||||
protected org.apache.lucene.search.spell.SpellChecker spellChecker;
|
protected org.apache.lucene.search.spell.SpellChecker spellChecker;
|
||||||
|
|
||||||
protected String sourceLocation;
|
protected String sourceLocation;
|
||||||
|
@ -117,7 +114,6 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {
|
||||||
} else {
|
} else {
|
||||||
comp = SuggestWordQueue.DEFAULT_COMPARATOR;
|
comp = SuggestWordQueue.DEFAULT_COMPARATOR;
|
||||||
}
|
}
|
||||||
field = (String) config.get(FIELD);
|
|
||||||
String strDistanceName = (String)config.get(STRING_DISTANCE);
|
String strDistanceName = (String)config.get(STRING_DISTANCE);
|
||||||
if (strDistanceName != null) {
|
if (strDistanceName != null) {
|
||||||
sd = (StringDistance) core.getResourceLoader().newInstance(strDistanceName);
|
sd = (StringDistance) core.getResourceLoader().newInstance(strDistanceName);
|
||||||
|
@ -140,18 +136,6 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {
|
||||||
"Unparseable accuracy given for dictionary: " + name, e);
|
"Unparseable accuracy given for dictionary: " + name, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (field != null && core.getSchema().getFieldTypeNoEx(field) != null) {
|
|
||||||
analyzer = core.getSchema().getFieldType(field).getQueryAnalyzer();
|
|
||||||
}
|
|
||||||
fieldTypeName = (String) config.get(FIELD_TYPE);
|
|
||||||
if (core.getSchema().getFieldTypes().containsKey(fieldTypeName)) {
|
|
||||||
FieldType fieldType = core.getSchema().getFieldTypes().get(fieldTypeName);
|
|
||||||
analyzer = fieldType.getQueryAnalyzer();
|
|
||||||
}
|
|
||||||
if (analyzer == null) {
|
|
||||||
log.info("Using WhitespaceAnalzyer for dictionary: " + name);
|
|
||||||
analyzer = new WhitespaceAnalyzer(core.getSolrConfig().luceneMatchVersion);
|
|
||||||
}
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,6 @@ public class DirectSolrSpellChecker extends SolrSpellChecker {
|
||||||
public static final String COMPARATOR_CLASS = AbstractLuceneSpellChecker.COMPARATOR_CLASS;
|
public static final String COMPARATOR_CLASS = AbstractLuceneSpellChecker.COMPARATOR_CLASS;
|
||||||
public static final String SCORE_COMP = AbstractLuceneSpellChecker.SCORE_COMP;
|
public static final String SCORE_COMP = AbstractLuceneSpellChecker.SCORE_COMP;
|
||||||
public static final String FREQ_COMP = AbstractLuceneSpellChecker.FREQ_COMP;
|
public static final String FREQ_COMP = AbstractLuceneSpellChecker.FREQ_COMP;
|
||||||
public static final String FIELD = AbstractLuceneSpellChecker.FIELD;
|
|
||||||
public static final String FIELD_TYPE = AbstractLuceneSpellChecker.FIELD_TYPE;
|
|
||||||
public static final String STRING_DISTANCE = AbstractLuceneSpellChecker.STRING_DISTANCE;
|
public static final String STRING_DISTANCE = AbstractLuceneSpellChecker.STRING_DISTANCE;
|
||||||
public static final String ACCURACY = AbstractLuceneSpellChecker.ACCURACY;
|
public static final String ACCURACY = AbstractLuceneSpellChecker.ACCURACY;
|
||||||
public static final String THRESHOLD_TOKEN_FREQUENCY = IndexBasedSpellChecker.THRESHOLD_TOKEN_FREQUENCY;
|
public static final String THRESHOLD_TOKEN_FREQUENCY = IndexBasedSpellChecker.THRESHOLD_TOKEN_FREQUENCY;
|
||||||
|
@ -94,8 +92,6 @@ public class DirectSolrSpellChecker extends SolrSpellChecker {
|
||||||
public static final float DEFAULT_MAXQUERYFREQUENCY = 0.01f;
|
public static final float DEFAULT_MAXQUERYFREQUENCY = 0.01f;
|
||||||
|
|
||||||
private DirectSpellChecker checker = new DirectSpellChecker();
|
private DirectSpellChecker checker = new DirectSpellChecker();
|
||||||
private String field;
|
|
||||||
private String fieldTypeName;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String init(NamedList config, SolrCore core) {
|
public String init(NamedList config, SolrCore core) {
|
||||||
|
@ -118,21 +114,6 @@ public class DirectSolrSpellChecker extends SolrSpellChecker {
|
||||||
if (distClass != null && !distClass.equalsIgnoreCase(INTERNAL_DISTANCE))
|
if (distClass != null && !distClass.equalsIgnoreCase(INTERNAL_DISTANCE))
|
||||||
sd = (StringDistance) core.getResourceLoader().newInstance(distClass);
|
sd = (StringDistance) core.getResourceLoader().newInstance(distClass);
|
||||||
|
|
||||||
field = (String) config.get(FIELD);
|
|
||||||
// setup analyzer for field
|
|
||||||
if (field != null && core.getSchema().getFieldTypeNoEx(field) != null) {
|
|
||||||
analyzer = core.getSchema().getFieldType(field).getQueryAnalyzer();
|
|
||||||
}
|
|
||||||
fieldTypeName = (String) config.get(FIELD_TYPE);
|
|
||||||
if (core.getSchema().getFieldTypes().containsKey(fieldTypeName)) {
|
|
||||||
FieldType fieldType = core.getSchema().getFieldTypes().get(fieldTypeName);
|
|
||||||
analyzer = fieldType.getQueryAnalyzer();
|
|
||||||
}
|
|
||||||
if (analyzer == null) {
|
|
||||||
LOG.info("Using WhitespaceAnalyzer for dictionary: " + name);
|
|
||||||
analyzer = new WhitespaceAnalyzer(core.getSolrConfig().luceneMatchVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
float minAccuracy = DEFAULT_ACCURACY;
|
float minAccuracy = DEFAULT_ACCURACY;
|
||||||
Float accuracy = (Float) config.get(ACCURACY);
|
Float accuracy = (Float) config.get(ACCURACY);
|
||||||
if (accuracy != null)
|
if (accuracy != null)
|
||||||
|
|
|
@ -17,8 +17,10 @@ package org.apache.solr.spelling;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
|
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
|
import org.apache.solr.schema.FieldType;
|
||||||
import org.apache.solr.search.SolrIndexSearcher;
|
import org.apache.solr.search.SolrIndexSearcher;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -35,15 +37,31 @@ import java.io.IOException;
|
||||||
public abstract class SolrSpellChecker {
|
public abstract class SolrSpellChecker {
|
||||||
public static final String DICTIONARY_NAME = "name";
|
public static final String DICTIONARY_NAME = "name";
|
||||||
public static final String DEFAULT_DICTIONARY_NAME = "default";
|
public static final String DEFAULT_DICTIONARY_NAME = "default";
|
||||||
|
public static final String FIELD = "field";
|
||||||
|
public static final String FIELD_TYPE = "fieldType";
|
||||||
/** Dictionary name */
|
/** Dictionary name */
|
||||||
protected String name;
|
protected String name;
|
||||||
protected Analyzer analyzer;
|
protected Analyzer analyzer;
|
||||||
|
protected String field;
|
||||||
|
protected String fieldTypeName;
|
||||||
|
|
||||||
public String init(NamedList config, SolrCore core) {
|
public String init(NamedList config, SolrCore core) {
|
||||||
name = (String) config.get(DICTIONARY_NAME);
|
name = (String) config.get(DICTIONARY_NAME);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = DEFAULT_DICTIONARY_NAME;
|
name = DEFAULT_DICTIONARY_NAME;
|
||||||
}
|
}
|
||||||
|
field = (String)config.get(FIELD);
|
||||||
|
if (field != null && core.getSchema().getFieldTypeNoEx(field) != null) {
|
||||||
|
analyzer = core.getSchema().getFieldType(field).getQueryAnalyzer();
|
||||||
|
}
|
||||||
|
fieldTypeName = (String) config.get(FIELD_TYPE);
|
||||||
|
if (core.getSchema().getFieldTypes().containsKey(fieldTypeName)) {
|
||||||
|
FieldType fieldType = core.getSchema().getFieldTypes().get(fieldTypeName);
|
||||||
|
analyzer = fieldType.getQueryAnalyzer();
|
||||||
|
}
|
||||||
|
if (analyzer == null) {
|
||||||
|
analyzer = new WhitespaceAnalyzer(core.getSolrConfig().luceneMatchVersion);
|
||||||
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,6 @@ public class Suggester extends SolrSpellChecker {
|
||||||
* current IndexReader.
|
* current IndexReader.
|
||||||
*/
|
*/
|
||||||
public static final String LOCATION = "sourceLocation";
|
public static final String LOCATION = "sourceLocation";
|
||||||
/** Field to use as the source of terms if using IndexReader. */
|
|
||||||
public static final String FIELD = "field";
|
|
||||||
/** Fully-qualified class of the {@link Lookup} implementation. */
|
/** Fully-qualified class of the {@link Lookup} implementation. */
|
||||||
public static final String LOOKUP_IMPL = "lookupImpl";
|
public static final String LOOKUP_IMPL = "lookupImpl";
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +66,6 @@ public class Suggester extends SolrSpellChecker {
|
||||||
|
|
||||||
protected String sourceLocation;
|
protected String sourceLocation;
|
||||||
protected File storeDir;
|
protected File storeDir;
|
||||||
protected String field;
|
|
||||||
protected float threshold;
|
protected float threshold;
|
||||||
protected Dictionary dictionary;
|
protected Dictionary dictionary;
|
||||||
protected IndexReader reader;
|
protected IndexReader reader;
|
||||||
|
@ -83,7 +80,6 @@ public class Suggester extends SolrSpellChecker {
|
||||||
threshold = config.get(THRESHOLD_TOKEN_FREQUENCY) == null ? 0.0f
|
threshold = config.get(THRESHOLD_TOKEN_FREQUENCY) == null ? 0.0f
|
||||||
: (Float)config.get(THRESHOLD_TOKEN_FREQUENCY);
|
: (Float)config.get(THRESHOLD_TOKEN_FREQUENCY);
|
||||||
sourceLocation = (String) config.get(LOCATION);
|
sourceLocation = (String) config.get(LOCATION);
|
||||||
field = (String)config.get(FIELD);
|
|
||||||
lookupImpl = (String)config.get(LOOKUP_IMPL);
|
lookupImpl = (String)config.get(LOOKUP_IMPL);
|
||||||
|
|
||||||
// support the old classnames without -Factory for config file backwards compatibility.
|
// support the old classnames without -Factory for config file backwards compatibility.
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.File;
|
||||||
|
|
||||||
import org.apache.solr.SolrTestCaseJ4;
|
import org.apache.solr.SolrTestCaseJ4;
|
||||||
import org.apache.solr.common.params.SpellingParams;
|
import org.apache.solr.common.params.SpellingParams;
|
||||||
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -95,4 +96,13 @@ public class SuggesterTest extends SolrTestCaseJ4 {
|
||||||
assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
|
assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
|
||||||
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']");
|
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SOLR-2726
|
||||||
|
public void testAnalyzer() throws Exception {
|
||||||
|
Suggester suggester = new Suggester();
|
||||||
|
NamedList params = new NamedList();
|
||||||
|
params.add("lookupImpl", "org.apache.solr.spelling.suggest.tst.TSTLookupFactory");
|
||||||
|
suggester.init(params, h.getCore());
|
||||||
|
assertTrue(suggester.getQueryAnalyzer() != null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue