/
Fulltext.php
102 lines (94 loc) · 2.8 KB
/
Fulltext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Model\ResourceModel;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\EntityManager\MetadataPool;
/**
* CatalogSearch Fulltext Index resource model
*
* @api
* @since 100.0.2
*/
class Fulltext extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
* Core event manager proxy
*
* @var \Magento\Framework\Event\ManagerInterface
*/
protected $_eventManager;
/**
* Holder for MetadataPool instance.
*
* @var MetadataPool
*/
private $metadataPool;
/**
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param string $connectionName
* @param MetadataPool $metadataPool
*/
public function __construct(
\Magento\Framework\Model\ResourceModel\Db\Context $context,
\Magento\Framework\Event\ManagerInterface $eventManager,
$connectionName = null,
MetadataPool $metadataPool = null
) {
$this->_eventManager = $eventManager;
$this->metadataPool = $metadataPool ? : ObjectManager::getInstance()->get(MetadataPool::class);
parent::__construct($context, $connectionName);
}
/**
* Init resource model
*
* @return void
*/
protected function _construct()
{
$this->_init('catalogsearch_fulltext', 'product_id');
}
/**
* Reset search results
*
* @return $this
*/
public function resetSearchResults()
{
$connection = $this->getConnection();
$connection->update($this->getTable('search_query'), ['is_processed' => 0], ['is_processed != 0']);
$this->_eventManager->dispatch('catalogsearch_reset_search_result');
return $this;
}
/**
* Retrieve product relations by children.
*
* @param int|array $childIds
* @return array
* @since 100.2.0
*/
public function getRelationsByChild($childIds)
{
$connection = $this->getConnection();
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$select = $connection
->select()
->from(
['relation' => $this->getTable('catalog_product_relation')],
[]
)->distinct(true)
->join(
['cpe' => $this->getTable('catalog_product_entity')],
'cpe.' . $linkField . ' = relation.parent_id',
['cpe.entity_id']
)->where(
'relation.child_id IN (?)',
$childIds
);
return $connection->fetchCol($select);
}
}