Home Reference Source
public class | source

Index

An index

Constructor Summary

Public Constructor
public

constructor(config: object)

Construct a new Index

Member Summary

Public Members
public

Information gain.

public

List of fields it should index.

public

List of filters supported.

public

Actual Index.

public

Field values this index can supply for sorting.

public

Type of index.

Protected Members
protected

List of field values by index.

Method Summary

Public Methods
public

async addDocuments(documentIndices: number[], documents: Document[])

Adds a set of documents to Index

public abstract

addToIndex(index: IndexImplementation, documentIndices: number[], documentValues: string[][])

Add to index.

public

analyseValue(row: *): *

public abstract

filterBasedOnIndex(index: IndexImplementation, queryFilter: QueryFilter, results: Results)

Filter results based on index

public

filterDocuments(queryFilter: QueryFilter, results: Results): *

Filter results based on query

public

async removeDocuments(documentIndices: number[])

Removes a set of documents from Index

public abstract

removeFromIndex(index: IndexImplementation, documentIndices: number[], documentValues: string[][])

Remove from index

public

async state(): object

Dump current index state.

Protected Methods
protected

analyseValues(values: object[][]): object[][]

Processing before adding to index.

protected

createIndex(): IndexImplementation

Create an empty index.

protected

Extract values out of a document object.

Public Constructors

public constructor(config: object) source

Construct a new Index

Params:

NameTypeAttributeDescription
config object
  • optional
  • default: {}

configuration; see properties

Public Members

public entropy: number source

Information gain. TODO: should determine which field to query first etc.

public fields: string[] source

List of fields it should index.

public filters: string source

List of filters supported. These are usually predefined values. Filled in by class.

public index: object source

Actual Index. Format depends on type of index. Override createIndex();

public sorts: string source

Field values this index can supply for sorting.

public type: string source

Type of index. These are usually predefined values. Filled in by class.

Protected Members

protected values: string source

List of field values by index. These values are used to add/remove documents from index and also used for sorting.

Public Methods

public async addDocuments(documentIndices: number[], documents: Document[]) source

Adds a set of documents to Index

Params:

NameTypeAttributeDescription
documentIndices number[]

Index of document ids in the list of ids. Indices must store document data by this index.

documents Document[]

Actual documents.

public abstract addToIndex(index: IndexImplementation, documentIndices: number[], documentValues: string[][]) source

Add to index.

Params:

NameTypeAttributeDescription
index IndexImplementation
documentIndices number[]
documentValues string[][]

public analyseValue(row: *): * source

Params:

NameTypeAttributeDescription
row *

Return:

*

public abstract filterBasedOnIndex(index: IndexImplementation, queryFilter: QueryFilter, results: Results) source

Filter results based on index

Params:

NameTypeAttributeDescription
index IndexImplementation
queryFilter QueryFilter
results Results

public filterDocuments(queryFilter: QueryFilter, results: Results): * source

Filter results based on query

Params:

NameTypeAttributeDescription
queryFilter QueryFilter

query to filter with

results Results

results to filter (modify results object)

Return:

*

public async removeDocuments(documentIndices: number[]) source

Removes a set of documents from Index

Params:

NameTypeAttributeDescription
documentIndices number[]

Index of document ids in the list of ids. Indices must store document data by this index.

public abstract removeFromIndex(index: IndexImplementation, documentIndices: number[], documentValues: string[][]) source

Remove from index

Params:

NameTypeAttributeDescription
index IndexImplementation
documentIndices number[]
documentValues string[][]

public async state(): object source

Dump current index state.

Return:

object

Protected Methods

protected analyseValues(values: object[][]): object[][] source

Processing before adding to index.

By default, it turns list of objects into a map of string representation of the objects to their occurance tally.

Params:

NameTypeAttributeDescription
values object[][]

list of values for each documents

Return:

object[][]

protected createIndex(): IndexImplementation source

Create an empty index.

Return:

IndexImplementation

default is {}

protected getDocumentValues(document: Document): object[] source

Extract values out of a document object.

It is set up like this so that we can override this method and filter the values we don't like.

Params:

NameTypeAttributeDescription
document Document

Return:

object[]

Example:

{field: ['a', 'b']} should return ['a', 'b']