Constructor
new SearchEngine(existingIndex, preprocessor, tokenizer) → {this}
Creates a new search engine.
Parameters:
Name | Type | Description |
---|---|---|
existingIndex |
object | The existing index or `undefined` (fresh index). |
preprocessor |
object | The preprocessor or `undefined` (`BasicPreprocessor`). |
tokenizer |
object | The tokenizer or `undefined` (`NGramTokenizer`). |
Returns:
- Type
- this
Methods
add(docId, doc) → {undefined}
Adds a document to the index.
Parameters:
Name | Type | Description |
---|---|---|
docId |
string | The unique identifier for the document. |
doc |
string | The text of the document. |
Returns:
- Type
- undefined
clear() → {undefined}
Clears out the entire index.
Returns:
- Type
- undefined
fromJson(indexData) → {undefined}
Loads the index from a JSON string.
This *clears* the index first!
Parameters:
Name | Type | Description |
---|---|---|
indexData |
string | The JSON of a previously-built index. |
Returns:
- Type
- undefined
remove(docId) → {undefined}
Removes a document from the index.
Safe to call even if the document isn't indexed.
WARNING: Depending on the size of your index, this may take a LONG time.
Parameters:
Name | Type | Description |
---|---|---|
docId |
string | The unique identifier for the document. |
Returns:
- Type
- undefined
scoreResult(rawResult) → {float}
Scores a raw result.
Mostly an internal method called by `_search`, but you can override if
needed/have a better way to score.
Parameters:
Name | Type | Description |
---|---|---|
rawResult |
object | The raw result to score. |
Returns:
- Type
- float
search(query, limit, start) → {array}
Performs a search against the index & returns results.
Parameters:
Name | Type | Description |
---|---|---|
query |
string | The user's query to search on. |
limit |
int | The number of results to return. |
start |
int | The starting offset of the results. |
Returns:
- Type
- array
toJson() → {string}
Dumps the index to a JSON string.
Useful for persisting an already-built index.
Returns:
- Type
- string