Re-index if search engine files get deleted
This commit is contained in:
parent
c598576683
commit
0b42b8ee49
40
ApplicationServices/UNTESTED/LibraryCommands.cs
Normal file
40
ApplicationServices/UNTESTED/LibraryCommands.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AudibleApi;
|
||||||
|
using DataLayer;
|
||||||
|
using DtoImporterService;
|
||||||
|
using InternalUtilities;
|
||||||
|
|
||||||
|
namespace ApplicationServices
|
||||||
|
{
|
||||||
|
public static class LibraryCommands
|
||||||
|
{
|
||||||
|
public static async Task<(int totalCount, int newCount)> IndexLibraryAsync(ILoginCallback callback)
|
||||||
|
{
|
||||||
|
var audibleApiActions = new AudibleApiActions();
|
||||||
|
var items = await audibleApiActions.GetAllLibraryItemsAsync(callback);
|
||||||
|
var totalCount = items.Count;
|
||||||
|
|
||||||
|
var libImporter = new LibraryImporter();
|
||||||
|
var newCount = await Task.Run(() => libImporter.Import(items));
|
||||||
|
|
||||||
|
await Task.Run(() => SearchEngineCommands.FullReIndex());
|
||||||
|
|
||||||
|
return (totalCount, newCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int IndexChangedTags(Book book)
|
||||||
|
{
|
||||||
|
// update disconnected entity
|
||||||
|
using var context = LibationContext.Create();
|
||||||
|
context.Update(book);
|
||||||
|
var qtyChanges = context.SaveChanges();
|
||||||
|
|
||||||
|
// this part is tags-specific
|
||||||
|
if (qtyChanges > 0)
|
||||||
|
SearchEngineCommands.UpdateBookTags(book);
|
||||||
|
|
||||||
|
return qtyChanges;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,25 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using AudibleApi;
|
|
||||||
using DtoImporterService;
|
|
||||||
using InternalUtilities;
|
|
||||||
|
|
||||||
namespace ApplicationServices
|
|
||||||
{
|
|
||||||
public class LibraryIndexer
|
|
||||||
{
|
|
||||||
public async Task<(int totalCount, int newCount)> IndexAsync(ILoginCallback callback)
|
|
||||||
{
|
|
||||||
var audibleApiActions = new AudibleApiActions();
|
|
||||||
var items = await audibleApiActions.GetAllLibraryItemsAsync(callback);
|
|
||||||
var totalCount = items.Count;
|
|
||||||
|
|
||||||
var libImporter = new LibraryImporter();
|
|
||||||
var newCount = await Task.Run(() => libImporter.Import(items));
|
|
||||||
|
|
||||||
await SearchEngineActions.FullReIndexAsync();
|
|
||||||
|
|
||||||
return (totalCount, newCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
using DataLayer;
|
|
||||||
|
|
||||||
namespace ApplicationServices
|
|
||||||
{
|
|
||||||
public static class SearchEngineActions
|
|
||||||
{
|
|
||||||
public static async Task FullReIndexAsync()
|
|
||||||
{
|
|
||||||
var engine = new LibationSearchEngine.SearchEngine();
|
|
||||||
await engine.CreateNewIndexAsync().ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void UpdateBookTags(Book book)
|
|
||||||
{
|
|
||||||
var engine = new LibationSearchEngine.SearchEngine();
|
|
||||||
engine.UpdateTags(book.AudibleProductId, book.UserDefinedItem.Tags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
43
ApplicationServices/UNTESTED/SearchEngineCommands.cs
Normal file
43
ApplicationServices/UNTESTED/SearchEngineCommands.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using DataLayer;
|
||||||
|
using LibationSearchEngine;
|
||||||
|
|
||||||
|
namespace ApplicationServices
|
||||||
|
{
|
||||||
|
public static class SearchEngineCommands
|
||||||
|
{
|
||||||
|
public static void FullReIndex()
|
||||||
|
{
|
||||||
|
var engine = new SearchEngine();
|
||||||
|
engine.CreateNewIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SearchResultSet Search(string searchString)
|
||||||
|
{
|
||||||
|
var engine = new SearchEngine();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return engine.Search(searchString);
|
||||||
|
}
|
||||||
|
catch (System.IO.FileNotFoundException)
|
||||||
|
{
|
||||||
|
FullReIndex();
|
||||||
|
return engine.Search(searchString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateBookTags(Book book)
|
||||||
|
{
|
||||||
|
var engine = new SearchEngine();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
engine.UpdateTags(book.AudibleProductId, book.UserDefinedItem.Tags);
|
||||||
|
}
|
||||||
|
catch (System.IO.FileNotFoundException)
|
||||||
|
{
|
||||||
|
FullReIndex();
|
||||||
|
engine.UpdateTags(book.AudibleProductId, book.UserDefinedItem.Tags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,21 +0,0 @@
|
|||||||
using DataLayer;
|
|
||||||
|
|
||||||
namespace ApplicationServices
|
|
||||||
{
|
|
||||||
public static class TagUpdater
|
|
||||||
{
|
|
||||||
public static int IndexChangedTags(Book book)
|
|
||||||
{
|
|
||||||
// update disconnected entity
|
|
||||||
using var context = LibationContext.Create();
|
|
||||||
context.Update(book);
|
|
||||||
var qtyChanges = context.SaveChanges();
|
|
||||||
|
|
||||||
// this part is tags-specific
|
|
||||||
if (qtyChanges > 0)
|
|
||||||
SearchEngineActions.UpdateBookTags(book);
|
|
||||||
|
|
||||||
return qtyChanges;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -160,8 +160,7 @@ namespace LibationSearchEngine
|
|||||||
|
|
||||||
private Directory getIndex() => FSDirectory.Open(SearchEngineDirectory);
|
private Directory getIndex() => FSDirectory.Open(SearchEngineDirectory);
|
||||||
|
|
||||||
public async Task CreateNewIndexAsync() => await Task.Run(() => createNewIndex(true));
|
public void CreateNewIndex(bool overwrite = true)
|
||||||
private void createNewIndex(bool overwrite)
|
|
||||||
{
|
{
|
||||||
// 300 products
|
// 300 products
|
||||||
// 1st run after app is started: 400ms
|
// 1st run after app is started: 400ms
|
||||||
|
|||||||
@ -31,8 +31,7 @@ namespace LibationWinForm
|
|||||||
public async Task DoMainWorkAsync()
|
public async Task DoMainWorkAsync()
|
||||||
{
|
{
|
||||||
var callback = new Login.WinformResponder();
|
var callback = new Login.WinformResponder();
|
||||||
var indexer = new LibraryIndexer();
|
(TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.IndexLibraryAsync(callback);
|
||||||
(TotalBooksProcessed, NewBooksAdded) = await indexer.IndexAsync(callback);
|
|
||||||
|
|
||||||
successMessages.Add($"Total processed: {TotalBooksProcessed}");
|
successMessages.Add($"Total processed: {TotalBooksProcessed}");
|
||||||
successMessages.Add($"New: {NewBooksAdded}");
|
successMessages.Add($"New: {NewBooksAdded}");
|
||||||
|
|||||||
@ -2,9 +2,10 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Dinah.Core.DataBinding;
|
using ApplicationServices;
|
||||||
using DataLayer;
|
using DataLayer;
|
||||||
using Dinah.Core.Collections.Generic;
|
using Dinah.Core.Collections.Generic;
|
||||||
|
using Dinah.Core.DataBinding;
|
||||||
|
|
||||||
namespace LibationWinForm
|
namespace LibationWinForm
|
||||||
{
|
{
|
||||||
@ -189,7 +190,7 @@ namespace LibationWinForm
|
|||||||
{
|
{
|
||||||
book.UserDefinedItem.Tags = newTags;
|
book.UserDefinedItem.Tags = newTags;
|
||||||
|
|
||||||
var qtyChanges = ApplicationServices.TagUpdater.IndexChangedTags(book);
|
var qtyChanges = LibraryCommands.IndexChangedTags(book);
|
||||||
return qtyChanges;
|
return qtyChanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +239,7 @@ namespace LibationWinForm
|
|||||||
if (dataGridView.Rows.Count == 0)
|
if (dataGridView.Rows.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var searchResults = new LibationSearchEngine.SearchEngine().Search(searchString);
|
var searchResults = SearchEngineCommands.Search(searchString);
|
||||||
var productIds = searchResults.Docs.Select(d => d.ProductId).ToList();
|
var productIds = searchResults.Docs.Select(d => d.ProductId).ToList();
|
||||||
|
|
||||||
// https://stackoverflow.com/a/18942430
|
// https://stackoverflow.com/a/18942430
|
||||||
|
|||||||
15
__TODO.txt
15
__TODO.txt
@ -1,21 +1,18 @@
|
|||||||
-- begin BETA ---------------------------------------------------------------------------------------------------------------------
|
-- begin BETA ---------------------------------------------------------------------------------------------------------------------
|
||||||
if db present but no search files -- re-create
|
if db present but no search files -- re-create
|
||||||
|
|
||||||
|
when library scan complete: close "Scan Library" dialog and THEN show results dialog
|
||||||
|
|
||||||
make sure the new "if (dataGridView.Rows.Count == 0)" doesn't break filtering if all are invisible
|
make sure the new "if (dataGridView.Rows.Count == 0)" doesn't break filtering if all are invisible
|
||||||
- load products. do a search with 0 results. do a search with results
|
- load products. do a search with 0 results. do a search with results
|
||||||
|
|
||||||
libation errors on another computer:
|
|
||||||
copy pw, LibationSettings.json
|
|
||||||
file not found. probably about file locations. the bottom right and bottom left counts don't update
|
|
||||||
ONLY file in libation files: IdentityTokens.json. no other files OR folders
|
|
||||||
exception after library scan
|
|
||||||
file not found. same file?
|
|
||||||
no mdf,ldf files created in C:\Users\[username]
|
|
||||||
|
|
||||||
throttle needed for downloading images, pdf.s
|
throttle needed for downloading images, pdf.s
|
||||||
|
|
||||||
|
no mdf,ldf files created in C:\Users\[username]
|
||||||
|
|
||||||
Warn of known performance issues
|
Warn of known performance issues
|
||||||
- Library import
|
- Library import
|
||||||
|
incl image d/l. need to throttle
|
||||||
- Tag add/edit
|
- Tag add/edit
|
||||||
- Grid is slow to respond loading when books aren't liberated
|
- Grid is slow to respond loading when books aren't liberated
|
||||||
- get decrypt key -- unavoidable
|
- get decrypt key -- unavoidable
|
||||||
@ -27,7 +24,7 @@ https://dotnetcoretutorials.com/2019/06/20/publishing-a-single-exe-file-in-net-c
|
|||||||
-- begin ENHANCEMENT, IMPORT UI ---------------------------------------------------------------------------------------------------------------------
|
-- begin ENHANCEMENT, IMPORT UI ---------------------------------------------------------------------------------------------------------------------
|
||||||
scan library in background?
|
scan library in background?
|
||||||
can include a notice somewhere that it's in-process
|
can include a notice somewhere that it's in-process
|
||||||
why block the UI?
|
why block the UI at all?
|
||||||
-- end ENHANCEMENT, IMPORT UI ---------------------------------------------------------------------------------------------------------------------
|
-- end ENHANCEMENT, IMPORT UI ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- begin BUG, FILE DOWNLOAD ---------------------------------------------------------------------------------------------------------------------
|
-- begin BUG, FILE DOWNLOAD ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user