-
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
Add support for inlined user dictionary in Nori #36123
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fd4a36a
Add support for inlined user dictionary in Nori
jimczi 41babe7
checkstyle
jimczi 450a578
add missing CONSOLE in docs
jimczi adecda4
Merge branch 'master' into nori_inlined_user_dict
jimczi adcee29
fix docs section
jimczi e618198
fix redundant end of section
jimczi 4ac0894
Merge branch 'master' into nori_inlined_user_dict
jimczi 3a97e16
Add an helper in Analysis to load the word list and check for duplica…
jimczi cb3ca2a
unused import
jimczi 39db1d9
fix error message
jimczi a2af275
Merge branch 'master' into nori_inlined_user_dict
jimczi 5fcfad4
address review
jimczi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,10 +29,14 @@ | |
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
import java.io.StringReader; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class NoriTokenizerFactory extends AbstractTokenizerFactory { | ||
private static final String USER_DICT_OPTION = "user_dictionary"; | ||
private static final String USER_DICT_PATH_OPTION = "user_dictionary"; | ||
private static final String USER_DICT_RULES_OPTION = "user_dictionary_rules"; | ||
|
||
private final UserDictionary userDictionary; | ||
private final KoreanTokenizer.DecompoundMode decompoundMode; | ||
|
@@ -44,14 +48,32 @@ public NoriTokenizerFactory(IndexSettings indexSettings, Environment env, String | |
} | ||
|
||
public static UserDictionary getUserDictionary(Environment env, Settings settings) { | ||
try (Reader reader = Analysis.getReaderFromFile(env, settings, USER_DICT_OPTION)) { | ||
if (reader == null) { | ||
if (settings.get(USER_DICT_PATH_OPTION) != null && settings.get(USER_DICT_RULES_OPTION) != null) { | ||
throw new ElasticsearchException("It is not allowed to use [" + USER_DICT_PATH_OPTION + "] in conjunction" + | ||
" with [" + USER_DICT_RULES_OPTION + "]"); | ||
|
||
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. nit: remove empty line. But I don't think its worth changing this if there are no other changes and CI is green, only if anything else needs changing anyway. |
||
} | ||
String path = settings.get(USER_DICT_PATH_OPTION); | ||
if (path != null) { | ||
try (Reader rulesReader = Analysis.getReaderFromFile(env, settings, USER_DICT_PATH_OPTION)) { | ||
return rulesReader == null ? null : UserDictionary.open(rulesReader); | ||
} catch (IOException e) { | ||
throw new ElasticsearchException("failed to load nori user dictionary", e); | ||
} | ||
} else { | ||
List<String> rulesList = settings.getAsList(USER_DICT_RULES_OPTION, Collections.emptyList(), false); | ||
if (rulesList == null || rulesList.size() == 0) { | ||
return null; | ||
} else { | ||
return UserDictionary.open(reader); | ||
} | ||
} catch (IOException e) { | ||
throw new ElasticsearchException("failed to load nori user dictionary", e); | ||
StringBuilder sb = new StringBuilder(); | ||
for (String line : rulesList) { | ||
sb.append(line).append(System.lineSeparator()); | ||
} | ||
try (Reader rulesReader = new StringReader(sb.toString())) { | ||
return UserDictionary.open(rulesReader); | ||
} catch (IOException e) { | ||
throw new ElasticsearchException("failed to load nori user dictionary", e); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For some reason this whole sections doesn't render when I build the docs locally. I played around with it a bit but couldn't get it to work but its probably worth taking another look.
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.
Good catch, thanks. I forgot to add the end of section (e.g.
--
) so the whole section was not displayed. I pushed adcee29 to fix this.