Skip to content

Commit

Permalink
Merge pull request #2 from omc/dan/validation_analyzer
Browse files Browse the repository at this point in the history
Use the whitespace analyzer for synonym rule validation
  • Loading branch information
dansimpson authored Oct 15, 2020
2 parents b73726c + 474add9 commit a555ac3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
group = io.bonsai
publishedPluginVersion=1.0.0
pluginVersion=1.0.0
publishedPluginVersion=1.0.1
pluginVersion=1.0.1
esVersion=7.7.1
pluginName=stored-synonyms
pluginClassname=io.bonsai.plugins.synonyms.StoredSynonymsPlugin
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/bonsai/plugins/synonyms/StoredSynonyms.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.List;
import java.util.Optional;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.core.SimpleAnalyzer;
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.lucene.analysis.synonym.SolrSynonymParser;
import org.apache.lucene.analysis.synonym.SynonymMap;
import org.elasticsearch.rest.RestStatus;
Expand Down Expand Up @@ -66,7 +66,7 @@ public static SynonymMap parseSynonymMap(Analyzer analyzer, List<String> rules)
public static void validate(StoredSynonyms synonyms) {
SynonymMap map;
try {
map = parseSynonymMap(new SimpleAnalyzer(), synonyms.getRules());
map = parseSynonymMap(new WhitespaceAnalyzer(), synonyms.getRules());
} catch (Exception error) {
throw new StoredSynonymsException(error, RestStatus.UNPROCESSABLE_ENTITY);
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/io/bonsai/plugins/synonyms/RestTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public void testInvalidSynonyms() throws IOException {
.body(getResourceStr("files/invalid_synonyms.json"))
.execute()) {
Assert.assertEquals(422, curlResponse.getHttpStatusCode());
Assert.assertTrue(
curlResponse.getContentAsString().contains("Invalid synonym rule at line 1"));
Assert.assertTrue(curlResponse.getContentAsString().contains("No rules accepted"));
}
}
}
2 changes: 1 addition & 1 deletion src/test/resources/files/invalid_synonyms.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test",
"rules": [
"fancy,],pants,["
",=>,....,,,,,,"
]
}

0 comments on commit a555ac3

Please sign in to comment.