Fuzzy_Search
Class to handle fuzzy search — MySQL stored-function lifecycle and score SQL generation.
Namespace: WebberZone\Better_Search\Pro
Source: includes/pro/class-fuzzy-search.php line 21
Methods
__construct()
Constructor.
Line: 26
public function __construct( );
activation_hook()
Activation hook.
Since: 4.0.0
Line: 47
public function activation_hook( );
create_fuzzy_index() static
Recreate the fuzzy helper functions in the database.
Since: 4.0.0
Line: 56
static public function create_fuzzy_index( );
delete_fuzzy_index() static
Drop all fuzzy stored functions.
Since: 4.3.0
Line: 275
static public function delete_fuzzy_index( );
is_fuzzy_index_installed() static
Check if the fuzzy index is installed.
Since: 4.0.0
Line: 292
static public function is_fuzzy_index_installed( ): bool;
Returns: bool — True if both functions are installed, false otherwise.
is_levenshtein_function_installed() static
Check if the Levenshtein function is installed.
Since: 4.0.0
Line: 331
static public function is_levenshtein_function_installed( ): bool;
Returns: bool — True if the function is installed, false otherwise.
is_phrase_similarity_lev_installed() static
Check if the levenshtein phrase similarity function is installed.
Since: 4.0.0
Line: 342
static public function is_phrase_similarity_lev_installed( ): bool;
Returns: bool — True if the function is installed, false otherwise.
is_phrase_similarity_soundex_installed() static
Check if the soundex phrase similarity function is installed.
Since: 4.0.0
Line: 353
static public function is_phrase_similarity_soundex_installed( ): bool;
Returns: bool — True if the function is installed, false otherwise.
get_fuzzy_index_name() static
Get the fuzzy index name.
Since: 4.0.0
Line: 382
static public function get_fuzzy_index_name( ): string;
Returns: string — The fuzzy index name.
get_fuzzy_index_level() static
Get the fuzzy index level.
Since: 4.0.0
Line: 394
static public function get_fuzzy_index_level( $args = ... ): int;
| Type | Name | Description |
|---|---|---|
array |
$args |
Array of arguments. |
Returns: int — The fuzzy index level.
is_fuzzy_active()
Check whether fuzzy scoring is active for a given search query.
Since: 4.3.0
Line: 420
public function is_fuzzy_active( string $search_query, array $args = ... ): bool;
| Type | Name | Description |
|---|---|---|
string |
$search_query |
The raw search string. |
array |
$args |
Query args. |
Returns: bool
get_fuzzy_score_sql()
Build the fuzzy score SQL fragment for a given search query.
When a content column and weight are supplied, the score is the sum of the title fuzzy score and the content fuzzy score, ensuring that a typo present only in post_content still produces a positive score.
Since: 4.3.0
Line: 446
public function get_fuzzy_score_sql( string $search_query, int $weight_title, array $args = ..., string $title_column = ..., string $content_column = ..., int $weight_content = ... ): string;
| Type | Name | Description |
|---|---|---|
string |
$search_query |
The raw search string. |
int |
$weight_title |
Title weight used to derive the fuzzy weight. |
array |
$args |
Query args. |
string |
$title_column |
Optional column expression. Defaults to wp_posts.post_title. |
string |
$content_column |
Optional content column expression. When non-empty, its score is added. |
int |
$weight_content |
Content weight used to derive the content fuzzy weight. |
Returns: string — SQL fragment or empty string.
get_did_you_mean_suggestion()
Find the closest known-good search term from the search log for a “Did you mean” suggestion.
Since: 4.4.0
Line: 497
public function get_did_you_mean_suggestion( string $token ): ?string;
| Type | Name | Description |
|---|---|---|
string |
$token |
The single search token that returned zero results. |
Returns: ?string — Suggested term, or null if nothing close enough was found.
find_closest_term() static
Shared first-letter + length-window prefilter + wz_levenshtein lookup.
Used by both the search-log corpus (Fuzzy_Search) and the content-index corpus (Spell_Dictionary). SOUNDEX() is not used because it rejects single-edit typos it should catch (e.g. SOUNDEX(‘WordPress’) != SOUNDEX(‘wordpess’)).
Since: 4.4.0
Line: 530
static public function find_closest_term( string $token, string $table, string $word_col, string $freq_col, int $min_freq = ... ): ?string;
| Type | Name | Description |
|---|---|---|
string |
$token |
Search token. |
string |
$table |
Fully-prefixed table name. |
string |
$word_col |
Word column name. |
string |
$freq_col |
Frequency column name. |
int |
$min_freq |
Minimum frequency to qualify. Default 0. |
Returns: ?string — Closest term, or null.
missing_index_notice()
Display admin notice if the fuzzy index is not created.
Since: 4.0.0
Line: 597
public function missing_index_notice( );