Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Solr4.3 #19

Merged
merged 2 commits into from
Jun 1, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Lucene/Solr Synonym-Expanding EDisMax Parser
=========================

Current version : 1.2.3 ([changelog][15])
Current version : 1.3.0 ([changelog][15])

Maintainer
-----------
Expand Down Expand Up @@ -37,6 +37,7 @@ Download the latest JAR file depending on your Solr version:
* [hon-lucene-synonyms-1.2.3-solr-3.x.jar][12] for Solr 3.4.0, 3.5.0, 3.6.0, 3.6.1, and 3.6.2
* [hon-lucene-synonyms-1.2.3-solr-4.0.0.jar][13] for Solr 4.0.0
* [hon-lucene-synonyms-1.2.3-solr-4.1.0.jar][14] for Solr 4.1.0 and 4.2.0
* [hon-lucene-synonyms-1.3.0-solr-4.3.0.jar][17] for Solr 4.3.0 (requires config change)

### Step 2

Expand Down Expand Up @@ -65,6 +66,8 @@ cd ..
Note that this plugin will not work in any location other than the ```WEB-INF/lib/``` directory of the ```solr.war```
itself, because of [issues with the ClassLoader][102].

**UPDATE**: We have tested to run with the jar in `$SOLR_HOME/lib` as well, and it works (Jetty).

### Step 5

Download [example_synonym_file.txt][5] and copy it to the ```solr/conf/``` directory
Expand All @@ -75,6 +78,7 @@ Download [example_synonym_file.txt][5] and copy it to the ```solr/conf/``` direc
Edit ```solr/conf/solrconfig.xml``` (```solr/collection1/conf/solrconfig.xml``` in 4.x) and add these lines near the
bottom (before ```</config>```):

#### Before version 1.3.0 (up to Solr 4.2.x):
```xml
<queryParser name="synonym_edismax" class="solr.SynonymExpandingExtendedDismaxQParserPlugin">
<str name="luceneMatchVersion">LUCENE_36</str>
Expand Down Expand Up @@ -105,6 +109,38 @@ bottom (before ```</config>```):
Note that you must modify the ```luceneMatchVersion``` above to match the
```<luceneMatchVersion>...</luceneMatchVersion>``` tag at the beginning of the ```solr/conf/solrconfig.xml``` file.

#### From version 1.3.0 and Solr 4.3 and beyond:
From version 1.3.0 for Solr 4.3.0 and beyond, there is a new way of loading Tokenizers and Token filters, and the XML format
is somewhat different:
```xml
<queryParser name="synonym_edismax" class="solr.SynonymExpandingExtendedDismaxQParserPlugin">
<lst name="synonymAnalyzers">
<lst name="myCoolAnalyzer">
<lst name="tokenizer">
<str name="class">standard</str>
<str name="luceneMatchVersion">LUCENE_43</str>
</lst>
<lst name="filter">
<str name="class">shingle</str>
<str name="luceneMatchVersion">LUCENE_43</str>
<str name="outputUnigramsIfNoShingles">true</str>
<str name="outputUnigrams">true</str>
<str name="minShingleSize">2</str>
<str name="maxShingleSize">4</str>
</lst>
<lst name="filter">
<str name="class">synonym</str>
<str name="luceneMatchVersion">LUCENE_43</str>
<str name="tokenizerFactory">solr.KeywordTokenizerFactory</str>
<str name="synonyms">example_synonym_file.txt</str>
<str name="expand">true</str>
<str name="ignoreCase">true</str>
</lst>
</lst>
</lst>
</queryParser>
```

### Step 7

Start up the app by running ```java -jar start.jar```. Jetty may print a ```ClassNotFoundException```, but
Expand Down Expand Up @@ -266,6 +302,10 @@ Currently I test against Solr 4.2.
Changelog
------------

* v1.3.0
* Added support for Solr 4.3.0 ([#219][219])
* New way of loading Tokenizers and TokenFilters
* New XML syntax for config in solrconfig.xml
* v1.2.3
* Fixed [#16][116]
* Verified support for Solr 4.2.0 with the 4.1.0 branch (unit tests passed)
Expand Down Expand Up @@ -297,9 +337,11 @@ Changelog
[14]: http://nolanlawson.s3.amazonaws.com/dist/org.healthonnet.lucene.synonyms/release/1.2.3-solr-4.1.0/hon-lucene-synonyms-1.2.3-solr-4.1.0.jar
[15]: https://github.com/healthonnet/hon-lucene-synonyms#changelog
[16]: http://wiki.apache.org/solr/DisMaxQParserPlugin#mm_.28Minimum_.27Should.27_Match.29
[17]: https://dl.dropboxusercontent.com/u/20080302/hon-lucene-synonyms-1.3.0-solr-4.3.0.jar
[101]: http://github.com/healthonnet/hon-lucene-synonyms/issues/1
[102]: http://github.com/healthonnet/hon-lucene-synonyms/issues/2
[103]: http://github.com/healthonnet/hon-lucene-synonyms/issues/3
[104]: http://github.com/healthonnet/hon-lucene-synonyms/issues/4
[105]: http://github.com/healthonnet/hon-lucene-synonyms/issues/5
[116]: http://github.com/healthonnet/hon-lucene-synonyms/issues/16
[219]: https://github.com/healthonnet/hon-lucene-synonyms/pull/19
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.healthonnet.lucene</groupId>
<artifactId>hon-lucene-synonyms</artifactId>
<version>1.2.3-solr-4.1.0</version>
<version>1.3.0-solr-4.3.0</version>
<dependencies>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr</artifactId>
<type>war</type>
<version>4.1.0</version>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>4.1.0</version>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.1.0</version>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.Version;
import org.apache.solr.analysis.TokenizerChain;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
Expand Down Expand Up @@ -98,15 +97,6 @@ public void inform(ResourceLoader loader) throws IOException {
// as a NamedList. But for now this is the hack I'm using
synonymAnalyzers = new HashMap<String, Analyzer>();

Object testMatchVersion = args.get("luceneMatchVersion");
Version luceneMatchVersion = null;
if (testMatchVersion == null || !(testMatchVersion instanceof String)) {
throw new SolrException(ErrorCode.SERVER_ERROR,
"luceneMatchVersion must be defined for the synonym_edismax parser");
} else {
luceneMatchVersion = Version.valueOf(args.get("luceneMatchVersion").toString());
}

Object xmlSynonymAnalyzers = args.get("synonymAnalyzers");

if (xmlSynonymAnalyzers != null && xmlSynonymAnalyzers instanceof NamedList) {
Expand Down Expand Up @@ -134,16 +124,12 @@ public void inform(ResourceLoader loader) throws IOException {

String className = params.get("class");
if (key.equals("tokenizer")) {
tokenizerFactory = (TokenizerFactory) loader.newInstance(className, TokenizerFactory.class);
tokenizerFactory.setLuceneMatchVersion(luceneMatchVersion);
tokenizerFactory.init(params);
tokenizerFactory = TokenizerFactory.forName(className, params);
if (tokenizerFactory instanceof ResourceLoaderAware) {
((ResourceLoaderAware)tokenizerFactory).inform(loader);
}
} else if (key.equals("filter")) {
TokenFilterFactory filterFactory = (TokenFilterFactory) loader.newInstance(className, TokenFilterFactory.class);
filterFactory.setLuceneMatchVersion(luceneMatchVersion);
filterFactory.init(params);
TokenFilterFactory filterFactory = TokenFilterFactory.forName(className, params);
if (filterFactory instanceof ResourceLoaderAware) {
((ResourceLoaderAware)filterFactory).inform(loader);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.apache.solr.search;

import org.junit.Assert;
import org.junit.Test;

import static junit.framework.Assert.*;

public class SynonymExpandingParserTest {

@Test
public void test1() throws ClassNotFoundException {
Class<?> cast = Class.forName("org.apache.solr.search.QParserPlugin");
Class<?> clazz = Class.forName("org.apache.solr.search.SynonymExpandingExtendedDismaxQParserPlugin");

Assert.assertTrue(cast.isAssignableFrom(clazz));
assertTrue(cast.isAssignableFrom(clazz));

}

Expand Down