Class yii\sphinx\ActiveDataProvider

Inheritanceyii\sphinx\ActiveDataProvider » yii\data\ActiveDataProvider » yii\data\BaseDataProvider » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable, yii\data\DataProviderInterface
Available since version2.0.4
Source Code https://github.com/yiisoft/yii2-sphinx/blob/master/ActiveDataProvider.php

ActiveDataProvider is an enhanced version of yii\data\ActiveDataProvider specific to the Sphinx.

It allows to fetch not only rows and total rows count, but also a meta information and facet results.

The following is an example of using ActiveDataProvider to provide facet results:

$provider = new ActiveDataProvider([
    'query' => Post::find()->facets(['author_id', 'category_id']),
    'pagination' => [
        'pageSize' => 20,
    ],
]);

// get the posts in the current page
$posts = $provider->getModels();

// get all facets
$facets = $provider->getFacets();

// get particular facet
$authorFacet = $provider->getFacet('author_id');

In case yii\sphinx\Query::showMeta() is set ActiveDataProvider will fetch total count value from the query meta information, avoiding extra counting query:

$provider = new ActiveDataProvider([
    'query' => Post::find()->showMeta(true),
    'pagination' => [
        'pageSize' => 20,
    ],
]);

$totalCount = $provider->getTotalCount(); // fetched from meta information

Note: when using 'meta' information results total count will be fetched after pagination limit applying, which eliminates ability to verify if requested page number actually exist. Data provider disables yii\data\Pagination::validatePage automatically in this case.

Note: because pagination offset and limit may exceed Sphinx 'max_matches' bounds, data provider will set 'max_matches' option automatically based on those values. However, if yii\sphinx\Query::showMeta() is set, such adjustment is not performed as it will break total count calculation, so you'll have to deal with 'max_matches' bounds on your own.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$behaviors yii\base\Behavior[] List of behaviors attached to this component. This property is read-only. yii\base\Component
$count integer The number of data models in the current page. This property is read-only. yii\data\BaseDataProvider
$db yii\db\Connection|array|string|null The DB connection object or the application component ID of the DB connection. yii\data\ActiveDataProvider
$facets array Query facet results. yii\sphinx\ActiveDataProvider
$id string An ID that uniquely identifies the data provider among all data providers. yii\data\BaseDataProvider
$key string|callable|null The column that is used as the key of the data models. yii\data\ActiveDataProvider
$keys array The list of key values corresponding to $models. Each data model in $models is uniquely identified by the corresponding key value in this array. yii\data\BaseDataProvider
$meta array Search query meta info yii\sphinx\ActiveDataProvider
$models array The list of data models in the current page. yii\data\BaseDataProvider
$pagination yii\data\Pagination|false The pagination object. If this is false, it means the pagination is disabled. Note that the type of this property differs in getter and setter. See getPagination() and setPagination() for details. yii\data\BaseDataProvider
$query yii\db\QueryInterface|null The query that is used to fetch data models and $totalCount if it is not explicitly set. yii\data\ActiveDataProvider
$sort yii\data\Sort|boolean The sorting object. If this is false, it means the sorting is disabled. Note that the type of this property differs in getter and setter. See getSort() and setSort() for details. yii\data\BaseDataProvider
$totalCount integer Total number of possible data models. yii\data\BaseDataProvider

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() yii\data\ActiveDataProvider
__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
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getCount() Returns the number of data models in the current page. yii\data\BaseDataProvider
getFacet() Returns results of the specified facet. yii\sphinx\ActiveDataProvider
getFacets() yii\sphinx\ActiveDataProvider
getKeys() Returns the key values associated with the data models. yii\data\BaseDataProvider
getMeta() yii\sphinx\ActiveDataProvider
getModels() Returns the data models in the current page. yii\data\BaseDataProvider
getPagination() Returns the pagination object used by this data provider. yii\data\BaseDataProvider
getSort() Returns the sorting object used by this data provider. yii\data\BaseDataProvider
getTotalCount() Returns the total number of data models. yii\data\BaseDataProvider
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
init() Initializes the DB connection component. yii\data\ActiveDataProvider
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
prepare() Prepares the data models and keys. yii\data\BaseDataProvider
refresh() Refreshes the data provider. yii\data\BaseDataProvider
setFacets() yii\sphinx\ActiveDataProvider
setKeys() Sets the key values associated with the data models. yii\data\BaseDataProvider
setMeta() yii\sphinx\ActiveDataProvider
setModels() Sets the data models in the current page. yii\data\BaseDataProvider
setPagination() Sets the pagination for this data provider. yii\data\BaseDataProvider
setSort() Sets the sort definition for this data provider. yii\data\ActiveDataProvider
setTotalCount() Sets the total number of data models. yii\data\BaseDataProvider
trigger() Triggers an event. yii\base\Component

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
prepareKeys() Prepares the keys associated with the currently available data models. yii\data\ActiveDataProvider
prepareModels() Prepares the data models that will be made available in the current page. yii\sphinx\ActiveDataProvider
prepareTotalCount() Returns a value indicating the total number of data models in this data provider. yii\sphinx\ActiveDataProvider

Property Details

$facets public property

Query facet results.

public array getFacets ( )
public void setFacets ( $facets )
$meta public property

Search query meta info

public array getMeta ( )
public void setMeta ( $meta )

Method Details

getFacet() public method

Returns results of the specified facet.

public array getFacet ( $name )
$name string

Facet name

return array

Facet results.

throws yii\base\InvalidCallException

if requested facet does not present in results.

getFacets() public method

public array getFacets ( )
return array

Query facet results.

getMeta() public method

public array getMeta ( )
return array

Search query meta info

prepareModels() protected method

Prepares the data models that will be made available in the current page.

protected array prepareModels ( )
return array

The available data models

prepareTotalCount() protected method

Returns a value indicating the total number of data models in this data provider.

protected integer prepareTotalCount ( )
return integer

Total number of data models in this data provider.

setFacets() public method

public void setFacets ( $facets )
$facets array

Query facet results.

setMeta() public method

public void setMeta ( $meta )
$meta array

Search query meta info