<commit_before>#include "searchHandler.h"

#include <boost/algorithm/string/trim.hpp>
#include <Poco/JSON/Object.h>

#include <Poco/Net/HTMLForm.h>
#include <Poco/URI.h>

namespace WikiMainPath {

	SearchHandler::SearchHandler(const std::string json_attribute_name, const std::vector<std::string>& vec, const InvertedIndex& inverted_index)
		:_json_attribute_name(json_attribute_name),
		_vector(vec),
		_inverted_index(inverted_index)
	{}

	void SearchHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
	{
		using namespace Poco::JSON;

		response.setChunkedTransferEncoding(true);
		response.setContentType("text/json");

		// get parameters
		Poco::URI uri(request.getURI());
		auto parameters = uri.getQueryParameters();

		if(parameters.size() != 1 || parameters[0].first != "query-str")
		{
			response.setStatus("400"); // = Bad Request

			Object root;
			root.set("error", "GET-Parameter query-str not specified or too many parameters.");

			root.stringify(response.send(), 4); 

			return;
		}

		std::string query_str = parameters[0].second;
		boost::trim(query_str);

		DocumentSet results;
		if(query_str != "")
			 results = query(_inverted_index, query_str);

		Object root;
		Array matchingCategoriesArray;

		for (auto res : results) {
			Object el;
			el.set("title", _vector[res]);
			el.set("id", res);

			matchingCategoriesArray.add(el);
		}

		root.set(_json_attribute_name, matchingCategoriesArray);

		root.stringify(response.send(), 4); 
	}

}
<commit_msg>Activated cross origin requests to backend<commit_after>#include "searchHandler.h"

#include <boost/algorithm/string/trim.hpp>
#include <Poco/JSON/Object.h>

#include <Poco/Net/HTMLForm.h>
#include <Poco/URI.h>

namespace WikiMainPath {

	SearchHandler::SearchHandler(const std::string json_attribute_name, const std::vector<std::string>& vec, const InvertedIndex& inverted_index)
		:_json_attribute_name(json_attribute_name),
		_vector(vec),
		_inverted_index(inverted_index)
	{}

	void SearchHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
	{
		using namespace Poco::JSON;

		response.setChunkedTransferEncoding(true);
		response.setContentType("text/json");
		response.set("Access-Control-Allow-Origin", "*");

		// get parameters
		Poco::URI uri(request.getURI());
		auto parameters = uri.getQueryParameters();

		if(parameters.size() != 1 || parameters[0].first != "query-str")
		{
			response.setStatus("400"); // = Bad Request

			Object root;
			root.set("error", "GET-Parameter query-str not specified or too many parameters.");

			root.stringify(response.send(), 4); 

			return;
		}

		std::string query_str = parameters[0].second;
		boost::trim(query_str);

		DocumentSet results;
		if(query_str != "")
			 results = query(_inverted_index, query_str);

		Object root;
		Array matchingCategoriesArray;

		for (auto res : results) {
			Object el;
			el.set("title", _vector[res]);
			el.set("id", res);

			matchingCategoriesArray.add(el);
		}

		root.set(_json_attribute_name, matchingCategoriesArray);

		root.stringify(response.send(), 4); 

	}

}

{'fraction_non_alphanumeric': 0.1443527918781726, 'fraction_numerical': 0.005076142131979695, 'mean_word_length': 5.07514450867052, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3394786', 'n_tokens_mistral': 1137, 'n_tokens_neox': 998, 'n_words': 188}