17
17
use Magento \Framework \Indexer \SaveHandler \IndexerInterface ;
18
18
use Magento \Framework \Search \Request \Dimension ;
19
19
use Magento \Framework \Indexer \CacheContext ;
20
+ use Magento \CatalogSearch \Model \Indexer \Fulltext \Processor ;
20
21
21
22
/**
22
23
* Indexer Handler for Elasticsearch engine.
@@ -80,6 +81,11 @@ class IndexerHandler implements IndexerInterface
80
81
*/
81
82
private $ cacheContext ;
82
83
84
+ /**
85
+ * @var Processor
86
+ */
87
+ private $ processor ;
88
+
83
89
/**
84
90
* IndexerHandler constructor.
85
91
* @param IndexStructureInterface $indexStructure
@@ -91,6 +97,7 @@ class IndexerHandler implements IndexerInterface
91
97
* @param int $batchSize
92
98
* @param DeploymentConfig|null $deploymentConfig
93
99
* @param CacheContext|null $cacheContext
100
+ * @param Processor|null $processor
94
101
*/
95
102
public function __construct (
96
103
IndexStructureInterface $ indexStructure ,
@@ -101,7 +108,8 @@ public function __construct(
101
108
array $ data = [],
102
109
int $ batchSize = self ::DEFAULT_BATCH_SIZE ,
103
110
?DeploymentConfig $ deploymentConfig = null ,
104
- ?CacheContext $ cacheContext = null
111
+ ?CacheContext $ cacheContext = null ,
112
+ ?Processor $ processor = null
105
113
) {
106
114
$ this ->indexStructure = $ indexStructure ;
107
115
$ this ->adapter = $ adapter ;
@@ -112,6 +120,7 @@ public function __construct(
112
120
$ this ->scopeResolver = $ scopeResolver ;
113
121
$ this ->deploymentConfig = $ deploymentConfig ?: ObjectManager::getInstance ()->get (DeploymentConfig::class);
114
122
$ this ->cacheContext = $ cacheContext ?: ObjectManager::getInstance ()->get (CacheContext::class);
123
+ $ this ->processor = $ processor ?: ObjectManager::getInstance ()->get (Processor::class);
115
124
}
116
125
117
126
/**
@@ -129,7 +138,9 @@ public function saveIndex($dimensions, \Traversable $documents)
129
138
foreach ($ this ->batch ->getItems ($ documents , $ this ->batchSize ) as $ documentsBatch ) {
130
139
$ docs = $ this ->adapter ->prepareDocsPerStore ($ documentsBatch , $ scopeId );
131
140
$ this ->adapter ->addDocs ($ docs , $ scopeId , $ this ->getIndexerId ());
132
- $ this ->updateCacheContext ($ docs );
141
+ if ($ this ->processor ->getIndexer ()->isScheduled ()) {
142
+ $ this ->updateCacheContext ($ docs );
143
+ }
133
144
}
134
145
$ this ->adapter ->updateAlias ($ scopeId , $ this ->getIndexerId ());
135
146
return $ this ;
0 commit comments