class CacheEngine implements EngineInterface (View source)

A TNTSearch engine that keeps each index as PHP arrays in a PSR-16 cache.

It needs no PHP extension and no database, so it works on every server. With the default cache config the indexes are files in the temp folder.

Like the other engines, each method that changes the index saves it before it returns. Saving the whole index for each change is slow, so make many changes between indexBeginTransaction() and indexEndTransaction() to save them once.

Traits

EngineTrait

Constants

CACHE_SERVICE

The name of the Injector service for the cache that holds the indexes.

Properties

public string $indexName
public array $config
public StemmerInterface $stemmer
public string $query
public bool $disableOutput
public string $primaryKey
protected bool $excludePrimaryKey
public bool $decodeHTMLEntities
public TokenizerInterface $tokenizer
public array $stopWords
public int $steps
public bool $inMemory
public FileReaderInterface|null $filereader
public bool $asYouType
public bool $fuzziness
public int $fuzzy_prefix_length
public int $fuzzy_max_expansions
public int $fuzzy_distance
public bool $fuzzy_no_limit
public int $maxDocs
public PDO|null $dbh

Methods

public
loadConfig(array $config)

No description

public
createIndex(string $indexName)

Create an empty index and save it, which replaces any index with the same name.

public
selectIndex(string $indexName)

No description

public
void
indexBeginTransaction()

Start a transaction. Changes are kept in memory until indexEndTransaction() saves them.

public
void
indexEndTransaction()

Save the changes made since indexBeginTransaction(), and end the transaction.

public
void
indexRollBackTransaction()

Discard the changes made since indexBeginTransaction(), and end the transaction.

public
flushIndex(string $indexName)

No description

public
updateInfoTable(string $key, $value)

No description

public
getValueFromInfoTable(string $value)

No description

public
run()

Index the rows from the query, or the files if the "driver" config is "filesystem".

public
readDocumentsFromFileSystem()

Index the files in the directory from the "location" config.

public
Collection
filesystemMapIdsToPaths(Collection $docs)

Get the file for each document ID from an index made by readDocumentsFromFileSystem().

public
buildDictionary($filename, int $count = -1, bool $hits = true, bool $docs = false)

Write each term to a file, most hits first, one term per line.

public
processDocument(Collection $row)

No description

public
excludePrimaryKey()

No description

public
setStopWords(array $stopWords)

No description

public
insert(array $document)

No description

public
update(int $id, array $document)

No description

public
saveToIndex(Collection $stems, int $docId)

No description

public
saveWordlist(Collection $stems)

Add the terms of one document to the wordlist.

public
saveDoclist(array $terms, int $docId)

No description

public
saveHitList(array $stems, int $docId, array $termsList)

No description

public
delete(int $documentId)

No description

public
totalDocumentsInCollection()

No description

public
getWordFromWordList(string $word)

No description

public
getWordlistByKeyword(string $keyword, bool $isLastWord = false, bool $noLimit = false)

No description

public
fuzzySearch(string $keyword)

No description

public
getAllDocumentsForStrictKeyword(array $word, bool $noLimit)

No description

public
getAllDocumentsForFuzzyKeyword(array $words, bool $noLimit)

No description

public
getAllDocumentsForWhereKeywordNot(string $keyword, bool $noLimit = false)

No description

Details

loadConfig(array $config)

No description

Parameters

array $config

createIndex(string $indexName)

Create an empty index and save it, which replaces any index with the same name.

Parameters

string $indexName

Exceptions

LogicException

selectIndex(string $indexName)

No description

Parameters

string $indexName

Exceptions

IndexNotFoundException
LogicException

void indexBeginTransaction()

Start a transaction. Changes are kept in memory until indexEndTransaction() saves them.

Return Value

void

Exceptions

LogicException

void indexEndTransaction()

Save the changes made since indexBeginTransaction(), and end the transaction.

If the changes can't be saved, the transaction stays open so that it can be rolled back.

Return Value

void

Exceptions

LogicException
RuntimeException

void indexRollBackTransaction()

Discard the changes made since indexBeginTransaction(), and end the transaction.

Return Value

void

Exceptions

LogicException

flushIndex(string $indexName)

No description

Parameters

string $indexName

updateInfoTable(string $key, $value)

No description

Parameters

string $key
$value

getValueFromInfoTable(string $value)

No description

Parameters

string $value

run()

Index the rows from the query, or the files if the "driver" config is "filesystem".

readDocumentsFromFileSystem()

Index the files in the directory from the "location" config.

The "extension" config sets which files to include, and the "exclude" config has paths to leave out.

Collection filesystemMapIdsToPaths(Collection $docs)

Get the file for each document ID from an index made by readDocumentsFromFileSystem().

Each value is an array with "id" and "path" keys, or null if the document has no file.

Parameters

Collection $docs

Return Value

Collection

buildDictionary($filename, int $count = -1, bool $hits = true, bool $docs = false)

Write each term to a file, most hits first, one term per line.

Parameters

$filename
int $count

The maximum number of terms. Use -1 for all terms.

bool $hits

If true, add the number of hits after each term.

bool $docs

If true, add the number of documents after each term.

Exceptions

RuntimeException

processDocument(Collection $row)

No description

Parameters

Collection $row

excludePrimaryKey()

No description

setStopWords(array $stopWords)

No description

Parameters

array $stopWords

insert(array $document)

No description

Parameters

array $document

update(int $id, array $document)

No description

Parameters

int $id
array $document

saveToIndex(Collection $stems, int $docId)

No description

Parameters

Collection $stems
int $docId

saveWordlist(Collection $stems)

Add the terms of one document to the wordlist.

Returns the number of hits in the document keyed by term.

Parameters

Collection $stems

saveDoclist(array $terms, int $docId)

No description

Parameters

array $terms
int $docId

saveHitList(array $stems, int $docId, array $termsList)

No description

Parameters

array $stems
int $docId
array $termsList

delete(int $documentId)

No description

Parameters

int $documentId

totalDocumentsInCollection()

No description

getWordFromWordList(string $word)

No description

Parameters

string $word

getWordlistByKeyword(string $keyword, bool $isLastWord = false, bool $noLimit = false)

No description

Parameters

string $keyword
bool $isLastWord
bool $noLimit

fuzzySearch(string $keyword)

No description

Parameters

string $keyword

getAllDocumentsForStrictKeyword(array $word, bool $noLimit)

No description

Parameters

array $word
bool $noLimit

getAllDocumentsForFuzzyKeyword(array $words, bool $noLimit)

No description

Parameters

array $words
bool $noLimit

getAllDocumentsForWhereKeywordNot(string $keyword, bool $noLimit = false)

No description

Parameters

string $keyword
bool $noLimit