diff --git a/HaWeb/Controllers/IndexController.cs b/HaWeb/Controllers/IndexController.cs index aef0ea4..29c8e82 100644 --- a/HaWeb/Controllers/IndexController.cs +++ b/HaWeb/Controllers/IndexController.cs @@ -65,27 +65,9 @@ public class IndexController : Controller { [Route("/HKB/")] // Order of actions: // Filter, sort by year, paginate, sort by Meta.Sort & .Order, parse - public IActionResult Index(string? search, int page = 0) { + public IActionResult Index(int page = 0) { var lib = _lib.GetLibrary(); List>? metasbyyear = null; - if (search != null) { - var stopwatch = new System.Diagnostics.Stopwatch(); - stopwatch.Start(); - search = search.Trim(); - var res = _xmlService.SearchCollection("letters", search, _readerService); - if (res == null || !res.Any()) return _error404(); - var ret = res.ToDictionary( - x => x.Index, - x => x.Results - .Select(y => new SearchResult(search, x.Index) { Page = y.Page, Line = y.Line, Preview = y.Preview }) - .ToList() - ); - var keys = res.Select(x => x.Index).Where(x => lib.Metas.ContainsKey(x)).Select(x => lib.Metas[x]); - var letters = keys.ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList(); - stopwatch.Stop(); - Console.WriteLine("SEARCH: " + stopwatch.ElapsedMilliseconds); - return _paginateSend(lib, page, letters, null, null, null, search, ret); - } metasbyyear = lib.MetasByYear.OrderBy(x => x.Key).ToList(); return _paginateSend(lib, page, metasbyyear); } @@ -125,7 +107,7 @@ public class IndexController : Controller { }; } - private List<(int StartYear, int EndYear)>? _paginate(List>? letters) { + internal static List<(int StartYear, int EndYear)>? Paginate(List>? letters, int lettersForPage) { if (letters == null || !letters.Any()) return null; List<(int StartYear, int EndYear)>? res = null; int startyear = 0; @@ -135,7 +117,7 @@ public class IndexController : Controller { startyear = letterlist.Key; } count += letterlist.Count(); - if (count >= _lettersForPage) { + if (count >= lettersForPage) { if (res == null) res = new List<(int StartYear, int EndYear)>(); res.Add((startyear, letterlist.Key)); count = 0; @@ -154,10 +136,8 @@ public class IndexController : Controller { List> metasbyyear, string? person = null, string? zhvolume = null, - string? zhpage = null, - string? activeSearch = null, - Dictionary>? searchResults = null) { - var pages = _paginate(metasbyyear); + string? zhpage = null) { + var pages = Paginate(metasbyyear, _lettersForPage); if (pages != null && page >= pages.Count) return _error404(); if (pages == null && page > 0) return _error404(); List<(int Year, List LetterList)>? letters = null; @@ -173,7 +153,7 @@ public class IndexController : Controller { List<(string Volume, List Pages)>? availablePages = null; availablePages = lib.Structure.Where(x => x.Key != "-1").Select(x => (x.Key, x.Value.Select(x => x.Key).ToList())).ToList(); zhvolume = zhvolume == null ? "1" : zhvolume; - var model = new IndexViewModel(letters, page, pages, _getAvailablePersons(lib), availablePages.OrderBy(x => x.Volume).ToList(), zhvolume, zhpage, activeSearch, searchResults); + var model = new IndexViewModel(letters, page, pages, _getAvailablePersons(lib), availablePages.OrderBy(x => x.Volume).ToList(), zhvolume, zhpage); if (person != null) model.ActivePerson = person; return View("~/Views/HKB/Dynamic/Index.cshtml", model); } diff --git a/HaWeb/Controllers/SucheController.cs b/HaWeb/Controllers/SucheController.cs index 15df963..32d9732 100644 --- a/HaWeb/Controllers/SucheController.cs +++ b/HaWeb/Controllers/SucheController.cs @@ -22,58 +22,22 @@ public class SucheController : Controller { _xmlService = service; _lettersForPage = config.GetValue("LettersOnPage"); } - - [Route("/HKB/Suche/{letterno}")] - public IActionResult GoTo(string letterno) { - if (String.IsNullOrWhiteSpace(letterno)) return _error404(); - letterno = letterno.Trim(); - var lib = _lib.GetLibrary(); - var letter = lib.Metas.Where(x => x.Value.Autopsic == letterno); - if (letter != null) - return RedirectToAction("Index", "Briefe", new { id = letterno }); - return _error404(); - } - - [Route("/HKB/Suche/{zhvolume}/{zhpage}")] - public IActionResult GoToZH(string zhvolume, string zhpage) { - if (String.IsNullOrWhiteSpace(zhvolume) || String.IsNullOrWhiteSpace(zhpage)) return _error404(); - zhvolume = zhvolume.Trim(); - zhpage = zhpage.Trim(); - var lib = _lib.GetLibrary(); - var pages = lib.Structure.ContainsKey(zhvolume) ? lib.Structure[zhvolume] : null; - if (pages == null) return _error404(); - var lines = pages.ContainsKey(zhpage) ? pages[zhpage] : null; - if (lines == null) return _error404(); - var letters = lines.Aggregate(new HashSet(), (x, y) => { x.Add(y.Value); return x; }); - if (letters != null && letters.Any() && letters.Count == 1) { - string? autopsic = null; - if (lib.Metas.ContainsKey(letters.First())) { - autopsic = lib.Metas[letters.First()].Autopsic; - } - if (autopsic == null) return _error404(); - return RedirectToAction("Index", "Briefe", new { id = autopsic }); - } - if (letters != null && letters.Any()) { - var metas = lib.Metas.Where(x => letters.Contains(x.Key)).Select(x => x.Value); - if (metas == null) return _error404(); - var metasbyyear = metas.ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList(); - return _paginateSend(lib, 0, metasbyyear, null, zhvolume, zhpage); - } - return _error404(); - } [Route("/HKB/Suche")] - // Order of actions: - // Filter, sort by year, paginate, sort by Meta.Sort & .Order, parse - public IActionResult Index(string? search, int page = 0) { + public IActionResult Index(string search, string category = "letters", int page = 0) { + if (search == null) return _error404(); var lib = _lib.GetLibrary(); - List>? metasbyyear = null; - if (search != null) { - var stopwatch = new System.Diagnostics.Stopwatch(); - stopwatch.Start(); + + var stopwatch = new System.Diagnostics.Stopwatch(); + stopwatch.Start(); + + if (category == "letters") { + if (String.IsNullOrWhiteSpace(search)) + return _paginateSendLetters(lib, page, search, SearchResultType.InvalidSearchTerm, null, null); search = search.Trim(); var res = _xmlService.SearchCollection("letters", search, _readerService); - if (res == null || !res.Any()) return _error404(); + if (res == null || !res.Any()) + return _paginateSendLetters(lib, page, search, SearchResultType.NotFound, null, null); var ret = res.ToDictionary( x => x.Index, x => x.Results @@ -82,29 +46,16 @@ public class SucheController : Controller { ); var keys = res.Select(x => x.Index).Where(x => lib.Metas.ContainsKey(x)).Select(x => lib.Metas[x]); var letters = keys.ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList(); - stopwatch.Stop(); - Console.WriteLine("SEARCH: " + stopwatch.ElapsedMilliseconds); - return _paginateSend(lib, page, letters, null, null, null, search, ret); + return _paginateSendLetters(lib, page, search, SearchResultType.Success, ret, letters); + } else if (category == " register") { + } - metasbyyear = lib.MetasByYear.OrderBy(x => x.Key).ToList(); - return _paginateSend(lib, page, metasbyyear); - } - [Route("/HKB/Suche/Person/{person}")] - public IActionResult Person(string person, int page = 0) { - if (String.IsNullOrWhiteSpace(person)) return _error404(); - person = person.Trim(); - var lib = _lib.GetLibrary(); - List>? metasbyyear = null; - var letters = lib.Metas - .Where(x => x.Value.Senders.Contains(person) || x.Value.Receivers.Contains(person)) - .Select(x => x.Value); - if (letters == null) return _error404(); - metasbyyear = letters.ToLookup(x => x.Sort.Year).OrderBy(x => x.Key).ToList(); - return _paginateSend(lib, page, metasbyyear, person); + stopwatch.Stop(); + Console.WriteLine("SEARCH: " + stopwatch.ElapsedMilliseconds); + return _error404(); } - private List<(string Key, string Person)> _getAvailablePersons(ILibrary lib) { return lib.Persons .OrderBy(x => x.Value.Surname) @@ -125,39 +76,28 @@ public class SucheController : Controller { }; } - private List<(int StartYear, int EndYear)>? _paginate(List>? letters) { - if (letters == null || !letters.Any()) return null; - List<(int StartYear, int EndYear)>? res = null; - int startyear = 0; - int count = 0; - foreach (var letterlist in letters) { - if (count == 0) { - startyear = letterlist.Key; - } - count += letterlist.Count(); - if (count >= _lettersForPage) { - if (res == null) res = new List<(int StartYear, int EndYear)>(); - res.Add((startyear, letterlist.Key)); - count = 0; - } - if (letterlist == letters.Last()) { - if (res == null) res = new List<(int StartYear, int EndYear)>(); - res.Add((startyear, letterlist.Key)); - } - } - return res; + private List? _paginate(List<(int StartYear, int EndYear)>? pages) { + return pages != null ? pages.Select(x => { + if (x.StartYear != x.EndYear) + return x.StartYear + "–" + x.EndYear; + else + return x.StartYear.ToString(); + }).ToList() : null; } - private IActionResult _paginateSend( + private List? _paginate(List comments) { + return null; + } + + private IActionResult _paginateSendLetters( ILibrary lib, int page, - List> metasbyyear, - string? person = null, - string? zhvolume = null, - string? zhpage = null, - string? activeSearch = null, - Dictionary>? searchResults = null) { - var pages = _paginate(metasbyyear); + string activeSearch, + SearchResultType SRT, + Dictionary>? searchResults, + List>? metasbyyear + ) { + var pages = IndexController.Paginate(metasbyyear, _lettersForPage); if (pages != null && page >= pages.Count) return _error404(); if (pages == null && page > 0) return _error404(); List<(int Year, List LetterList)>? letters = null; @@ -170,11 +110,7 @@ public class SucheController : Controller { .ThenBy(x => x.Meta.Order) .ToList())) .ToList(); - List<(string Volume, List Pages)>? availablePages = null; - availablePages = lib.Structure.Where(x => x.Key != "-1").Select(x => (x.Key, x.Value.Select(x => x.Key).ToList())).ToList(); - zhvolume = zhvolume == null ? "1" : zhvolume; - var model = new SucheViewModel(letters, page, pages, _getAvailablePersons(lib), availablePages.OrderBy(x => x.Volume).ToList(), zhvolume, zhpage, activeSearch, searchResults); - if (person != null) model.ActivePerson = person; + var model = new SucheViewModel(SearchType.Letter, SearchResultType.Success, page, _paginate(pages), activeSearch, searchResults, letters); return View("~/Views/HKB/Dynamic/Suche.cshtml", model); } diff --git a/HaWeb/Models/IndexViewModel.cs b/HaWeb/Models/IndexViewModel.cs index a97cad5..237a8eb 100644 --- a/HaWeb/Models/IndexViewModel.cs +++ b/HaWeb/Models/IndexViewModel.cs @@ -11,8 +11,6 @@ public class IndexViewModel { public List<(string Volume, List Pages)>? AvailablePages { get; private set; } public string? ActiveVolume { get; private set; } public string? ActivePage { get; private set; } - public string? ActiveSearch { get; private set; } - public Dictionary>? SearchResults { get; private set; } public IndexViewModel( List<(int Year, List LetterList)>? letters, @@ -21,9 +19,7 @@ public class IndexViewModel { List<(string Key, string Name)>? availablePersons, List<(string Volume, List Pages)>? availablePages, string? activeVolume, - string? activePage, - string? activeSearch, - Dictionary>? searchResults + string? activePage ) { Letters = letters; if (letters != null) @@ -36,7 +32,5 @@ public class IndexViewModel { AvailablePages = availablePages; ActiveVolume = activeVolume; ActivePage = activePage; - ActiveSearch = activeSearch; - SearchResults = searchResults; } } \ No newline at end of file diff --git a/HaWeb/Models/SearchResult.cs b/HaWeb/Models/SearchResult.cs index e01c0e5..67d3689 100644 --- a/HaWeb/Models/SearchResult.cs +++ b/HaWeb/Models/SearchResult.cs @@ -9,6 +9,8 @@ public class SearchResult { public string Index { get; private set; } public string? Page { get; set; } public string? Line { get; set; } + public string? Lemma { get; set; } + public string? Link { get; set; } public string? Preview { get; set; } // TODO: public string? ParsedPreview { get; set; } diff --git a/HaWeb/Models/SucheViewModel.cs b/HaWeb/Models/SucheViewModel.cs index 1fbee2f..867be42 100644 --- a/HaWeb/Models/SucheViewModel.cs +++ b/HaWeb/Models/SucheViewModel.cs @@ -1,41 +1,48 @@ namespace HaWeb.Models; using HaDocument.Models; +public enum SearchType { + Letter, + Register, + Marginals +} + +public enum SearchResultType { + Success, + OutOfBounds, + NotFound, + InvalidSearchTerm +} + public class SucheViewModel { public List<(int Year, List LetterList)>? Letters { get; private set; } public int Count { get; private set; } - public int ActiveYear { get; private set; } - public List<(int StartYear, int EndYear)>? AvailableYears { get; private set; } - public string? ActivePerson { get; set; } - public List<(string Key, string Name)>? AvailablePersons { get; private set; } - public List<(string Volume, List Pages)>? AvailablePages { get; private set; } - public string? ActiveVolume { get; private set; } - public string? ActivePage { get; private set; } - public string? ActiveSearch { get; private set; } + public int ActivePage { get; private set; } + public List? AvailablePages { get; private set; } + public string ActiveSearch { get; private set; } public Dictionary>? SearchResults { get; private set; } + public SearchResultType SearchResultType { get; private set; } + public SearchType SearchType { get; private set; } public SucheViewModel( - List<(int Year, List LetterList)>? letters, - int activeYear, - List<(int StartYear, int EndYear)>? availableYears, - List<(string Key, string Name)>? availablePersons, - List<(string Volume, List Pages)>? availablePages, - string? activeVolume, - string? activePage, - string? activeSearch, - Dictionary>? searchResults + SearchType searchType, + SearchResultType searchResultType, + int activePage, + List? availablePages, + string activeSearch, + Dictionary>? searchResults, + List<(int Year, List LetterList)>? letters ) { Letters = letters; if (letters != null) Count = letters.Select(x => x.LetterList.Count).Aggregate(0, (x, y) => { x += y; return x; }); else Count = 0; - ActiveYear = activeYear; - AvailableYears = availableYears; - AvailablePersons = availablePersons; - AvailablePages = availablePages; - ActiveVolume = activeVolume; + + SearchType = searchType; + SearchResultType = searchResultType; ActivePage = activePage; + AvailablePages = availablePages; ActiveSearch = activeSearch; SearchResults = searchResults; } diff --git a/HaWeb/Views/HKB/Dynamic/Index.cshtml b/HaWeb/Views/HKB/Dynamic/Index.cshtml index b170326..09d8a51 100644 --- a/HaWeb/Views/HKB/Dynamic/Index.cshtml +++ b/HaWeb/Views/HKB/Dynamic/Index.cshtml @@ -13,7 +13,7 @@
@if (Model.AvailableYears != null && Model.AvailableYears.Any() && Model.AvailableYears.Count > 1) { @for(var i = 0; i < Model.AvailableYears.Count; i++) { - + @if (Model.AvailableYears[i].StartYear != Model.AvailableYears[i].EndYear) { @Model.AvailableYears[i].StartYear-@Model.AvailableYears[i].EndYear @@ -38,15 +38,6 @@ } @@ -152,12 +143,9 @@
Volltextsuche - @if (Model.ActiveSearch != null) { - ← Auswahl aufheben - }
- +
diff --git a/HaWeb/Views/HKB/Dynamic/Suche.cshtml b/HaWeb/Views/HKB/Dynamic/Suche.cshtml index f12e99e..3c4fadf 100644 --- a/HaWeb/Views/HKB/Dynamic/Suche.cshtml +++ b/HaWeb/Views/HKB/Dynamic/Suche.cshtml @@ -10,20 +10,46 @@

Suche

+ + @* Full-Text-Search *@ +
+
+ @if (Model.ActiveSearch != null) { + + ← Auswahl aufheben + } +
+
+ + +
+
+ +
- @if (Model.AvailableYears != null && Model.AvailableYears.Any() && Model.AvailableYears.Count > 1) { - @for(var i = 0; i < Model.AvailableYears.Count; i++) { - - @if (Model.AvailableYears[i].StartYear != Model.AvailableYears[i].EndYear) { - - @Model.AvailableYears[i].StartYear-@Model.AvailableYears[i].EndYear - - } - else { - - @Model.AvailableYears[i].StartYear - - } + @if (Model.AvailablePages != null && Model.AvailablePages.Any() && Model.AvailablePages.Count > 1) { + @for(var i = 0; i < Model.AvailablePages.Count; i++) { + + + @Model.AvailablePages[i] + } } @@ -38,15 +64,6 @@
- @* Go To Letter *@ -
-
H K B
-
-
- Briefnummer -
- - -
-
- - - @* ZH Loopkup *@ - @if (Model.AvailablePages != null) { -
-
- Suche in Z H - @if (Model.ActivePage != null) { - ← Auswahl aufheben - } -
-
- Z H Band - - / - - -
-
- - } - - @* Full-Text-Search *@ -
-
- Volltextsuche - @if (Model.ActiveSearch != null) { - ← Auswahl aufheben - } -
-
- - -
-
- - - @* Person Filter *@ - @if(Model.AvailablePersons != null) { -
-
- Korrespondenzpartner:innen - @if (Model.ActivePerson != null) { - ← Auswahl aufheben - } -
-
- Alle - @foreach (var person in Model.AvailablePersons) { - - @person.Name - - } -
-
- }
-
}
\ No newline at end of file diff --git a/HaWeb/appsettings.json b/HaWeb/appsettings.json index 2b62182..c3b86d2 100644 --- a/HaWeb/appsettings.json +++ b/HaWeb/appsettings.json @@ -14,7 +14,7 @@ }, "AllowedHosts": "*", "StoredFilePathLinux": "/home/simon/Downloads/test/", - "StoredFilePathWindows": "C:/Users/simon/Downloads/test/", + "StoredFilePathWindows": "D:/test/", "FileSizeLimit": 52428800, "AvailableStartYear": 1700, "AvailableEndYear": 1800,