-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the char_group tokenizer (#3427)
(cherry picked from commit 9ab4384)
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace Nest | ||
{ | ||
/// <summary> | ||
/// A tokenizer that breaks text into terms whenever it encounters a character which is in a defined set. It is mostly useful | ||
/// for cases where a simple custom tokenization is desired, and the overhead of use of <see cref="PatternTokenizer"/> is not acceptable. | ||
/// </summary> | ||
public interface ICharGroupTokenizer : ITokenizer | ||
{ | ||
/// <summary> | ||
/// A list containing a list of characters to tokenize the string on. Whenever a character from this list is encountered, a | ||
/// new token is started. This accepts either single characters like eg. -, or character groups: whitespace, letter, digit, | ||
/// punctuation, symbol. | ||
/// </summary> | ||
[JsonProperty("tokenize_on_chars")] | ||
IEnumerable<string> TokenizeOnCharacters { get; set; } | ||
} | ||
|
||
/// <inheritdoc cref="ICharGroupTokenizer"/> | ||
public class CharGroupTokenizer : TokenizerBase, ICharGroupTokenizer | ||
{ | ||
internal const string TokenizerType = "char_group"; | ||
|
||
public CharGroupTokenizer() => this.Type = TokenizerType; | ||
|
||
/// <inheritdoc cref="ICharGroupTokenizer.TokenizeOnCharacters"/> | ||
public IEnumerable<string> TokenizeOnCharacters { get; set; } | ||
} | ||
|
||
/// <inheritdoc cref="ICharGroupTokenizer"/> | ||
public class CharGroupTokenizerDescriptor | ||
: TokenizerDescriptorBase<CharGroupTokenizerDescriptor, ICharGroupTokenizer>, ICharGroupTokenizer | ||
{ | ||
protected override string Type => CharGroupTokenizer.TokenizerType; | ||
|
||
IEnumerable<string> ICharGroupTokenizer.TokenizeOnCharacters { get; set; } | ||
|
||
/// <inheritdoc cref="ICharGroupTokenizer.TokenizeOnCharacters"/> | ||
public CharGroupTokenizerDescriptor TokenizeOnCharacters(params string[] characters) => | ||
Assign(a => a.TokenizeOnCharacters = characters); | ||
|
||
/// <inheritdoc cref="ICharGroupTokenizer.TokenizeOnCharacters"/> | ||
public CharGroupTokenizerDescriptor TokenizeOnCharacters(IEnumerable<string> characters) => | ||
Assign(a => a.TokenizeOnCharacters = 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
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