diff --git a/91.md b/91.md new file mode 100644 index 0000000000..c4e6ef7495 --- /dev/null +++ b/91.md @@ -0,0 +1,20 @@ +# NIP-91: AND Operator in Filters + +Enable `AND` within a single tag filter by using an `&` modifier in filters for indexable tags. + +``` +filters: { + "kinds": [1], + "&t": ["meme", "cat"], + "#t": ["meme", "cat", "black", "white"] +} +// returns kind `1` events with `t` tags that have both "meme" and "cat" that have the tag "black" or "white" by NIP-91 relays, whereas relays without NIP-91 return entire result for local intersection. +``` + +## Rules + +- `AND` **MUST** take precedence over `OR` by relays +- Any tag value used in `AND` **SHOULD** be ignored in `OR` by relays supporting NIP-91 +- Tag values used in `AND` by libraries and clients **MUST** include standard `OR` tags [`#`] for compatibility with relays that do not support NIP-91. +- libraries and clients `SHOULD` run `&` post-filters after recieving results from relays; already standard practice. + diff --git a/README.md b/README.md index a3e37e99cd..cc6a3bf9a2 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,8 @@ NIPs listed here are not a protocol checklist. Nothing forces any software to im - [NIP-88: Polls](88.md) - [NIP-89: Recommended Application Handlers](89.md) - ~~[NIP-90: Data Vending Machines](90.md) --- **unrecommended**: this got totally out of control, prefer use-case-specific microstandards~~ -- [NIP-92: Media Attachments Metadata (`imeta`)](92.md) +- [NIP-91: AND filters](91.md) +- [NIP-92: Media Attachments](92.md) - [NIP-94: File Metadata](94.md) - ~~[NIP-96: HTTP File Storage Integration](96.md) --- **unrecommended**: replaced by Blossom~~ - [NIP-98: HTTP Auth](98.md) @@ -306,6 +307,17 @@ This table is not exhaustive. For a machine-readable registry of all known event [marmot]: https://github.com/marmot-protocol/marmot +## Filters + +| kind | description | NIP | +| --------------- | -------------------------- | ------------------------ | +| `authors` | by pubkey | [01](01.md) | +| `ids` | by ids | [01](01.md) | +| `kinds` | by kinds | [01](01.md) | +| `#{}` | by indexable tag (OR) | [01](01.md) | +| `&{}` | by indexable tag (AND) | [91](91.md) | +| `search` | by search times | [50](50.md) | + ## Message types ### Client to Relay