Closed marbemac closed 1 year ago
Hey @marbemac . This is a great point, and a really useful patch. Thanks for contributing it!
I have a few suggestions of cosmetic changes to keep this in the style of the rest of the plugin. Would you be willing to make them?
Can we add a couple helper methods to Query to make willHaveResults
read more clearly:
_isStopWord: ->
(@_firstWord() in @stopWords) && (@value.length < @_firstWord().length + @minLength)
_firstWord: ->
@value.split(' ')[0]
Then, willHaveResults
will read:
willHaveResults: ->
@_isValid() && !@_isEmpty() && !@_isStopWord()
I've also changed the 3
to be @minLength
, though I may have miss-understood that constant.
Also, it would be pretty sweet to have a couple quick specs to ensure that willHaveResults
properly exhibits the new behaviour. If you check out the bottom of spec/query_spec.coffee
, it should be clear how to add those specs without any pain. Maybe something like:
it 'is false if the current value is a stop word'
...
Anyway, whether you find time for that or not, thanks for the contribution!
Cheers, Mitch
Soulmate treats "vs", "at", and "the" as stop words, removing them from the combinations in redis.
Right now if one searches for "The Dark Knight" soulmate.js will stop searching when "the" returns no results. A search for "dark knight" will return the correct results.
This small patch makes soulmate.js essentially ignore stop words at the start of the search query.
Signed-off-by: Marc MacLeod marbemac@gmail.com