public bool UpdateIndex(string indexName) { ILockFile lockFile = null; var settingsFilename = GetSettingsFileName(indexName); var lockFilename = settingsFilename + ".lock"; // acquire a lock file on the index if (!lockFileManager.TryAcquireLock(lockFilename, ref lockFile)) { logger.Value.Info("Index was requested but is already running"); return(false); } using (lockFile) { if (!indexManager.HasIndexProvider()) { return(false); } // load index settings to know what is the current state of indexing var indexSettings = LoadSettings(indexName); indexProvider = indexManager.GetSearchIndexProvider(); indexProvider.CreateIndex(indexName); return(UpdateIndex(indexName, settingsFilename, indexSettings)); } }
/// <summary> /// Loads file items from index. /// Recreates index if index needs to be updated or forced to be rebuild by rebuildIndex parameter. /// </summary> /// <param name="rebuildIndex"></param> public void LoadItems(bool rebuildIndex) { if (rebuildIndex) { fileIndex.CreateIndex(); } else { fileIndex.LoadIndex(); } }
public bool UpdateIndexBatch(string indexName) { ILockFile lockFile = null; var settingsFilename = GetSettingsFileName(indexName); var lockFilename = settingsFilename + ".lock"; // acquire a lock file on the index if (!_lockFileManager.TryAcquireLock(lockFilename, ref lockFile)) { Logger.Information("Index was requested but is already running"); return(false); } using (lockFile) { if (!_indexManager.HasIndexProvider()) { return(false); } // load index settings to know what is the current state of indexing var indexSettings = LoadSettings(indexName); _indexProvider = _indexManager.GetSearchIndexProvider(); if (indexSettings.Mode == IndexingMode.Rebuild && indexSettings.LastContentId == 0) { _indexProvider.CreateIndex(indexName); // mark the last available task at the moment the process is started. // once the Rebuild is done, Update will start at this point of the table indexSettings.LastIndexedId = _taskRepository .Table .OrderByDescending(x => x.Id) .Select(x => x.Id) .FirstOrDefault(); } // execute indexing commands by batch of [ContentItemsPerLoop] content items return(BatchIndex(indexName, settingsFilename, indexSettings)); } }
public bool UpdateIndexBatch(string indexName) { ILockFile lockFile = null; var settingsFilename = GetSettingsFileName(indexName); var lockFilename = settingsFilename + ".lock"; // acquire a lock file on the index if (!_lockFileManager.TryAcquireLock(lockFilename, ref lockFile)) { Logger.Information("Index was requested but is already running"); return false; } using (lockFile) { if (!_indexManager.HasIndexProvider()) { return false; } // load index settings to know what is the current state of indexing var indexSettings = LoadSettings(indexName); _indexProvider = _indexManager.GetSearchIndexProvider(); if (indexSettings.Mode == IndexingMode.Rebuild && indexSettings.LastContentId == 0) { _indexProvider.CreateIndex(indexName); // mark the last available task at the moment the process is started. // once the Rebuild is done, Update will start at this point of the table indexSettings.LastIndexedId = _taskRepository .Table .OrderByDescending(x => x.Id) .Select(x => x.Id) .FirstOrDefault(); } // execute indexing commands by batch of [ContentItemsPerLoop] content items return BatchIndex(indexName, settingsFilename, indexSettings); } }
public void IndexProviderShouldCreateNewIndex() { Assert.That(Indexes().Count(), Is.EqualTo(0)); _provider.CreateIndex("default"); Assert.That(Indexes().Count(), Is.EqualTo(1)); }
public void SearchTermsShouldBeFoundInMultipleFields() { _provider.CreateIndex("default"); _provider.Store("default", _provider.New(42) .Add("title", "title1 title2 title3").Analyze() .Add("date", new DateTime(2010, 05, 28, 14, 13, 56, 123)) ); Assert.IsNotNull(_provider.CreateSearchBuilder("default").Get(42)); Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title1").Search().FirstOrDefault()); Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title2").Search().FirstOrDefault()); Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title3").Search().FirstOrDefault()); Assert.IsNull(_provider.CreateSearchBuilder("default").WithField("title", "title4").Search().FirstOrDefault()); }