SOLR-604: Make relative spellchecking dir be relative to the Solr data dir. Also added sample file based sc to the example

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@670973 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2008-06-23 23:59:12 +00:00
parent a10b2432c3
commit e598716210
8 changed files with 71 additions and 25 deletions

View File

@ -440,6 +440,8 @@ Bug Fixes
36. SOLR-585: Now sets the QParser on the ResponseBuilder (gsingers) 36. SOLR-585: Now sets the QParser on the ResponseBuilder (gsingers)
37. SOLR-604: If the spellchecking path is relative, make it relative to the Solr Data Directory. (Shalin Shekhar Mangar via gsingers)
Other Changes Other Changes
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the 1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
build scripts to make two jars: apache-solr-1.3.jar and build scripts to make two jars: apache-solr-1.3.jar and

View File

@ -504,7 +504,7 @@
<lst name="spellchecker"> <lst name="spellchecker">
<str name="name">default</str> <str name="name">default</str>
<str name="field">spell</str> <str name="field">spell</str>
<str name="spellcheckIndexDir">./spellchecker</str> <str name="spellcheckIndexDir">./spellchecker1</str>
</lst> </lst>
<lst name="spellchecker"> <lst name="spellchecker">
@ -512,17 +512,17 @@
<str name="field">spell</str> <str name="field">spell</str>
<!-- Use a different Distance Measure --> <!-- Use a different Distance Measure -->
<str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str> <str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>
<str name="spellcheckIndexDir">./spellchecker</str> <str name="spellcheckIndexDir">./spellchecker2</str>
</lst> </lst>
<!--<lst name="spellchecker"> <lst name="spellchecker">
<str name="classname">solr.FileBasedSpellChecker</str> <str name="classname">solr.FileBasedSpellChecker</str>
<str name="name">external</str> <str name="name">file</str>
<str name="sourceLocation">spellings.txt</str> <str name="sourceLocation">spellings.txt</str>
<str name="characterEncoding">UTF-8</str> <str name="characterEncoding">UTF-8</str>
<str name="indexDir">./spellchecker</str> <str name="indexDir">./spellcheckerFile</str>
</lst>--> </lst>
</searchComponent> </searchComponent>
<queryConverter name="queryConverter" class="org.apache.solr.spelling.SpellingQueryConverter"/> <queryConverter name="queryConverter" class="org.apache.solr.spelling.SpellingQueryConverter"/>

View File

@ -0,0 +1,2 @@
pizza
history

View File

@ -64,6 +64,7 @@ public class SolrResourceLoader implements ResourceLoader
private final ClassLoader classLoader; private final ClassLoader classLoader;
private final String instanceDir; private final String instanceDir;
private String dataDir;
private final List<SolrCoreAware> waitingForCore = new ArrayList<SolrCoreAware>(); private final List<SolrCoreAware> waitingForCore = new ArrayList<SolrCoreAware>();
private final List<ResourceLoaderAware> waitingForResources = new ArrayList<ResourceLoaderAware>(); private final List<ResourceLoaderAware> waitingForResources = new ArrayList<ResourceLoaderAware>();
@ -123,6 +124,10 @@ public class SolrResourceLoader implements ResourceLoader
return instanceDir + "conf/"; return instanceDir + "conf/";
} }
public String getDataDir() {
return dataDir;
}
/** Opens a schema resource by its name. /** Opens a schema resource by its name.
* Override this method to customize loading schema resources. * Override this method to customize loading schema resources.
*@return the stream for the named schema *@return the stream for the named schema
@ -283,6 +288,7 @@ public class SolrResourceLoader implements ResourceLoader
*/ */
public void inform(SolrCore core) public void inform(SolrCore core)
{ {
this.dataDir = core.getDataDir();
for( SolrCoreAware aware : waitingForCore ) { for( SolrCoreAware aware : waitingForCore ) {
aware.inform( core ); aware.inform( core );
} }

View File

@ -1,23 +1,24 @@
package org.apache.solr.spelling; package org.apache.solr.spelling;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.apache.lucene.analysis.Token; import org.apache.lucene.analysis.Token;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.search.spell.Dictionary; import org.apache.lucene.search.spell.Dictionary;
import org.apache.lucene.search.spell.LevensteinDistance;
import org.apache.lucene.search.spell.SpellChecker; import org.apache.lucene.search.spell.SpellChecker;
import org.apache.lucene.search.spell.StringDistance; import org.apache.lucene.search.spell.StringDistance;
import org.apache.lucene.search.spell.LevensteinDistance;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.store.RAMDirectory;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrResourceLoader; import org.apache.solr.core.SolrResourceLoader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/** /**
* Abstract base class for all Lucene based spell checking implementations. * Abstract base class for all Lucene based spell checking implementations.
@ -51,6 +52,12 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {
public String init(NamedList config, SolrResourceLoader loader) { public String init(NamedList config, SolrResourceLoader loader) {
super.init(config, loader); super.init(config, loader);
indexDir = (String) config.get(INDEX_DIR); indexDir = (String) config.get(INDEX_DIR);
//If indexDir is relative then create index inside core.getDataDir()
if (indexDir != null) {
if (!new File(indexDir).isAbsolute()) {
indexDir = loader.getDataDir() + File.separator + indexDir;
}
}
sourceLocation = (String) config.get(LOCATION); sourceLocation = (String) config.get(LOCATION);
field = (String) config.get(FIELD); field = (String) config.get(FIELD);
String strDistanceName = (String)config.get(STRING_DISTANCE); String strDistanceName = (String)config.get(STRING_DISTANCE);

View File

@ -115,7 +115,7 @@ public class FileBasedSpellChecker extends AbstractLuceneSpellChecker {
analyzer = fieldType.getQueryAnalyzer(); analyzer = fieldType.getQueryAnalyzer();
} else { } else {
log.warning("No fieldType: " + fieldTypeName log.warning("No fieldType: " + fieldTypeName
+ " found for dictionary: " + name); + " found for dictionary: " + name + ". Using WhitespaceAnalzyer.");
analyzer = new WhitespaceAnalyzer(); analyzer = new WhitespaceAnalyzer();
// check if character encoding is defined // check if character encoding is defined

View File

@ -17,6 +17,11 @@
package org.apache.solr.handler.component; package org.apache.solr.handler.component;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.MapSolrParams; import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.ModifiableSolrParams;
@ -27,12 +32,8 @@ import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse; import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.request.SolrRequestHandler; import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.spelling.IndexBasedSpellChecker; import org.apache.solr.spelling.IndexBasedSpellChecker;
import org.apache.solr.util.AbstractSolrTestCase;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/** /**
* @since solr 1.3 * @since solr 1.3
@ -140,8 +141,6 @@ public class SpellCheckComponentTest extends AbstractSolrTestCase {
idx = blue.indexOf("suggestion", idx + 1); idx = blue.indexOf("suggestion", idx + 1);
assertTrue(idx + " does not equal: " + -1, idx == -1); assertTrue(idx + " does not equal: " + -1, idx == -1);
} }
public void test() throws Exception { public void test() throws Exception {
@ -282,6 +281,37 @@ public class SpellCheckComponentTest extends AbstractSolrTestCase {
} }
@SuppressWarnings("unchecked")
public void testRelativeIndexDirLocation() throws Exception {
SolrCore core = h.getCore();
Map<String, String> args = new HashMap<String, String>();
args.put(CommonParams.Q, "test");
args.put(CommonParams.QT, "spellCheckCompRH");
args.put(SpellCheckComponent.SPELLCHECK_BUILD, "true");
args.put(SpellCheckComponent.COMPONENT_NAME, "true");
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(
args));
File indexDir = new File(core.getDataDir() + File.separator
+ "spellchecker1");
assertTrue(
"spellcheckerIndexDir was not created inside the configured value for dataDir folder as configured in solrconfig.xml",
indexDir.exists());
indexDir = new File(core.getDataDir() + File.separator
+ "spellchecker2");
assertTrue(
"spellcheckerIndexDir was not created inside the configured value for dataDir folder as configured in solrconfig.xml",
indexDir.exists());
indexDir = new File(core.getDataDir() + File.separator
+ "spellchecker3");
assertTrue(
"spellcheckerIndexDir was not created inside the configured value for dataDir folder as configured in solrconfig.xml",
indexDir.exists());
}
// TODO: add more tests for various spelling options // TODO: add more tests for various spelling options
} }

View File

@ -331,8 +331,7 @@
<lst name="spellchecker"> <lst name="spellchecker">
<str name="name">default</str> <str name="name">default</str>
<str name="field">lowerfilt</str> <str name="field">lowerfilt</str>
<str name="spellcheckIndexDir">./spellchecker</str> <str name="spellcheckIndexDir">spellchecker1</str>
</lst> </lst>
<!-- Example of using different distance measure --> <!-- Example of using different distance measure -->
<lst name="spellchecker"> <lst name="spellchecker">
@ -340,7 +339,7 @@
<str name="field">lowerfilt</str> <str name="field">lowerfilt</str>
<!-- Use a different Distance Measure --> <!-- Use a different Distance Measure -->
<str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str> <str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>
<str name="spellcheckIndexDir">./spellchecker</str> <str name="spellcheckIndexDir">spellchecker2</str>
</lst> </lst>
<lst name="spellchecker"> <lst name="spellchecker">
@ -348,7 +347,7 @@
<str name="name">external</str> <str name="name">external</str>
<str name="sourceLocation">spellings.txt</str> <str name="sourceLocation">spellings.txt</str>
<str name="characterEncoding">UTF-8</str> <str name="characterEncoding">UTF-8</str>
<str name="spellcheckIndexDir">./spellchecker</str> <str name="spellcheckIndexDir">spellchecker3</str>
</lst> </lst>
</searchComponent> </searchComponent>
<!-- <!--