forked from microsoft/winget-pkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete initial version of source interface (microsoft#34)
- Loading branch information
Showing
3 changed files
with
108 additions
and
15 deletions.
There are no files selected for viewing
90 changes: 88 additions & 2 deletions
90
src/AppInstallerRepositoryCore/Public/AppInstallerRepositorySearch.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,105 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
#pragma once | ||
#include <Manifest/Manifest.h> | ||
|
||
#include <memory> | ||
#include <optional> | ||
#include <string> | ||
#include <string_view> | ||
#include <vector> | ||
|
||
|
||
namespace AppInstaller::Repository | ||
{ | ||
// The type of matching to perform during a search. | ||
enum class MatchType | ||
{ | ||
Exact, | ||
Substring, | ||
Wildcard, | ||
Fuzzy, | ||
}; | ||
|
||
// The field to match on. | ||
enum class ApplicationMatchField | ||
{ | ||
Id, | ||
Name, | ||
Moniker, | ||
Tag, | ||
Command, | ||
Protocol, | ||
Extension, | ||
}; | ||
|
||
// A single match to be performed during a search. | ||
struct RequestMatch | ||
{ | ||
MatchType Type; | ||
std::string Value; | ||
|
||
RequestMatch(MatchType t, std::string v) : Type(t), Value(std::move(v)) {} | ||
}; | ||
|
||
// A match on a specific field to be performed during a search. | ||
struct ApplicationMatchFilter : public RequestMatch | ||
{ | ||
ApplicationMatchField Field; | ||
|
||
ApplicationMatchFilter(ApplicationMatchField f, MatchType t, std::string v) : RequestMatch(t, std::move(v)), Field(f) {} | ||
}; | ||
|
||
// Container for data used to filter the available manifests in a source. | ||
struct SearchFilter | ||
struct SearchRequest | ||
{ | ||
// The generic query matches against a source defined set of fields. | ||
// If not provided, the filters should be used against the entire dataset. | ||
std::optional<RequestMatch> Query; | ||
|
||
// Specific fields used to filter the data further. | ||
std::vector<ApplicationMatchFilter> Filters; | ||
|
||
// The maximum number of results to return. | ||
// The default of 0 will place no limit. | ||
size_t MaximumResults{}; | ||
}; | ||
|
||
// A single application result from a search. | ||
struct IApplication | ||
{ | ||
// Gets the id of the application. | ||
virtual std::string GetId() const = 0; | ||
|
||
// Gets the name of the application (the latest name). | ||
virtual std::string GetName() const = 0; | ||
|
||
// Gets a manifest for this application. | ||
// An empty version implies 'latest'. | ||
// An empty channel is the 'general audience'. | ||
virtual Manifest::Manifest GetManifest(std::string_view version, std::string_view channel) const = 0; | ||
|
||
// Gets all versions of this application. | ||
// The pair is <version, channel>. | ||
virtual std::vector<std::pair<std::string, std::string>> GetVersions() const = 0; | ||
}; | ||
|
||
// A single result from the search. | ||
struct ResultMatch | ||
{ | ||
// The application found by the search request. | ||
std::unique_ptr<IApplication> Application; | ||
|
||
// The highest order field on which the application matched the search. | ||
ApplicationMatchFilter MatchCriteria; | ||
|
||
ResultMatch(std::unique_ptr<IApplication> a, ApplicationMatchFilter f) : Application(std::move(a)), MatchCriteria(std::move(f)) {} | ||
}; | ||
|
||
// Search result data. | ||
struct SearchResult | ||
{ | ||
|
||
// The full set of results from the search. | ||
std::vector<ResultMatch> Matches; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters