Query_Modifier
Class to modify Better_Search_Query with Pro features.
Namespace: WebberZone\Better_Search\Pro
Since: 4.2.0
Source: includes/class-query-modifier.php line 23
Methods
__construct()
Constructor
Line: 49
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: 61
public function hooks( );
get_weights()
Get the weights for the title, content, excerpt, taxonomies and primary boost.
Since: 4.2.0
Line: 87
public function get_weights( $args ): array;
| Type | Name | Description |
|---|---|---|
array | $args | Query arguments. |
Returns: array — Array of weights.
get_custom_table_content_clauses()
Get content match clauses for custom tables.
Since: 4.2.0
Line: 125
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: 164
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: 328
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: 367
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: 515
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: 578
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: 721
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: 741
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: 796
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: 815
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: 844
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: 863
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: 895
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: 947
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: 986
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: 1020
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: 1050
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: 1115
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: 1171
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.