diff --git a/Oqtane.Client/Modules/Admin/Search/Index.razor b/Oqtane.Client/Modules/Admin/Search/Index.razor
index 8a32ff22..88653cca 100644
--- a/Oqtane.Client/Modules/Admin/Search/Index.razor
+++ b/Oqtane.Client/Modules/Admin/Search/Index.razor
@@ -106,9 +106,7 @@
try
{
_lastIndexedOn = DateTime.MinValue.ToString();
- var settings = await SettingService.GetSiteSettingsAsync(PageState.Site.SiteId);
- settings = SettingService.SetSetting(settings, "Search_LastIndexedOn", _lastIndexedOn, true);
- await SettingService.UpdateSiteSettingsAsync(settings, PageState.Site.SiteId);
+ await Save();
AddModuleMessage(Localizer["Message.Reindex"], MessageType.Success);
}
catch (Exception ex)
diff --git a/Oqtane.Server/Infrastructure/Jobs/SearchIndexJob.cs b/Oqtane.Server/Infrastructure/Jobs/SearchIndexJob.cs
index 21b28e40..22e16f0f 100644
--- a/Oqtane.Server/Infrastructure/Jobs/SearchIndexJob.cs
+++ b/Oqtane.Server/Infrastructure/Jobs/SearchIndexJob.cs
@@ -59,6 +59,13 @@ namespace Oqtane.Infrastructure
var currentTime = DateTime.UtcNow;
var lastIndexedOn = Convert.ToDateTime(siteSettings.GetValue(SearchLastIndexedOnSetting, DateTime.MinValue.ToString()));
+ if (lastIndexedOn == DateTime.MinValue)
+ {
+ // reset index
+ log += $"*Site Index Reset*
";
+ await searchService.DeleteSearchContentsAsync(site.SiteId);
+ }
+
var ignorePages = siteSettings.GetValue(SearchIgnorePagesSetting, "").Split(',');
var ignoreEntities = siteSettings.GetValue(SearchIgnoreEntitiesSetting, "").Split(',');
diff --git a/Oqtane.Server/Modules/Admin/Files/Manager/FileManager.cs b/Oqtane.Server/Modules/Admin/Files/Manager/FileManager.cs
index 96b75879..43dbda33 100644
--- a/Oqtane.Server/Modules/Admin/Files/Manager/FileManager.cs
+++ b/Oqtane.Server/Modules/Admin/Files/Manager/FileManager.cs
@@ -45,10 +45,25 @@ namespace Oqtane.Modules.Admin.Files.Manager
var path = folder.Path + file.Name;
var body = "";
- if (DocumentExtensions.Contains(Path.GetExtension(file.Name)))
+ if (System.IO.File.Exists(_fileRepository.GetFilePath(file)))
{
- // get the contents of the file
- body = System.IO.File.ReadAllText(_fileRepository.GetFilePath(file));
+ // only non-binary files can be indexed
+ if (DocumentExtensions.Contains(Path.GetExtension(file.Name)))
+ {
+ // get the contents of the file
+ try
+ {
+ body = System.IO.File.ReadAllText(_fileRepository.GetFilePath(file));
+ }
+ catch
+ {
+ // could not read the file
+ }
+ }
+ }
+ else
+ {
+ removed = true; // file does not exist on disk
}
var searchContent = new SearchContent
diff --git a/Oqtane.Server/Providers/DatabaseSearchProvider.cs b/Oqtane.Server/Providers/DatabaseSearchProvider.cs
index c3e5d28e..a662b106 100644
--- a/Oqtane.Server/Providers/DatabaseSearchProvider.cs
+++ b/Oqtane.Server/Providers/DatabaseSearchProvider.cs
@@ -235,9 +235,9 @@ namespace Oqtane.Providers
return text;
}
- public Task ResetIndex()
+ public Task DeleteSearchContent(int siteId)
{
- _searchContentRepository.DeleteAllSearchContent();
+ _searchContentRepository.DeleteAllSearchContent(siteId);
return Task.CompletedTask;
}
}
diff --git a/Oqtane.Server/Repository/Interfaces/ISearchContentRepository.cs b/Oqtane.Server/Repository/Interfaces/ISearchContentRepository.cs
index 8511b438..022c8012 100644
--- a/Oqtane.Server/Repository/Interfaces/ISearchContentRepository.cs
+++ b/Oqtane.Server/Repository/Interfaces/ISearchContentRepository.cs
@@ -12,7 +12,7 @@ namespace Oqtane.Repository
void DeleteSearchContent(int searchContentId);
void DeleteSearchContent(string entityName, string entryId);
void DeleteSearchContent(string uniqueKey);
- void DeleteAllSearchContent();
+ void DeleteAllSearchContent(int siteId);
SearchWord GetSearchWord(string word);
SearchWord AddSearchWord(SearchWord searchWord);
diff --git a/Oqtane.Server/Repository/SearchContentRepository.cs b/Oqtane.Server/Repository/SearchContentRepository.cs
index 53d736a5..5aa214ae 100644
--- a/Oqtane.Server/Repository/SearchContentRepository.cs
+++ b/Oqtane.Server/Repository/SearchContentRepository.cs
@@ -152,11 +152,17 @@ namespace Oqtane.Repository
}
}
- public void DeleteAllSearchContent()
+ public void DeleteAllSearchContent(int siteId)
{
using var db = _dbContextFactory.CreateDbContext();
- db.SearchContent.RemoveRange(db.SearchContent);
- db.SaveChanges();
+ // delete in batches of 100 records
+ var searchContents = db.SearchContent.Where(item => item.SiteId == siteId).Take(100).ToList();
+ while (searchContents.Count > 0)
+ {
+ db.SearchContent.RemoveRange(searchContents);
+ db.SaveChanges();
+ searchContents = db.SearchContent.Where(item => item.SiteId == siteId).Take(100).ToList();
+ }
}
public SearchWord GetSearchWord(string word)
diff --git a/Oqtane.Server/Services/SearchService.cs b/Oqtane.Server/Services/SearchService.cs
index 528f48e1..9a4f7ea1 100644
--- a/Oqtane.Server/Services/SearchService.cs
+++ b/Oqtane.Server/Services/SearchService.cs
@@ -149,6 +149,12 @@ namespace Oqtane.Services
return result;
}
+ public async Task DeleteSearchContentsAsync(int siteId)
+ {
+ var searchProvider = GetSearchProvider(siteId);
+ await searchProvider.DeleteSearchContent(siteId);
+ }
+
private ISearchProvider GetSearchProvider(int siteId)
{
var providerName = GetSearchProviderSetting(siteId);
diff --git a/Oqtane.Shared/Interfaces/ISearchProvider.cs b/Oqtane.Shared/Interfaces/ISearchProvider.cs
index 43981e8d..23713334 100644
--- a/Oqtane.Shared/Interfaces/ISearchProvider.cs
+++ b/Oqtane.Shared/Interfaces/ISearchProvider.cs
@@ -11,7 +11,7 @@ namespace Oqtane.Services
Task> GetSearchResultsAsync(SearchQuery searchQuery);
Task SaveSearchContent(SearchContent searchContent, Dictionary siteSettings);
-
- Task ResetIndex();
+
+ Task DeleteSearchContent(int siteId);
}
}
diff --git a/Oqtane.Shared/Interfaces/ISearchService.cs b/Oqtane.Shared/Interfaces/ISearchService.cs
index 48cef29c..7acf9764 100644
--- a/Oqtane.Shared/Interfaces/ISearchService.cs
+++ b/Oqtane.Shared/Interfaces/ISearchService.cs
@@ -9,5 +9,7 @@ namespace Oqtane.Services
Task GetSearchResultsAsync(SearchQuery searchQuery);
Task SaveSearchContentsAsync(List searchContents, Dictionary siteSettings);
+
+ Task DeleteSearchContentsAsync(int siteId);
}
}