This commit is contained in:
parent
48c2ef7baa
commit
aaaeb4429f
@ -264,14 +264,15 @@ Application::Application(const std::string &path)
|
|||||||
s.body() = boost::json::serialize(reply);
|
s.body() = boost::json::serialize(reply);
|
||||||
s.prepare_payload();
|
s.prepare_payload();
|
||||||
session.reply(std::move(s));
|
session.reply(std::move(s));
|
||||||
});
|
});
|
||||||
m_router->insert("/api/v1/search/reindex", [this](HttpSession &session, const Request &request, const boost::urls::matches &matches) {
|
m_router->insert("/api/v1/search/reindex", [this](HttpSession &session, const Request &request, const boost::urls::matches &matches) {
|
||||||
using namespace boost::beast;
|
using namespace boost::beast;
|
||||||
auto key = getMeiliSearchApiKey();
|
auto key = getMeiliSearchApiKey();
|
||||||
auto config = getMeiliSearchConfig();
|
auto config = getMeiliSearchConfig();
|
||||||
|
boost::json::object reply;
|
||||||
if (!key.empty() && !config.empty()) {
|
if (!key.empty() && !config.empty()) {
|
||||||
config = std::filesystem::absolute(config);
|
config = std::filesystem::absolute(config);
|
||||||
LOG(info)<<"config path: "<<config;
|
LOG(info) << "config path: " << config;
|
||||||
boost::process::process process(session.executor(), "/usr/bin/docker", {"run", "-t", "--rm", "--network=host",
|
boost::process::process process(session.executor(), "/usr/bin/docker", {"run", "-t", "--rm", "--network=host",
|
||||||
"--env=MEILISEARCH_HOST_URL=http://localhost:7700",
|
"--env=MEILISEARCH_HOST_URL=http://localhost:7700",
|
||||||
std::format("--env=MEILISEARCH_API_KEY={}", key),
|
std::format("--env=MEILISEARCH_API_KEY={}", key),
|
||||||
@ -281,16 +282,17 @@ Application::Application(const std::string &path)
|
|||||||
});
|
});
|
||||||
boost::process::error_code error;
|
boost::process::error_code error;
|
||||||
int code = process.wait(error);
|
int code = process.wait(error);
|
||||||
if (error) {
|
reply["status"] = code;
|
||||||
LOG(error) << error.message();
|
reply["message"] = error ? error.message() : "succeed.";
|
||||||
} else {
|
} else {
|
||||||
LOG(info) << "reindex code:" << code;
|
reply["status"] = 404;
|
||||||
}
|
reply["message"] = "please fill MeiliSearchApiKey and MeiliSearchConfig.";
|
||||||
}
|
}
|
||||||
http::response<boost::beast::http::string_body> s{boost::beast::http::status::ok, request.version()};
|
http::response<boost::beast::http::string_body> s{boost::beast::http::status::ok, request.version()};
|
||||||
s.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
s.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||||
s.set(http::field::content_type, "application/json;charset=UTF-8");
|
s.set(http::field::content_type, "application/json;charset=UTF-8");
|
||||||
s.keep_alive(request.keep_alive());
|
s.keep_alive(request.keep_alive());
|
||||||
|
s.body() = boost::json::serialize(reply);
|
||||||
s.prepare_payload();
|
s.prepare_payload();
|
||||||
session.reply(std::move(s));
|
session.reply(std::move(s));
|
||||||
});
|
});
|
||||||
|
32
resources/meilisearch.json
Normal file
32
resources/meilisearch.json
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"index_uid": "amass_blog",
|
||||||
|
"start_urls": [
|
||||||
|
"https://amass.fun/"
|
||||||
|
],
|
||||||
|
"sitemap_urls": [
|
||||||
|
"https://amass.fun/sitemap.xml"
|
||||||
|
],
|
||||||
|
"sitemap_alternate_links": true,
|
||||||
|
"stop_urls": [
|
||||||
|
"https://amass.fun/gitea"
|
||||||
|
],
|
||||||
|
"selectors": {
|
||||||
|
"lvl0": {
|
||||||
|
"selector": "(//ul[contains(@class,'menu__list')]//a[contains(@class, 'menu__link menu__link--sublist menu__link--active')]/text() | //nav[contains(@class, 'navbar')]//a[contains(@class, 'navbar__link--active')]/text())[last()]",
|
||||||
|
"type": "xpath",
|
||||||
|
"global": true,
|
||||||
|
"default_value": "Documentation"
|
||||||
|
},
|
||||||
|
"lvl1": "header h1",
|
||||||
|
"lvl2": "article h2",
|
||||||
|
"lvl3": "article h3",
|
||||||
|
"lvl4": "article h4",
|
||||||
|
"lvl5": "article h5, article td:first-child",
|
||||||
|
"lvl6": "article h6",
|
||||||
|
"text": "article p, article li, article td:last-child"
|
||||||
|
},
|
||||||
|
"strip_chars": " .,;:#",
|
||||||
|
"custom_settings": {
|
||||||
|
},
|
||||||
|
"nb_hits": 46250
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user