Basic search outline config UI implemented.
This commit is contained in:
@@ -13,6 +13,6 @@ namespace Props.Services.Modules
|
||||
|
||||
public void RegisterSearchQuery(string query);
|
||||
|
||||
public void RegisterListing(ProductListing productListing, string shopName);
|
||||
public void RegisterProductListing(ProductListing productListing, string shopName);
|
||||
}
|
||||
}
|
@@ -1,21 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Props.Data;
|
||||
using Props.Models.Search;
|
||||
using Props.Options;
|
||||
using Props.Shop.Framework;
|
||||
|
||||
namespace Props.Services.Modules
|
||||
{
|
||||
public class LiveMetricsManager : IMetricsManager
|
||||
{
|
||||
private MetricsOptions metricsOptions;
|
||||
private ILogger<LiveMetricsManager> logger;
|
||||
ApplicationDbContext dbContext;
|
||||
public LiveMetricsManager(ApplicationDbContext dbContext, ILogger<LiveMetricsManager> logger)
|
||||
private ApplicationDbContext dbContext;
|
||||
private IQueryable<ProductListingInfo> leastPopularProductListings;
|
||||
private IQueryable<QueryWordInfo> leastPopularQueryWords;
|
||||
public LiveMetricsManager(ApplicationDbContext dbContext, ILogger<LiveMetricsManager> logger, IConfiguration configuration)
|
||||
{
|
||||
this.metricsOptions = configuration.GetSection(MetricsOptions.Metrics).Get<MetricsOptions>();
|
||||
this.logger = logger;
|
||||
this.dbContext = dbContext;
|
||||
leastPopularProductListings = from listing in dbContext.ProductListingInfos orderby listing.Hits ascending select listing;
|
||||
leastPopularQueryWords = from word in dbContext.QueryWords orderby word.Hits ascending select word;
|
||||
}
|
||||
public IEnumerable<ProductListingInfo> RetrieveTopListings(int max)
|
||||
{
|
||||
@@ -27,8 +35,8 @@ namespace Props.Services.Modules
|
||||
|
||||
public IEnumerable<string> RetrieveCommonKeywords(int max)
|
||||
{
|
||||
if (dbContext.Keywords == null) return null;
|
||||
return (from k in dbContext.Keywords
|
||||
if (dbContext.QueryWords == null) return null;
|
||||
return (from k in dbContext.QueryWords
|
||||
orderby k.Hits descending
|
||||
select k.Word).Take(max);
|
||||
}
|
||||
@@ -40,11 +48,11 @@ namespace Props.Services.Modules
|
||||
QueryWordInfo[] wordInfos = new QueryWordInfo[tokens.Length];
|
||||
for (int wordIndex = 0; wordIndex < tokens.Length; wordIndex++)
|
||||
{
|
||||
QueryWordInfo queryWordInfo = dbContext.Keywords.Where((k) => k.Word.ToLower().Equals(tokens[wordIndex])).SingleOrDefault() ?? new QueryWordInfo();
|
||||
QueryWordInfo queryWordInfo = dbContext.QueryWords.Where((k) => k.Word.ToLower().Equals(tokens[wordIndex])).SingleOrDefault() ?? new QueryWordInfo();
|
||||
if (queryWordInfo.Hits == 0)
|
||||
{
|
||||
queryWordInfo.Word = tokens[wordIndex];
|
||||
dbContext.Keywords.Add(queryWordInfo);
|
||||
dbContext.QueryWords.Add(queryWordInfo);
|
||||
}
|
||||
queryWordInfo.Hits += 1;
|
||||
wordInfos[wordIndex] = queryWordInfo;
|
||||
@@ -60,11 +68,12 @@ namespace Props.Services.Modules
|
||||
wordInfos[wordIndex].Following.Add(wordInfos[afterIndex]);
|
||||
}
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
|
||||
CullQueryWords();
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public void RegisterListing(ProductListing productListing, string shopName)
|
||||
public void RegisterProductListing(ProductListing productListing, string shopName)
|
||||
{
|
||||
ProductListingInfo productListingInfo =
|
||||
(from info in dbContext.ProductListingInfos
|
||||
@@ -78,7 +87,27 @@ namespace Props.Services.Modules
|
||||
productListingInfo.ProductListing = productListing;
|
||||
productListingInfo.ProductListingIdentifier = productListing.Identifier;
|
||||
productListingInfo.Hits += 1;
|
||||
|
||||
CullProductListings();
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
private void CullProductListings()
|
||||
{
|
||||
int surplus = dbContext.ProductListingInfos.Count() - metricsOptions.MaxProductListings;
|
||||
if (surplus > 0)
|
||||
{
|
||||
dbContext.RemoveRange(leastPopularProductListings.Take(surplus));
|
||||
}
|
||||
}
|
||||
|
||||
private void CullQueryWords()
|
||||
{
|
||||
int surplus = dbContext.QueryWords.Count() - metricsOptions.MaxQueryWords;
|
||||
if (surplus > 0)
|
||||
{
|
||||
dbContext.RemoveRange(leastPopularQueryWords.Take(surplus));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -34,7 +34,7 @@ namespace Props.Services.Modules
|
||||
|
||||
foreach (string shopName in await ShopManager.GetAllShopNames())
|
||||
{
|
||||
if (searchOutline.Enabled[shopName])
|
||||
if (searchOutline.DisabledShops[shopName])
|
||||
{
|
||||
logger.LogDebug("Checking \"{0}\".", shopName);
|
||||
int amount = 0;
|
||||
@@ -43,7 +43,7 @@ namespace Props.Services.Modules
|
||||
if (searchOutline.Filters.Validate(product))
|
||||
{
|
||||
amount += 1;
|
||||
metricsManager.RegisterListing(product, shopName);
|
||||
metricsManager.RegisterProductListing(product, shopName);
|
||||
results.Add(product);
|
||||
}
|
||||
if (amount >= searchOptions.MaxResults) break;
|
||||
|
Reference in New Issue
Block a user