From 086d224e1d75366ec45d23544159ed9c5610010a Mon Sep 17 00:00:00 2001 From: Artur Brugeman Date: Tue, 17 Jan 2023 18:49:10 +0300 Subject: [PATCH 1/4] NIP-50: Keywords Filter --- 50.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 50.md diff --git a/50.md b/50.md new file mode 100644 index 00000000..f0ee8432 --- /dev/null +++ b/50.md @@ -0,0 +1,52 @@ +NIP-50 +====== + +Keywords Filter +--------------- + +`draft` `optional` `author:brugeman` + +## Abstract + +Many Nostr use cases require some form of search by `content` field. The meaning and format of `content` differs +with event kind and use case. Thus, this NIP only establishes a general framework for search over `content`, +and specifies the details for kind `0` and kind `1` events. + +## `keywords` filter field + +A new `keywords` field is introduced for `REQ` messages from clients: +```json +{ + "kinds": + "keywords": +} +``` +A filter with `keywords` field MUST also include `kinds` field. This NIP specifies the behavior for kinds `0` and `1`, +if none of these kinds are provided along with `keywords`, relay SHOULD ignore the filter, and MAY send +a `NOTICE` to inform the client. Future NIPs will specify behavior for other event kinds. + +A filter matches if one of the provided `keywords` matches. Each keyword string may contain several conditions - `words`, +all the words must match for a keyword to match. The meaning of `words` depends on event kind. + +Clients SHOULD query several relays supporting this NIP and specific kind to compensate for potentially different +implementation details between relays (like string sanitization, etc). + +Clients SHOULD verify that events returned by a relay match the specified `keywords` in the way that suits the +client's use case, and MAY stop querying relays that have low precision. + +## Keyword search for kind `0` and kind `1` + +For kind `0` and kind `1`, each keyword is a lowercase string consisting of words separated by spaces (in most languages), punctuation/control +characters are ignored. + +For kind `1`, an event must include all words in it's `content` field for it to match the keyword. + +For kind `0`, an event must include all mentioned words in the json object stored at the `content` field. Recommended +json fields for matching are `about`, `display_name`, `name`, `nip05`, `lud06` and `lud18`. + +A keyword may contain a word starting with prefix `option:` (like `option:no_spam`), such words specify additional +constraints for event matching, and are reserved for the future extensions. Relay SHOULD ignore `option:` words that it does not support. + +Relay MAY support these options for kind `0` and kind `1` events: +- `option:no_spam` - only include events deemed 'high-quality' by whatever internal metric the relay adopts + From a5a4f312ccb44a33dd2c685d735a96bf0acb8838 Mon Sep 17 00:00:00 2001 From: Artur Brugeman Date: Tue, 24 Jan 2023 09:03:59 +0300 Subject: [PATCH 2/4] Add mention of supported_nips by mikedilger --- 50.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/50.md b/50.md index f0ee8432..470da1c4 100644 --- a/50.md +++ b/50.md @@ -4,7 +4,7 @@ NIP-50 Keywords Filter --------------- -`draft` `optional` `author:brugeman` +`draft` `optional` `author:brugeman` `author:mikedilger` ## Abstract @@ -28,6 +28,8 @@ a `NOTICE` to inform the client. Future NIPs will specify behavior for other eve A filter matches if one of the provided `keywords` matches. Each keyword string may contain several conditions - `words`, all the words must match for a keyword to match. The meaning of `words` depends on event kind. +Clients SHOULD use the supported_nips field to learn if a relay supports keyword filter queries. + Clients SHOULD query several relays supporting this NIP and specific kind to compensate for potentially different implementation details between relays (like string sanitization, etc). From d534df39c05f26e26d47f1813cbacbb02c9d7718 Mon Sep 17 00:00:00 2001 From: Artur Brugeman Date: Wed, 25 Jan 2023 14:46:28 +0300 Subject: [PATCH 3/4] Add hint about client-side filtering --- 50.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/50.md b/50.md index 470da1c4..b02a3f3a 100644 --- a/50.md +++ b/50.md @@ -28,7 +28,7 @@ a `NOTICE` to inform the client. Future NIPs will specify behavior for other eve A filter matches if one of the provided `keywords` matches. Each keyword string may contain several conditions - `words`, all the words must match for a keyword to match. The meaning of `words` depends on event kind. -Clients SHOULD use the supported_nips field to learn if a relay supports keyword filter queries. +Clients 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. Clients SHOULD query several relays supporting this NIP and specific kind to compensate for potentially different implementation details between relays (like string sanitization, etc). From f6cf3b6c3c76d15f9b17e42ea05b72deff359183 Mon Sep 17 00:00:00 2001 From: Artur Brugeman Date: Thu, 26 Jan 2023 15:14:44 +0300 Subject: [PATCH 4/4] Fix: change lud18 to lud16 --- 50.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/50.md b/50.md index b02a3f3a..0692fd1d 100644 --- a/50.md +++ b/50.md @@ -44,7 +44,7 @@ characters are ignored. For kind `1`, an event must include all words in it's `content` field for it to match the keyword. For kind `0`, an event must include all mentioned words in the json object stored at the `content` field. Recommended -json fields for matching are `about`, `display_name`, `name`, `nip05`, `lud06` and `lud18`. +json fields for matching are `about`, `display_name`, `name`, `nip05`, `lud06` and `lud16`. A keyword may contain a word starting with prefix `option:` (like `option:no_spam`), such words specify additional constraints for event matching, and are reserved for the future extensions. Relay SHOULD ignore `option:` words that it does not support.