upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/50.md
diff options
context:
space:
mode:
Diffstat (limited to '50.md')
-rw-r--r--50.md61
1 files changed, 28 insertions, 33 deletions
diff --git a/50.md b/50.md
index 0692fd1..230b8e0 100644
--- a/50.md
+++ b/50.md
@@ -1,54 +1,49 @@
1NIP-50 1NIP-50
2====== 2======
3 3
4Keywords Filter 4Keyword Search
5--------------- 5--------------
6 6
7`draft` `optional` `author:brugeman` `author:mikedilger` 7`draft` `optional` `author:brugeman` `author:mikedilger` `author:fiatjaf`
8 8
9## Abstract 9## Abstract
10 10
11Many Nostr use cases require some form of search by `content` field. The meaning and format of `content` differs 11Many Nostr use cases require some form of general search feature, in addition to structured queries by tags or ids.
12with event kind and use case. Thus, this NIP only establishes a general framework for search over `content`, 12Specifics of the search algorithms will differ between event kinds, this NIP only describes a general
13and specifies the details for kind `0` and kind `1` events. 13extensible framework for performing such queries.
14 14
15## `keywords` filter field 15## `search` filter field
16 16
17A new `keywords` field is introduced for `REQ` messages from clients: 17A new `search` field is introduced for `REQ` messages from clients:
18```json 18```json
19{ 19{
20 "kinds": <an array of kind numbers> 20 ...
21 "keywords": <an array of strings> 21 "search": <string>
22} 22}
23``` 23```
24A filter with `keywords` field MUST also include `kinds` field. This NIP specifies the behavior for kinds `0` and `1`, 24`search` field is a string describing a query in a human-readable form, i.e. "best nostr apps".
25if none of these kinds are provided along with `keywords`, relay SHOULD ignore the filter, and MAY send 25Relays SHOULD interpret the query to the best of their ability and return events that match it.
26a `NOTICE` to inform the client. Future NIPs will specify behavior for other event kinds. 26Relays SHOULD perform matching against `content` event field, and MAY perform
27matching against other fields if that makes sense in the context of a specific kind.
27 28
28A filter matches if one of the provided `keywords` matches. Each keyword string may contain several conditions - `words`, 29A query string may contain `key:value` pairs (two words separated by colon), these are extensions, relays SHOULD ignore
29all the words must match for a keyword to match. The meaning of `words` depends on event kind. 30extensions they don't support.
30 31
31Clients SHOULD use the supported_nips field to learn if a relay supports keyword filter queries. Clients MAY send keyword filter queries to any relay, if they are prepared to filter out extraneous responses from relays that do not support this NIP. 32Clients may specify several search filters, i.e. `["REQ", "", [{"search":"orange"},{"search":"purple"}]`. Clients may
33include `kinds`, `ids` and other filter field to restrict the search results to particular event kinds.
32 34
33Clients SHOULD query several relays supporting this NIP and specific kind to compensate for potentially different 35Clients SHOULD use the supported_nips field to learn if a relay supports `search` filter. Clients MAY send `search`
34implementation details between relays (like string sanitization, etc). 36filter queries to any relay, if they are prepared to filter out extraneous responses from relays that do not support this NIP.
35 37
36Clients SHOULD verify that events returned by a relay match the specified `keywords` in the way that suits the 38Clients SHOULD query several relays supporting this NIP to compensate for potentially different
37client's use case, and MAY stop querying relays that have low precision. 39implementation details between relays.
38
39## Keyword search for kind `0` and kind `1`
40
41For kind `0` and kind `1`, each keyword is a lowercase string consisting of words separated by spaces (in most languages), punctuation/control
42characters are ignored.
43 40
44For kind `1`, an event must include all words in it's `content` field for it to match the keyword. 41Clients MAY verify that events returned by a relay match the specified query in a way that suits the
45 42client's use case, and MAY stop querying relays that have low precision.
46For kind `0`, an event must include all mentioned words in the json object stored at the `content` field. Recommended
47json fields for matching are `about`, `display_name`, `name`, `nip05`, `lud06` and `lud16`.
48 43
49A keyword may contain a word starting with prefix `option:` (like `option:no_spam`), such words specify additional 44Relays SHOULD exclude spam from search results by default if they supports some form of spam filtering.
50constraints for event matching, and are reserved for the future extensions. Relay SHOULD ignore `option:` words that it does not support.
51 45
52Relay MAY support these options for kind `0` and kind `1` events: 46## Extensions
53- `option:no_spam` - only include events deemed 'high-quality' by whatever internal metric the relay adopts
54 47
48Relay MAY support these extensions:
49- `include:spam` - turn off spam filtering, if it was enabled by default