Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect step size when string is longer than the number of n-grams desired #18

Open
dblock opened this issue Feb 26, 2014 · 0 comments
Labels

Comments

@dblock
Copy link
Contributor

dblock commented Feb 26, 2014

In https://github.com/artsy/mongoid_fulltext/blob/master/lib/mongoid_fulltext.rb:

# Figure out how many ngrams to extract from the string. If we can't afford to extract all ngrams,
# step over the string in evenly spaced strides to extract ngrams. For example, to extract 3 3-letter
# ngrams from 'abcdefghijk', we'd want to extract 'abc', 'efg', and 'ijk'.
if bound_number_returned
   step_size = [((filtered_str.length - config[:ngram_width]).to_f / config[:max_ngrams_to_search]).ceil, 1].max
else
   step_size = 1
end

If we want to get 3 n-grams: abc, efg and ijk from abcdefghijk (11) we need a step of 4, not 3.

(11.to_f - 3) / 3 = 2.6, ceil to 3

I think this needs to not do - config[:ngram_width].

However, I wonder whether the comment is incorrect and we want the first 3 n-grams instead of skipping characters.

cc: @aaw

@dblock dblock added the bug? label Sep 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant