Skip to content

Commit

Permalink
HSEARCH-2434 Configure server-defined analyzers directly in tests ins…
Browse files Browse the repository at this point in the history
…tead of doing so in elasticsearch.yml

This is required for ES5, where analyzers cannot be configured in
elasticsearch.yml.
  • Loading branch information
yrodiere committed Mar 21, 2017
1 parent 6258e79 commit 088e004
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
import org.hibernate.search.elasticsearch.testutil.TestElasticsearchClient;
import org.hibernate.search.test.SearchTestBase;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.google.gson.JsonParser;

/**
* Test the use of Elasticsearch built-in and server-defined, custom analyzers,
* <strong>without</strong> using {@link AnalyzerDef}.
Expand All @@ -37,6 +42,43 @@
*/
public class ElasticsearchAnalyzerIT extends SearchTestBase {

@Rule
public TestElasticsearchClient elasticsearchClient = new TestElasticsearchClient();

@Override
@Before
public void setUp() throws Exception {
// Make sure automatically created indexes will have the "server-defined-custom-analyzer" analyzer definition
elasticsearchClient.template( "server-defined-custom-analyzer" )
.create(
"*",
new JsonParser().parse(
"{"
+ "'index': {"
+ "'analysis': {"
+ "'analyzer': {"
+ "'server-defined-custom-analyzer': {"
+ "'char_filter': ['html_strip'],"
+ "'tokenizer': 'standard',"
+ "'filter': ['server-defined-custom-filter', 'lowercase']"
+ "}"
+ "},"
+ "'filter': {"
+ "'server-defined-custom-filter': {"
+ "'type': 'stop',"
+ "'stopwords': ['test1', 'close']"
+ "}"
+ "}"
+ "}"
+ "}"
+ "}"
)
.getAsJsonObject()
);

super.setUp();
}

@Test
public void testDefaultAnalyzer() throws Exception {
try ( Session session = openSession() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,3 @@ index.number_of_replicas: 0

# Enable Groovy scripting support for search: useful for spatial queries
script.engine.groovy.inline.search: on

# Custom analyzer used in tests
# See ElasticsearchAnalyzerIT
index.analysis:
analyzer:
server-defined-custom-analyzer:
type: custom
tokenizer: standard
filter: [server-defined-custom-filter, lowercase]
filter:
server-defined-custom-filter:
type : stop
stopwords : [test1, close]

0 comments on commit 088e004

Please sign in to comment.