Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-2219 Translate Lucene analyzer definitions to their Elasticse…
…arch equivalent automatically There are a few gotchas, most notably: * parameters expecting a list of file paths only accept *one* file in Elasticsearch * the files targeted by file path parameters must be in the config directory of Elasticsearch, instead of being in the classpath * TypeTokenFilterFactory is not supported, because the "keep_types" parameter is a file path in Lucene, but an array of elements in Elasticsearch * HunspellStemFilterFactory is not supported, because the "dictionary" parameter is a list of files in Lucene, but does not exist in Elasticsearch (a "locale" parameter is expected instead) * A few parameters that are supported in Lucene but not in Elasticsearch will trigger an exception when used * For now, extra parameters that are not even supported by Lucene will not trigger any exception. This may change in the future.
- Loading branch information
Showing
36 changed files
with
2,073 additions
and
90 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...ava/org/hibernate/search/elasticsearch/analyzer/impl/CustomElasticsearchAnalyzerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.analyzer.impl; | ||
|
||
import org.hibernate.search.annotations.AnalyzerDef; | ||
|
||
/** | ||
* A description of an Elasticsearch analyzer built through an analyzer definition. | ||
* <p> | ||
* This implementation is used whenever {@code @Analyzer(definition = "foo")} is encountered | ||
* and an {@code @AnalyzerDefinition} exists with the given name ("foo" in this example). | ||
* | ||
* @author Guillaume Smet | ||
* @author Yoann Rodiere | ||
*/ | ||
public class CustomElasticsearchAnalyzerImpl implements ElasticsearchAnalyzer { | ||
|
||
private final AnalyzerDef definition; | ||
|
||
public CustomElasticsearchAnalyzerImpl(AnalyzerDef definition) { | ||
this.definition = definition; | ||
} | ||
|
||
@Override | ||
public String getName(String fieldName) { | ||
return definition.name(); | ||
} | ||
|
||
@Override | ||
public AnalyzerDef getDefinition(String fieldName) { | ||
return definition; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// nothing to close | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append( getClass().getSimpleName() ); | ||
sb.append( "<" ); | ||
sb.append( definition ); | ||
sb.append( ">" ); | ||
return sb.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
...main/java/org/hibernate/search/elasticsearch/analyzer/impl/ElasticsearchAnalyzerImpl.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
.../org/hibernate/search/elasticsearch/analyzer/impl/UndefinedElasticsearchAnalyzerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.analyzer.impl; | ||
|
||
import org.hibernate.search.annotations.AnalyzerDef; | ||
|
||
/** | ||
* An Elasticsearch analyzer for which no definition was found in the Hibernate Search mapping. | ||
* <p> | ||
* Such an analyzer is expected to be defined separately on Elasticsearch. | ||
* <p> | ||
* This implementation is used whenever {@code @Analyzer(definition = "foo")} is encountered | ||
* and <strong>no</strong> {@code @AnalyzerDefinition} exists with the given name | ||
* ("foo" in this example). | ||
* | ||
* @author Yoann Rodiere | ||
*/ | ||
public class UndefinedElasticsearchAnalyzerImpl implements ElasticsearchAnalyzer { | ||
|
||
private final String remoteName; | ||
|
||
public UndefinedElasticsearchAnalyzerImpl(String remoteName) { | ||
this.remoteName = remoteName; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public String getName(String fieldName) { | ||
return remoteName; | ||
} | ||
|
||
@Override | ||
public AnalyzerDef getDefinition(String fieldName) { | ||
// No definition | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.