public async Task <Unit> Handle(RebuildSearchIndex request, CancellationToken cancellationToken)
    {
        bool indexFolderExists = Directory.Exists(FileSystemLayout.SearchIndexFolder);

        await _searchIndex.Initialize(_localFileSystem);

        if (!indexFolderExists ||
            await _configElementRepository.GetValue <int>(ConfigElementKey.SearchIndexVersion) <
            _searchIndex.Version)
        {
            _logger.LogInformation("Migrating search index to version {Version}", _searchIndex.Version);

            List <int> itemIds = await _searchRepository.GetItemIdsToIndex();

            await _searchIndex.Rebuild(_searchRepository, itemIds);

            await _configElementRepository.Upsert(ConfigElementKey.SearchIndexVersion, _searchIndex.Version);

            _logger.LogInformation("Done migrating search index");
        }
        else
        {
            _logger.LogInformation("Search index is already version {Version}", _searchIndex.Version);
        }

        return(Unit.Default);
    }
Ejemplo n.º 2
0
        private void IndexRebuild(string indexName)
        {
            Log.Info("CI: RebuildSearchIndexes started: " + indexName, this);

            if (indexName == "system")
            {
                Sitecore.Search.SearchManager.GetIndex("system").Rebuild();
            }
            else
            {
                ISearchIndex index = ContentSearchManager.GetIndex(indexName);
                index.Rebuild();
            }

            Log.Info("CI: RebuildSearchIndexes finished: " + indexName, this);
        }
Ejemplo n.º 3
0
        public async Task <Unit> Handle(RebuildSearchIndex request, CancellationToken cancellationToken)
        {
            bool indexFolderExists = Directory.Exists(FileSystemLayout.SearchIndexFolder);

            if (!indexFolderExists ||
                await _configElementRepository.GetValue <int>(ConfigElementKey.SearchIndexVersion) <
                _searchIndex.Version)
            {
                _logger.LogDebug("Migrating search index to version {Version}", _searchIndex.Version);

                List <int> itemIds = await _searchRepository.GetItemIdsToIndex();

                await _searchIndex.Rebuild(itemIds);

                Option <ConfigElement> maybeVersion =
                    await _configElementRepository.Get(ConfigElementKey.SearchIndexVersion);

                await maybeVersion.Match(
                    version =>
                {
                    version.Value = _searchIndex.Version.ToString();
                    return(_configElementRepository.Update(version));
                },
                    () =>
                {
                    var configElement = new ConfigElement
                    {
                        Key   = ConfigElementKey.SearchIndexVersion.Key,
                        Value = _searchIndex.Version.ToString()
                    };
                    return(_configElementRepository.Add(configElement));
                });

                _logger.LogDebug("Done migrating search index");
            }
            else
            {
                _logger.LogDebug("Search index is already version {Version}", _searchIndex.Version);
            }

            return(Unit.Default);
        }
Ejemplo n.º 4
0
 public void Rebuild()
 {
     this.CloseSearcher();
     _searchIndex.Rebuild();
 }