Constructor
new QuickScore(itemsopt, optionsopt)
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
items |
Array.<(string|object)> |
<optional> |
The list of items to score. If
the list is not a flat array of strings, a |
|||||||||||||||||||||||||||||||||||
options |
Array.<ItemKey> | Options |
<optional> |
If the Properties
|
- Source:
Classes
Members
(readonly) items :Array.<object>
The array of items to search, which should only be modified via the setItems() method.
Type:
- Array.<object>
- Source:
(readonly) keys :Array.<ItemKey>
The keys to search on each item, which should only be modified via the setItems() method.
Type:
- Array.<ItemKey>
- Source:
Methods
search(query) → {Array.<(ScoredString|ScoredObject)>}
Scores the instance's items against the query
and sorts them from
highest to lowest.
Parameters:
Name | Type | Description |
---|---|---|
query |
string | The string to score each item against. The
instance's |
- Source:
Returns:
When the instance's items
are flat strings, an array of ScoredString
objects containing the following properties is returned:
item
: the string that was scoredscore
: the floating point score of the string for the current querymatches
: an array of arrays that specify the character ranges where the query matched the string
When the items
are objects, an array of ScoredObject
results is returned:
item
: the object that was scoredscore
: the highest score from among the individual key scoresscoreKey
: the name of the key with the highest score, which will be an empty string if they're all zeroscoreValue
: the value of the key with the highest score, which makes it easier to access if it's a nested stringscores
: a hash of the individual scores for each keymatches
: a hash of arrays that specify the character ranges of the query match for each key
The results array is sorted high to low on each item's score. Items with
identical scores are sorted alphabetically and case-insensitively on the
sortKey
option. Items with scores that are <= the minimumScore
option
(defaults to 0
) are not returned, unless the query
is falsy, in which
case all of the items are returned, sorted alphabetically.
The start and end indices in each RangeTuple
in the
matches
array can be used as parameters to the substring()
method to
extract the characters from each string that match the query. This can
then be used to format the matching characters with a different color or
style.
Each ScoredObject
item also has a _
property, which caches transformed
versions of the item's strings, and might contain additional internal
metadata in the future. It can be ignored.
- Type
- Array.<(ScoredString|ScoredObject)>
setItems(items)
Sets the items
array and caches a transformed copy of all the item
strings specified by the keys
parameter to the constructor, using the
transformString
option (which defaults to toLocaleLowerCase()
).
Parameters:
Name | Type | Description |
---|---|---|
items |
Array.<(string|object)> | List of items to score. |
- Source:
setKeys(keys, sortKeyopt)
Sets the keys
configuration. setItems()
must be called after
changing the keys so that the items' transformed strings get cached.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
keys |
Array.<ItemKey> | List of keys to score, as either strings
or |
||
sortKey |
string |
<optional> |
keys[0] | Name of key on which to sort
identically scored items. Defaults to the first |
- Source: