libkazv
Loading...
Searching...
No Matches
search.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
3 */
4
5#pragma once
6
7#include "basejob.hpp"
9
10namespace Kazv::Api {
11
16class SearchJob : public BaseJob {
17public:
18 // Inner data structures
19
23 {
26 std::optional<int> beforeLimit;
29 std::optional<int> afterLimit;
34 std::optional<bool> includeProfile;
35
36 };
37
39 struct Group
40 {
42 std::optional<std::string> key;
43
44 };
45
48 struct Groupings
49 {
51 immer::array<Group> groupBy;
52
53 };
54
57 {
59 std::string searchTerm;
61 immer::array<std::string> keys;
66 std::optional<std::string> orderBy;
69 std::optional<IncludeEventContext> eventContext;
72 std::optional<bool> includeState;
75 std::optional<Groupings> groupings;
76
77 };
78
81 {
83 std::optional<RoomEventsCriteria> roomEvents;
84
85 };
86
89 {
91 std::optional<std::string> displayname;
93 std::optional<std::string> avatarUrl;
94
95 };
96
99 {
101 std::optional<std::string> start;
103 std::optional<std::string> end;
109 immer::map<std::string, UserProfile> profileInfo;
114
115 };
116
118 struct Result
119 {
121 std::optional<double> rank;
125 std::optional<EventContext> context;
126
127 };
128
131 {
137 std::optional<std::string> nextBatch;
140 std::optional<int> order;
142 immer::array<std::string> results;
143
144 };
145
148 {
150 std::optional<int> count;
152 immer::array<std::string> highlights;
154 immer::array<Result> results;
161 immer::map<std::string, EventList> state;
167 immer::map<std::string, immer::map<std::string, GroupValue>> groups;
172 std::optional<std::string> nextBatch;
173
174 };
175
178 {
180 std::optional<ResultRoomEvents> roomEvents;
181
182 };
183
184
185
186class JobResponse : public Response
187{
188
189public:
191 bool success() const;
192
193 // Result properties
194
195
196
197
200
201};
202 static constexpr auto needsAuth() {
203 return true
204 ;
205 }
206
207
208// Construction/destruction
209
219 explicit SearchJob(std::string serverUrl
220 , std::string _accessToken
221 ,
222 Categories searchCategories , std::optional<std::string> nextBatch = std::nullopt
223 );
224
225
227 std::optional<std::string> nextBatch);
228
229 static BaseJob::Body buildBody(Categories searchCategories, std::optional<std::string> nextBatch);
230
231
232
233
234
236 SearchJob withData(JsonWrap j) const &;
237 };
239 }
240 namespace nlohmann
241 {
242 using namespace Kazv;
243 using namespace Kazv::Api;
244 template<>
245 struct adl_serializer<SearchJob::IncludeEventContext> {
246
247 static void to_json(json& jo, const SearchJob::IncludeEventContext &pod)
248 {
249 if (! jo.is_object()) { jo = json::object(); }
250
251
252
253 addToJsonIfNeeded(jo, "before_limit"s, pod.beforeLimit);
254
255 addToJsonIfNeeded(jo, "after_limit"s, pod.afterLimit);
256
257 addToJsonIfNeeded(jo, "include_profile"s, pod.includeProfile);
258 }
259
260 static void from_json(const json &jo, SearchJob::IncludeEventContext& result)
261 {
262
263 if (jo.contains("before_limit"s)) {
264 result.beforeLimit = jo.at("before_limit"s);
265 }
266 if (jo.contains("after_limit"s)) {
267 result.afterLimit = jo.at("after_limit"s);
268 }
269 if (jo.contains("include_profile"s)) {
270 result.includeProfile = jo.at("include_profile"s);
271 }
272
273 }
274
275};
276 template<>
277 struct adl_serializer<SearchJob::Group> {
278
279 static void to_json(json& jo, const SearchJob::Group &pod)
280 {
281 if (! jo.is_object()) { jo = json::object(); }
282
283
284
285 addToJsonIfNeeded(jo, "key"s, pod.key);
286 }
287
288 static void from_json(const json &jo, SearchJob::Group& result)
289 {
290
291 if (jo.contains("key"s)) {
292 result.key = jo.at("key"s);
293 }
294
295 }
296
297};
298 template<>
299 struct adl_serializer<SearchJob::Groupings> {
300
301 static void to_json(json& jo, const SearchJob::Groupings &pod)
302 {
303 if (! jo.is_object()) { jo = json::object(); }
304
305
306
307 addToJsonIfNeeded(jo, "group_by"s, pod.groupBy);
308 }
309
310 static void from_json(const json &jo, SearchJob::Groupings& result)
311 {
312
313 if (jo.contains("group_by"s)) {
314 result.groupBy = jo.at("group_by"s);
315 }
316
317 }
318
319};
320 template<>
321 struct adl_serializer<SearchJob::RoomEventsCriteria> {
322
323 static void to_json(json& jo, const SearchJob::RoomEventsCriteria &pod)
324 {
325 if (! jo.is_object()) { jo = json::object(); }
326
327
328 jo["search_term"s] = pod.searchTerm;
329
330
331 addToJsonIfNeeded(jo, "keys"s, pod.keys);
332
333 addToJsonIfNeeded(jo, "filter"s, pod.filter);
334
335 addToJsonIfNeeded(jo, "order_by"s, pod.orderBy);
336
337 addToJsonIfNeeded(jo, "event_context"s, pod.eventContext);
338
339 addToJsonIfNeeded(jo, "include_state"s, pod.includeState);
340
341 addToJsonIfNeeded(jo, "groupings"s, pod.groupings);
342 }
343
344 static void from_json(const json &jo, SearchJob::RoomEventsCriteria& result)
345 {
346
347 if (jo.contains("search_term"s)) {
348 result.searchTerm = jo.at("search_term"s);
349 }
350 if (jo.contains("keys"s)) {
351 result.keys = jo.at("keys"s);
352 }
353 if (jo.contains("filter"s)) {
354 result.filter = jo.at("filter"s);
355 }
356 if (jo.contains("order_by"s)) {
357 result.orderBy = jo.at("order_by"s);
358 }
359 if (jo.contains("event_context"s)) {
360 result.eventContext = jo.at("event_context"s);
361 }
362 if (jo.contains("include_state"s)) {
363 result.includeState = jo.at("include_state"s);
364 }
365 if (jo.contains("groupings"s)) {
366 result.groupings = jo.at("groupings"s);
367 }
368
369 }
370
371};
372 template<>
373 struct adl_serializer<SearchJob::Categories> {
374
375 static void to_json(json& jo, const SearchJob::Categories &pod)
376 {
377 if (! jo.is_object()) { jo = json::object(); }
378
379
380
381 addToJsonIfNeeded(jo, "room_events"s, pod.roomEvents);
382 }
383
384 static void from_json(const json &jo, SearchJob::Categories& result)
385 {
386
387 if (jo.contains("room_events"s)) {
388 result.roomEvents = jo.at("room_events"s);
389 }
390
391 }
392
393};
394 template<>
395 struct adl_serializer<SearchJob::UserProfile> {
396
397 static void to_json(json& jo, const SearchJob::UserProfile &pod)
398 {
399 if (! jo.is_object()) { jo = json::object(); }
400
401
402
403 addToJsonIfNeeded(jo, "displayname"s, pod.displayname);
404
405 addToJsonIfNeeded(jo, "avatar_url"s, pod.avatarUrl);
406 }
407
408 static void from_json(const json &jo, SearchJob::UserProfile& result)
409 {
410
411 if (jo.contains("displayname"s)) {
412 result.displayname = jo.at("displayname"s);
413 }
414 if (jo.contains("avatar_url"s)) {
415 result.avatarUrl = jo.at("avatar_url"s);
416 }
417
418 }
419
420};
421 template<>
422 struct adl_serializer<SearchJob::EventContext> {
423
424 static void to_json(json& jo, const SearchJob::EventContext &pod)
425 {
426 if (! jo.is_object()) { jo = json::object(); }
427
428
429
430 addToJsonIfNeeded(jo, "start"s, pod.start);
431
432 addToJsonIfNeeded(jo, "end"s, pod.end);
433
434 addToJsonIfNeeded(jo, "profile_info"s, pod.profileInfo);
435
436 addToJsonIfNeeded(jo, "events_before"s, pod.eventsBefore);
437
438 addToJsonIfNeeded(jo, "events_after"s, pod.eventsAfter);
439 }
440
441 static void from_json(const json &jo, SearchJob::EventContext& result)
442 {
443
444 if (jo.contains("start"s)) {
445 result.start = jo.at("start"s);
446 }
447 if (jo.contains("end"s)) {
448 result.end = jo.at("end"s);
449 }
450 if (jo.contains("profile_info"s)) {
451 result.profileInfo = jo.at("profile_info"s);
452 }
453 if (jo.contains("events_before"s)) {
454 result.eventsBefore = jo.at("events_before"s);
455 }
456 if (jo.contains("events_after"s)) {
457 result.eventsAfter = jo.at("events_after"s);
458 }
459
460 }
461
462};
463 template<>
464 struct adl_serializer<SearchJob::Result> {
465
466 static void to_json(json& jo, const SearchJob::Result &pod)
467 {
468 if (! jo.is_object()) { jo = json::object(); }
469
470
471
472 addToJsonIfNeeded(jo, "rank"s, pod.rank);
473
474 addToJsonIfNeeded(jo, "result"s, pod.result);
475
476 addToJsonIfNeeded(jo, "context"s, pod.context);
477 }
478
479 static void from_json(const json &jo, SearchJob::Result& result)
480 {
481
482 if (jo.contains("rank"s)) {
483 result.rank = jo.at("rank"s);
484 }
485 if (jo.contains("result"s)) {
486 result.result = jo.at("result"s);
487 }
488 if (jo.contains("context"s)) {
489 result.context = jo.at("context"s);
490 }
491
492 }
493
494};
495 template<>
496 struct adl_serializer<SearchJob::GroupValue> {
497
498 static void to_json(json& jo, const SearchJob::GroupValue &pod)
499 {
500 if (! jo.is_object()) { jo = json::object(); }
501
502
503
504 addToJsonIfNeeded(jo, "next_batch"s, pod.nextBatch);
505
506 addToJsonIfNeeded(jo, "order"s, pod.order);
507
508 addToJsonIfNeeded(jo, "results"s, pod.results);
509 }
510
511 static void from_json(const json &jo, SearchJob::GroupValue& result)
512 {
513
514 if (jo.contains("next_batch"s)) {
515 result.nextBatch = jo.at("next_batch"s);
516 }
517 if (jo.contains("order"s)) {
518 result.order = jo.at("order"s);
519 }
520 if (jo.contains("results"s)) {
521 result.results = jo.at("results"s);
522 }
523
524 }
525
526};
527 template<>
528 struct adl_serializer<SearchJob::ResultRoomEvents> {
529
530 static void to_json(json& jo, const SearchJob::ResultRoomEvents &pod)
531 {
532 if (! jo.is_object()) { jo = json::object(); }
533
534
535
536 addToJsonIfNeeded(jo, "count"s, pod.count);
537
538 addToJsonIfNeeded(jo, "highlights"s, pod.highlights);
539
540 addToJsonIfNeeded(jo, "results"s, pod.results);
541
542 addToJsonIfNeeded(jo, "state"s, pod.state);
543
544 addToJsonIfNeeded(jo, "groups"s, pod.groups);
545
546 addToJsonIfNeeded(jo, "next_batch"s, pod.nextBatch);
547 }
548
549 static void from_json(const json &jo, SearchJob::ResultRoomEvents& result)
550 {
551
552 if (jo.contains("count"s)) {
553 result.count = jo.at("count"s);
554 }
555 if (jo.contains("highlights"s)) {
556 result.highlights = jo.at("highlights"s);
557 }
558 if (jo.contains("results"s)) {
559 result.results = jo.at("results"s);
560 }
561 if (jo.contains("state"s)) {
562 result.state = jo.at("state"s);
563 }
564 if (jo.contains("groups"s)) {
565 result.groups = jo.at("groups"s);
566 }
567 if (jo.contains("next_batch"s)) {
568 result.nextBatch = jo.at("next_batch"s);
569 }
570
571 }
572
573};
574 template<>
575 struct adl_serializer<SearchJob::ResultCategories> {
576
577 static void to_json(json& jo, const SearchJob::ResultCategories &pod)
578 {
579 if (! jo.is_object()) { jo = json::object(); }
580
581
582
583 addToJsonIfNeeded(jo, "room_events"s, pod.roomEvents);
584 }
585
586 static void from_json(const json &jo, SearchJob::ResultCategories& result)
587 {
588
589 if (jo.contains("room_events"s)) {
590 result.roomEvents = jo.at("room_events"s);
591 }
592
593 }
594
595};
596 }
597
598 namespace Kazv::Api
599 {
600
601} // namespace Kazv::Api
Definition search.hpp:187
bool success() const
Definition search.cpp:77
ResultCategories searchCategories() const
Describes which categories to search in and their criteria.
Definition search.cpp:88
Perform a server-side search.
Definition search.hpp:16
SearchJob withData(JsonWrap j) &&
Definition search.cpp:60
static constexpr auto needsAuth()
Definition search.hpp:202
static BaseJob::Query buildQuery(std::optional< std::string > nextBatch)
Definition search.cpp:13
static BaseJob::Body buildBody(Categories searchCategories, std::optional< std::string > nextBatch)
Definition search.cpp:22
Definition basejob.hpp:94
Definition basejob.hpp:68
::Kazv::Body Body
Definition basejob.hpp:103
Definition jsonwrap.hpp:23
Definition location.hpp:10
Definition location.hpp:10
void addToJsonIfNeeded(json &j, std::string name, T &&arg)
Definition types.hpp:80
nlohmann::json json
Definition jsonwrap.hpp:20
immer::flex_vector< Event > EventList
Definition types.hpp:107
Definition location.hpp:27
Definition room_event_filter.hpp:13
Describes which categories to search in and their criteria.
Definition search.hpp:81
std::optional< RoomEventsCriteria > roomEvents
Mapping of category name to search criteria.
Definition search.hpp:83
Context for result, if requested.
Definition search.hpp:99
EventList eventsBefore
Events just before the result.
Definition search.hpp:111
immer::map< std::string, UserProfile > profileInfo
The historic profile information of the users that sent the events returned.
Definition search.hpp:109
std::optional< std::string > start
Pagination token for the start of the chunk.
Definition search.hpp:101
std::optional< std::string > end
Pagination token for the end of the chunk.
Definition search.hpp:103
EventList eventsAfter
Events just after the result.
Definition search.hpp:113
The results for a particular group value.
Definition search.hpp:131
std::optional< int > order
Key that can be used to order different groups.
Definition search.hpp:140
std::optional< std::string > nextBatch
Token that can be used to get the next batch of results in the group, by passing as the next_batch pa...
Definition search.hpp:137
immer::array< std::string > results
Which results are in this group.
Definition search.hpp:142
Configuration for group.
Definition search.hpp:40
std::optional< std::string > key
Key that defines the group.
Definition search.hpp:42
Requests that the server partitions the result set based on the provided list of keys.
Definition search.hpp:49
immer::array< Group > groupBy
List of groups to request.
Definition search.hpp:51
Configures whether any context for the events returned are included in the response.
Definition search.hpp:23
std::optional< int > beforeLimit
How many events before the result are returned.
Definition search.hpp:26
std::optional< int > afterLimit
How many events after the result are returned.
Definition search.hpp:29
std::optional< bool > includeProfile
Requests that the server returns the historic profile information for the users that sent the events ...
Definition search.hpp:34
Describes which categories to search in and their criteria.
Definition search.hpp:178
std::optional< ResultRoomEvents > roomEvents
Mapping of category name to search criteria.
Definition search.hpp:180
Mapping of category name to search criteria.
Definition search.hpp:148
std::optional< std::string > nextBatch
Token that can be used to get the next batch of results, by passing as the next_batch parameter to th...
Definition search.hpp:172
immer::map< std::string, immer::map< std::string, GroupValue > > groups
Any groups that were requested.
Definition search.hpp:167
immer::array< Result > results
List of results in the requested order.
Definition search.hpp:154
std::optional< int > count
An approximate count of the total number of results found.
Definition search.hpp:150
immer::map< std::string, EventList > state
The current state for every room in the results.
Definition search.hpp:161
immer::array< std::string > highlights
List of words which should be highlighted, useful for stemming which may change the query terms.
Definition search.hpp:152
The result object.
Definition search.hpp:119
JsonWrap result
The event that matched.
Definition search.hpp:123
std::optional< double > rank
A number that describes how closely this result matches the search. Higher is closer.
Definition search.hpp:121
std::optional< EventContext > context
Context for result, if requested.
Definition search.hpp:125
Mapping of category name to search criteria.
Definition search.hpp:57
std::optional< bool > includeState
Requests the server return the current state for each room returned.
Definition search.hpp:72
std::string searchTerm
The string to search events for.
Definition search.hpp:59
RoomEventFilter filter
This takes a filter.
Definition search.hpp:63
std::optional< std::string > orderBy
The order in which to search for results.
Definition search.hpp:66
std::optional< Groupings > groupings
Requests that the server partitions the result set based on the provided list of keys.
Definition search.hpp:75
immer::array< std::string > keys
The keys to search. Defaults to all.
Definition search.hpp:61
std::optional< IncludeEventContext > eventContext
Configures whether any context for the events returned are included in the response.
Definition search.hpp:69
Performs a full text search across different categories.
Definition search.hpp:89
std::optional< std::string > displayname
Performs a full text search across different categories.
Definition search.hpp:91
std::optional< std::string > avatarUrl
Performs a full text search across different categories.
Definition search.hpp:93
Definition basejob.hpp:49
static void from_json(const json &jo, SearchJob::Categories &result)
Definition search.hpp:384
static void to_json(json &jo, const SearchJob::Categories &pod)
Definition search.hpp:375
static void to_json(json &jo, const SearchJob::EventContext &pod)
Definition search.hpp:424
static void from_json(const json &jo, SearchJob::EventContext &result)
Definition search.hpp:441
static void from_json(const json &jo, SearchJob::GroupValue &result)
Definition search.hpp:511
static void to_json(json &jo, const SearchJob::GroupValue &pod)
Definition search.hpp:498
static void from_json(const json &jo, SearchJob::Group &result)
Definition search.hpp:288
static void to_json(json &jo, const SearchJob::Group &pod)
Definition search.hpp:279
static void to_json(json &jo, const SearchJob::Groupings &pod)
Definition search.hpp:301
static void from_json(const json &jo, SearchJob::Groupings &result)
Definition search.hpp:310
static void to_json(json &jo, const SearchJob::IncludeEventContext &pod)
Definition search.hpp:247
static void from_json(const json &jo, SearchJob::IncludeEventContext &result)
Definition search.hpp:260
static void to_json(json &jo, const SearchJob::ResultCategories &pod)
Definition search.hpp:577
static void from_json(const json &jo, SearchJob::ResultCategories &result)
Definition search.hpp:586
static void to_json(json &jo, const SearchJob::ResultRoomEvents &pod)
Definition search.hpp:530
static void from_json(const json &jo, SearchJob::ResultRoomEvents &result)
Definition search.hpp:549
static void from_json(const json &jo, SearchJob::Result &result)
Definition search.hpp:479
static void to_json(json &jo, const SearchJob::Result &pod)
Definition search.hpp:466
static void from_json(const json &jo, SearchJob::RoomEventsCriteria &result)
Definition search.hpp:344
static void to_json(json &jo, const SearchJob::RoomEventsCriteria &pod)
Definition search.hpp:323
static void from_json(const json &jo, SearchJob::UserProfile &result)
Definition search.hpp:408
static void to_json(json &jo, const SearchJob::UserProfile &pod)
Definition search.hpp:397