Craft 3 Class Reference

Class craft\services\Search

Inheritance
craft\services\Search » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/services/Search.php

Handles search operations.

An instance of the Search service is globally accessible in Craft via Craft::$app->search.

Public Properties
Property Type Description Defined By
$maxPostgresKeywordLength integer Because the keywords column in the search index table is a B-TREE index on Postgres, you can get an "index row size exceeds maximum for index" error with a lot of data. craft\services\Search
$minFullTextWordLength integer The minimum word length that keywords must be in order to use a full-text search. craft\services\Search
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
filterElementIdsByQuery() Filters a list of element IDs by a given search query. craft\services\Search
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
indexElementAttributes() Indexes the attributes of a given element defined by its element type. craft\services\Search
indexElementFields() Indexes the field values for a given element and site. craft\services\Search
init() Initializes the object. craft\services\Search
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
trigger() Triggers an event. yii\base\Component
Events
Event Type Description Defined By

Property Details

$maxPostgresKeywordLength public property #

Because the keywords column in the search index table is a B-TREE index on Postgres, you can get an "index row size exceeds maximum for index" error with a lot of data. This value is a hard limit to truncate search index data for a single row in Postgres.

public integer $maxPostgresKeywordLength 2450

$minFullTextWordLength public property #

The minimum word length that keywords must be in order to use a full-text search.

public integer $minFullTextWordLength null

Method Details

filterElementIdsByQuery() public method #

Filters a list of element IDs by a given search query.

public array filterElementIdsByQuery ( array $elementIds, $query, \craft\services\bool $scoreResults true, \craft\services\int $siteId null, \craft\services\bool $returnScores false )
$elementIds integer[] The list of element IDs to filter by the search query.
$query string, array, craft\search\SearchQuery The search query (either a string or a SearchQuery instance)
$scoreResults boolean Whether to order the results based on how closely they match the query.
$siteId integer, null The site ID to filter by.
$returnScores boolean Whether the search scores should be included in the results. If true, results will be returned as element ID => score.
return array The filtered list of element IDs.

indexElementAttributes() public method #

Indexes the attributes of a given element defined by its element type.

public boolean indexElementAttributes ( craft\base\ElementInterface $element )
$element craft\base\ElementInterface
return boolean Whether the indexing was a success.
throws craft\errors\SiteNotFoundException

indexElementFields() public method #

Indexes the field values for a given element and site.

public boolean indexElementFields ( \craft\services\int $elementId, \craft\services\int $siteId, array $fields )
$elementId integer The ID of the element getting indexed.
$siteId integer The site ID of the content getting indexed.
$fields array The field values, indexed by field ID.
return boolean Whether the indexing was a success.
throws craft\errors\SiteNotFoundException

init() public method #

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )

Event Details

EVENT_AFTER_SEARCH event of type craft\events\SearchEvent #

The event that is triggered after a search is performed.

EVENT_BEFORE_SEARCH event of type craft\events\SearchEvent #

The event that is triggered before a search is performed.