lucene-solr
lucene-solr copied to clipboard
LUCENE-8183: Added the abbility to get noSubMatches and noOverlapping Matches
Description
This is the solution for LUCENE-8183. The change is taken form the patch in the workitem.
Solution
New Parameters:
noSubMatches: true/false noOverlappingMatches: true/false together with the existing onlyLongestMatch those can be used to define what subwords should be added as tokens. Functionality is as described above.
Typically users will only want to include one of the three attributes as enabling noOverlappingMatches is the most restrictive and noSubMatches is more restrictive as onlyLongestMatch. When enabling a more restrictive option the state of the less restrictive does not have any effect.
Because of that it would be an option to refactor this to an single attribute with different setting, but this would require to think about backward compatibility for configurations that do use onlyLongestMatch=true at the moment.
Algorithm
If processing of subWords is deactivated (any of onlyLongestMatch, noSubMatches, noOverlappingMatches is active) the algorithm first checks if the token is part of the dictionary. If so it returns immediately. This is to avoid adding tokens for subwords if the token itself is in the dictionary (see #testNoSubAndTokenInDictionary for more info).
I changed the iteration direction of the inner for loop to start with the longest possible subword as this simplified the code.
NOTE: that this also changes the order of the Tokens in the token stream but as all tokens are at the same position that should not make any difference. I had however to modify some existing tests as those where sensitive to the ordering
Tests
I added two test methods in TestCompoundWordTokenFilter
- #testNoSubAndNoOverlap() tests the expected behaviour of the noSubMatches and noOverlappingMatches options
- #testNoSubAndTokenInDictionary() tests that no tokens for subwords are added in the case that the token in part of the dictionary
In addition TestHyphenationCompoundWordTokenFilterFactory#testLucene8183() asserts that the new configuration options are parsed.
Checklist
Please review the following and check all that apply:
- [x] I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
- [x] I have created a Jira issue and added the issue ID to my pull request title.
- [x] I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
- [x] I have developed this patch against the
master
branch. - [x] I have run
./gradlew check
. - [x] I have added tests for my changes.
- [ ] I have added documentation for the Ref Guide (for Solr changes only).