Query_Modifier
Class to modify Better_Search_Query with Pro features.
Namespace: WebberZone\Better_Search\Pro
Since: 4.2.0
Source: includes/pro/class-query-modifier.php line 24
Methods
__construct()
Constructor
Line: 50
public function __construct( Custom_Tables\Custom_Tables $custom_tables, ?Fuzzy_Search $fuzzy_search = ... );
| Type | Name | Description |
|---|---|---|
Custom_Tables\Custom_Tables |
$custom_tables |
Custom Tables instance. |
Fuzzy_Search|null |
$fuzzy_search |
Fuzzy search service. |
hooks()
Register hooks
Since: 4.2.0
Line: 62
public function hooks( );
get_weights()
Get the weights for the title, content, excerpt, taxonomies and primary boost.
Since: 4.2.0
Line: 88
public function get_weights( $args ): array;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: array — Array of weights.
get_recency_settings() static
Resolve the recency boost settings, clamped to their valid ranges.
Since: 4.5.0
Line: 127
static public function get_recency_settings( array $args = ... ): array;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: array — float, halflife: float} Boost percentage and half-life in days.
get_recency_args() static
Resolved recency values to hand to a search path that cannot read the query args itself.
Always returns the resolved pair, including an explicit zero: a query that switches the boost off has to switch it off everywhere, not fall back to the site setting.
Since: 4.5.0
Line: 148
static public function get_recency_args( array $args = ... ): array;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: array — float, recency_halflife: float} Recency arguments.
is_recency_boost_active() static
Whether the recency boost is active for this query.
Since: 4.5.0
Line: 165
static public function is_recency_boost_active( array $args = ... ): bool;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: bool — True when an age-decayed multiplier should be applied to the ordering.
is_relevance_ordered() static
Whether a query is ordered by relevance rather than an explicit column.
Since: 4.5.0
Line: 179
static public function is_relevance_ordered( array $args = ... ): bool;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: bool — True when results are ranked by the relevance score.
get_recency_sql() static
Build the age-decay multiplier applied to the relevance score in ORDER BY.
Emits (1 + b * COALESCE(1 / (1 + age_days / halflife), 0)), which multiplies the raw
relevance score in ordering only. The reference date is supplied by PHP rather than NOW()
so the SQL text stays stable for the whole cache window. A NULL or zero date yields a
decay term of 0, i.e. no boost rather than a NULL score.
Since: 4.5.0
Line: 199
static public function get_recency_sql( string $date_column, array $args = ... ): string;
| Type | Name | Description |
|---|---|---|
string |
$date_column |
Fully qualified UTC date column, e.g. wp_posts.post_date_gmt. |
array |
$args |
Query arguments. |
Returns: string — SQL expression, or an empty string when the boost is off or unsupported.
get_recency_cache_cap() static
Maximum lifetime for a result set cached under a recency-boosted ordering.
The cap has to match the granularity of the reference date the decay is measured against, otherwise the extra refreshes either return identical ordering or the ordering goes stale.
Since: 4.5.0
Line: 249
static public function get_recency_cache_cap( array $args = ... ): int;
| Type | Name | Description |
|---|---|---|
array |
$args |
Query arguments. |
Returns: int — Cap in seconds, 0 when the boost is inactive.
get_recency_orderby() static
Apply the recency multiplier to a bare relevance-ordering expression.
Since: 4.5.0
Line: 269
static public function get_recency_orderby( string $score_column, string $date_column, array $args = ... ): string;
| Type | Name | Description |
|---|---|---|
string |
$score_column |
Score column or alias, e.g. score or sub_query.score. |
string |
$date_column |
UTC date column the decay is measured from. |
array |
$args |
Query arguments. |
Returns: string — Ordering expression including the trailing direction.
get_field_weight_clauses()
Build flat-weight score clauses for slug, meta, author and comment matches.
Since: 4.5.0
Line: 289
public function get_field_weight_clauses( array $weights, $instance, $query ): array;
| Type | Name | Description |
|---|---|---|
array |
$weights |
Array of weights. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
\WP_Query|\Better_Search_Query |
$query |
The WP_Query instance. |
Returns: array — Array of prepared SQL score expressions.
get_custom_table_content_clauses()
Get content match clauses for custom tables.
Since: 4.2.0
Line: 447
public function get_custom_table_content_clauses( string $search_query, array $weights, bool $boolean_mode = ..., bool $search_excerpt = ... ): array;
| Type | Name | Description |
|---|---|---|
string |
$search_query |
The search query string. |
array |
$weights |
Array of weights for content fields. |
bool |
$boolean_mode |
Whether to use BOOLEAN mode in MATCH clauses. |
bool |
$search_excerpt |
Whether “Search Excerpt” is enabled, including excerpt even at zero weight. |
Returns: array — Array of content match clauses.
get_custom_table_taxonomy_clauses()
Process custom table taxonomy matches and return taxonomy clauses for relevance calculation.
Since: 4.2.0
Line: 486
public function get_custom_table_taxonomy_clauses( string $search_query, array $weights, array $args ): array;
| Type | Name | Description |
|---|---|---|
string |
$search_query |
The search query string. |
array |
$weights |
Array of weights for taxonomies. |
array |
$args |
Arguments array. |
Returns: array — Array containing taxonomy clauses and data.
get_wp_content_clauses()
Get content match clauses for WordPress posts table.
Since: 4.2.0
Line: 657
public function get_wp_content_clauses( string $search_query, array $weights, bool $boolean_mode = ..., bool $search_excerpt = ... ): array;
| Type | Name | Description |
|---|---|---|
string |
$search_query |
The search query string. |
array |
$weights |
Array of weights for content fields. |
bool |
$boolean_mode |
Whether to use BOOLEAN mode in MATCH clauses. |
bool |
$search_excerpt |
Whether “Search Excerpt” is enabled, including excerpt even at zero weight. |
Returns: array — Array of content match clauses.
get_taxonomy_match_clauses()
Process taxonomy matches and return taxonomy clauses for relevance calculation.
Since: 4.2.0
Line: 696
public function get_taxonomy_match_clauses( string $search_query, array $weights ): array;
| Type | Name | Description |
|---|---|---|
string |
$search_query |
The search query string. |
array |
$weights |
Array of weights for taxonomies. |
Returns: array — Array containing taxonomy clauses and data.
query_posts_fields()
Modify the posts_fields clause.
Since: 4.2.0
Line: 852
public function query_posts_fields( $fields, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$fields |
The SELECT clause of the query. |
\WP_Query|\Better_Search_Query |
$query |
The WP_Query or Better_Search_Query instance. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
Returns: string — Updated Fields
query_posts_where_match()
Modify the MATCH clause of the WHERE clause to filter relevant posts.
Since: 4.2.0
Line: 928
public function query_posts_where_match( $match_clause, $where, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$match_clause |
The MATCH section of the WHERE clause of the query. |
string |
$where |
The WHERE clause of the query. |
\WP_Query|\Better_Search_Query |
$query |
The WP_Query or Better_Search_Query instance. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
Returns: string — Modified MATCH clause of the WHERE clause.
query_posts_groupby()
Update the groupby clause.
Since: 4.2.0
Line: 1071
public function query_posts_groupby( $groupby ): string;
| Type | Name | Description |
|---|---|---|
string |
$groupby |
The current groupby clause. |
Returns: string — Updated groupby clause.
query_posts_orderby_clauses()
Update the orderby clauses for CRP queries.
Since: 3.5.2
Line: 1091
public function query_posts_orderby_clauses( $orderby_clauses, $query, $instance ): array;
| Type | Name | Description |
|---|---|---|
array |
$orderby_clauses |
Array of clauses. |
\WP_Query|\Better_Search_Query |
$query |
The WP_Query or Better_Search_Query instance. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance (optional). |
Returns: array — Updated array of clauses.
find_approximate_index()
Find the approximate index of a substring in an array of strings.
Since: 3.5.2
Line: 1152
public function find_approximate_index( $input_array, $substring ): int|bool;
| Type | Name | Description |
|---|---|---|
array |
$input_array |
Array of strings. |
string |
$substring |
Substring to search for. |
Returns: int|bool — Index of the substring in the array.
custom_table_join()
Modify the JOIN clause to include our custom tables.
Since: 4.2.0
Line: 1171
public function custom_table_join( $join, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$join |
The JOIN clause of the query. |
\WP_Query |
$query |
The WP_Query instance. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
Returns: string — Modified join.
modify_like_columns()
Swap LIKE column references from wp_posts.* to ct.* when custom tables are active.
Since: 4.3.1
Line: 1200
public function modify_like_columns( $like_columns, $instance ): array;
| Type | Name | Description |
|---|---|---|
array |
$like_columns |
Default column references array. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
Returns: array — Modified column references array.
should_use_custom_tables()
Determine if we should use custom tables for queries.
Since: 4.2.0
Line: 1219
public function should_use_custom_tables( ): bool;
Returns: bool — True if custom tables should be used.
query_posts_join()
Modify the posts_join clause for taxonomy weightage.
Since: 4.2.0
Line: 1253
public function query_posts_join( $join, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$join |
The JOIN clause of the query. |
\WP_Query |
$query |
The WP_Query instance. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
Returns: string — Updated JOIN clause.
add_max_execution_time()
Adds MAX_EXECUTION_TIME hint to MySQL queries.
Since: 4.2.0
Line: 1314
public function add_max_execution_time( $sql, $query ): string;
| Type | Name | Description |
|---|---|---|
string |
$sql |
The complete SQL query. |
\WP_Query |
$query |
The WP_Query instance. |
Returns: string — Modified SQL query with MAX_EXECUTION_TIME hint.
enforce_short_term_score_order()
Ensure final SQL orders short-term LIKE searches by computed score first.
Since: 4.3.0
Line: 1353
public function enforce_short_term_score_order( $sql, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$sql |
The complete SQL query. |
\WP_Query |
$query |
The WP_Query instance. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
Returns: string — Updated SQL query.
relax_like_restriction()
Relax the LIKE WHERE restriction when fuzzy search is active.
Since: 4.3.0
Line: 1469
public function relax_like_restriction( $where, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$where |
The search WHERE clause. |
\WP_Query |
$query |
The WP_Query instance. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
Returns: string — Updated WHERE clause.
wrap_fuzzy_like_request()
Wrap fuzzy LIKE requests so the outer query can filter by score.
Since: 4.3.0
Line: 1512
public function wrap_fuzzy_like_request( $request, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$request |
The SQL query. |
\WP_Query |
$query |
The WP_Query instance. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
Returns: string — Updated SQL query.
enforce_positive_score_filter()
Ensure fuzzy LIKE queries only return rows with positive computed score.
Since: 4.3.0
Line: 1580
public function enforce_positive_score_filter( $sql, $query, $instance ): string;
| Type | Name | Description |
|---|---|---|
string |
$sql |
The complete SQL query. |
\WP_Query |
$query |
The WP_Query instance. |
\Better_Search_Core_Query |
$instance |
The Better_Search_Core_Query instance. |
Returns: string — Updated SQL query.
add_cornerstone_posts()
Add cornerstone posts to the related posts list.
Since: 4.2.0
Line: 1667
public function add_cornerstone_posts( $posts, $query ): array;
| Type | Name | Description |
|---|---|---|
array |
$posts |
Array of post objects. |
\WP_Query |
$query |
The WP_Query instance. |
Returns: array — Modified array of post objects.