SearchResultsTable.h (2511B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <winget/SQLiteWrapper.h> 5 #include <winget/SQLiteTempTable.h> 6 #include "Microsoft/Schema/ISQLiteIndex.h" 7 #include "Public/winget/RepositorySearch.h" 8 9 #include <optional> 10 #include <utility> 11 #include <vector> 12 13 14 namespace AppInstaller::Repository::Microsoft::Schema::V1_0 15 { 16 // Table for holding temporary search results. 17 struct SearchResultsTable : public SQLite::TempTable 18 { 19 SearchResultsTable(const SQLite::Connection& connection); 20 21 SearchResultsTable(const SearchResultsTable&) = delete; 22 SearchResultsTable& operator=(const SearchResultsTable&) = delete; 23 24 SearchResultsTable(SearchResultsTable&&) = default; 25 SearchResultsTable& operator=(SearchResultsTable&&) = default; 26 27 // Performs the requested search type on the requested field. 28 void SearchOnField(const PackageMatchFilter& filter); 29 30 // Removes rows with manifest ids whose sort order is below the highest one. 31 void RemoveDuplicateManifestRows(); 32 33 // Prepares the table for a filtering pass. 34 void PrepareToFilter(); 35 36 // Performs the requested filter type on the requested field. 37 void FilterOnField(const PackageMatchFilter& filter); 38 39 // Completes a filtering pass, removing filtered rows. 40 void CompleteFilter(); 41 42 // Gets the results from the table. 43 ISQLiteIndex::SearchResult GetSearchResults(size_t limit = 0); 44 45 protected: 46 // Builds the search statement for the specified field and match type. 47 std::vector<int> BuildSearchStatement(SQLite::Builder::StatementBuilder& builder, PackageMatchField field, MatchType match) const; 48 49 virtual std::vector<int> BuildSearchStatement( 50 SQLite::Builder::StatementBuilder& builder, 51 PackageMatchField field, 52 std::string_view manifestAlias, 53 std::string_view valueAlias, 54 bool useLike) const; 55 56 static bool MatchUsesLike(MatchType match); 57 void BindStatementForMatchType(SQLite::Statement& statement, MatchType match, int bindIndex, std::string_view value); 58 59 virtual void BindStatementForMatchType(SQLite::Statement& statement, const PackageMatchFilter& filter, const std::vector<int>& bindIndex); 60 61 private: 62 const SQLite::Connection& m_connection; 63 int m_sortOrdinalValue = 0; 64 }; 65 }