6
6
namespace Magento \CatalogSearch \Model \Indexer ;
7
7
8
8
use Magento \CatalogSearch \Model \Indexer \Fulltext \Action \FullFactory ;
9
- use Magento \CatalogSearch \Model \Indexer \Scope \State ;
9
+ use Magento \CatalogSearch \Model \Indexer \Scope \StateFactory ;
10
10
use Magento \CatalogSearch \Model \ResourceModel \Fulltext as FulltextResource ;
11
- use Magento \Framework \App \ObjectManager ;
12
- use Magento \Framework \Search \Request \Config as SearchRequestConfig ;
13
- use Magento \Framework \Search \Request \DimensionFactory ;
14
- use Magento \Store \Model \StoreManagerInterface ;
11
+ use Magento \Framework \Indexer \Dimension \DimensionProviderInterface ;
12
+ use Magento \Store \Model \StoreDimensionProvider ;
15
13
16
14
/**
17
15
* Provide functionality for Fulltext Search indexing.
18
16
*
19
17
* @api
20
18
* @since 100.0.2
21
19
*/
22
- class Fulltext implements \Magento \Framework \Indexer \ActionInterface, \Magento \Framework \Mview \ActionInterface
20
+ class Fulltext implements
21
+ \Magento \Framework \Indexer \ActionInterface,
22
+ \Magento \Framework \Mview \ActionInterface,
23
+ \Magento \Framework \Indexer \Dimension \DimensionalIndexerInterface
23
24
{
24
25
/**
25
26
* Indexer ID in configuration
@@ -36,16 +37,6 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
36
37
*/
37
38
private $ indexerHandlerFactory ;
38
39
39
- /**
40
- * @var StoreManagerInterface
41
- */
42
- private $ storeManager ;
43
-
44
- /**
45
- * @var \Magento\Framework\Search\Request\DimensionFactory
46
- */
47
- private $ dimensionFactory ;
48
-
49
40
/**
50
41
* @var \Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full
51
42
*/
@@ -56,11 +47,6 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
56
47
*/
57
48
private $ fulltextResource ;
58
49
59
- /**
60
- * @var \Magento\Framework\Search\Request\Config
61
- */
62
- private $ searchRequestConfig ;
63
-
64
50
/**
65
51
* @var IndexSwitcherInterface
66
52
*/
@@ -71,90 +57,97 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
71
57
*/
72
58
private $ indexScopeState ;
73
59
60
+ /**
61
+ * @var DimensionProviderInterface
62
+ */
63
+ private $ dimensionProvider ;
64
+
74
65
/**
75
66
* @param FullFactory $fullActionFactory
76
67
* @param IndexerHandlerFactory $indexerHandlerFactory
77
- * @param StoreManagerInterface $storeManager
78
- * @param DimensionFactory $dimensionFactory
79
68
* @param FulltextResource $fulltextResource
80
- * @param SearchRequestConfig $searchRequestConfig
81
69
* @param array $data
82
70
* @param IndexSwitcherInterface $indexSwitcher
83
- * @param Scope\State $indexScopeState
71
+ * @param StateFactory $indexScopeStateFactory
72
+ * @param DimensionProviderInterface $dimensionProvider
84
73
*/
85
74
public function __construct (
86
75
FullFactory $ fullActionFactory ,
87
76
IndexerHandlerFactory $ indexerHandlerFactory ,
88
- StoreManagerInterface $ storeManager ,
89
- DimensionFactory $ dimensionFactory ,
90
77
FulltextResource $ fulltextResource ,
91
- SearchRequestConfig $ searchRequestConfig ,
92
- array $ data ,
93
- IndexSwitcherInterface $ indexSwitcher = null ,
94
- State $ indexScopeState = null
78
+ IndexSwitcherInterface $ indexSwitcher ,
79
+ StateFactory $ indexScopeStateFactory ,
80
+ DimensionProviderInterface $ dimensionProvider ,
81
+ array $ data
95
82
) {
96
83
$ this ->fullAction = $ fullActionFactory ->create (['data ' => $ data ]);
97
84
$ this ->indexerHandlerFactory = $ indexerHandlerFactory ;
98
- $ this ->storeManager = $ storeManager ;
99
- $ this ->dimensionFactory = $ dimensionFactory ;
100
85
$ this ->fulltextResource = $ fulltextResource ;
101
- $ this ->searchRequestConfig = $ searchRequestConfig ;
102
86
$ this ->data = $ data ;
103
- if (null === $ indexSwitcher ) {
104
- $ indexSwitcher = ObjectManager::getInstance ()->get (IndexSwitcherInterface::class);
105
- }
106
- if (null === $ indexScopeState ) {
107
- $ indexScopeState = ObjectManager::getInstance ()->get (State::class);
108
- }
109
87
$ this ->indexSwitcher = $ indexSwitcher ;
110
- $ this ->indexScopeState = $ indexScopeState ;
88
+ $ this ->indexScopeState = $ indexScopeStateFactory ->create ();
89
+ $ this ->dimensionProvider = $ dimensionProvider ;
111
90
}
112
91
113
92
/**
114
93
* Execute materialization on ids entities
115
94
*
116
- * @param int[] $ids
95
+ * @param int[] $entityIds
117
96
* @return void
97
+ * @throws \InvalidArgumentException
118
98
*/
119
- public function execute ($ ids )
99
+ public function execute ($ entityIds )
120
100
{
121
- $ storeIds = array_keys ($ this ->storeManager ->getStores ());
122
- /** @var IndexerHandler $saveHandler */
123
- $ saveHandler = $ this ->indexerHandlerFactory ->create ([
124
- 'data ' => $ this ->data
125
- ]);
126
- foreach ($ storeIds as $ storeId ) {
127
- $ dimension = $ this ->dimensionFactory ->create (['name ' => 'scope ' , 'value ' => $ storeId ]);
128
- $ productIds = array_unique (array_merge ($ ids , $ this ->fulltextResource ->getRelationsByChild ($ ids )));
129
- $ saveHandler ->deleteIndex ([$ dimension ], new \ArrayObject ($ productIds ));
130
- $ saveHandler ->saveIndex ([$ dimension ], $ this ->fullAction ->rebuildStoreIndex ($ storeId , $ ids ));
101
+ foreach ($ this ->dimensionProvider ->getIterator () as $ dimension ) {
102
+ $ this ->executeByDimension ($ dimension , new \ArrayIterator ($ entityIds ));
131
103
}
132
104
}
133
105
134
106
/**
135
- * Execute full indexation
136
- *
137
- * @return void
107
+ * {@inheritdoc}
108
+ * @throws \InvalidArgumentException
138
109
*/
139
- public function executeFull ( )
110
+ public function executeByDimension ( array $ dimensions , \ Traversable $ entityIds = null )
140
111
{
141
- $ storeIds = array_keys ($ this ->storeManager ->getStores ());
142
- /** @var IndexerHandler $saveHandler */
112
+ if (count ($ dimensions ) > 1 || !isset ($ dimensions [StoreDimensionProvider::DIMENSION_NAME ])) {
113
+ throw new \InvalidArgumentException ('Indexer " ' . self ::INDEXER_ID . '" support only Store dimension ' );
114
+ }
115
+ $ storeId = $ dimensions [StoreDimensionProvider::DIMENSION_NAME ]->getValue ();
143
116
$ saveHandler = $ this ->indexerHandlerFactory ->create ([
144
117
'data ' => $ this ->data
145
118
]);
146
- foreach ($ storeIds as $ storeId ) {
147
- $ dimensions = [$ this ->dimensionFactory ->create (['name ' => 'scope ' , 'value ' => $ storeId ])];
148
- $ this ->indexScopeState ->useTemporaryIndex ();
149
119
120
+ if (null === $ entityIds ) {
121
+ $ this ->indexScopeState ->useTemporaryIndex ();
150
122
$ saveHandler ->cleanIndex ($ dimensions );
151
123
$ saveHandler ->saveIndex ($ dimensions , $ this ->fullAction ->rebuildStoreIndex ($ storeId ));
152
124
153
125
$ this ->indexSwitcher ->switchIndex ($ dimensions );
154
126
$ this ->indexScopeState ->useRegularIndex ();
127
+
128
+ $ this ->fulltextResource ->resetSearchResultsByStore ($ storeId );
129
+ } else {
130
+ // internal implementation works only with array
131
+ $ entityIds = iterator_to_array ($ entityIds );
132
+ $ productIds = array_unique (
133
+ array_merge ($ entityIds , $ this ->fulltextResource ->getRelationsByChild ($ entityIds ))
134
+ );
135
+ $ saveHandler ->deleteIndex ($ dimensions , new \ArrayIterator ($ productIds ));
136
+ $ saveHandler ->saveIndex ($ dimensions , $ this ->fullAction ->rebuildStoreIndex ($ storeId , $ entityIds ));
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Execute full indexation
142
+ *
143
+ * @return void
144
+ * @throws \InvalidArgumentException
145
+ */
146
+ public function executeFull ()
147
+ {
148
+ foreach ($ this ->dimensionProvider ->getIterator () as $ dimension ) {
149
+ $ this ->executeByDimension ($ dimension );
155
150
}
156
- $ this ->fulltextResource ->resetSearchResults ();
157
- $ this ->searchRequestConfig ->reset ();
158
151
}
159
152
160
153
/**
0 commit comments