mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Issue 1233: product filter should only match if name begins withs search term
This commit is contained in:
committed by
Rob Harrington
parent
699da16049
commit
7a07e8fa16
@@ -5,4 +5,4 @@ Darkswarm.filter 'products', (Matcher) ->
|
||||
return products if text == ""
|
||||
products.filter (product) =>
|
||||
propertiesToMatch = [product.name, product.variant_names, product.supplier.name, product.primary_taxon.name]
|
||||
Matcher.match propertiesToMatch, text
|
||||
Matcher.matchBeginning propertiesToMatch, text
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
Darkswarm.factory "Matcher", ->
|
||||
# Match text fragment in an array of strings.
|
||||
new class Matcher
|
||||
|
||||
# Match text fragment in an array of strings.
|
||||
match: (properties, text)->
|
||||
properties.some (prop)->
|
||||
prop ||= ""
|
||||
prop.toLowerCase().indexOf(text.toLowerCase()) != -1
|
||||
|
||||
# Return true if text occurs at the beginning of any word present in an array of strings
|
||||
matchBeginning: (properties, text) ->
|
||||
text = text.trim()
|
||||
properties.some (prop) ->
|
||||
prop ||= ""
|
||||
prop.split(' ').some (word) ->
|
||||
word.toLowerCase().indexOf(text.toLowerCase()) == 0
|
||||
|
||||
Reference in New Issue
Block a user