SearchLight

search-light. SearchLight

new SearchLight()

Source:

Members

length

Source:

Length of matches

matches

Source:

Gets all items that match all the constraints

partialMatches

Source:

Gets all items that only match some of the constraints

allMatches

Source:

Gets all items that match any of the constraints

allItems

Source:

Gets all items in the collection

Methods

(static) search(collection) → {SearchLight}

Source:

Creates a new SearchLight instance and sets the collection

Example
search( ['one', 'two', 'three'] )
Parameters:
Name Type Description
collection Collection

Array or object of items or properties to search

Returns:

instance - new SearchLight instance

Type
SearchLight

for(constraint) → {SearchLight}

Source:

Set search terms or filters

Example
// sets the search text to be 'something'
search(collection).for('something')
Parameters:
Name Type Description
constraint Constraint

Search text or filter to replace current constraints with

Returns:
Type
SearchLight

and(constraint) → {SearchLight}

Source:

Add additional search terms or filters

Example
// adds 'nothing' to the existing search text of 'something'
search(items).for('something').and('nothing')
Parameters:
Name Type Description
constraint Constraint

Search text or filter to replace current constraints with

Returns:
Type
SearchLight

in(keys) → {SearchLight}

Source:

Set keys to search by

Example
// sets keys to be ['an_object_property']
search(items).for('something').in('an_object_property')
Parameters:
Name Type Description
keys string | Array

key or array of keys

Returns:
Type
SearchLight

or(keys) → {SearchLight}

Source:

Add additional keys to search by

Example
// adds 3 to existing array of keys ([1, 3])
search(items).for('something').in(1).or(3)
Parameters:
Name Type Description
keys string | Array

key or array of keys

Returns:
Type
SearchLight

sorted() → {SearchLight}

Source:

Sets the sort setting to true

Returns:
Type
SearchLight

unsorted() → {SearchLight}

Source:

Sets the sort setting to false

Returns:
Type
SearchLight

sortUsing() → {SearchLight}

Source:

Sets a custom sort function to use on the matches

Parameters:
Type Description
SortCallback
Returns:
Type
SearchLight

compareCase() → {SearchLight}

Source:

Sets the case-sensitive setting to true

Returns:
Type
SearchLight

ignoreCase() → {SearchLight}

Source:

Sets the case-sensitive setting to false

Returns:
Type
SearchLight

withStats(propertyopt) → {SearchLight}

Source:

Sets the inject.enabled setting to true and optionally sets the inject.property setting too

Parameters:
Name Type Attributes Description
property * <optional>

the property stats are injected as

Returns:
Type
SearchLight

withoutStats() → {SearchLight}

Source:

Sets the inject.enabled setting to false

Returns:
Type
SearchLight

then(successopt, failureopt) → {SearchLight}

Source:

Promise support Allows for asynchronous processing of large collections

Example
search(items).for('something')
             .then(
                 function(results) { console.log(results.matches) },
                 function(error) { console.log(error) }
             )
Parameters:
Name Type Attributes Description
success SuccessCallback <optional>

callback to run when/if promise completes successfully

failure FailureCallback <optional>

callback to run when/if promise completes unsuccessfully

Returns:
Type
SearchLight

catch(failure) → {SearchLight}

Source:

Allows promises to be written in a more readable format

Example
search(items).for('something')
             .then((results) => do_something(results.matches))
             .catch((error) => { console.log(error) })
Parameters:
Name Type Description
failure FailureCallback

callback to run when/if promise completes unsuccessfully

Returns:
Type
SearchLight