Skip to content

Commit

Permalink
search works
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-zhur committed Jun 24, 2024
1 parent 4529bbb commit 41e453e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using HarmonyDB.Index.Analysis.Services;
using HarmonyDB.Index.Api.Services;
using HarmonyDB.Index.BusinessLogic.Models;
using HarmonyDB.Index.BusinessLogic.Services;
using HarmonyDB.Index.DownstreamApi.Client;
Expand All @@ -19,14 +21,18 @@ public class IndexFunctions
private readonly ProgressionsCache _progressionsCache;
private readonly LoopsStatisticsCache _loopsStatisticsCache;
private readonly IndexHeadersCache _indexHeadersCache;
private readonly InputParser _inputParser;
private readonly ProgressionsSearch _progressionsSearch;

public IndexFunctions(ILogger<IndexFunctions> logger, DownstreamApiClient downstreamApiClient, ProgressionsCache progressionsCache, LoopsStatisticsCache loopsStatisticsCache, SecurityContext securityContext, IndexHeadersCache indexHeadersCache)
public IndexFunctions(ILogger<IndexFunctions> logger, DownstreamApiClient downstreamApiClient, ProgressionsCache progressionsCache, LoopsStatisticsCache loopsStatisticsCache, SecurityContext securityContext, IndexHeadersCache indexHeadersCache, InputParser inputParser, ProgressionsSearch progressionsSearch)
{
_logger = logger;
_downstreamApiClient = downstreamApiClient;
_progressionsCache = progressionsCache;
_loopsStatisticsCache = loopsStatisticsCache;
_indexHeadersCache = indexHeadersCache;
_inputParser = inputParser;
_progressionsSearch = progressionsSearch;

securityContext.InitService();
}
Expand Down Expand Up @@ -129,4 +135,10 @@ public async Task<IActionResult> VDevRebuildLoopStatisticsCache([HttpTrigger(Aut
await _loopsStatisticsCache.Rebuild();
return new OkObjectResult((await _loopsStatisticsCache.Get()).Count);
}

[Function(nameof(VDevFindAndCount))]
public async Task<IActionResult> VDevFindAndCount([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req, string searchQuery)
{
return new OkObjectResult(_progressionsSearch.Search((await _progressionsCache.Get()).Values, _inputParser.Parse(searchQuery)).Count);
}
}
1 change: 1 addition & 0 deletions HarmonyDB.Index/HarmonyDB.Index.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.AddAuthorizationApiClient(context.Configuration)
.AddDownstreamApiClient(context.Configuration)
.AddScoped<CommonExecutions>()
.AddScoped<InputParser>()
.AddIndexBusinessLogic()
.AddSecurityContext();
})
Expand Down
41 changes: 41 additions & 0 deletions HarmonyDB.Index/HarmonyDB.Index.Api/Services/InputParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using HarmonyDB.Common.Representations.OneShelf;
using HarmonyDB.Index.Analysis.Models;
using HarmonyDB.Index.Analysis.Services;

namespace HarmonyDB.Index.Api.Services;

public class InputParser
{
private readonly ProgressionsBuilder _progressionsBuilder;
private readonly ChordDataParser _chordDataParser;

public InputParser(ProgressionsBuilder progressionsBuilder, ChordDataParser chordDataParser)
{
_progressionsBuilder = progressionsBuilder;
_chordDataParser = chordDataParser;
}

public HarmonyMovementsSequence Parse(string input)
{
var html = new NodeHtml
{
Name = "pre",
Children = input
.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Select(c => new NodeChord
{
Children = [new NodeText(c).AsChild()]
}.AsChild())
.ToList(),
};
var chordsProgression =
_progressionsBuilder.BuildProgression(html.AsChords(new()).Select(_chordDataParser.GetProgressionData)
.ToList());

var sequence = chordsProgression.ExtendedHarmonyMovementsSequences.Single();

Console.WriteLine(string.Join(" ", sequence.Movements.Select(m => m.Title)));

return sequence;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class LoopsStatisticsCache : FileCacheBase<IReadOnlyDictionary<string, Co
private readonly ProgressionsSearch _progressionsSearch;
private readonly ProgressionsCache _progressionsCache;

public LoopsStatisticsCache(ILogger<LoopsStatisticsCache> logger, ProgressionsSearch progressionsSearch, ProgressionsCache progressionsCache)
public LoopsStatisticsCache(ILogger<LoopsStatisticsCache> logger, ProgressionsSearch progressionsSearch, ProgressionsCache progressionsCache)
: base(logger)
{
_progressionsSearch = progressionsSearch;
Expand Down

0 comments on commit 41e453e

Please sign in to comment.