Skip to content

Commit

Permalink
Fix _analyze API to correctly use normalizers when specified (#48866)
Browse files Browse the repository at this point in the history
Currently the `_analyze` endpoint doesn't correctly use normalizers specified
in the request. This change fixes that by returning the resolved normalizer from
TransportAnalyzeAction#getAnalyzer and updates test to be able to catch this
in the future.

Closes #48650
  • Loading branch information
gaobinlong authored and Christoph Büscher committed Nov 14, 2019
1 parent e0df257 commit a666fb2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private static Analyzer getAnalyzer(AnalyzeAction.Request request, AnalysisRegis
if (analyzer == null) {
throw new IllegalArgumentException("failed to find normalizer under [" + request.normalizer() + "]");
}
return analyzer;
}
if (request.field() != null) {
if (indexService == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,14 @@ public void testCustomCharFilterWithParameters() throws IOException {
public void testNormalizerWithIndex() throws IOException {
AnalyzeAction.Request request = new AnalyzeAction.Request("index");
request.normalizer("my_normalizer");
request.text("ABc");
// this should be lowercased and only emit a single token
request.text("Wi-fi");
AnalyzeAction.Response analyze
= TransportAnalyzeAction.analyze(request, registry, mockIndexService(), maxTokenCount);
List<AnalyzeAction.AnalyzeToken> tokens = analyze.getTokens();

assertEquals(1, tokens.size());
assertEquals("abc", tokens.get(0).getTerm());
assertEquals("wi-fi", tokens.get(0).getTerm());
}

/**
Expand Down

0 comments on commit a666fb2

Please sign in to comment.