SearchWP

\SearchWP\Rule

Table of Contents

\SearchWP\Rule is responsible for modeling constraints surrounding which search results (\SearchWP\Entry) are considered when executing a \SearchWP\Query. For example:

  • Exclude Posts in the “Uncategorized” Category
  • Only show Updates published within the past 6 months
  • etc…

As opposed to db_where() in a \SearchWP\Source which always applies, \SearchWP\Rules are user-facing and are established when configuring Engines. \SearchWP\Rules are applied both during indexing and searching.

Arguments

When instantiating a new \SearchWP\Rule an array of the following can be provided:

name (string)
A unique name. (default: '')
label (string)
Display label. (default: value of name)
options (false|array|callable)
Options. (default: false)
option_values_ajax_tag (string)
AJAX callback to retrieve options on the fly. (default: value of '')
conditions (false|array)
Conditions that can be applied. (default: false)
When array the following values may be used: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'EXISTS', 'NOT EXISTS'
values (false|\SearchWP\Option[])
When options are made available, these are the correlating values to choose from. (default: false)
When callable the following arguments are passed:
$option (string) The chosen option.
$search (string) Search string when searching.
$include (string) options to use as a limiter when returning.
application (array|callable)
The application of this \SearchWP\Rule. Returns either a prepared SQL statement that applies, or an array of \SearchWP\Entry IDs that satisfy the \SearchWP\Rule. (default: null)
When callable the following argument (array with the following keys) is passed:
'option' (string) The chosen option.
'value' (string) The chosen value.
'condition' (string) The chosen condition.

Methods

When working with \SearchWP\Rule there are a number of methods to consider.

get_name()
Getter for name.
get_label()
Getter for label.
get_options()
Getter for options.
get_conditions()
Getter for conditions.
get_values( $option = '', $search = false, array $include = [] )
Getter for values.
get_application( array $settings )
Getter for application.
get_settings()
Getter for settings (i.e. as considered by an \SearchWP\Engine).