interface SearchIndexInterface (View source)

Provides search index management functions.

Methods

string[]
index(string $type, int $sid, string $langcode, string $text, bool $update_weights = TRUE)

Updates the full-text search index for a particular item.

clear(string|null $type = NULL, int|array|null $sid = NULL, string|null $langcode = NULL)

Clears either a part of, or the entire search index.

markForReindex(string $type = NULL, int $sid = NULL, string $langcode = NULL)

Changes the timestamp on indexed items to 'now' to force reindexing.

updateWordWeights(array $words)

Updates the {search_total} database table.

Details

string[] index(string $type, int $sid, string $langcode, string $text, bool $update_weights = TRUE)

Updates the full-text search index for a particular item.

Parameters

string $type

The plugin ID or other machine-readable type of this item, which should be less than 64 bytes.

int $sid

An ID number identifying this particular item (e.g., node ID).

string $langcode

Language code for the language of the text being indexed.

string $text

The content of this item. Must be a piece of HTML or plain text.

bool $update_weights

(optional) TRUE if word weights should be updated. FALSE otherwise; defaults to TRUE. If you pass in FALSE, then you need to have your calls to this method in a try/finally block, and at the end of your index run in the finally clause, you will need to call self::updateWordWeights(), passing in all of the returned words, to update the word weights.

Return Value

string[]

The words to be updated.

Exceptions

SearchIndexException

clear(string|null $type = NULL, int|array|null $sid = NULL, string|null $langcode = NULL)

Clears either a part of, or the entire search index.

This function is meant for use by search page plugins, or for building a user interface that lets users clear all or parts of the search index.

Parameters

string|null $type

(optional) The plugin ID or other machine-readable type for the items to remove from the search index. If omitted, $sid and $langcode are ignored and the entire search index is cleared.

int|array|null $sid

(optional) The ID or array of IDs of the items to remove from the search index. If omitted, all items matching $type are cleared, and $langcode is ignored.

string|null $langcode

(optional) Language code of the item to remove from the search index. If omitted, all items matching $sid and $type are cleared.

Exceptions

SearchIndexException

markForReindex(string $type = NULL, int $sid = NULL, string $langcode = NULL)

Changes the timestamp on indexed items to 'now' to force reindexing.

This function is meant for use by search page plugins, or for building a user interface that lets users mark all or parts of the search index for reindexing.

Parameters

string $type

(optional) The plugin ID or other machine-readable type of this item. If omitted, the entire search index is marked for reindexing, and $sid and $langcode are ignored.

int $sid

(optional) An ID number identifying this particular item (e.g., node ID). If omitted, everything matching $type is marked, and $langcode is ignored.

string $langcode

(optional) The language code to mark. If omitted, everything matching $type and $sid is marked.

Exceptions

SearchIndexException

updateWordWeights(array $words)

Updates the {search_total} database table.

Parameters

array $words

An array whose keys are words from self::index() whose total weights need to be updated.

Exceptions

SearchIndexException