82 lines
2.2 KiB
C++
82 lines
2.2 KiB
C++
/*
|
|
Copyright© 2021 John Sennesael
|
|
|
|
UsenetSearch is Free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
UsenetSearch is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with UsenetSearch. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "usenetsearch/Application.h"
|
|
#include "usenetsearch/Filter.h"
|
|
#include "usenetsearch/UsenetClient.h"
|
|
#include "usenetsearch/ThreadPool.h"
|
|
|
|
#include <codecvt>
|
|
#include <cstdint>
|
|
#include <locale>
|
|
#include <vector>
|
|
|
|
namespace usenetsearch {
|
|
|
|
class SearchResult
|
|
{
|
|
|
|
std::uint32_t m_newsgroupId{0};
|
|
std::uint32_t m_articleId{0};
|
|
size_t m_numHits{0};
|
|
|
|
public:
|
|
|
|
SearchResult() = default;
|
|
SearchResult(const ArticleEntry& entry);
|
|
SearchResult(std::uint32_t newsgroupId, std::uint32_t articleId);
|
|
SearchResult(const SearchResult& other);
|
|
|
|
std::uint32_t ArticleId() const;
|
|
size_t Hits() const;
|
|
void Inc();
|
|
std::uint32_t NewsgroupId() const;
|
|
|
|
void operator=(const SearchResult& other);
|
|
bool operator==(const SearchResult& other) const;
|
|
bool operator!=(const SearchResult& other) const;
|
|
bool operator<(const SearchResult& other) const;
|
|
bool operator>(const SearchResult& other) const;
|
|
bool operator>=(const SearchResult& other) const;
|
|
bool operator<=(const SearchResult& other) const;
|
|
};
|
|
|
|
typedef std::vector<SearchResult> SearchResults;
|
|
|
|
class Indexer
|
|
{
|
|
Application& m_app;
|
|
UsenetClient& m_client;
|
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> m_conv;
|
|
ThreadPool m_threads;
|
|
|
|
public:
|
|
|
|
Indexer(Application& app, UsenetClient& client);
|
|
|
|
void Connect();
|
|
void Index(const std::vector<NntpListEntry>& newsgroups);
|
|
std::unique_ptr<SearchResults> Search(
|
|
const std::string& searchString
|
|
);
|
|
|
|
};
|
|
|
|
} // namespace usenetsearch
|