Merge pull request #4405 from sbwalker/dev
testing search indexing of files
This commit is contained in:
commit
8c0271643d
19
Oqtane.Client/Modules/Admin/Files/ModuleInfo.cs
Normal file
19
Oqtane.Client/Modules/Admin/Files/ModuleInfo.cs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
using Oqtane.Documentation;
|
||||||
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
|
||||||
|
namespace Oqtane.Modules.Admin.Files
|
||||||
|
{
|
||||||
|
[PrivateApi("Mark this as private, since it's not very useful in the public docs")]
|
||||||
|
public class ModuleInfo : IModule
|
||||||
|
{
|
||||||
|
public ModuleDefinition ModuleDefinition => new ModuleDefinition
|
||||||
|
{
|
||||||
|
Name = "File Management",
|
||||||
|
Description = "File Management",
|
||||||
|
Version = Constants.Version,
|
||||||
|
Categories = "Admin",
|
||||||
|
ServerManagerType = "Oqtane.Modules.Admin.Files.Manager.FileManager, Oqtane.Server"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -90,7 +90,7 @@ namespace Oqtane.Infrastructure
|
||||||
EntityId = page.PageId.ToString(),
|
EntityId = page.PageId.ToString(),
|
||||||
Title = !string.IsNullOrEmpty(page.Title) ? page.Title : page.Name,
|
Title = !string.IsNullOrEmpty(page.Title) ? page.Title : page.Name,
|
||||||
Description = string.Empty,
|
Description = string.Empty,
|
||||||
Body = $"{page.Name} {page.Title}",
|
Body = string.Empty,
|
||||||
Url = $"{(!string.IsNullOrEmpty(page.Path) && !page.Path.StartsWith("/") ? "/" : "")}{page.Path}",
|
Url = $"{(!string.IsNullOrEmpty(page.Path) && !page.Path.StartsWith("/") ? "/" : "")}{page.Path}",
|
||||||
Permissions = $"{EntityNames.Page}:{page.PageId}",
|
Permissions = $"{EntityNames.Page}:{page.PageId}",
|
||||||
ContentModifiedBy = page.ModifiedBy,
|
ContentModifiedBy = page.ModifiedBy,
|
||||||
|
@ -141,7 +141,7 @@ namespace Oqtane.Infrastructure
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log += ex.Message + "<br />";
|
log += $"Error Indexing Module {pageModule.Module.ModuleDefinition.Name} - {ex.Message}<br />";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ namespace Oqtane.Infrastructure
|
||||||
EntityId = pageModule.ModuleId.ToString(),
|
EntityId = pageModule.ModuleId.ToString(),
|
||||||
Title = pageModule.Title,
|
Title = pageModule.Title,
|
||||||
Description = string.Empty,
|
Description = string.Empty,
|
||||||
Body = $"{pageModule.Title}",
|
Body = string.Empty,
|
||||||
Url = $"{(!string.IsNullOrEmpty(page.Path) && !page.Path.StartsWith("/") ? "/" : "")}{page.Path}",
|
Url = $"{(!string.IsNullOrEmpty(page.Path) && !page.Path.StartsWith("/") ? "/" : "")}{page.Path}",
|
||||||
Permissions = $"{EntityNames.Module}:{pageModule.ModuleId},{EntityNames.Page}:{pageModule.PageId}",
|
Permissions = $"{EntityNames.Module}:{pageModule.ModuleId},{EntityNames.Page}:{pageModule.PageId}",
|
||||||
ContentModifiedBy = pageModule.ModifiedBy,
|
ContentModifiedBy = pageModule.ModifiedBy,
|
||||||
|
|
82
Oqtane.Server/Modules/Admin/Files/Manager/FileManager.cs
Normal file
82
Oqtane.Server/Modules/Admin/Files/Manager/FileManager.cs
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
using Oqtane.Models;
|
||||||
|
using Oqtane.Repository;
|
||||||
|
using Oqtane.Documentation;
|
||||||
|
using Oqtane.Interfaces;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Oqtane.Shared;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Oqtane.Modules.Admin.Files.Manager
|
||||||
|
{
|
||||||
|
public class FileManager : ISearchable
|
||||||
|
{
|
||||||
|
private readonly IFolderRepository _folderRepository;
|
||||||
|
private readonly IFileRepository _fileRepository;
|
||||||
|
private const string DocumentExtensions = ".txt,.htm,.html";
|
||||||
|
|
||||||
|
public FileManager(IFolderRepository folderRepository, IFileRepository fileRepository)
|
||||||
|
{
|
||||||
|
_folderRepository = folderRepository;
|
||||||
|
_fileRepository = fileRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<SearchContent>> GetSearchContentsAsync(PageModule pageModule, DateTime lastIndexedOn)
|
||||||
|
{
|
||||||
|
await Task.CompletedTask;
|
||||||
|
|
||||||
|
var searchContents = new List<SearchContent>();
|
||||||
|
|
||||||
|
var folders = _folderRepository.GetFolders(pageModule.Module.SiteId);
|
||||||
|
foreach ( var folder in folders)
|
||||||
|
{
|
||||||
|
bool changed = false;
|
||||||
|
bool removed = false;
|
||||||
|
|
||||||
|
if (folder.ModifiedOn >= lastIndexedOn)
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
removed = folder.IsDeleted.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var files = _fileRepository.GetFiles(folder.FolderId);
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
if (file.ModifiedOn >= lastIndexedOn || changed)
|
||||||
|
{
|
||||||
|
var path = folder.Path + file.Name;
|
||||||
|
|
||||||
|
var body = "";
|
||||||
|
if (DocumentExtensions.Contains(Path.GetExtension(file.Name)))
|
||||||
|
{
|
||||||
|
// get the contents of the file
|
||||||
|
body = System.IO.File.ReadAllText(_fileRepository.GetFilePath(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
var searchContent = new SearchContent
|
||||||
|
{
|
||||||
|
SiteId = folder.SiteId,
|
||||||
|
EntityName = EntityNames.File,
|
||||||
|
EntityId = file.FileId.ToString(),
|
||||||
|
Title = path,
|
||||||
|
Description = string.Empty,
|
||||||
|
Body = body,
|
||||||
|
Url = $"{Constants.FileUrl}{folder.Path}{file.Name}",
|
||||||
|
Permissions = $"{EntityNames.Folder}:{folder.FolderId}",
|
||||||
|
ContentModifiedBy = file.ModifiedBy,
|
||||||
|
ContentModifiedOn = file.ModifiedOn,
|
||||||
|
AdditionalContent = string.Empty,
|
||||||
|
CreatedOn = DateTime.UtcNow,
|
||||||
|
IsDeleted = (removed || file.IsDeleted.Value)
|
||||||
|
};
|
||||||
|
searchContents.Add(searchContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return searchContents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,7 +53,7 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||||
{
|
{
|
||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
|
|
||||||
var searchContentList = new List<SearchContent>();
|
var searchContents = new List<SearchContent>();
|
||||||
|
|
||||||
var htmltexts = _htmlText.GetHtmlTexts(pageModule.ModuleId);
|
var htmltexts = _htmlText.GetHtmlTexts(pageModule.ModuleId);
|
||||||
if (htmltexts != null && htmltexts.Any())
|
if (htmltexts != null && htmltexts.Any())
|
||||||
|
@ -61,7 +61,7 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||||
var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First();
|
var htmltext = htmltexts.OrderByDescending(item => item.CreatedOn).First();
|
||||||
if (htmltext.CreatedOn >= lastIndexedOn)
|
if (htmltext.CreatedOn >= lastIndexedOn)
|
||||||
{
|
{
|
||||||
searchContentList.Add(new SearchContent
|
searchContents.Add(new SearchContent
|
||||||
{
|
{
|
||||||
Title = pageModule.Module.Title,
|
Title = pageModule.Module.Title,
|
||||||
Description = string.Empty,
|
Description = string.Empty,
|
||||||
|
@ -72,7 +72,7 @@ namespace Oqtane.Modules.HtmlText.Manager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return searchContentList;
|
return searchContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ImportModule(Module module, string content, string version)
|
public void ImportModule(Module module, string content, string version)
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace Oqtane.Providers
|
||||||
Title = searchContent.Title,
|
Title = searchContent.Title,
|
||||||
Description = searchContent.Description,
|
Description = searchContent.Description,
|
||||||
Body = searchContent.Body,
|
Body = searchContent.Body,
|
||||||
Url = searchContent.Url,
|
Url = Utilities.TenantUrl(searchQuery.Alias, searchContent.Url),
|
||||||
Permissions = searchContent.Permissions,
|
Permissions = searchContent.Permissions,
|
||||||
ContentModifiedBy = searchContent.ContentModifiedBy,
|
ContentModifiedBy = searchContent.ContentModifiedBy,
|
||||||
ContentModifiedOn = searchContent.ContentModifiedOn,
|
ContentModifiedOn = searchContent.ContentModifiedOn,
|
||||||
|
|
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Oqtane.Models;
|
using Oqtane.Models;
|
||||||
using Oqtane.Repository;
|
using Oqtane.Repository;
|
||||||
using Oqtane.Security;
|
using Oqtane.Security;
|
||||||
|
@ -18,18 +17,15 @@ namespace Oqtane.Services
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly ISettingRepository _settingRepository;
|
private readonly ISettingRepository _settingRepository;
|
||||||
private readonly IPermissionRepository _permissionRepository;
|
private readonly IPermissionRepository _permissionRepository;
|
||||||
private readonly ILogger<SearchService> _logger;
|
|
||||||
|
|
||||||
public SearchService(
|
public SearchService(
|
||||||
IServiceProvider serviceProvider,
|
IServiceProvider serviceProvider,
|
||||||
ISettingRepository settingRepository,
|
ISettingRepository settingRepository,
|
||||||
IPermissionRepository permissionRepository,
|
IPermissionRepository permissionRepository)
|
||||||
ILogger<SearchService> logger)
|
|
||||||
{
|
{
|
||||||
_settingRepository = settingRepository;
|
_settingRepository = settingRepository;
|
||||||
_permissionRepository = permissionRepository;
|
_permissionRepository = permissionRepository;
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<SearchResults> GetSearchResultsAsync(SearchQuery searchQuery)
|
public async Task<SearchResults> GetSearchResultsAsync(SearchQuery searchQuery)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user