simplepatternsplit-tokenizer.asciidoc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. [[analysis-simplepatternsplit-tokenizer]]
  2. === Simple Pattern Split Tokenizer
  3. experimental[This functionality is marked as experimental in Lucene]
  4. The `simple_pattern_split` tokenizer uses a regular expression to split the
  5. input into terms at pattern matches. The set of regular expression features it
  6. supports is more limited than the <<analysis-pattern-tokenizer,`pattern`>>
  7. tokenizer, but the tokenization is generally faster.
  8. This tokenizer does not produce terms from the matches themselves. To produce
  9. terms from matches using patterns in the same restricted regular expression
  10. subset, see the <<analysis-simplepattern-tokenizer,`simple_pattern`>>
  11. tokenizer.
  12. This tokenizer uses {lucene-core-javadoc}/org/apache/lucene/util/automaton/RegExp.html[Lucene regular expressions].
  13. For an explanation of the supported features and syntax, see <<regexp-syntax,Regular Expression Syntax>>.
  14. The default pattern is the empty string, which produces one term containing the
  15. full input. This tokenizer should always be configured with a non-default
  16. pattern.
  17. [float]
  18. === Configuration
  19. The `simple_pattern_split` tokenizer accepts the following parameters:
  20. [horizontal]
  21. `pattern`::
  22. A {lucene-core-javadoc}/org/apache/lucene/util/automaton/RegExp.html[Lucene regular expression], defaults to the empty string.
  23. [float]
  24. === Example configuration
  25. This example configures the `simple_pattern_split` tokenizer to split the input
  26. text on underscores.
  27. [source,js]
  28. ----------------------------
  29. PUT my_index
  30. {
  31. "settings": {
  32. "analysis": {
  33. "analyzer": {
  34. "my_analyzer": {
  35. "tokenizer": "my_tokenizer"
  36. }
  37. },
  38. "tokenizer": {
  39. "my_tokenizer": {
  40. "type": "simple_pattern_split",
  41. "pattern": "_"
  42. }
  43. }
  44. }
  45. }
  46. }
  47. POST my_index/_analyze
  48. {
  49. "analyzer": "my_analyzer",
  50. "text": "an_underscored_phrase"
  51. }
  52. ----------------------------
  53. // CONSOLE
  54. /////////////////////
  55. [source,console-result]
  56. ----------------------------
  57. {
  58. "tokens" : [
  59. {
  60. "token" : "an",
  61. "start_offset" : 0,
  62. "end_offset" : 2,
  63. "type" : "word",
  64. "position" : 0
  65. },
  66. {
  67. "token" : "underscored",
  68. "start_offset" : 3,
  69. "end_offset" : 14,
  70. "type" : "word",
  71. "position" : 1
  72. },
  73. {
  74. "token" : "phrase",
  75. "start_offset" : 15,
  76. "end_offset" : 21,
  77. "type" : "word",
  78. "position" : 2
  79. }
  80. ]
  81. }
  82. ----------------------------
  83. /////////////////////
  84. The above example produces these terms:
  85. [source,text]
  86. ---------------------------
  87. [ an, underscored, phrase ]
  88. ---------------------------