Merge pull request #4338 from sbwalker/dev

use List instead of IList, remove "List" from method names. remove unnecessary using statements
This commit is contained in:
Shaun Walker 2024-06-11 10:39:03 -04:00 committed by GitHub
commit af7ca5b897
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 23 additions and 32 deletions

View File

@ -36,7 +36,7 @@ namespace Oqtane.Managers.Search
public override int Priority => ModuleSearchIndexManagerPriority;
public override int IndexContent(int siteId, DateTime? startTime, Action<IList<SearchContent>> processSearchContent, Action<string> handleError)
public override int IndexContent(int siteId, DateTime? startTime, Action<List<SearchContent>> processSearchContent, Action<string> handleError)
{
var pageModules = _pageModuleRepostory.GetPageModules(siteId).DistinctBy(i => i.ModuleId);
var searchContentList = new List<SearchContent>();

View File

@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Reflection.Metadata;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Oqtane.Interfaces;
using Oqtane.Models;
using Oqtane.Repository;
using Oqtane.Shared;
@ -35,7 +31,7 @@ namespace Oqtane.Managers.Search
public override int Priority => PageSearchIndexManagerPriority;
public override int IndexContent(int siteId, DateTime? startTime, Action<IList<SearchContent>> processSearchContent, Action<string> handleError)
public override int IndexContent(int siteId, DateTime? startTime, Action<List<SearchContent>> processSearchContent, Action<string> handleError)
{
var startTimeValue = startTime.GetValueOrDefault(DateTime.MinValue);
var pages = _pageRepository.GetPages(siteId).Where(i => i.ModifiedOn >= startTimeValue);

View File

@ -23,7 +23,7 @@ namespace Oqtane.Managers.Search
public abstract string Name { get; }
public abstract int IndexContent(int siteId, DateTime? startDate, Action<IList<SearchContent>> processSearchContent, Action<string> handleError);
public abstract int IndexContent(int siteId, DateTime? startDate, Action<List<SearchContent>> processSearchContent, Action<string> handleError);
public virtual bool IsIndexEnabled(int siteId)
{

View File

@ -147,7 +147,7 @@ namespace Oqtane.Providers
private float CalculateScore(SearchContent searchContent, SearchQuery searchQuery)
{
var score = 0f;
foreach (var keyword in SearchUtils.GetKeywordsList(searchQuery.Keywords))
foreach (var keyword in SearchUtils.GetKeywords(searchQuery.Keywords))
{
score += searchContent.SearchContentWords.Where(i => i.SearchWord.Word.StartsWith(keyword)).Sum(i => i.Count);
}
@ -159,7 +159,7 @@ namespace Oqtane.Providers
{
var content = $"{searchContent.Title} {searchContent.Description} {searchContent.Body}";
var snippet = string.Empty;
foreach (var keyword in SearchUtils.GetKeywordsList(searchQuery.Keywords))
foreach (var keyword in SearchUtils.GetKeywords(searchQuery.Keywords))
{
if (!string.IsNullOrWhiteSpace(keyword) && content.Contains(keyword, StringComparison.OrdinalIgnoreCase))
{
@ -191,7 +191,7 @@ namespace Oqtane.Providers
snippet = content.Substring(0, searchQuery.BodySnippetLength);
}
foreach (var keyword in SearchUtils.GetKeywordsList(searchQuery.Keywords))
foreach (var keyword in SearchUtils.GetKeywords(searchQuery.Keywords))
{
snippet = Regex.Replace(snippet, $"({keyword})", $"<b>$1</b>", RegexOptions.IgnoreCase);
}

View File

@ -20,7 +20,7 @@ namespace Oqtane.Repository
public async Task<IEnumerable<SearchContent>> GetSearchContentsAsync(SearchQuery searchQuery)
{
using var db = _dbContextFactory.CreateDbContext();
var searchContentList = db.SearchContent.AsNoTracking()
var searchContents = db.SearchContent.AsNoTracking()
.Include(i => i.SearchContentProperties)
.Include(i => i.SearchContentWords)
.ThenInclude(w => w.SearchWord)
@ -28,33 +28,33 @@ namespace Oqtane.Repository
if (searchQuery.EntityNames != null && searchQuery.EntityNames.Any())
{
searchContentList = searchContentList.Where(i => searchQuery.EntityNames.Contains(i.EntityName));
searchContents = searchContents.Where(i => searchQuery.EntityNames.Contains(i.EntityName));
}
if (searchQuery.BeginModifiedTimeUtc != DateTime.MinValue)
{
searchContentList = searchContentList.Where(i => i.ModifiedTime >= searchQuery.BeginModifiedTimeUtc);
searchContents = searchContents.Where(i => i.ModifiedTime >= searchQuery.BeginModifiedTimeUtc);
}
if (searchQuery.EndModifiedTimeUtc != DateTime.MinValue)
{
searchContentList = searchContentList.Where(i => i.ModifiedTime <= searchQuery.EndModifiedTimeUtc);
searchContents = searchContents.Where(i => i.ModifiedTime <= searchQuery.EndModifiedTimeUtc);
}
if (searchQuery.Properties != null && searchQuery.Properties.Any())
{
foreach (var property in searchQuery.Properties)
{
searchContentList = searchContentList.Where(i => i.SearchContentProperties.Any(p => p.Name == property.Key && p.Value == property.Value));
searchContents = searchContents.Where(i => i.SearchContentProperties.Any(p => p.Name == property.Key && p.Value == property.Value));
}
}
var filteredContentList = new List<SearchContent>();
if (!string.IsNullOrEmpty(searchQuery.Keywords))
{
foreach (var keyword in SearchUtils.GetKeywordsList(searchQuery.Keywords))
foreach (var keyword in SearchUtils.GetKeywords(searchQuery.Keywords))
{
filteredContentList.AddRange(await searchContentList.Where(i => i.SearchContentWords.Any(w => w.SearchWord.Word.StartsWith(keyword))).ToListAsync());
filteredContentList.AddRange(await searchContents.Where(i => i.SearchContentWords.Any(w => w.SearchWord.Word.StartsWith(keyword))).ToListAsync());
}
}

View File

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using HtmlAgilityPack;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -143,7 +141,7 @@ namespace Oqtane.Services
_tenantManager.SetAlias(alias);
}
private IList<ISearchIndexManager> GetSearchIndexManagers(Action<ISearchIndexManager> initManager)
private List<ISearchIndexManager> GetSearchIndexManagers(Action<ISearchIndexManager> initManager)
{
var managers = new List<ISearchIndexManager>();
var managerTypes = AppDomain.CurrentDomain.GetAssemblies()
@ -160,7 +158,7 @@ namespace Oqtane.Services
return managers.OrderBy(i => i.Priority).ToList();
}
private IList<ISearchResultManager> GetSearchResultManagers()
private List<ISearchResultManager> GetSearchResultManagers()
{
var managers = new List<ISearchResultManager>();
var managerTypes = AppDomain.CurrentDomain.GetAssemblies()
@ -176,7 +174,7 @@ namespace Oqtane.Services
return managers.ToList();
}
private void SaveSearchContent(IList<SearchContent> searchContentList)
private void SaveSearchContent(List<SearchContent> searchContentList)
{
if(searchContentList.Any())
{

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using Oqtane.Models;
namespace Oqtane.Services
@ -15,6 +12,6 @@ namespace Oqtane.Services
bool IsIndexEnabled(int siteId);
int IndexContent(int siteId, DateTime? startTime, Action<IList<SearchContent>> processSearchContent, Action<string> handleError);
int IndexContent(int siteId, DateTime? startTime, Action<List<SearchContent>> processSearchContent, Action<string> handleError);
}
}

View File

@ -31,9 +31,9 @@ namespace Oqtane.Models
public string AdditionalContent { get; set; }
public IList<SearchContentProperty> SearchContentProperties { get; set; }
public List<SearchContentProperty> SearchContentProperties { get; set; }
public IList<SearchContentWord> SearchContentWords { get; set; }
public List<SearchContentWord> SearchContentWords { get; set; }
public override string ToString()
{

View File

@ -14,7 +14,7 @@ namespace Oqtane.Models
public string Keywords { get; set; }
public IList<string> EntityNames { get; set; } = new List<string>();
public List<string> EntityNames { get; set; } = new List<string>();
public DateTime BeginModifiedTimeUtc { get; set; }

View File

@ -4,7 +4,7 @@ namespace Oqtane.Models
{
public class SearchResults
{
public IList<SearchResult> Results { get; set; }
public List<SearchResult> Results { get; set; }
public int TotalResults { get; set; }
}

View File

@ -4,14 +4,14 @@ namespace Oqtane.Shared
{
public sealed class SearchUtils
{
private static readonly IList<string> _systemPages;
private static readonly List<string> _systemPages;
static SearchUtils()
{
_systemPages = new List<string> { "login", "register", "profile", "404", "search" };
}
public static IList<string> GetKeywordsList(string keywords)
public static List<string> GetKeywords(string keywords)
{
var keywordsList = new List<string>();
if(!string.IsNullOrEmpty(keywords))