文档负载

Payload support (deprecated) (已弃用)

警告:
payload 功能在 2.0 中已弃用

通常,Redis Stack 将文档存储为哈希或 JSON。但是,如果您想访问一些数据以进行聚合或评分功能,Redis 可以将该数据存储为内联有效负载。这将使我们能够以非常低的成本评估文档的属性以进行评分。

由于评分函数已经可以访问包含文档标志和分数的 DocumentMetaData,因此 Redis 可以添加可在运行时评估的自定义有效负载。

有效负载不会编制索引,引擎也不会以任何方式处理这些负载。它们只是为了在查询时评估它们,并选择性地检索它们。它们可以是 JSON 对象、字符串,或者如果您对快速评估感兴趣,最好是某种可以快速解码的二进制编码数据。

在查询时评估有效负载

在实现评分函数时,公开的函数的签名为:

double (*ScoringFunction)(DocumentMetadata *dmd, IndexResult *h);
Note:
Currently, scoring functions cannot be dynamically added, and forking the engine and replacing them is required.

DocumentMetaData includes a few fields, one of them being the payload. It wraps a simple byte array with arbitrary length:

typedef struct  {
    char *data,
    uint32_t len;
} DocumentPayload;

If no payload was set to the document, it is simply NULL. If it is not, you can go ahead and decode it. It is recommended to encode some metadata about the payload inside it, like a leading version number, etc.

Retrieving payloads from documents

When searching, it is possible to request the document payloads from the engine.

This is done by adding the keyword WITHPAYLOADS to FT.SEARCH.

If WITHPAYLOADS is set, the payloads follow the document id in the returned result. If WITHSCORES is set as well, the payloads follow the scores.

RATE THIS PAGE
Back to top ↑