Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Query Class Reference
Inheritance diagram for Query:
AbstractModel QueryInterface DataObject

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, Registry $registry, QueryCollectionFactory $queryCollectionFactory, CollectionFactory $searchCollectionFactory, StoreManagerInterface $storeManager, ScopeConfigInterface $scopeConfig, AbstractResource $resource=null, DbCollection $resourceCollection=null, array $data=[])
 
 getSearchCollection ()
 
 getSuggestCollection ()
 
 loadByQuery ($text)
 
 loadByQueryText ($text)
 
 setStoreId ($storeId)
 
 getStoreId ()
 
 prepare ()
 
 saveIncrementalPopularity ()
 
 saveNumResults ($numResults)
 
 getMinQueryLength ()
 
 getMaxQueryLength ()
 
 getQueryText ()
 
 isQueryTextExceeded ()
 
 isQueryTextShort ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const CACHE_TAG = 'SEARCH_QUERY'
 
const XML_PATH_MIN_QUERY_LENGTH = 'catalog/search/min_query_length'
 
const XML_PATH_MAX_QUERY_LENGTH = 'catalog/search/max_query_length'
 

Protected Member Functions

 _construct ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_eventPrefix = 'search_query'
 
 $_eventObject = 'search_query'
 
 $_scopeConfig
 
 $_storeManager
 
 $_searchCollectionFactory
 
 $_queryCollectionFactory
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Search query model

@method \Magento\Search\Model\Query setQueryText(string $value) @method int getNumResults() @method \Magento\Search\Model\Query setNumResults(int $value) @method int getPopularity() @method \Magento\Search\Model\Query setPopularity(int $value) @method string getRedirect() @method \Magento\Search\Model\Query setRedirect(string $value) @method int getDisplayInTerms() @method \Magento\Search\Model\Query setDisplayInTerms(int $value) @method \Magento\Search\Model\Query setQueryNameExceeded(bool $value) @method int getIsActive() @method \Magento\Search\Model\Query setIsActive(int $value) @method int getIsProcessed() @method \Magento\Search\Model\Query setIsProcessed(int $value) @method string getUpdatedAt() @method \Magento\Search\Model\Query setUpdatedAt(string $value) @method \Magento\Search\Model\Query setIsQueryTextExceeded(bool $value) @method \Magento\Search\Model\Query setIsQueryTextShort(bool $value) @SuppressWarnings(PHPMD.CouplingBetweenObjects) @api

Since
100.0.2

Definition at line 44 of file Query.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
Registry  $registry,
QueryCollectionFactory  $queryCollectionFactory,
CollectionFactory  $searchCollectionFactory,
StoreManagerInterface  $storeManager,
ScopeConfigInterface  $scopeConfig,
AbstractResource  $resource = null,
DbCollection  $resourceCollection = null,
array  $data = [] 
)

Construct

Parameters
\Magento\Framework\Model\Context$context
Registry$registry
QueryCollectionFactory$queryCollectionFactory
CollectionFactory$searchCollectionFactory
StoreManagerInterface$storeManager
ScopeConfigInterface$scopeConfig
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
DbCollection$resourceCollection
array$data

Definition at line 107 of file Query.php.

117  {
118  $this->_queryCollectionFactory = $queryCollectionFactory;
119  $this->_searchCollectionFactory = $searchCollectionFactory;
120  $this->_storeManager = $storeManager;
121  $this->_scopeConfig = $scopeConfig;
122  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
123  }
$storeManager
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _construct()

_construct ( )
protected

Init resource model

Returns
void

Definition at line 130 of file Query.php.

131  {
132  $this->_init(\Magento\Search\Model\ResourceModel\Query::class);
133  }

◆ getMaxQueryLength()

getMaxQueryLength ( )

Retrieve maximum query length

Returns
int
Exceptions

Definition at line 288 of file Query.php.

289  {
290  return $this->_scopeConfig->getValue(
291  self::XML_PATH_MAX_QUERY_LENGTH,
292  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
293  $this->getStoreId()
294  );
295  }

◆ getMinQueryLength()

getMinQueryLength ( )

Retrieve minimum query length

Returns
int
Exceptions

Definition at line 273 of file Query.php.

274  {
275  return $this->_scopeConfig->getValue(
276  self::XML_PATH_MIN_QUERY_LENGTH,
277  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
278  $this->getStoreId()
279  );
280  }

◆ getQueryText()

getQueryText ( )

Returns
string

Implements QueryInterface.

Definition at line 300 of file Query.php.

301  {
302  return $this->getDataByKey('query_text');
303  }

◆ getSearchCollection()

getSearchCollection ( )

Retrieve search collection

Returns
Collection

Definition at line 140 of file Query.php.

141  {
142  return $this->_searchCollectionFactory->create();
143  }

◆ getStoreId()

getStoreId ( )

Retrieve store Id

Returns
int
Exceptions

Definition at line 211 of file Query.php.

212  {
213  if (!($storeId = $this->getData('store_id'))) {
214  $storeId = $this->_storeManager->getStore()->getId();
215  }
216  return $storeId;
217  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getSuggestCollection()

getSuggestCollection ( )

Retrieve collection of suggest queries

Returns
QueryCollection
Exceptions

Definition at line 151 of file Query.php.

152  {
153  $collection = $this->getData('suggest_collection');
154  if ($collection === null) {
155  $collection = $this->_queryCollectionFactory->create()->setStoreId(
156  $this->getStoreId()
157  )->setQueryFilter(
158  $this->getQueryText()
159  );
160  $this->setData('suggest_collection', $collection);
161  }
162  return $collection;
163  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ isQueryTextExceeded()

isQueryTextExceeded ( )

Check if query maximum length exceeded.

Returns
bool @codeCoverageIgnore

Definition at line 311 of file Query.php.

312  {
313  return $this->getData('is_query_text_exceeded');
314  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ isQueryTextShort()

isQueryTextShort ( )

Check if minimum query length reached.

Returns
bool @codeCoverageIgnore
Since
100.1.0

Definition at line 323 of file Query.php.

324  {
325  return $this->getData('is_query_text_short');
326  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ loadByQuery()

loadByQuery (   $text)

Load Query object by query string

Parameters
string$text
Returns
$this
Exceptions

Definition at line 173 of file Query.php.

174  {
175  $this->loadByQueryText($text);
176  return $this;
177  }
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43

◆ loadByQueryText()

loadByQueryText (   $text)

Load Query object only by query text

Parameters
string$text
Returns
$this
Exceptions

Definition at line 186 of file Query.php.

187  {
188  $this->_getResource()->loadByQueryText($this, $text);
189  $this->_afterLoad();
190  $this->setOrigData();
191  return $this;
192  }
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43

◆ prepare()

prepare ( )

Prepare save query for result

Returns
$this
Exceptions

Definition at line 225 of file Query.php.

226  {
227  if (!$this->getId()) {
228  $this->setIsActive(0);
229  $this->setIsProcessed(0);
230  $this->save();
231  $this->setIsActive(1);
232  }
233 
234  return $this;
235  }

◆ saveIncrementalPopularity()

saveIncrementalPopularity ( )

Save query with incremental popularity

Returns
$this
Exceptions

Definition at line 244 of file Query.php.

245  {
246  $this->getResource()->saveIncrementalPopularity($this);
247 
248  return $this;
249  }

◆ saveNumResults()

saveNumResults (   $numResults)

Save query with number of results

Parameters
int$numResults
Returns
$this
Exceptions

Definition at line 259 of file Query.php.

260  {
261  $this->setNumResults($numResults);
262  $this->getResource()->saveNumResults($this);
263 
264  return $this;
265  }

◆ setStoreId()

setStoreId (   $storeId)

Set Store Id

Parameters
int$storeId
Returns
void

Definition at line 200 of file Query.php.

201  {
202  $this->setData('store_id', $storeId);
203  }

Field Documentation

◆ $_eventObject

$_eventObject = 'search_query'
protected

Definition at line 58 of file Query.php.

◆ $_eventPrefix

$_eventPrefix = 'search_query'
protected

Definition at line 51 of file Query.php.

◆ $_queryCollectionFactory

$_queryCollectionFactory
protected

Definition at line 92 of file Query.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 71 of file Query.php.

◆ $_searchCollectionFactory

$_searchCollectionFactory
protected

Definition at line 85 of file Query.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 78 of file Query.php.

◆ CACHE_TAG

const CACHE_TAG = 'SEARCH_QUERY'

Definition at line 60 of file Query.php.

◆ XML_PATH_MAX_QUERY_LENGTH

const XML_PATH_MAX_QUERY_LENGTH = 'catalog/search/max_query_length'

Definition at line 64 of file Query.php.

◆ XML_PATH_MIN_QUERY_LENGTH

const XML_PATH_MIN_QUERY_LENGTH = 'catalog/search/min_query_length'

Definition at line 62 of file Query.php.


The documentation for this class was generated from the following file: