Bånder

SuggestionManager
in package

Table of Contents

Properties

$redis  : Redis

Methods

__construct()  : mixed
addSuggestion()  : bool
Add a new suggestion or update the score of an existing one.
deleteSuggestion()  : bool
Remove a specific suggestion from the dictionary.
getSuggestions()  : array<string|int, mixed>
Get autocomplete suggestions based on the provided prefix.
getSuggestionsCount()  : int
Get the current number of suggestions in the dictionary.

Properties

Methods

__construct()

public __construct(Redis $redis) : mixed
Parameters
$redis : Redis

addSuggestion()

Add a new suggestion or update the score of an existing one.

public addSuggestion(string $dictionaryName, string $suggestion, float $score[, bool $increment = false ]) : bool
Parameters
$dictionaryName : string

The name of the suggestion dictionary.

$suggestion : string

The suggestion text.

$score : float

The score for this suggestion (higher is better).

$increment : bool = false

Whether to increment the score (if true) or overwrite it (if false).

Return values
bool

True if the suggestion was successfully added.

deleteSuggestion()

Remove a specific suggestion from the dictionary.

public deleteSuggestion(string $dictionaryName, string $suggestion) : bool
Parameters
$dictionaryName : string

The name of the suggestion dictionary.

$suggestion : string

The suggestion entry to remove.

Return values
bool

True if the suggestion was successfully deleted.

getSuggestions()

Get autocomplete suggestions based on the provided prefix.

public getSuggestions(string $dictionaryName, string $prefix[, bool $fuzzy = false ][, int $maxSuggestions = 10 ][, bool $withScores = false ][, bool $withPayloads = false ]) : array<string|int, mixed>
Parameters
$dictionaryName : string

The name of the suggestion dictionary.

$prefix : string

The prefix to search for.

$fuzzy : bool = false

Whether to allow fuzzy matching.

$maxSuggestions : int = 10

Maximum number of suggestions to retrieve.

$withScores : bool = false

If true, include scores for each suggestion.

$withPayloads : bool = false

If true, include payloads associated with each suggestion.

Return values
array<string|int, mixed>

List of suggestions.

getSuggestionsCount()

Get the current number of suggestions in the dictionary.

public getSuggestionsCount(string $dictionaryName) : int
Parameters
$dictionaryName : string

The name of the suggestion dictionary.

Return values
int

The number of suggestions.


        
On this page

Search results