Build and register custom text analyzers from Tantivy builtins #425
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.
This PR adds the ability to build new text analyzers using Tantivy's builtin tokenizers and filters, as listed in the tokenizer module docs (https://docs.rs/tantivy/latest/tantivy/tokenizer/index.html). New analyzers are registered with an index by name. The registered name links analyzers to the tokenizer name specified by text fields in the index's schema.
Here is an example:
Building a text analyzer happens through an interface that (more or less) follows Tantivy's design. I had to deviate from it in some places, usually because of some mismatch between Rust's way of doing things and what PyO3 permits.
Differences:
Tokenizer.simple()
,Tokenizer.raw()
, etc... instead of Tantivy'sSimpleTokenizer
,RawTokenizer
, etc.Filter.lowercase()
instead of Tantivy'sLowerCaser
. Why: same reason as previous point.index.register_tokenizer()
instead of Tantivy'sindex.tokenizers().register()
. The extra indirection didn't seem worth it to me.SchemaBuilder
directly instead of asSchema.builder()
(the Tantivy way), my design instantiatesTextAnalyzerBuilder
directly, instead of asTextAnalyzer.builder()
Extras:
State of this PR:
Next steps:
Random: