| 1 | /****************************************************************************** |
| 2 | * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN |
| 3 | */ |
| 4 | |
| 5 | #pragma once |
| 6 | |
| 7 | #include <Quotient/csapi/definitions/room_event_filter.h> |
| 8 | |
| 9 | #include <Quotient/events/roomevent.h> |
| 10 | #include <Quotient/events/stateevent.h> |
| 11 | #include <Quotient/jobs/basejob.h> |
| 12 | |
| 13 | namespace Quotient { |
| 14 | |
| 15 | /*! \brief Perform a server-side search. |
| 16 | * |
| 17 | * Performs a full text search across different categories. |
| 18 | */ |
| 19 | class QUOTIENT_API SearchJob : public BaseJob { |
| 20 | public: |
| 21 | // Inner data structures |
| 22 | |
| 23 | /// Configures whether any context for the events |
| 24 | /// returned are included in the response. |
| 25 | struct IncludeEventContext { |
| 26 | /// How many events before the result are |
| 27 | /// returned. By default, this is `5`. |
| 28 | Omittable<int> beforeLimit{}; |
| 29 | /// How many events after the result are |
| 30 | /// returned. By default, this is `5`. |
| 31 | Omittable<int> afterLimit{}; |
| 32 | /// Requests that the server returns the |
| 33 | /// historic profile information for the users |
| 34 | /// that sent the events that were returned. |
| 35 | /// By default, this is `false`. |
| 36 | Omittable<bool> includeProfile{}; |
| 37 | }; |
| 38 | |
| 39 | /// Configuration for group. |
| 40 | struct Group { |
| 41 | /// Key that defines the group. |
| 42 | QString key{}; |
| 43 | }; |
| 44 | |
| 45 | /// Requests that the server partitions the result set |
| 46 | /// based on the provided list of keys. |
| 47 | struct Groupings { |
| 48 | /// List of groups to request. |
| 49 | QVector<Group> groupBy{}; |
| 50 | }; |
| 51 | |
| 52 | /// Mapping of category name to search criteria. |
| 53 | struct RoomEventsCriteria { |
| 54 | /// The string to search events for |
| 55 | QString searchTerm; |
| 56 | /// The keys to search. Defaults to all. |
| 57 | QStringList keys{}; |
| 58 | /// This takes a [filter](/client-server-api/#filtering). |
| 59 | RoomEventFilter filter{}; |
| 60 | /// The order in which to search for results. |
| 61 | /// By default, this is `"rank"`. |
| 62 | QString orderBy{}; |
| 63 | /// Configures whether any context for the events |
| 64 | /// returned are included in the response. |
| 65 | Omittable<IncludeEventContext> eventContext{}; |
| 66 | /// Requests the server return the current state for |
| 67 | /// each room returned. |
| 68 | Omittable<bool> includeState{}; |
| 69 | /// Requests that the server partitions the result set |
| 70 | /// based on the provided list of keys. |
| 71 | Omittable<Groupings> groupings{}; |
| 72 | }; |
| 73 | |
| 74 | /// Describes which categories to search in and their criteria. |
| 75 | struct Categories { |
| 76 | /// Mapping of category name to search criteria. |
| 77 | Omittable<RoomEventsCriteria> roomEvents{}; |
| 78 | }; |
| 79 | |
| 80 | /// Performs a full text search across different categories. |
| 81 | struct UserProfile { |
| 82 | /// Performs a full text search across different categories. |
| 83 | QString displayname{}; |
| 84 | /// Performs a full text search across different categories. |
| 85 | QUrl avatarUrl{}; |
| 86 | }; |
| 87 | |
| 88 | /// Context for result, if requested. |
| 89 | struct EventContext { |
| 90 | /// Pagination token for the start of the chunk |
| 91 | QString begin{}; |
| 92 | /// Pagination token for the end of the chunk |
| 93 | QString end{}; |
| 94 | /// The historic profile information of the |
| 95 | /// users that sent the events returned. |
| 96 | /// |
| 97 | /// The `string` key is the user ID for which |
| 98 | /// the profile belongs to. |
| 99 | QHash<QString, UserProfile> profileInfo{}; |
| 100 | /// Events just before the result. |
| 101 | RoomEvents eventsBefore{}; |
| 102 | /// Events just after the result. |
| 103 | RoomEvents eventsAfter{}; |
| 104 | }; |
| 105 | |
| 106 | /// The result object. |
| 107 | struct Result { |
| 108 | /// A number that describes how closely this result matches the search. |
| 109 | /// Higher is closer. |
| 110 | Omittable<double> rank{}; |
| 111 | /// The event that matched. |
| 112 | RoomEventPtr result{}; |
| 113 | /// Context for result, if requested. |
| 114 | Omittable<EventContext> context{}; |
| 115 | }; |
| 116 | |
| 117 | /// The results for a particular group value. |
| 118 | struct GroupValue { |
| 119 | /// Token that can be used to get the next batch |
| 120 | /// of results in the group, by passing as the |
| 121 | /// `next_batch` parameter to the next call. If |
| 122 | /// this field is absent, there are no more |
| 123 | /// results in this group. |
| 124 | QString nextBatch{}; |
| 125 | /// Key that can be used to order different |
| 126 | /// groups. |
| 127 | Omittable<int> order{}; |
| 128 | /// Which results are in this group. |
| 129 | QStringList results{}; |
| 130 | }; |
| 131 | |
| 132 | /// Mapping of category name to search criteria. |
| 133 | struct ResultRoomEvents { |
| 134 | /// An approximate count of the total number of results found. |
| 135 | Omittable<int> count{}; |
| 136 | /// List of words which should be highlighted, useful for stemming which |
| 137 | /// may change the query terms. |
| 138 | QStringList highlights{}; |
| 139 | /// List of results in the requested order. |
| 140 | std::vector<Result> results{}; |
| 141 | /// The current state for every room in the results. |
| 142 | /// This is included if the request had the |
| 143 | /// `include_state` key set with a value of `true`. |
| 144 | /// |
| 145 | /// The `string` key is the room ID for which the `State |
| 146 | /// Event` array belongs to. |
| 147 | UnorderedMap<QString, StateEvents> state{}; |
| 148 | /// Any groups that were requested. |
| 149 | /// |
| 150 | /// The outer `string` key is the group key requested (eg: `room_id` |
| 151 | /// or `sender`). The inner `string` key is the grouped value (eg: |
| 152 | /// a room's ID or a user's ID). |
| 153 | QHash<QString, QHash<QString, GroupValue>> groups{}; |
| 154 | /// Token that can be used to get the next batch of |
| 155 | /// results, by passing as the `next_batch` parameter to |
| 156 | /// the next call. If this field is absent, there are no |
| 157 | /// more results. |
| 158 | QString nextBatch{}; |
| 159 | }; |
| 160 | |
| 161 | /// Describes which categories to search in and their criteria. |
| 162 | struct ResultCategories { |
| 163 | /// Mapping of category name to search criteria. |
| 164 | Omittable<ResultRoomEvents> roomEvents{}; |
| 165 | }; |
| 166 | |
| 167 | // Construction/destruction |
| 168 | |
| 169 | /*! \brief Perform a server-side search. |
| 170 | * |
| 171 | * \param searchCategories |
| 172 | * Describes which categories to search in and their criteria. |
| 173 | * |
| 174 | * \param nextBatch |
| 175 | * The point to return events from. If given, this should be a |
| 176 | * `next_batch` result from a previous call to this endpoint. |
| 177 | */ |
| 178 | explicit SearchJob(const Categories& searchCategories, |
| 179 | const QString& nextBatch = {}); |
| 180 | |
| 181 | // Result properties |
| 182 | |
| 183 | /// Describes which categories to search in and their criteria. |
| 184 | ResultCategories searchCategories() const |
| 185 | { |
| 186 | return loadFromJson<ResultCategories>(keyName: "search_categories"_ls ); |
| 187 | } |
| 188 | }; |
| 189 | |
| 190 | template <> |
| 191 | struct JsonObjectConverter<SearchJob::IncludeEventContext> { |
| 192 | static void dumpTo(QJsonObject& jo, |
| 193 | const SearchJob::IncludeEventContext& pod) |
| 194 | { |
| 195 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("before_limit" ), |
| 196 | value: pod.beforeLimit); |
| 197 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("after_limit" ), value: pod.afterLimit); |
| 198 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("include_profile" ), |
| 199 | value: pod.includeProfile); |
| 200 | } |
| 201 | }; |
| 202 | |
| 203 | template <> |
| 204 | struct JsonObjectConverter<SearchJob::Group> { |
| 205 | static void dumpTo(QJsonObject& jo, const SearchJob::Group& pod) |
| 206 | { |
| 207 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("key" ), value: pod.key); |
| 208 | } |
| 209 | }; |
| 210 | |
| 211 | template <> |
| 212 | struct JsonObjectConverter<SearchJob::Groupings> { |
| 213 | static void dumpTo(QJsonObject& jo, const SearchJob::Groupings& pod) |
| 214 | { |
| 215 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("group_by" ), value: pod.groupBy); |
| 216 | } |
| 217 | }; |
| 218 | |
| 219 | template <> |
| 220 | struct JsonObjectConverter<SearchJob::RoomEventsCriteria> { |
| 221 | static void dumpTo(QJsonObject& jo, const SearchJob::RoomEventsCriteria& pod) |
| 222 | { |
| 223 | addParam<>(container&: jo, QStringLiteral("search_term" ), value: pod.searchTerm); |
| 224 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("keys" ), value: pod.keys); |
| 225 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("filter" ), value: pod.filter); |
| 226 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("order_by" ), value: pod.orderBy); |
| 227 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("event_context" ), |
| 228 | value: pod.eventContext); |
| 229 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("include_state" ), |
| 230 | value: pod.includeState); |
| 231 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("groupings" ), value: pod.groupings); |
| 232 | } |
| 233 | }; |
| 234 | |
| 235 | template <> |
| 236 | struct JsonObjectConverter<SearchJob::Categories> { |
| 237 | static void dumpTo(QJsonObject& jo, const SearchJob::Categories& pod) |
| 238 | { |
| 239 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("room_events" ), value: pod.roomEvents); |
| 240 | } |
| 241 | }; |
| 242 | |
| 243 | template <> |
| 244 | struct JsonObjectConverter<SearchJob::UserProfile> { |
| 245 | static void fillFrom(const QJsonObject& jo, SearchJob::UserProfile& result) |
| 246 | { |
| 247 | fillFromJson(jv: jo.value(key: "displayname"_ls ), pod&: result.displayname); |
| 248 | fillFromJson(jv: jo.value(key: "avatar_url"_ls ), pod&: result.avatarUrl); |
| 249 | } |
| 250 | }; |
| 251 | |
| 252 | template <> |
| 253 | struct JsonObjectConverter<SearchJob::EventContext> { |
| 254 | static void fillFrom(const QJsonObject& jo, SearchJob::EventContext& result) |
| 255 | { |
| 256 | fillFromJson(jv: jo.value(key: "start"_ls ), pod&: result.begin); |
| 257 | fillFromJson(jv: jo.value(key: "end"_ls ), pod&: result.end); |
| 258 | fillFromJson(jv: jo.value(key: "profile_info"_ls ), pod&: result.profileInfo); |
| 259 | fillFromJson(jv: jo.value(key: "events_before"_ls ), pod&: result.eventsBefore); |
| 260 | fillFromJson(jv: jo.value(key: "events_after"_ls ), pod&: result.eventsAfter); |
| 261 | } |
| 262 | }; |
| 263 | |
| 264 | template <> |
| 265 | struct JsonObjectConverter<SearchJob::Result> { |
| 266 | static void fillFrom(const QJsonObject& jo, SearchJob::Result& result) |
| 267 | { |
| 268 | fillFromJson(jv: jo.value(key: "rank"_ls ), pod&: result.rank); |
| 269 | fillFromJson(jv: jo.value(key: "result"_ls ), pod&: result.result); |
| 270 | fillFromJson(jv: jo.value(key: "context"_ls ), pod&: result.context); |
| 271 | } |
| 272 | }; |
| 273 | |
| 274 | template <> |
| 275 | struct JsonObjectConverter<SearchJob::GroupValue> { |
| 276 | static void fillFrom(const QJsonObject& jo, SearchJob::GroupValue& result) |
| 277 | { |
| 278 | fillFromJson(jv: jo.value(key: "next_batch"_ls ), pod&: result.nextBatch); |
| 279 | fillFromJson(jv: jo.value(key: "order"_ls ), pod&: result.order); |
| 280 | fillFromJson(jv: jo.value(key: "results"_ls ), pod&: result.results); |
| 281 | } |
| 282 | }; |
| 283 | |
| 284 | template <> |
| 285 | struct JsonObjectConverter<SearchJob::ResultRoomEvents> { |
| 286 | static void fillFrom(const QJsonObject& jo, |
| 287 | SearchJob::ResultRoomEvents& result) |
| 288 | { |
| 289 | fillFromJson(jv: jo.value(key: "count"_ls ), pod&: result.count); |
| 290 | fillFromJson(jv: jo.value(key: "highlights"_ls ), pod&: result.highlights); |
| 291 | fillFromJson(jv: jo.value(key: "results"_ls ), pod&: result.results); |
| 292 | fillFromJson(jv: jo.value(key: "state"_ls ), pod&: result.state); |
| 293 | fillFromJson(jv: jo.value(key: "groups"_ls ), pod&: result.groups); |
| 294 | fillFromJson(jv: jo.value(key: "next_batch"_ls ), pod&: result.nextBatch); |
| 295 | } |
| 296 | }; |
| 297 | |
| 298 | template <> |
| 299 | struct JsonObjectConverter<SearchJob::ResultCategories> { |
| 300 | static void fillFrom(const QJsonObject& jo, |
| 301 | SearchJob::ResultCategories& result) |
| 302 | { |
| 303 | fillFromJson(jv: jo.value(key: "room_events"_ls ), pod&: result.roomEvents); |
| 304 | } |
| 305 | }; |
| 306 | |
| 307 | } // namespace Quotient |
| 308 | |