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 |
|
matches |
Array.<RangeTuple> |
<optional> |
If supplied, |
transformedString |
string |
<optional> |
A transformed version of the string that
will be used for matching. This defaults to a lowercase version of |
transformedQuery |
string |
<optional> |
A transformed version of |
config |
object |
<optional> |
A configuration object that can modify how the
|
stringRange |
Range |
<optional> |
The range of characters in |
- 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:
- KeyName | Object
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. |
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>
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 |
transformString |
TransformStringFunction |
<optional> |
A function that takes
a |
scorer |
ScorerFunction |
<optional> |
A function that takes |
config |
Config |
<optional> |
An object that is passed to the scorer function to further customize its behavior. |
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. |
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. |
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. |
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 |
|
matches |
Array.<RangeTuple> |
<optional> |
If supplied, the function should push
onto |
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. |
Returns:
The string with the transform applied to it.
- Type
- string