Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ksv committed Mar 27, 2022
0 parents commit e379453
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/cmake-build-debug/
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.21)
project(search_engine)
include(FetchContent)

set(CMAKE_CXX_STANDARD 14)

FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.10.5/json.tar.xz)
FetchContent_MakeAvailable(json)

add_executable(search_engine main.cpp ConverterJSON.cpp ConverterJSON.h)

target_link_libraries(search_engine PRIVATE nlohmann_json::nlohmann_json)
11 changes: 11 additions & 0 deletions ConverterJSON.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Created by ksv on 27.03.2022.
//

#include "ConverterJSON.h"

std::vector<std::string> ConverterJSON::GetTextDocuments() {
std::vector<std::string> response = std::vector<std::string>();

return response;
}
44 changes: 44 additions & 0 deletions ConverterJSON.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <vector>
#include <string>
#include <fstream>

#include "nlohmann/json.hpp"

struct config_json {
struct {
std::string name;
std::string version;
int max_responses;
} config;
std::vector<std::string> files;
};

/**
* Класс для работы с JSON-файлами
*/
class ConverterJSON {
public:
ConverterJSON() = default;
/**
* Метод получения содержимого файлов
* @return Возвращает список с содержимым файлов перечисленных
* в config.json
*/
std::vector<std::string> GetTextDocuments();
/**
* Метод считывает поле max_responses для определения предельного
* количества ответов на один запрос
* @return
*/
int GetResponsesLimit();
/**
* Метод получения запросов из файла requests.json
* @return возвращает список запросов из файла requests.json
*/
std::vector<std::string> GetRequests();
/**
* Положить в файл answers.json результаты поисковых запросов
*/
void putAnswers(std::vector<std::vector<std::pair<int, float>>>
answers);
};
46 changes: 46 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>

#include "ConverterJSON.h"

int main() {

auto config_file = std::ifstream("config.json");

if(!config_file.is_open()){
std::cerr << "config file is missing." << std::endl;
return 1;
}

nlohmann::json conf;
config_file >> conf;

auto cf = config_json();

if(conf["config"].is_null()){
std::cerr << "config file is empty." << std::endl;
return 1;
}

if(!conf["config"]["name"].is_null()){
cf.config.name = conf["config"]["name"];
}else{
cf.config.name = "Undefined";
}
if(!conf["config"]["version"].is_null()) {
cf.config.version = conf["config"]["version"];
}
cf.config.max_responses = conf["config"]["max_responses"];

for (auto f: conf["files"]) {
cf.files.push_back(f);
}

std::cout << cf.config.name << ((cf.config.version == "")? "" : " version: ") << cf.config.version << std::endl;

// for (auto f: cf.files) {
// std::cout << f << std::endl;
// }

return 0;

}

0 comments on commit e379453

Please sign in to comment.