Skip to content

Commit

Permalink
filtering out non-empty results
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Jun 26, 2024
1 parent 95e2b52 commit abd4689
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ public class IndexFunctions
private readonly IndexHeadersCache _indexHeadersCache;
private readonly InputParser _inputParser;
private readonly ProgressionsSearch _progressionsSearch;
private readonly SearchOrderCache _searchOrderCache;

public IndexFunctions(ILogger<IndexFunctions> logger, DownstreamApiClient downstreamApiClient, ProgressionsCache progressionsCache, LoopsStatisticsCache loopsStatisticsCache, SecurityContext securityContext, IndexHeadersCache indexHeadersCache, InputParser inputParser, ProgressionsSearch progressionsSearch, SearchOrderCache searchOrderCache)
public IndexFunctions(ILogger<IndexFunctions> logger, DownstreamApiClient downstreamApiClient, ProgressionsCache progressionsCache, LoopsStatisticsCache loopsStatisticsCache, SecurityContext securityContext, IndexHeadersCache indexHeadersCache, InputParser inputParser, ProgressionsSearch progressionsSearch)
{
_logger = logger;
_downstreamApiClient = downstreamApiClient;
Expand All @@ -35,7 +34,6 @@ public IndexFunctions(ILogger<IndexFunctions> logger, DownstreamApiClient downst
_indexHeadersCache = indexHeadersCache;
_inputParser = inputParser;
_progressionsSearch = progressionsSearch;
_searchOrderCache = searchOrderCache;

securityContext.InitService();
}
Expand Down Expand Up @@ -165,20 +163,4 @@ public async Task<IActionResult> VDevFindAndCount([HttpTrigger(AuthorizationLeve
{
return new OkObjectResult(_progressionsSearch.Search((await _progressionsCache.Get()).Values, _inputParser.Parse(searchQuery)).Count);
}

[Function(nameof(VDevFindTop100))]
public async Task<IActionResult> VDevFindTop100([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req, string searchQuery)
{
var progressions = await _progressionsCache.Get();
var progressionsReverse = progressions.ToDictionary(x => (ISearchableChordsProgression)x.Value, x => x.Key);
var searchOrder = await _searchOrderCache.Get();
var headers = await _indexHeadersCache.Get();
var found = _progressionsSearch.Search(searchOrder.Select(x => progressions[x]), _inputParser.Parse(searchQuery), 100);

return new OkObjectResult(found.Select(x => new
{
Header = headers.Headers[progressionsReverse[x.Key]],
Coverage = x.Value,
}).ToList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ public class Search : ServiceFunctionBase<SearchRequest, SearchResponse>
private readonly ProgressionsCache _progressionsCache;
private readonly IndexHeadersCache _indexHeadersCache;
private readonly ProgressionsSearch _progressionsSearch;
private readonly SearchOrderCache _searchOrderCache;
private readonly InputParser _inputParser;
private readonly DownstreamApiClient _downstreamApiClient;
private readonly IndexApiOptions _options;
private readonly IndexApiClient _indexApiClient;

public Search(ILoggerFactory loggerFactory, SecurityContext securityContext, ProgressionsCache progressionsCache, IndexHeadersCache indexHeadersCache, ProgressionsSearch progressionsSearch, SearchOrderCache searchOrderCache, InputParser inputParser, DownstreamApiClient downstreamApiClient, ConcurrencyLimiter concurrencyLimiter, IOptions<IndexApiOptions> options, IndexApiClient indexApiClient)
public Search(ILoggerFactory loggerFactory, SecurityContext securityContext, ProgressionsCache progressionsCache, IndexHeadersCache indexHeadersCache, ProgressionsSearch progressionsSearch, InputParser inputParser, DownstreamApiClient downstreamApiClient, ConcurrencyLimiter concurrencyLimiter, IOptions<IndexApiOptions> options, IndexApiClient indexApiClient)
: base(loggerFactory, securityContext, concurrencyLimiter, options.Value.RedirectCachesToIndex)
{
_progressionsCache = progressionsCache;
_indexHeadersCache = indexHeadersCache;
_progressionsSearch = progressionsSearch;
_searchOrderCache = searchOrderCache;
_inputParser = inputParser;
_downstreamApiClient = downstreamApiClient;
_indexApiClient = indexApiClient;
Expand All @@ -54,9 +52,12 @@ protected override async Task<SearchResponse> Execute(SearchRequest request)
}

var progressions = await _progressionsCache.Get();
var searchOrder = await _searchOrderCache.Get();
var headers = await _indexHeadersCache.Get();
var found = _progressionsSearch.Search(searchOrder.Select(x => progressions[x]), _inputParser.Parse(request.Query));
var found = _progressionsSearch.Search(
headers.Headers.Values.Join(progressions, h => h.ExternalId, p => p.Key, (h, p) => (h, p))
.Where(x => !string.IsNullOrWhiteSpace(x.h.Title) && x.h.Artists?.Any(a => !string.IsNullOrWhiteSpace(a)) == true && !string.IsNullOrWhiteSpace(_downstreamApiClient.GetSourceTitle(x.h.Source)))
.Select(x => x.p.Value),
_inputParser.Parse(request.Query));

var results = headers.Headers
.Select(h => progressions.TryGetValue(h.Key, out var progression) && found.TryGetValue(progression, out var coverage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public static IServiceCollection AddIndexBusinessLogic(this IServiceCollection s
.AddSingleton<ProgressionsCache>()
.AddSingleton<LoopsStatisticsCache>()
.AddSingleton<IndexHeadersCache>()
.AddSingleton<SearchOrderCache>()
.AddIndexAnalysis()
.Configure<FileCacheBaseOptions>(o => configuration.GetSection(nameof(FileCacheBaseOptions)).Bind(o));
}

This file was deleted.

This file was deleted.

0 comments on commit abd4689

Please sign in to comment.