Flow.Launcher/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingSearchManager.cs
Hongtao Zhang 8b1c125bdf
Custom Exception & Some Refactor
- Try use ReadOnlySpan<char> instead of String for applicable API
- Use Customized Exception to return error result
2022-09-21 19:18:20 -05:00

53 lines
1.8 KiB
C#

using System;
using Flow.Launcher.Plugin.Explorer.Search.WindowsIndex;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Flow.Launcher.Plugin.Explorer.Search.IProvider;
namespace Flow.Launcher.Plugin.Explorer.Search.Everything
{
public class EverythingSearchManager : IIndexProvider, IContentIndexProvider, IPathIndexProvider
{
private Settings Settings { get; }
public EverythingSearchManager(Settings settings)
{
Settings = settings;
}
public IAsyncEnumerable<SearchResult> SearchAsync(ReadOnlySpan<char> search, CancellationToken token)
{
return EverythingApi.SearchAsync(
new EverythingSearchOption(search, Settings.SortOption),
token);
}
public IAsyncEnumerable<SearchResult> ContentSearchAsync(ReadOnlySpan<char> plainSearch,
ReadOnlySpan<char> contentSearch, CancellationToken token)
{
if (!Settings.EnableEverythingContentSearch)
{
return AsyncEnumerable.Empty<SearchResult>();
}
return EverythingApi.SearchAsync(
new EverythingSearchOption(
plainSearch,
Settings.SortOption,
true,
contentSearch),
token);
}
public IAsyncEnumerable<SearchResult> EnumerateAsync(ReadOnlySpan<char> path, ReadOnlySpan<char> search, bool recursive, CancellationToken token)
{
return EverythingApi.SearchAsync(
new EverythingSearchOption(search,
Settings.SortOption,
ParentPath: path,
IsRecursive: recursive),
token);
}
}
}