diff options
| author | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2026-01-02 01:37:06 +0900 |
|---|---|---|
| committer | Yasuhiro Matsumoto <mattn.jp@gmail.com> | 2026-01-02 01:37:06 +0900 |
| commit | e943ab847ae25341eff688ef47812f8003c3043e (patch) | |
| tree | 7de36bef3716edc17648fecc40240fec9db7e634 | |
| parent | fa9281af8b7c964542dd1145ba61a9fd851af713 (diff) | |
add NIP-50 query extensionnip50-query
| -rw-r--r-- | 50.md | 43 |
1 files changed, 41 insertions, 2 deletions
| @@ -26,11 +26,50 @@ Relays SHOULD interpret the query to the best of their ability and return events | |||
| 26 | Relays SHOULD perform matching against `content` event field, and MAY perform | 26 | Relays SHOULD perform matching against `content` event field, and MAY perform |
| 27 | matching against other fields if that makes sense in the context of a specific kind. | 27 | matching against other fields if that makes sense in the context of a specific kind. |
| 28 | 28 | ||
| 29 | Results SHOULD be returned in descending order by quality of search result (as defined by the implementation), | ||
| 30 | not by the usual `.created_at`. The `limit` filter SHOULD be applied after sorting by matching score. | ||
| 31 | A query string may contain `key:value` pairs (two words separated by colon), these are extensions, relays SHOULD ignore | 29 | A query string may contain `key:value` pairs (two words separated by colon), these are extensions, relays SHOULD ignore |
| 32 | extensions they don't support. | 30 | extensions they don't support. |
| 33 | 31 | ||
| 32 | ### Query Expression Extensions | ||
| 33 | |||
| 34 | Relays MAY support query expressions with boolean operators and filter attributes. When supported, this MUST be advertised in NIP-11: | ||
| 35 | |||
| 36 | ```json | ||
| 37 | { | ||
| 38 | "supported_nips": [50], | ||
| 39 | "nip50_search": { | ||
| 40 | "boolean_operators": true, | ||
| 41 | "filter_attributes": ["limit", "since", "until"] | ||
| 42 | } | ||
| 43 | } | ||
| 44 | ``` | ||
| 45 | |||
| 46 | When `boolean_operators` is `true`, relays SHOULD support: | ||
| 47 | |||
| 48 | - Terms split by whitespace (implicit AND) | ||
| 49 | - Double quotes for phrase matching: `"hello world"` | ||
| 50 | - Boolean operators: `AND`, `OR` (uppercase, case-sensitive) | ||
| 51 | - Parentheses for grouping: `(cat AND dog) OR bird` | ||
| 52 | - Operator precedence: `AND` binds tighter than `OR` | ||
| 53 | |||
| 54 | Examples: | ||
| 55 | - `hello world` → both terms required (implicit AND) | ||
| 56 | - `hello OR world` → either term matches | ||
| 57 | - `cat AND (dog OR bird)` → "cat" plus either "dog" or "bird" | ||
| 58 | |||
| 59 | When `filter_attributes` is present, relays SHOULD support filter attributes in the query string: | ||
| 60 | |||
| 61 | - `limit:<number>` - limit number of results (e.g., `limit:50`) | ||
| 62 | - `since:<unix timestamp>` - filter events after timestamp (e.g., `since:1609459200`) | ||
| 63 | - `until:<unix timestamp>` - filter events before timestamp (e.g., `until:1640995200`) | ||
| 64 | |||
| 65 | Examples: | ||
| 66 | - `nostr limit:50` → search "nostr" and return up to 50 results | ||
| 67 | - `bitcoin since:1609459200` → search "bitcoin" for events after the specified time | ||
| 68 | - `cats OR dogs limit:100 since:1640995200` → combined query with filters | ||
| 69 | |||
| 70 | Results SHOULD be returned in descending order by quality of search result (as defined by the implementation), | ||
| 71 | not by the usual `.created_at`. The `limit` filter SHOULD be applied after sorting by matching score. | ||
| 72 | |||
| 34 | Clients may specify several search filters, i.e. `["REQ", "", { "search": "orange" }, { "kinds": [1, 2], "search": "purple" }]`. Clients may | 73 | Clients may specify several search filters, i.e. `["REQ", "", { "search": "orange" }, { "kinds": [1, 2], "search": "purple" }]`. Clients may |
| 35 | include `kinds`, `ids` and other filter field to restrict the search results to particular event kinds. | 74 | include `kinds`, `ids` and other filter field to restrict the search results to particular event kinds. |
| 36 | 75 | ||