g1.fuzzysearch(data, options) returns a fuzzy search function that filters
the data based on the text.
For example:
var data = [
{ product: "Cider Apple Vinegar" },
{ product: "JBL In-Ear Headphones" },
{ product: "Vaseline Body Lotion" },
{ product: "Redux Men's Watch" },
{ product: "Omega3 Fish Oil" },
];
var search = g1.fuzzysearch(data, {
keys: ["product"], // Search within these keys
limit: 2, // Return only the top 2 results
});
search("omega");
// Returns {product: "Omega3 Fish Oil", ...} since it's the only one
search("red");
// Returns {product: "Redux Men's Watch"} and {product: "JBL In-Ear Headphones"}
// The second matches r (in "Ear"), followed by e then d in "Headphones"
It matches with the following priority. For example, if the string is “alpha beta”, then:
It accepts an options dict with these keys:
keys: a list of keys to search in. The keys are calculated and joined with a
space. (Default: assumes that data is a string list.) Each key can be either:"name", "title") picks keys from the objects in the
data list.function (v) { return v['key'] })) runs the function on
each element in the data listlimit: the maximum number of results to return. (Default: 100)case: true for case-sensitive comparisons. (Default: false)