Skip to content

infinity.fts

Provides in-memory fulltext search functionality within one infinity instance.

Module: infinity.fts

Example:

infinity.loadModule('infinity.fts');

infinity.fts.open('books');

let doc = {title: 'The Little Prince', author: 'Antoine de Saint-Exupéry', genre: 'Fantasy'};
infinity.fts.add('books', 1, 0, doc);
infinity.fts.add('books', 2, 0, {title: 'The Adventures of Pinocchio', author: 'Carlo Collodi', genre: 'Fantasy'});
infinity.fts.add('books', 3, 0, {title: 'Fahrenheit 451', author: 'Ray Bradbury', genre: 'Drama'});

//Simple search:
console.debug(infinity.fts.find('books', 'little'));

//Phrase search: all search terms must occur in the exact same order
console.debug(infinity.fts.find('books', '"The Adventures of Pinocchio"'));

//And search: all search terms must occur, the order is not considered (+)
console.debug(infinity.fts.find('books', 'Adventures + Pinocchio'));

//Or search: at least one search term must occur (|)
console.debug(infinity.fts.find('books', 'Adventures | Pinocchio'));

//Search with exclusion: the search term before the hyphen must occur, the term after the hyphen must not occur (-)
console.debug(infinity.fts.find('books', 'Adventures - Pinocchio'));

//Wildcard search: the search term must start with the characters before the asterisk (*)
console.debug(infinity.fts.find('books', 'Pin*'));

//Searching within specified fields
console.debug(infinity.fts.find('books', 'fantasy', 0, 10, ['genre']));

infinity.fts.remove('books', 3);
console.debug(infinity.fts.find('books', 'drama', 0, 10, ['genre']));

infinity.fts.close('books');

Interfaces

resultArray

Extends: Array<{id: number, relevance: number}>

An array of objects containing the search results of find().


stringArray

Extends: Array<string>

An array of strings.


Functions

add()

Adds the given dataset to the fulltext search library under the specified namespace.

Signature:

add( namespace: string, docId: number, group: number, document: object ): void

Parameters:

  • namespace: string

    Specifies the namespace for the dataset to be stored under.

  • docId: number

    The unique document identification number.

  • group: number

    An additional property for the document. Can be used to group documents (e.g. for separating documents by different tenants).

  • document: object

    The data to be stored.

Example:

let doc = {title: 'The Little Prince', author: 'Antoine de Saint-Exupéry', genre: 'Fantasy'};
infinity.fts.add('books', 1, 0, doc);
infinity.fts.add('books', 2, 0, {title: 'The Adventures of Pinocchio', author: 'Carlo Collodi', genre: 'Fantasy'});

clear()

Clears the fulltext search library under the specified namespace.

Signature:

clear( namespace: string ): void

Parameters:

  • namespace: string

    The namespace under which the data has to be cleared.

Example:

infinity.fts.clear('books');

close()

Closes the fulltext search library under the specified namespace.

Signature:

close( namespace: string ): void

Parameters:

  • namespace: string

    The namespace of the library to be closed.

Example:

infinity.fts.close('books');

find()

Returns the results of a search with the given query parameters under the specified namespace.

Signature:

find( namespace: string, query: string, group?: number, maxResults?: number, attributes?: infinity.fts.stringArray ): infinity.fts.resultArray

Parameters:

  • namespace: string

    The namespace for the search.

  • query: string

    The search term. Simple term searches, "and" searches, "or" searches, searches with term exclusion and wildcard searches are supported.

  • group: number

    An additional property for the document. Can be used to find only documents by the given group.

  • maxResults: number, optional

    The maximum limit of results to be returned.

  • attributes: infinity.fts.stringArray, optional

    Attributes (e.g. data field names) of the dataset to be considered.

Return type: infinity.fts.resultArray

Example:

console.debug(infinity.fts.find('books', 'fantasy', 0, 10, ['genre']));

open()

Initializes a fulltext search library under the specified namespace.

Signature:

open( namespace: string ): void

Parameters:

  • namespace: string

    The namespace under which the fulltext search library should be initialized.

Example:

infinity.fts.open('books');

remove()

Removes the specified dataset from the fulltext search library under the specified namespace.

Signature:

remove( namespace: string, docId: number ): void

Parameters:

  • namespace: string

    The namespace under which the dataset should be removed.

  • docId: number

    The document identification number of the dataset to be removed.

Example:

infinity.fts.remove('books', 2);