Skip to content

SearchEvent ​

Type
Class
Namespace
craft\events
Inherits
craft\events\SearchEvent » craft\base\Event » yii\base\Event » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0.0

SearchEvent class.

View source

Public Properties ​

PropertyDescription
datamixed – The data that is passed to yii\base\Component::on() when attaching an event handler.
elementIdsinteger[], null
elementQuerycraft\elements\db\ElementQuery – The element query being executed.
handledboolean – Whether the event is handled.
namestring – The event name.
querycraft\search\SearchQuery – The search query
resultsarray, null – The raw search result data This will only be set ahead of time for craft\services\Search::EVENT_BEFORE_SCORE_RESULTS and craft\services\Search::EVENT_AFTER_SEARCH.
scoresarray<string,int>, null – The element scores indexed by element ID and site ID (e.g. '100-1').
senderobject, null – The sender of this event.
siteIdinteger, integer[], null – The site ID(s) to filter by

elementIds ​

Type
integer[], null
Default value
null

View source

elementQuery ​

Type
craft\elements\db\ElementQuery
Default value
null
Since
3.7.14

The element query being executed.

View source

query ​

Type
craft\search\SearchQuery
Default value
null

The search query

View source

results ​

Type
array, null
Default value
null
Since
3.6.0

The raw search result data

This will only be set ahead of time for craft\services\Search::EVENT_BEFORE_SCORE_RESULTS and craft\services\Search::EVENT_AFTER_SEARCH.

If an event handler modifies this from craft\services\Search::EVENT_BEFORE_SCORE_RESULTS, then craft\services\Search::searchElements() will score the results set on the event rather than the original results.

View source

scores ​

Type
array<string,int>, null
Default value
null
Since
4.3.0

The element scores indexed by element ID and site ID (e.g. '100-1').

This will only be set ahead of time for craft\services\Search::EVENT_AFTER_SEARCH.

If an event handler sets this from craft\services\Search::EVENT_BEFORE_SCORE_RESULTS or modifies it from craft\services\Search::EVENT_AFTER_SEARCH, then craft\services\Search::searchElements() will return its value rather than calculate the result scores itself.

View source

siteId ​

DEPRECATED

Deprecated in 5.0.0. The siteId property on elementQuery should be used instead.

Type
integer, integer[], null
Default value
null

The site ID(s) to filter by

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__construct()
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
hasHandlers()Returns a value indicating whether there is any handler attached to the specified class-level event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
off()Detaches an event handler from a class-level event.
offAll()Detaches all registered class-level event handlers.
on()Attaches an event handler to a class-level event.
once()Attaches an event handler to a class-level event, which will be triggered at most one time.
trigger()Triggers a class-level event.