ui.ac.CachingMatcher Extends
A matcher which wraps another (typically slow) matcher and keeps a client-side cache of the results. For instance, you can use this to wrap a RemoteArrayMatcher to hide the latency of the underlying matcher having to make ajax request. Objects in the cache are deduped on their stringified forms. Note - when the user types a character, they will instantly get a set of local results, and then some time later, the results from the server will show up.

Inheritance

Constructor

goog.ui.ac.CachingMatcher(baseMatcher)

Parameters

baseMatcher : !Object
The underlying matcher to use. Must implement requestMatchingRows.

Instance Methods

Public Protected Private
addRows_(rows)
Adds the specified rows to the cache.
Arguments:
rows : !Array.<!Object>
.
code »
clearCacheIfTooLarge_()
Checks if the cache is larger than the maximum cache size. If so clears it.
code »
getMatchesForRows_()
Local matching function.
code »
onBaseMatch_(tokenmatches)
Handles a match response from the base matcher.
Arguments:
token : string
The token against which the base match was called.
matches : !Array.<!Object>
The matches returned by the base matcher.
code »
requestMatchingRows(tokenmaxMatchesmatchHandler)
Function used to pass matches to the autocomplete.
Arguments:
token : string
Token to match.
maxMatches : number
Max number of matches to return.
matchHandler : Function
callback to execute after matching.
code »
setBaseMatcherMaxMatches(maxMatches)
Sets the maxMatches to use for the base matcher. If the base matcher makes AJAX requests, it may help to make this a large number so that the local cache gets populated quickly. Default value: 100.
Arguments:
maxMatches : number
The value to set.
code »
setLocalMatcher(localMatcher)
Sets the local matcher to use. The local matcher should be a function with the same signature as goog.ui.ac.ArrayMatcher.getMatchesForRows, i.e. its arguments are searchToken, maxMatches, rowsToSearch; and it returns a list of matching rows. Default value: goog.ui.ac.ArrayMatcher.getMatchesForRows.
Arguments:
localMatcher : function(string, number, !Array.<!Object>): !Array.<!Objec>>
No description.
code »
setMaxCacheSize(maxCacheSize)
Sets the maximum size of the local cache. If the local cache grows larger than this size, it will be emptied. Default value: 1000.
Arguments:
maxCacheSize : number
.
code »
setThrottleTime(throttleTime)
Sets the number of milliseconds with which to throttle the match requests on the underlying matcher. Default value: 150.
Arguments:
throttleTime : number
.
code »
triggerBaseMatch_()
Triggers a match request against the base matcher. This function is unthrottled, so don't call it directly; instead use this.throttledTriggerBaseMatch_.
code »

Instance Properties

baseMatcherMaxMatches_ :
No description.
Code »
baseMatcher_ :
No description.
Code »
maxCacheSize_ :
Maximum number of rows in the cache. If the cache grows larger than this, the entire cache will be emptied.
Code »
mostRecentMatchHandler_ :
No description.
Code »
mostRecentMatches_ :
The set of rows which we last displayed. NOTE(reinerp): The need for this is subtle. When a server result comes back, we don't want to suddenly change the list of results without the user doing anything. So we make sure to add the new server results to the end of the currently displayed list. We need to keep track of the last rows we displayed, because the "similar matcher" we use locally might otherwise reorder results.
Code »
mostRecentMaxMatches_ :
No description.
Code »
mostRecentToken_ :
No description.
Code »
rowStrings_ :
Set of stringified rows, for fast deduping. Each element of this.rows_ is stored in rowStrings_ as (' ' + row) to ensure we avoid builtin properties like 'toString'.
Code »
rows_ :
No description.
Code »
throttledTriggerBaseMatch_ : goog.async.Throttle
No description.
Code »

Package ui.ac

Package Reference