Edit this topic

File index

: shell

: index-store

: file-index

: /modules/core/search/services/file-index.js

: https://github.com/DecentCMS/DecentCMS/blob/master/modules/core/search/services/file-index.js

Globals

class: FileIndex

class: FileIndexFactory

class: FileIndex

new FileIndex(scope, [idFilter], map, [orderBy], [name])

An in-memory index implementation with file storage suitable for small sites.

Param Type Description
scope object The scope.
[idFilter] RegExp A regular expression that validates content item ids before they are read and indexed.
map function The map function takes a content item and returns an array of index entries, a single index entry, or null. An index entry should have an id property. The index will automatically add an itemId property set to be the id of the item that was used to build the index entries.
[orderBy] function The function that defines the order on which the index entry should be sorted. The sort order can be a simple string, date, number, or it can be an array, in which case the items in the array will be used one after the other. It takes an index entry, and returns the sort order.
[name] string A name for the index. If not provided, one will be built from the other parameters.

fileIndex.filter(options, done)

Filters the index with a where clause.

Param Type Description
options object The options object.
options.where function The where function. It takes an index entry, and returns true if the entry should be included.
[options.start] Number The index of the first entry to be returned that evaluates true from the where clause.
[options.count] Number The number of entries to return. Omit if an unlimited number of items can be returned.
done function The callback, that takes the array of index entries satisfying the where clause and within the range as its parameter.

fileIndex.reduce(options, done)

Reduces the index to an aggregated object.

Param Type Description
options object The options object.
[options.where] function A condition on the index entries.
options.reduce function The reduce function. It takes the previous value, the entry to process, and the index of the entry. It returns the new value.
options.initialValue * The initial value or seed of the aggregation.
done function The callback, that takes the aggregated value of index entries satisfying the where clause.

fileIndex._addToIndex(index, indexEntries, id, [sorted])

Adds index entries to the provided internal index.

Param Type Description
index Array The internal index array to which the entries will be added.
indexEntries Array The result of a map call.
id string The id of the item that was mapped.
[sorted] Boolean Is the index sorted already?

fileIndex.build()

Builds or re-builds the index. Having called that method does not mean that the index will be filled on the next instruction, as this works asynchronously.

fileIndex._removeExistingEntries(index, itemId) ⇒ boolean

Removes existing entries for a specific item id from an internal index.

Returns: boolean - Whether the itemId was present in the index.

Param Type Description
index Array The internal index.
itemId Number The item id to remove.

fileIndex.updateWith(item)

Updates the index with the results of mapping the provided item.

Param Type Description
item object The item to index.

fileIndex.remove(item)

Remove entries corresponding to the provided item from the index.

Param Type Description
item object The content item to remove.

fileIndex.getProgress() ⇒ Number

Gets the current progress of the indexing process.

Returns: Number - The number of entries that have already been added to the index. Once the indexing process is finished, the number of index entries is returned.

fileIndex.getLength() ⇒ Number

Gets the number of entries available in the index at the time the function is called. To know how many entries have been added to the index, but that are not necessarily available for querying yet, use getProgress.

Returns: Number - The number of entries in the index.

FileIndex._toName ⇒ string

Generates a valid identifier from one or several objects, using their string form.

Returns: string - A valid name built from the objects passed in.

Param Type Description
[arguments] Array.<function()> The function for which a name is needed.

class: FileIndexFactory

new FileIndexFactory(scope)

Creates and caches index objects.

Param Type Description
scope object The scope.

fileIndexFactory.getIndex([idFilter], map, [orderBy], [name]) ⇒ object

Gets or creates the index for the provided map and order by functions.

Returns: object - The index object.

Param Type Description
[idFilter] RegExp A regular expression that validates content item ids before they are read and indexed.
map function The map function. It takes a content item and returns null, an index entry, or an array of index entries.
[orderBy] function The function that defines the order on which the index entries should be sorted. It takes an index entry, and returns the sort order. The sort order can be a simple string, date, number, or it can be an array, in which case the items in the array will be used one after the other. It is recommended to name the order function.
[name] string A unique name for the index. If it's not provided, one will be generated from the source code of the filter, map, and orderBy parameters.