-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Analysis] Support normalizer in request param #24767
Changes from all commits
012749d
6dc62f5
37bb2f1
c6dd360
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,9 @@ public void setUp() throws Exception { | |
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) | ||
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) | ||
.put("index.analysis.analyzer.custom_analyzer.tokenizer", "standard") | ||
.put("index.analysis.analyzer.custom_analyzer.filter", "mock").build(); | ||
.put("index.analysis.analyzer.custom_analyzer.filter", "mock") | ||
.put("index.analysis.normalizer.my_normalizer.type", "custom") | ||
.putArray("index.analysis.normalizer.my_normalizer.filter", "lowercase").build(); | ||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", indexSettings); | ||
environment = new Environment(settings); | ||
AnalysisPlugin plugin = new AnalysisPlugin() { | ||
|
@@ -304,6 +306,14 @@ public void testUnknown() throws IOException { | |
} else { | ||
assertEquals(e.getMessage(), "failed to find global char filter under [foobar]"); | ||
} | ||
|
||
e = expectThrows(IllegalArgumentException.class, | ||
() -> TransportAnalyzeAction.analyze( | ||
new AnalyzeRequest() | ||
.normalizer("foobar") | ||
.text("the qu1ck brown fox"), | ||
AllFieldMapper.NAME, null, indexAnalyzers, registry, environment)); | ||
assertEquals(e.getMessage(), "failed to find normalizer under [foobar]"); | ||
} | ||
|
||
public void testNonPreBuildTokenFilter() throws IOException { | ||
|
@@ -317,6 +327,16 @@ public void testNonPreBuildTokenFilter() throws IOException { | |
int default_bucket_size = 512; | ||
int default_hash_set_size = 1; | ||
assertEquals(default_hash_count * default_bucket_size * default_hash_set_size, tokens.size()); | ||
} | ||
|
||
public void testNormalizerWithIndex() throws IOException { | ||
AnalyzeRequest request = new AnalyzeRequest("index"); | ||
request.normalizer("my_normalizer"); | ||
request.text("ABc"); | ||
AnalyzeResponse analyze = TransportAnalyzeAction.analyze(request, AllFieldMapper.NAME, null, indexAnalyzers, registry, environment); | ||
List<AnalyzeResponse.AnalyzeToken> tokens = analyze.getTokens(); | ||
|
||
assertEquals(1, tokens.size()); | ||
assertEquals("abc", tokens.get(0).getTerm()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to add a test for the second code path added in this PR (the case where normalizer == null but filter or char_filter is not null and tokenizer/analyzer is null)? I don't know if it is possible with this test setup but it might be useful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I added that test case in rest api test. Now, we are moving to filter/char_filter to analysis-common module, so I think it would be better than in this test class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for this parsing part to RestAnalyzeActionTests?