SearchWP

\SearchWP\Attribute

Table of Contents

\SearchWP\Attribute responsible for modeling the individual parts that make up a \SearchWP\Source. For example:

  • Entry title
  • Entry content
  • Entry slug
  • Custom Fields
  • etc…

Arguments

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

name (string)
A unique name. (default: '')
label (string)
Display label. (default: value of name)
default (false|integer)
If this \SearchWP\Attribute should be enabled by default return int. (default: false)
options (array|callable)
When provided, multiple instances of this \SearchWP\Attribute are considered, e.g. Custom Fields each with a meta_key. (default: [])
allow_custom (boolean)
Whether user-defined options can be added. (default: false)
phrases (boolean|array)
Whether this \SearchWP\Attribute should support phrase based searching. (default: false)
When array the following array keys apply:
table (string) The database table name.
column (string) The database table column to match phrases against.
id (string) The database table column tracking entry IDs.
data (mixed)
The data for this \SearchWP\Attribute. (default: null)
When callable the following arguments are passed:
id (string) \SearchWP\Source ID.
chosen_option (string) The chosen \SearchWP\Attribute option when applicable.

Methods

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

get_name()
Getter for name.
get_label( $source )
Getter for label. If a \SearchWP\Source is provided the searchwp\source\attribute\label filter is applied.
get_phrases()
Getter for phrase support argument value.
options_static()
Whether options is static (as opposed to callable).
get_options()
Getter for options.
get_settings()
Getter for settings (i.e. as considered by an \SearchWP\Engine).
get_default()
Getter for default.
set_settings() (integer|array $settings)
Setter for settings (i.e. as considered by an \SearchWP\Engine). Use integer when there are no options, else use array with keys for each option and corresponding integer values.
get_data() ( $id, $option = '', $raw = false )
Getter for data.
$id (string) \SearchWP\Source ID.
$option (string) option value, when applicable.
$raw (boolean) Whether to return the raw data, default is to tokenize.

Hooks

There are a number of hooks available to further modify the behavior of \SearchWP\Attribute: