# NIP50

## 搜索能力

`draft` `optional` `author:brugeman` `author:mikedilger` `author:fiatjaf`

## 抽象的

除了通过标签或 ID 进行结构化查询之外，许多 NOSTR 用例还需要某种形式的通用搜索功能。搜索算法的细节因事件类型而异，本 NIP 仅描述了用于执行此类查询的通用可扩展框架。

## `search` 筛选字段

为 `REQ` 来自客户端的消息引入了一个新 `search` 字段：

```json
{
  ...
  "search": <string>
}
```

`search` 字段是以人类可读的形式描述查询的字符串，即“最佳 NOSTR 应用程序”。中继应尽其所能解释查询，并返回与之匹配的事件。中继应针对 `content` 事件字段执行匹配，如果在特定类型的上下文中有意义，则可以针对其他字段执行匹配。

查询字符串可能包含 `key:value` 对（由冒号分隔的两个单词），这些是扩展，中继应该忽略它们不支持的扩展。

客户可以指定几个搜索过滤器，即 `["REQ", "", { "search": "orange"}, { "kinds": [1, 2], "search": "purple"}]` 客户端可以包括 `kinds` `ids` 和其他筛选字段，以将搜索结果限制为特定的事件类型。

客户端应使用支持的 \_NIPS 字段来了解中继是否支持 `search` 过滤器。如果客户端准备过滤掉来自不支持此 NIP 的中继的无关响应，则客户端可以向任何中继发送 `search` 过滤器查询。

客户端应查询支持此 NIP 的多个中继，以补偿中继之间可能不同的实现细节。

客户端可以以适合客户端的使用情形的方式验证中继返回的事件是否与指定的查询匹配，并且可以停止查询具有低精度的中继。

如果中继支持某种形式的垃圾邮件过滤，则默认情况下应从搜索结果中排除垃圾邮件。

## 扩展

Relay 可能支持以下扩展：

* `include:spam` -关闭垃圾邮件过滤（如果默认情况下已启用）


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sherry-pang.gitbook.io/nostr-cn/fu-lu-1-nip-xiang-jie/50.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
