:orphan: .. role:: json(code) :language: json .. role:: python(code) :language: python Streams API =========== .. contents:: :depth: 3 Skeleton ######## Examples -------- .. code:: xml .. code:: xml /> .. code:: xml /> .. code:: xml Attributes ---------- - ``stream.id`` - the stream configuration ID which is unique to the layouts - ``stream.bucket`` - the stream bucket reference - *family(family_id, arg1, arg2, arg3...)* -- references a particular bucket in a family - ``stream.use_pins`` - whether to use pins or not (default: ``false``) - ``stream.period.type`` -- the type of period to use for the stream - *window* -- a window of time - ``stream.period.size`` -- the size of the window in units - ``stream.period.unit_in_seconds`` -- the unit of time in seconds - *lifetime* -- the lifetime - ``posts.stream_id`` -- the stream configuration ID to use for the posts - ``posts.bucket`` -- the stream bucket reference to use for the posts (@see ``stream.bucket``) - ``posts.use_pins`` - whether to use pins or not (@see ``stream.use_pins``) Endpoints ######### Get Families ------------ .. code:: GET /core/v1/streams/families 200 OK ****** .. code:: json { "families": [ { "id": "648ab3c9522b443bd06774d1", "title": null, // or "Some interesting posts [v1.0]", "entity": , "status": , "filter": null, // or "scores": null // or } ] } Hints: - (see: :ref:`taxonomy-entities`) - (see: `Family Statuses`_) - (see: `Family Filter Configuration`_) - (see: `Family Scores Configuration`_) Create Family ------------- .. code:: POST /core/v1/streams/families .. code:: json { "entity": , "commands": [ , , ... ] } 200 OK ****** .. code:: json { "family": { "id": "648ab3c9522b443bd06774d1", "title": null, "entity": , "status": , "filter": null, // or "scores": null // or } } Hints: * (see: `Family Commands`_) * (see: :ref:`taxonomy-entities`) * (see: `Family Statuses`_) * (see: `Family Filter Configuration`_) * (see: `Family Scores Configuration`_) Update Family ------------- .. code:: PUT /core/v1/streams/families/648ab3c9522b443bd06774d1 .. code:: json { "commands": [ , , ... ] } 200 OK ****** .. code:: json { "family": { "id": "648ab3c9522b443bd06774d1", "title": null, // or "Some interesting posts [v1.0]", "entity": , "status": , "filter": null, // or "scores": null // or } } Hints: * (see: `Family Commands`_) * (see: :ref:`taxonomy-entities`) * (see: `Family Statuses`_) * (see: `Family Filter Configuration`_) * (see: `Family Scores Configuration`_) Reindex Family -------------- .. code:: POST /core/v1/streams/families/648ab3c9522b443bd06774d1/reindex?should_reset_cache=true .. code:: GET /core/v1/streams/families/648ab3c9522b443bd06774d1/reindex?task_id=38e9eea7-fc5b-4373-90f0-cb2d59109113 200 OK ****** .. code:: json { "task": { "id": "38e9eea7-fc5b-4373-90f0-cb2d59109113", "is_ready": true, "progress": null, // or same as "response" "response": { "entities": { "total_count": 12343, "indexed_count": 12343 } }, "exception": null } Delete Family ------------- .. code:: DELETE /core/v1/streams/families/648ab3c9522b443bd06774d1 200 OK ****** .. code:: json {} Find Stream Records ------------------- .. code:: GET /core/v1/streams/records?bucket=&limit=[&offset=[&cursor=[&mode=default|ignore-pins|ignore-pins-and-reverse-order]]] 200 OK ****** .. code:: json { "records": [ { "entity": , "cursor": // or `null` if the entity is pinned in this position }, ... ] } Hints: - (see: :ref:`taxonomy-entities`) - (e.g., `family(648ab40ba34e015fa57ee579, , $$any, $$none, $$empty, None)`) Count Stream Records -------------------- .. code:: GET /core/v1/streams/records/count?bucket= 200 OK ****** .. code:: json { "count": 592 } Hints: - (e.g., `family(648ab40ba34e015fa57ee579, , $$any, $$none, $$empty, None)`) Update Stream Records --------------------- .. code:: POST /core/v1/streams/records?bucket= 200 OK ****** .. code:: json { "commands": [ , , ... ] } Hints: - (e.g., `family(648ab40ba34e015fa57ee579, , $$any, $$none, $$empty, None)`) - (see: `Stream Commands`_) Families ######## .. image:: /_static/images/content/streams/family-concept.png :alt: Family of Streams .. _Family Statuses: Statuses -------- * ``{"paused": {}}`` -- the family is paused. Allows to configure the family and remove it * ``{"active": {}}`` -- the family is active. Allows entities to be routed by the family configuration into appropriate buckets in the required order .. _Family Commands: Commands -------- #. Configure family * Set Title :json:`{"set-title": "Some less interesting posts [v1.1]"}` * Set Filter :json:`{"set-filter": }` * Set Scores :json:`{"set-scores": }` #. Manage family status * Activate :json:`{"activate": {}}` * Pause :json:`{"pause": {}}}` Hints: * (see: `Family Filter Configuration`_) * (see: `Family Scores Configuration`_) .. _Family Filter Configuration: Filters ------- Taxonomy ******** .. code:: json {"taxonomy": { variables: [ , , ... ], filters: [ , , , ... ] }} Variables ~~~~~~~~~ .. code:: json { "alias": null, // or "some_alias", not implemented yet "scope": , "yields": [ "", "", ... ] } Yields: * :json:`"$any"` -- route the entity to buckets where this variable is ignored (e.g. `post.sections` not empty --> an `$any` bucket) * :json:`"$none"` -- route the entity to buckets where this variable is either not set or represent an empty lists (e.g. `post.sections` is empty --> a `$none` bucket) * :json:`"$each"` -- route the entity to buckets where this variable takes one of the values from the variable scope (e.g. `post.sections` --> N `section_id` buckets) Scopes: * :json:`{"post-authors": {}}` -- yields indexed post author IDs * :json:`{"post-primary-tags": {}}` -- yields indexed post primary tag slug * :json:`{"post-regular-tags": {}}` -- yields indexed post regular tag slugs * :json:`{"post-primary-sections": {}}` -- yields indexed post primary section ID * :json:`{"post-regular-sections": {}}` -- yields indexed post regular section IDs * :json:`{"post-custom-field-values": {"path": "path.to.field"}}` -- yields indexed post custom field values * :json:`{"site-sections": {"filters": [
,
, ...]}}` -- yields indexed post primary topic ID * :json:`{"manual": {"state": }}` -- yields manually added values States: * :json:`{"tags": {"slugs": [, , ...]}}` -- yields manually added tag slugs * :json:`{"sections": {"ids": [, , ...]}}` -- yields manually added section IDs * :json:`{"scalars": {"type": "str" | "int" | "float", "values": [, , ...]}}` -- yields manually added scalar values Filters ~~~~~~~ Variable filters allow to distribute entities into buckets based on the values of the variables. The following variable filters are supported: - Resolve variable reference to a set of taxonomy filters .. code:: json {"$switch": { "$ref": "$$1", // or "$some_alias" (not implemented yet), "$cases": { "$any": [ // an entity goes to this bucket no matter the variable value , ... ], "$none": [ // an entity goes to this bucket if the variable value is not set or is an empty list , ... ], "$each": [ // an entity goes to a bucket for each value the variable yields {"any_label": [ {"$return": {"value": { "field": , "value": "$$1" // or "$some_alias" (not implemented yet) }}}, , ... ]}, {"any_range": [ {"$return": { "field": , "min": "$$1[1]", // or "$some_alias[1]" (not implemented yet) "max": "$$1[2]" // or "$some_alias[2]" (not implemented yet) }}, , ... ]}, , ... ] } }} - Return a set of taxonomy filters without applying any variables .. code:: json {"$return": [ , , ... ]} Hints: - (e.g., `{"any_label": {"$return": [, ...]}}`) - (e.g., `{"$return": }`) - (e.g., `{"$return": }`) - (see: :ref:`taxonomy-filters`) - (see: :ref:`taxonomy-labels`) - (see: :ref:`taxonomy-ranges`) - (see: :ref:`taxonomy-entity-fields`) .. _Family Scores Configuration: Scores ------ Static ****** .. code:: json { "static": { "mode": , "field": , "scale": null // or a float number to scale the score taken from the entity field }} } Modes: - :json:`{"init": {}}` -- when an entity indexed for the first time calculate the value and never update it - :json:`{"track": {}}` -- when an entity indexed for the first time calculate the value and update it when the entity is updated - :json:`{"track-until-moved": {}}` -- when an entity indexed for the first time calculate the value and update it when the entity is updated. Stop tracking the score for a particular bucket as soon as the entity is manually moved in that bucket Incremental *********** .. code:: json { "incremental": { "period": , "weights": [ {"event": , "weight": } ] }} } Periods: - :json:`{"window": {"size": 7, "unit_in_seconds": 86400}}` -- a window of time, e.g. 7 days - :json:`{"lifetime": {}}` -- the lifetime Hints: - (see: :ref:`taxonomy-entity-fields`) - (see: :ref:`taxonomy-entity-events`) Streams ######## .. _Stream Commands: Commands -------- * Pin entity :json:`{"pin": {"entity": , "position": }}` * Unpin entity :json:`{"unpin": {"entity": }}` * Move entity to position :json:`{"move-to": {"entity": , "position": }}` * Move entity after another entity :json:`{"move-after": {"entity": , "other_entity": }}` Hints: - (see: :ref:`taxonomy-entities`) - -- a numeric rank in the stream starting with 0