-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
52 lines (49 loc) · 1.83 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include "ConverterJSON.h"
#include "InvertedIndex.h"
#include "SearchServer.h"
/**
* Write answers to the JSON file answers.json
* @param [in] allRequestsResults result of search for relevant pages
*/
void writeAnswers(const std::vector<std::vector<RelativeIndex>>& allRequestsResults)
{
if (allRequestsResults.empty())
{
std::cout << "No matches are found.\n";
return;
}
std::vector<std::vector<std::pair<int, float>>> allRequestsResultsReadyForJSON;
for (auto& requestResult : allRequestsResults)
{
std::vector<std::pair<int, float>> requestResultReadyForJSON;
for (auto& pageRelevance : requestResult)
{
std::pair<int, float> relevancePair;
relevancePair.first = (int) pageRelevance.doc_id;
relevancePair.second = pageRelevance.rank;
requestResultReadyForJSON.push_back(relevancePair);
}
allRequestsResultsReadyForJSON.push_back(requestResultReadyForJSON);
}
ConverterJSON::getInstance()->putAnswers(allRequestsResultsReadyForJSON);
}
int main()
{
//Initialization:
ConverterJSON::getInstance()->readConfigFile();
ConverterJSON::getInstance()->readRequestFile();
std::vector<std::string> documents = ConverterJSON::getInstance()->getTextDocuments();
auto* invertedIndex = new InvertedIndex();
invertedIndex->updateDocumentBase(documents);
//Search:
std::cout << "Searching...\n";
SearchServer searchServer(*invertedIndex);
searchServer.setMaxResponses(ConverterJSON::getInstance()->getMaxResponses());
auto allRequestsResults = searchServer.search(ConverterJSON::getInstance()->getRequests());
writeAnswers(allRequestsResults);
std::cout << "End of search.\n";
//Pause the console - uncomment if pause is necessary:
std::cin.get();
return 0;
}