68 private $stopwordsModule;
73 private $stopwordsDirectory;
99 $stopwordsModule =
'',
100 $stopwordsDirectory =
'' 108 $this->stopwordsModule = $stopwordsModule;
109 $this->stopwordsDirectory = $stopwordsDirectory;
119 $queryParts = explode(
' ',
$query);
120 $query = implode(
' ', array_diff($queryParts, $stopwords));
133 $fileDir = $this->moduleDirReader->getModuleDir(
Dir::MODULE_ETC_DIR, $this->stopwordsModule)
134 .
'/' . $this->stopwordsDirectory;
135 $source = $this->readFactory->create($fileDir);
136 $fileStats =
$source->stat($filename);
137 if (((
time() - $fileStats[
'mtime']) > self::STOPWORDS_FILE_MODIFICATION_TIME_GAP)
138 && ($cachedValue = $this->configCache->load(self::CACHE_ID))) {
139 $stopwords = $this->getSerializer()->unserialize($cachedValue);
141 $fileContent =
$source->readFile($filename);
142 $stopwords = explode(
"\n", $fileContent);
143 $this->configCache->save($this->getSerializer()->serialize($stopwords), self::CACHE_ID);
156 $stopwordsInfo = $this->esConfig->getStopwordsInfo();
157 $storeId = $this->storeManager->getStore()->getId();
158 $this->localeResolver->emulate(
$storeId);
159 $locale = $this->localeResolver->getLocale();
160 $stopwordsFile = isset($stopwordsInfo[$locale]) ? $stopwordsInfo[$locale] : $stopwordsInfo[
'default'];
161 return $stopwordsFile;
170 private function getSerializer()
172 if (
null === $this->serializer) {
176 return $this->serializer;
const STOPWORDS_FILE_MODIFICATION_TIME_GAP
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Locale\Resolver $localeResolver, ReadFactory $readFactory, \Magento\Framework\App\Cache\Type\Config $configCache, EsConfigInterface $esConfig, \Magento\Framework\Module\Dir\Reader $moduleDirReader, $stopwordsModule='', $stopwordsDirectory='')