\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
optionson the fly. (default: value of'') conditions(false|array)- Conditions that can be applied. (default:
false) - When
arraythe following values may be used:'=','!=','>','>=','<','<=','LIKE','NOT LIKE','IN','NOT IN','BETWEEN','NOT BETWEEN','EXISTS','NOT EXISTS' values(false|\SearchWP\Option[])- When
optionsare made available, these are the correlatingvaluesto choose from. (default:false) - When
callablethe following arguments are passed: $option(string) The chosenoption.$search(string) Search string when searching.$include(string)optionsto use as a limiter when returning.application(array|callable)- The application of this
\SearchWP\Rule. Returns either a preparedSQLstatement that applies, or anarrayof\SearchWP\EntryIDs that satisfy the\SearchWP\Rule. (default:null) - When
callablethe following argument (arraywith the following keys) is passed: 'option'(string) The chosenoption.'value'(string) The chosenvalue.'condition'(string) The chosencondition.
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).

