Skip to content

Commit

Permalink
When no suggested tags are found, run a metadata search.
Browse files Browse the repository at this point in the history
  • Loading branch information
WetHat committed Apr 10, 2022
1 parent ff19bf7 commit 1f8590f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 2 additions & 6 deletions OneNoteTaggingKit/HierarchyBuilder/PageHierarchy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,9 @@ public void AddPages(SearchScope scope, string query = null) {
// search by tags only
// collect all page tags on pages which have page tags. Tag search appears to
// be broken using work around
if (Properties.Settings.Default.UseWindowsSearch) {
searchResult = _onenote.FindPagesByMetadata(scopeID, MetaCollection.PageTagsMetaKey);
} else {
searchResult = _onenote.GetHierarchy(scopeID, HierarchyScope.hsPages);
}
searchResult = _onenote.FindPagesByMetadata(scopeID, MetaCollection.PageTagsMetaKey);
} else {
searchResult = _onenote.FindPages(scopeID, query);
searchResult = _onenote.FindPages(scopeID, query);
}
buildHierarchy(searchResult.Root, null);
}
Expand Down
18 changes: 13 additions & 5 deletions OneNoteTaggingKit/common/KnownTagsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using WetHatLab.OneNote.TaggingKit.common.ui;
using WetHatLab.OneNote.TaggingKit.HierarchyBuilder;

namespace WetHatLab.OneNote.TaggingKit.common
{
Expand Down Expand Up @@ -33,14 +34,21 @@ public KnownTagsSource(OneNoteProxy onenote) {
/// <returns>awaitable task object</returns>
public async Task LoadKnownTagsAsync() {
Clear();
IEnumerable<T> mdls = await Task<IEnumerable<T>>.Run(() => LoadPersistedTags());
IEnumerable<T> mdls = await Task<IEnumerable<T>>.Run(() => {
if (_onenote.KnownTags.IsEmpty) {
// nothing known - search for tags on pages
var ph = new PageHierarchy(_onenote);
ph.AddPages(SearchScope.AllNotebooks);
foreach (var pg in ph.Pages) {
_onenote.KnownTags.UnionWith(pg.Tags);
}
_onenote.SaveSettings();
}
return from pt in _onenote.KnownTags select new T() { Tag = pt };
});
AddAll(mdls);
}

private IEnumerable<T> LoadPersistedTags() {
return from pt in _onenote.KnownTags select new T() { Tag = pt };
}

/// <summary>
/// Save the current set of suggested tags to the add-in settings store.
/// </summary>
Expand Down

0 comments on commit 1f8590f

Please sign in to comment.