55using LinqToOneNote . Abstractions ;
66using OneNoteApp = LinqToOneNote . OneNote ;
77
8-
98namespace Flow . Launcher . Plugin . OneNote . Search
109{
11- public class NotebookExplorer : SearchBase
10+ public class NotebookExplorer ( PluginInitContext context , Settings settings , ResultCreator resultCreator , TitleSearch titleSearch , RootCache rootCache )
11+ : SearchBase ( context , settings , resultCreator , settings . Keywords . NotebookExplorer )
1212 {
13- private readonly TitleSearch titleSearch ;
14- private Root ? cache ;
15- private bool updateCache ;
16- public NotebookExplorer ( PluginInitContext context , Settings settings , ResultCreator resultCreator , TitleSearch titleSearch , VisibilityChanged visibilityChanged )
17- : base ( context , settings , resultCreator , settings . Keywords . NotebookExplorer )
18- {
19- this . titleSearch = titleSearch ;
20- visibilityChanged . Subscribe ( isVisible =>
21- {
22- if ( ! isVisible )
23- {
24- updateCache = true ;
25- }
26- } ) ;
27- }
28-
29- internal List < Result > GetResults ( Query query )
13+ public override List < Result > GetResults ( Query query )
3014 {
3115 if ( ! ValidateSearch ( query , out string ? search , out IOneNoteItem ? parent , out IEnumerable < IOneNoteItem > collection ) )
3216 return resultCreator . InvalidQuery ( false ) ;
@@ -49,19 +33,12 @@ internal List<Result> GetResults(Query query)
4933 return results ;
5034 }
5135
52- public override List < Result > GetResults ( string query ) => GetResults ( query ) ;
53-
5436 private bool ValidateSearch ( Query query , out string ? lastSearch , out IOneNoteItem ? parent , out IEnumerable < IOneNoteItem > collection )
5537 {
5638 lastSearch = null ;
5739 parent = null ;
58- if ( updateCache || query . IsReQuery || cache == null )
59- {
60- cache = OneNoteApp . GetFullHierarchy ( ) ;
61- updateCache = false ;
62- }
6340
64- collection = cache . Notebooks ;
41+ collection = rootCache . Root . Notebooks ;
6542
6643 string search = query . Search [ ( query . Search . IndexOf ( Keywords . NotebookExplorer , StringComparison . Ordinal ) + Keywords . NotebookExplorer . Length ) ..] ;
6744 const string separator = Keywords . NotebookExplorerSeparator ;
@@ -102,7 +79,7 @@ private List<Result> ScopedSearch(string query, IOneNoteItem parent)
10279 if ( ! char . IsLetterOrDigit ( query [ Keywords . ScopedSearch . Length ] ) )
10380 return resultCreator . InvalidQuery ( ) ;
10481
105- string currentSearch = query [ Keywords . TitleSearch . Length ..] ;
82+ string currentSearch = query [ Keywords . ScopedSearch . Length ..] ;
10683
10784 var results = OneNoteApp . FindPages ( currentSearch , parent )
10885 . Select ( pg => resultCreator . CreatePageResult ( pg , currentSearch ) )
0 commit comments