From 9cfae84454c03edbe77d5d7506d2954fd3199898 Mon Sep 17 00:00:00 2001 From: philippus Date: Sat, 11 May 2024 23:41:25 +0200 Subject: [PATCH] Add tests for synonym token filters --- .../synonymgraphtokenfilter_path_raw.json | 10 ++++ .../synonymgraphtokenfilter_synonyms_raw.json | 13 +++++ .../synonymtokenfilter_path_raw.json | 10 ++++ .../synonymtokenfilter_synonyms_raw.json | 13 +++++ .../elastic4s/analysis/TokenFilterTest.scala | 58 +++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymgraphtokenfilter_path_raw.json create mode 100644 elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymgraphtokenfilter_synonyms_raw.json create mode 100644 elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymtokenfilter_path_raw.json create mode 100644 elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymtokenfilter_synonyms_raw.json diff --git a/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymgraphtokenfilter_path_raw.json b/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymgraphtokenfilter_path_raw.json new file mode 100644 index 000000000..889d49c85 --- /dev/null +++ b/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymgraphtokenfilter_path_raw.json @@ -0,0 +1,10 @@ +{ + "type": "synonym_graph", + "synonyms_path": "analysis/synonyms.txt", + "format": "solr", + "ignore_case": true, + "updateable": true, + "expand": true, + "lenient": true, + "tokenizer": "whitespace" +} diff --git a/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymgraphtokenfilter_synonyms_raw.json b/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymgraphtokenfilter_synonyms_raw.json new file mode 100644 index 000000000..a924de1e8 --- /dev/null +++ b/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymgraphtokenfilter_synonyms_raw.json @@ -0,0 +1,13 @@ +{ + "type": "synonym_graph", + "synonyms": [ + "british,english", + "queen,monarch" + ], + "format": "solr", + "ignore_case": true, + "updateable": true, + "expand": true, + "lenient": true, + "tokenizer": "whitespace" +} diff --git a/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymtokenfilter_path_raw.json b/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymtokenfilter_path_raw.json new file mode 100644 index 000000000..60d4292a0 --- /dev/null +++ b/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymtokenfilter_path_raw.json @@ -0,0 +1,10 @@ +{ + "type": "synonym", + "synonyms_path": "analysis/synonyms.txt", + "format": "solr", + "ignore_case": true, + "updateable": true, + "expand": true, + "lenient": true, + "tokenizer": "whitespace" +} diff --git a/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymtokenfilter_synonyms_raw.json b/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymtokenfilter_synonyms_raw.json new file mode 100644 index 000000000..77446c89e --- /dev/null +++ b/elastic4s-tests/src/test/resources/json/analysis/tokenfilter/synonymtokenfilter_synonyms_raw.json @@ -0,0 +1,13 @@ +{ + "type": "synonym", + "synonyms": [ + "british,english", + "queen,monarch" + ], + "format": "solr", + "ignore_case": true, + "updateable": true, + "expand": true, + "lenient": true, + "tokenizer": "whitespace" +} diff --git a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/analysis/TokenFilterTest.scala b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/analysis/TokenFilterTest.scala index 50874d4e7..9341c833d 100644 --- a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/analysis/TokenFilterTest.scala +++ b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/analysis/TokenFilterTest.scala @@ -5,6 +5,64 @@ import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec class TokenFilterTest extends AnyWordSpec with Matchers with JsonSugar { + "SynonymTokenFilter" should { + "build json with synonyms" in { + SynonymTokenFilter( + name = "my_synonym", + path = Option("analysis/synonyms.txt"), + synonyms = Set("british,english", "queen,monarch"), + ignoreCase = Option(true), + format = Option("solr"), + expand = Option(true), + tokenizer = Option("whitespace"), + updateable = Option(true), + lenient = Option(true) + ).build.string should matchJsonResource("/json/analysis/tokenfilter/synonymtokenfilter_synonyms_raw.json") + } + + "build json with path" in { + SynonymTokenFilter( + name = "my_synonym", + path = Option("analysis/synonyms.txt"), + ignoreCase = Option(true), + format = Option("solr"), + expand = Option(true), + tokenizer = Option("whitespace"), + updateable = Option(true), + lenient = Option(true) + ).build.string should matchJsonResource("/json/analysis/tokenfilter/synonymtokenfilter_path_raw.json") + } + } + + "SynonymGraphTokenFilter" should { + "build json with synonyms" in { + SynonymGraphTokenFilter( + name = "my_synonym", + path = Option("analysis/synonyms.txt"), + synonyms = Set("british,english", "queen,monarch"), + ignoreCase = Option(true), + format = Option("solr"), + expand = Option(true), + tokenizer = Option("whitespace"), + updateable = Option(true), + lenient = Option(true) + ).build.string should matchJsonResource("/json/analysis/tokenfilter/synonymgraphtokenfilter_synonyms_raw.json") + } + + "build json with path" in { + SynonymGraphTokenFilter( + name = "my_synonym", + path = Option("analysis/synonyms.txt"), + ignoreCase = Option(true), + format = Option("solr"), + expand = Option(true), + tokenizer = Option("whitespace"), + updateable = Option(true), + lenient = Option(true) + ).build.string should matchJsonResource("/json/analysis/tokenfilter/synonymgraphtokenfilter_path_raw.json") + } + } + "WordDelimiterGraphTokenFilter" should { "build json" in { WordDelimiterGraphTokenFilter(