nips/119.md

25 lines
1.1 KiB
Markdown
Raw Normal View History

2024-07-15 08:57:34 -04:00
# NIP-119: 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": ["black", "white"]
}
// returns kind `1` events with `t` tags that have both "meme" and "cat" that have the tag "black" or "white"
```
## Rationale
- Reduce bandwidth for all, with an emphasis on mobile users: `meme AND cat` objectively consumes less bandwidth than `meme OR cat `
- Reduce clock-time for relays, indexing with `AND` is fast for all common index formats, and faster compared to `OR` for some index formats. (See section below)
- Reduce client-side caching requirements
- Reduce centralization vectors by reducing or even eliminating the need for centralized REST, GraphQL APIs or specialized relay "feed" endpoints.
- Give relays the option to be more useful at the protocol level while improving efficiency for all parties.
## Rules
- `AND` **MUST** take precedence over `OR`
- Tags used in `AND` **SHOULD NOT** be used in standard `OR` tags [`#`]
- Any tag used in `AND` **SHOULD** be ignored in `OR`