mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
modules/client/search: Move resources into namespace; add log facility.
This commit is contained in:
parent
b7f2bd8e63
commit
50cb49d558
1 changed files with 56 additions and 40 deletions
|
@ -8,7 +8,14 @@
|
||||||
// copyright notice and this permission notice is present in all copies. The
|
// copyright notice and this permission notice is present in all copies. The
|
||||||
// full license for this software is available in the LICENSE file.
|
// full license for this software is available in the LICENSE file.
|
||||||
|
|
||||||
using namespace ircd;
|
namespace ircd::m::search
|
||||||
|
{
|
||||||
|
static void handle_room_events(client &, const resource::request &, const json::object &, json::stack::object &);
|
||||||
|
static resource::response search_post_handle(client &, const resource::request &);
|
||||||
|
extern resource::method search_post;
|
||||||
|
extern resource search_resource;
|
||||||
|
extern log::log log;
|
||||||
|
}
|
||||||
|
|
||||||
ircd::mapi::header
|
ircd::mapi::header
|
||||||
IRCD_MODULE
|
IRCD_MODULE
|
||||||
|
@ -16,8 +23,14 @@ IRCD_MODULE
|
||||||
"Client 11.14 :Server Side Search"
|
"Client 11.14 :Server Side Search"
|
||||||
};
|
};
|
||||||
|
|
||||||
ircd::resource
|
decltype(ircd::m::search::log)
|
||||||
search_resource
|
ircd::m::search::log
|
||||||
|
{
|
||||||
|
"m.search"
|
||||||
|
};
|
||||||
|
|
||||||
|
decltype(ircd::m::search::search_resource)
|
||||||
|
ircd::m::search::search_resource
|
||||||
{
|
{
|
||||||
"/_matrix/client/r0/search",
|
"/_matrix/client/r0/search",
|
||||||
{
|
{
|
||||||
|
@ -29,26 +42,18 @@ search_resource
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
decltype(ircd::m::search::search_post)
|
||||||
handle_room_events(client &client,
|
ircd::m::search::search_post
|
||||||
const resource::request &request,
|
|
||||||
const json::object &,
|
|
||||||
json::stack::object &);
|
|
||||||
|
|
||||||
static resource::response
|
|
||||||
post__search(client &client, const resource::request &request);
|
|
||||||
|
|
||||||
resource::method
|
|
||||||
post_method
|
|
||||||
{
|
{
|
||||||
search_resource, "POST", post__search,
|
search_resource, "POST", search_post_handle,
|
||||||
{
|
{
|
||||||
post_method.REQUIRES_AUTH
|
search_post.REQUIRES_AUTH
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
resource::response
|
ircd::m::resource::response
|
||||||
post__search(client &client, const resource::request &request)
|
ircd::m::search::search_post_handle(client &client,
|
||||||
|
const resource::request &request)
|
||||||
{
|
{
|
||||||
const auto &batch
|
const auto &batch
|
||||||
{
|
{
|
||||||
|
@ -80,50 +85,61 @@ post__search(client &client, const resource::request &request)
|
||||||
top, "search_categories"
|
top, "search_categories"
|
||||||
};
|
};
|
||||||
|
|
||||||
handle_room_events(client, request, search_categories, result_categories);
|
if(search_categories.has("room_events"))
|
||||||
|
{
|
||||||
|
json::stack::object room_events_result
|
||||||
|
{
|
||||||
|
result_categories, "room_events"
|
||||||
|
};
|
||||||
|
|
||||||
|
handle_room_events(client, request, search_categories, room_events_result);
|
||||||
|
}
|
||||||
|
|
||||||
return std::move(response);
|
return std::move(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_room_events(client &client,
|
ircd::m::search::handle_room_events(client &client,
|
||||||
const resource::request &request,
|
const resource::request &request,
|
||||||
const json::object &search_categories,
|
const json::object &search_categories,
|
||||||
json::stack::object &result_categories)
|
json::stack::object &room_events_result)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(!search_categories.has("room_events"))
|
|
||||||
return;
|
|
||||||
|
|
||||||
const m::search::room_events room_events
|
const m::search::room_events room_events
|
||||||
{
|
{
|
||||||
search_categories["room_events"]
|
search_categories["room_events"]
|
||||||
};
|
};
|
||||||
|
|
||||||
json::stack::object room_events_result
|
|
||||||
{
|
|
||||||
result_categories, "room_events"
|
|
||||||
};
|
|
||||||
|
|
||||||
json::stack::array results
|
|
||||||
{
|
|
||||||
room_events_result, "results"
|
|
||||||
};
|
|
||||||
|
|
||||||
const json::string &search_term
|
const json::string &search_term
|
||||||
{
|
{
|
||||||
at<"search_term"_>(room_events)
|
at<"search_term"_>(room_events)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const m::room_event_filter filter
|
||||||
|
{
|
||||||
|
json::get<"filter"_>(room_events)
|
||||||
|
};
|
||||||
|
|
||||||
|
const json::array rooms
|
||||||
|
{
|
||||||
|
json::get<"rooms"_>(filter)
|
||||||
|
};
|
||||||
|
|
||||||
log::debug
|
log::debug
|
||||||
{
|
{
|
||||||
//TODO: search::log
|
log, "Query '%s' by %s keys:%s order_by:%s inc_state:%b",
|
||||||
m::log, "Search [%s] keys:%s order_by:%s inc_state:%b user:%s",
|
|
||||||
search_term,
|
search_term,
|
||||||
|
string_view{request.user_id},
|
||||||
json::get<"keys"_>(room_events),
|
json::get<"keys"_>(room_events),
|
||||||
json::get<"order_by"_>(room_events),
|
json::get<"order_by"_>(room_events),
|
||||||
json::get<"include_state"_>(room_events),
|
json::get<"include_state"_>(room_events),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
json::stack::array results
|
||||||
|
{
|
||||||
|
room_events_result, "results"
|
||||||
|
};
|
||||||
|
|
||||||
long count(0);
|
long count(0);
|
||||||
{
|
{
|
||||||
json::stack::object result
|
json::stack::object result
|
||||||
|
@ -169,7 +185,7 @@ catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
log::error
|
log::error
|
||||||
{
|
{
|
||||||
//TODO: search::log
|
log, "search :%s",
|
||||||
m::log, "Search error :%s", e.what()
|
e.what()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue