Class: MiniSearch::NgramTokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_search/ngram_tokenizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ NgramTokenizer

Returns a new instance of NgramTokenizer.



6
7
8
# File 'lib/mini_search/ngram_tokenizer.rb', line 6

def initialize(n)
  @n = n || 2
end

Instance Method Details

#execute(string) ⇒ Object



10
11
12
13
# File 'lib/mini_search/ngram_tokenizer.rb', line 10

def execute(string)
  # In the future, we may want to consider doing a strip on tokens to remove whitespace.
  string.ngrams(regex: //, n: @n).map(&:join)
end