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)
37. SOLR-604: If the spellchecking path is relative, make it relative to the Solr Data Directory. (Shalin Shekhar Mangar via gsingers)
Other Changes
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

View File

@ -504,7 +504,7 @@
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">spell</str>
<str name="spellcheckIndexDir">./spellchecker</str>
<str name="spellcheckIndexDir">./spellchecker1</str>
</lst>
<lst name="spellchecker">
@ -512,17 +512,17 @@
<str name="field">spell</str>
<!-- Use a different Distance Measure -->
<str name="distanceMeasure">org.apache.lucene.search.spell.JaroWinklerDistance</str>
<str name="spellcheckIndexDir">./spellchecker</str>
<str name="spellcheckIndexDir">./spellchecker2</str>
</lst>
<!--<lst name="spellchecker">
<lst name="spellchecker">
<str name="classname">solr.FileBasedSpellChecker</str>
<str name="name">external</str>
<str name="name">file</str>
<str name="sourceLocation">spellings.txt</str>
<str name="characterEncoding">UTF-8</str>
<str name="indexDir">./spellchecker</str>
</lst>-->
<str name="indexDir">./spellcheckerFile</str>
</lst>
</searchComponent>
<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 String instanceDir;
private String dataDir;
private final List<SolrCoreAware> waitingForCore = new ArrayList<SolrCoreAware>();
private final List<ResourceLoaderAware> waitingForResources = new ArrayList<ResourceLoaderAware>();
@ -123,6 +124,10 @@ public class SolrResourceLoader implements ResourceLoader
return instanceDir + "conf/";
}
public String getDataDir() {
return dataDir;
}
/** Opens a schema resource by its name.
* Override this method to customize loading schema resources.
*@return the stream for the named schema
@ -283,6 +288,7 @@ public class SolrResourceLoader implements ResourceLoader
*/
public void inform(SolrCore core)
{
this.dataDir = core.getDataDir();
for( SolrCoreAware aware : waitingForCore ) {
aware.inform( core );
}

View File

@ -1,23 +1,24 @@
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.index.IndexReader;
import org.apache.lucene.index.Term;
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.StringDistance;
import org.apache.lucene.search.spell.LevensteinDistance;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.solr.common.util.NamedList;
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.
@ -51,6 +52,12 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {
public String init(NamedList config, SolrResourceLoader loader) {
super.init(config, loader);
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);
field = (String) config.get(FIELD);
String strDistanceName = (String)config.get(STRING_DISTANCE);

View File

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

View File

@ -17,6 +17,11 @@
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.MapSolrParams;
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.SolrQueryResponse;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.spelling.IndexBasedSpellChecker;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.solr.util.AbstractSolrTestCase;
/**
* @since solr 1.3
@ -140,8 +141,6 @@ public class SpellCheckComponentTest extends AbstractSolrTestCase {
idx = blue.indexOf("suggestion", idx + 1);
assertTrue(idx + " does not equal: " + -1, idx == -1);
}
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
}

View File

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