Global

Methods

quickScore(string, query, matchesopt, transformedStringopt, transformedQueryopt, configopt, stringRangeopt) → {number}

Scores a string against a query.

Parameters:
Name Type Attributes Description
string string

The string to score.

query string

The query string to score the string parameter against.

matches Array.<RangeTuple> <optional>

If supplied, quickScore() will push onto matches an array with start and end indexes for each substring range of string that matches query. These indexes can be used to highlight the matching characters in an auto-complete UI.

transformedString string <optional>

A transformed version of the string that will be used for matching. This defaults to a lowercase version of string, but it could also be used to match against a string with all the diacritics removed, so an unaccented character in the query would match an accented one in the string.

transformedQuery string <optional>

A transformed version of query. The same transformation applied to transformedString should be applied to this parameter, or both can be left as undefined for the default lowercase transformation.

config object <optional>

A configuration object that can modify how the quickScore algorithm behaves.

stringRange Range <optional>

The range of characters in string that should be checked for matches against query. Defaults to the entire string parameter.

Source:
Returns:

A number between 0 and 1 that represents how well the query matches the string.

Type
number

Type Definitions

ItemKey

A reference to an item's key to search. This type can also include a custom scoring function to use for the given key.

Type:
Properties:
Name Type Attributes Description
name KeyName <optional>

The name of a key to search.

scorer ScorerFunction <optional>

The function that will be used to score the named string.

Source:

KeyName

A reference to an item's key to search. The key names can point to a nested key by passing either a dot-delimited string or an array of sub-keys that specify the path to the value.

Type:
  • string | Array.<string>
Source:

Options

An object specifying various options that can customize QuickScore's scoring behavior.

Type:
  • object
Properties:
Name Type Attributes Description
keys Array.<ItemKey> <optional>

An array that specifies which keys to search.

sortKey string <optional>

The name of the key that will be used to sort items with identical scores.

minimumScore number <optional>

The minimum score an item must have to appear in the results returned from search().

transformString TransformStringFunction <optional>

A function that takes a string parameter and returns a transformed version of that string.

scorer ScorerFunction <optional>

A function that takes string and query parameters and returns a floating point number between 0 and 1 that represents how well the query matches the string.

config Config <optional>

An object that is passed to the scorer function to further customize its behavior.

Source:

RangeTuple

A tuple containing a range's start and end indexes.

Type:
  • Array.<number>
Properties:
Name Type Description
0 number

Start index.

1 number

End index.

Source:

ScoredObject

An object representing the results of scoring an items array that contains objects.

Type:
  • object
Properties:
Name Type Description
item object

The object that was scored.

score number

The highest score from among the individual key scores.

scoreKey string

The name of the key with the highest score, which will be an empty string if they're all zero.

scoreValue string

The value of the key with the highest score, which makes it easier to access if it's a nested string.

scores object

A hash of the individual scores for each key.

matches object

A hash of arrays that specify the character ranges of the query match for each key.

_ object

An internal cache of the transformed versions of this item's strings and other metadata, which can be ignored.

Source:

ScoredString

An object representing the results of scoring an items array that contains strings.

Type:
  • object
Properties:
Name Type Description
item string

The string that was scored.

score number

The floating point score of the string for the current query.

matches Array.<RangeTuple>

An array of tuples that specify the character ranges where the query matched the string.

Source:

ScorerFunction(string, query, matchesopt) → {number}

A function that takes string and query parameters and returns a floating point number between 0 and 1 that represents how well the query matches the string. It defaults to the quickScore() function in this library.

If the function gets a third matches parameter, it should fill the passed-in array with indexes corresponding to where the query matches the string, as described in the search() method.

Parameters:
Name Type Attributes Description
string string

The string to score.

query string

The query string to score the string parameter against.

matches Array.<RangeTuple> <optional>

If supplied, the function should push onto matches a tuple with start and end indexes for each substring range of string that matches query.

Source:
Returns:

A number between 0 and 1 that represents how well the query matches the string.

Type
number

TransformStringFunction(string) → {string}

A function that takes a string parameter and returns a transformed version of that string.

Parameters:
Name Type Description
string string

The string to be transformed.

Source:
Returns:

The string with the transform applied to it.

Type
string