57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
|
|
#include "usenetsearch/Application.h"
|
|
#include "usenetsearch/UsenetClient.h"
|
|
#include "usenetsearch/Indexer.h"
|
|
|
|
#include <iostream>
|
|
|
|
using namespace usenetsearch;
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
Application app;
|
|
std::string searchString;
|
|
app.AddStringOption('s', "Search string",
|
|
[&searchString](const std::string& s){
|
|
searchString = s;
|
|
}
|
|
);
|
|
int maxResults{0};
|
|
app.AddIntegerOption('n', "Maximum results",
|
|
[&maxResults](int n){
|
|
maxResults = n;
|
|
}
|
|
);
|
|
if (!app.Init(argc, argv)) return 1;
|
|
if (searchString.empty())
|
|
{
|
|
std::cerr << "Missing search string." << std::endl;
|
|
app.Usage(argv[0]);
|
|
return 1;
|
|
}
|
|
UsenetClient client(app);
|
|
Indexer idx(app, client);
|
|
std::unique_ptr<SearchResults> results = idx.Search(
|
|
searchString
|
|
);
|
|
if (!results)
|
|
{
|
|
std::cout << "Nothing found." << std::endl;
|
|
return 0;
|
|
}
|
|
size_t resultCounter{0};
|
|
for (const auto& sr: *results)
|
|
{
|
|
std::cout << std::left
|
|
<< std::setw(18) << "Newsgroup id: " + std::to_string(sr.NewsgroupId())
|
|
<< std::setw(4) << " | "
|
|
<< std::setw(17) << "Article id: " + std::to_string(sr.ArticleId())
|
|
<< std::setw(4) << " | "
|
|
<< std::setw(10) << "Hits: " + std::to_string(sr.Hits())
|
|
<< std::endl;
|
|
resultCounter++;
|
|
if ((maxResults > 0) && (resultCounter >= maxResults)) break;
|
|
}
|
|
return 0;
|
|
}
|