refactoring the code.
This commit is contained in:
@ -15,6 +15,6 @@ namespace Oqtane.Services
|
||||
|
||||
bool IsIndexEnabled(int siteId);
|
||||
|
||||
int IndexDocuments(int siteId, DateTime? startTime, Action<IList<SearchDocument>> processSearchDocuments, Action<string> handleError);
|
||||
int IndexContent(int siteId, DateTime? startTime, Action<IList<SearchContent>> processSearchContent, Action<string> handleError);
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ namespace Oqtane.Services
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
void SaveDocument(SearchDocument document, bool autoCommit = false);
|
||||
void SaveSearchContent(SearchContent searchContent, bool autoCommit = false);
|
||||
|
||||
void DeleteDocument(string id);
|
||||
void DeleteSearchContent(string id);
|
||||
|
||||
Task<SearchResults> SearchAsync(SearchQuery searchQuery, Func<SearchDocument, SearchQuery, bool> validateFunc);
|
||||
Task<SearchResults> SearchAsync(SearchQuery searchQuery, Func<SearchContent, SearchQuery, bool> validateFunc);
|
||||
|
||||
bool Optimize();
|
||||
|
||||
|
@ -7,7 +7,7 @@ namespace Oqtane.Services
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
bool Visible(SearchDocument searchResult, SearchQuery searchQuery);
|
||||
bool Visible(SearchContent searchResult, SearchQuery searchQuery);
|
||||
|
||||
string GetUrl(SearchResult searchResult, SearchQuery searchQuery);
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Interfaces
|
||||
{
|
||||
public interface IModuleSearch
|
||||
public interface ISearchable
|
||||
{
|
||||
public IList<SearchDocument> GetSearchDocuments(Module module, DateTime startTime);
|
||||
public IList<SearchContent> GetSearchContentList(Module module, DateTime startTime);
|
||||
}
|
||||
}
|
@ -4,16 +4,16 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json;
|
||||
namespace Oqtane.Models
|
||||
{
|
||||
public class SearchDocument : ModelBase
|
||||
public class SearchContent : ModelBase
|
||||
{
|
||||
public int SearchDocumentId { get; set; }
|
||||
public int SearchContentId { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public string UniqueKey => $"{IndexerName}:{EntryId}";
|
||||
public string UniqueKey => $"{EntityName}:{EntityId}";
|
||||
|
||||
public int EntryId { get; set; }
|
||||
public string EntityName { get; set; }
|
||||
|
||||
public string IndexerName { get; set; }
|
||||
public int EntityId { get; set; }
|
||||
|
||||
public int SiteId { get; set; }
|
||||
|
||||
@ -27,15 +27,13 @@ namespace Oqtane.Models
|
||||
|
||||
public DateTime ModifiedTime { get; set; }
|
||||
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
public string AdditionalContent { get; set; }
|
||||
|
||||
public string LanguageCode { get; set; }
|
||||
public IList<SearchContentProperty> Properties { get; set; }
|
||||
|
||||
public IList<SearchDocumentTag> Tags { get; set; }
|
||||
|
||||
public IList<SearchDocumentProperty> Properties { get; set; }
|
||||
public IList<SearchContentWords> Words { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
@ -3,12 +3,12 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Oqtane.Models
|
||||
{
|
||||
public class SearchDocumentProperty
|
||||
public class SearchContentProperty
|
||||
{
|
||||
[Key]
|
||||
public int PropertyId { get; set; }
|
||||
|
||||
public int SearchDocumentId { get; set; }
|
||||
public int SearchContentId { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
12
Oqtane.Shared/Models/SearchContentWordSource.cs
Normal file
12
Oqtane.Shared/Models/SearchContentWordSource.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Oqtane.Models
|
||||
{
|
||||
public class SearchContentWordSource
|
||||
{
|
||||
[Key]
|
||||
public int WordSourceId { get; set; }
|
||||
|
||||
public string Word { get; set; }
|
||||
}
|
||||
}
|
19
Oqtane.Shared/Models/SearchContentWords.cs
Normal file
19
Oqtane.Shared/Models/SearchContentWords.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Oqtane.Models
|
||||
{
|
||||
public class SearchContentWords
|
||||
{
|
||||
[Key]
|
||||
public int WordId { get; set; }
|
||||
|
||||
public int SearchContentId { get; set; }
|
||||
|
||||
public int WordSourceId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public SearchContentWordSource WordSource { get; set; }
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Oqtane.Models
|
||||
{
|
||||
public class SearchDocumentTag
|
||||
{
|
||||
[Key]
|
||||
public int TagId { get; set; }
|
||||
|
||||
public int SearchDocumentId { get; set; }
|
||||
|
||||
public string Tag { get; set; }
|
||||
}
|
||||
}
|
@ -14,14 +14,12 @@ namespace Oqtane.Models
|
||||
|
||||
public string Keywords { get; set; }
|
||||
|
||||
public IList<string> Sources { get; set; } = new List<string>();
|
||||
public IList<string> EntityNames { get; set; } = new List<string>();
|
||||
|
||||
public DateTime BeginModifiedTimeUtc { get; set; }
|
||||
|
||||
public DateTime EndModifiedTimeUtc { get; set; }
|
||||
|
||||
public IList<string> Tags { get; set; } = new List<string>();
|
||||
|
||||
public IDictionary<string, string> Properties { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
public int PageIndex { get; set; }
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace Oqtane.Models
|
||||
{
|
||||
public class SearchResult : SearchDocument
|
||||
public class SearchResult : SearchContent
|
||||
{
|
||||
public float Score { get; set; }
|
||||
|
||||
|
@ -77,22 +77,10 @@ namespace Oqtane.Shared
|
||||
|
||||
public static readonly string VisitorCookiePrefix = "APP_VISITOR_";
|
||||
|
||||
public const string SearchIndexManagerEnabledSettingFormat = "SearchIndexManager_{0}_Enabled";
|
||||
public const string SearchIndexStartTimeSettingName = "SearchIndex_StartTime";
|
||||
public const string SearchResultManagersCacheName = "SearchResultManagers";
|
||||
public const int SearchDefaultPageSize = 10;
|
||||
public const string DefaultSearchProviderName = "Database";
|
||||
public const string SearchPageIdPropertyName = "PageId";
|
||||
public const string SearchModuleIdPropertyName = "ModuleId";
|
||||
public const string DefaultSearchProviderName = "Database";
|
||||
public const string SearchProviderSettingName = "SearchProvider";
|
||||
public const string SearchEnabledSettingName = "SearchEnabled";
|
||||
|
||||
public const string ModuleSearchIndexManagerName = "Module";
|
||||
public const string PageSearchIndexManagerName = "Page";
|
||||
|
||||
public const int PageSearchIndexManagerPriority = 100;
|
||||
public const int ModuleSearchIndexManagerPriority = 200;
|
||||
|
||||
|
||||
// Obsolete constants
|
||||
|
||||
const string RoleObsoleteMessage = "Use the corresponding member from Oqtane.Shared.RoleNames";
|
||||
|
@ -1,40 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Oqtane.Shared
|
||||
{
|
||||
public sealed class SearchUtils
|
||||
{
|
||||
private const string PunctuationMatch = "[~!#\\$%\\^&*\\(\\)-+=\\{\\[\\}\\]\\|;:\\x22'<,>\\.\\?\\\\\\t\\r\\v\\f\\n]";
|
||||
private static readonly Regex _stripWhiteSpaceRegex = new Regex("\\s+", RegexOptions.Compiled);
|
||||
private static readonly Regex _stripTagsRegex = new Regex("<[^<>]*>", RegexOptions.Compiled);
|
||||
private static readonly Regex _afterRegEx = new Regex(PunctuationMatch + "\\s", RegexOptions.Compiled);
|
||||
private static readonly Regex _beforeRegEx = new Regex("\\s" + PunctuationMatch, RegexOptions.Compiled);
|
||||
private static readonly IList<string> _systemPages;
|
||||
|
||||
public static string Clean(string html, bool removePunctuation)
|
||||
static SearchUtils()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(html))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (html.Contains("<"))
|
||||
{
|
||||
html = WebUtility.HtmlDecode(html);
|
||||
}
|
||||
|
||||
html = StripTags(html, true);
|
||||
html = WebUtility.HtmlDecode(html);
|
||||
|
||||
if (removePunctuation)
|
||||
{
|
||||
html = StripPunctuation(html, true);
|
||||
html = StripWhiteSpace(html, true);
|
||||
}
|
||||
|
||||
return html;
|
||||
_systemPages = new List<string> { "login", "register", "profile", "404", "search" };
|
||||
}
|
||||
|
||||
public static IList<string> GetKeywordsList(string keywords)
|
||||
@ -54,42 +28,9 @@ namespace Oqtane.Shared
|
||||
return keywordsList;
|
||||
}
|
||||
|
||||
private static string StripTags(string html, bool retainSpace)
|
||||
public static bool IsSystemPage(Models.Page page)
|
||||
{
|
||||
return _stripTagsRegex.Replace(html, retainSpace ? " " : string.Empty);
|
||||
}
|
||||
|
||||
private static string StripPunctuation(string html, bool retainSpace)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(html))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string retHTML = html + " ";
|
||||
|
||||
var repString = retainSpace ? " " : string.Empty;
|
||||
while (_beforeRegEx.IsMatch(retHTML))
|
||||
{
|
||||
retHTML = _beforeRegEx.Replace(retHTML, repString);
|
||||
}
|
||||
|
||||
while (_afterRegEx.IsMatch(retHTML))
|
||||
{
|
||||
retHTML = _afterRegEx.Replace(retHTML, repString);
|
||||
}
|
||||
|
||||
return retHTML.Trim('"');
|
||||
}
|
||||
|
||||
private static string StripWhiteSpace(string html, bool retainSpace)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(html))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return _stripWhiteSpaceRegex.Replace(html, retainSpace ? " " : string.Empty);
|
||||
return page.Path.Contains("admin") || _systemPages.Contains(page.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user