Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question regarding NIP-12 #278

Open
wozuo opened this issue Feb 20, 2023 · 10 comments
Open

Question regarding NIP-12 #278

wozuo opened this issue Feb 20, 2023 · 10 comments

Comments

@wozuo
Copy link

wozuo commented Feb 20, 2023

First off: I'm really enjoying exploring the Nostr protocol, amazing work so far! One thing is not entirely clear to me though: What's the rationale behind only allowing tag queries in which there is at least one tag value in common with the filter and event in NIP-12? This prevents filtering for events with a specific tag name in cases where the client doesn't care about the tag value. I can image clients filtering e.g. for all kind 1 events with a reference (tag r) or geohash tag set (tag g). Wouldn't it be useful if clients could filter for events which match the tag name only?

@Giszmo
Copy link
Member

Giszmo commented Feb 20, 2023

I thought this might already be possible by virtue of prefix filtering. Some relays allow as per nip-1 I think to send pubkey prefixes in author queries, so it would make sense to extend that to "#p" tags, making a filter for "#p":[""] work as per your request but I get inconsistent results.

One relay (wss://nostr-pub.wellorder.net) returns no results while another relay (wss://relay.damus.io) gives me:

["NOTICE","ERROR: bad msg: bad message"]
["NOTICE","ERROR: bad req: filter item too small"]

@wozuo
Copy link
Author

wozuo commented Feb 20, 2023

@Giszmo thanks for your quick response, can confirm! Plus looking at the code of e.g. relayer https://github.com/fiatjaf/relayer/blob/d7750ad15f213687e4bc01da235604e7a8606c6a/storage/postgresql/query.go#L91 the intended behaviour is to ignore queries without tag values

@barkyq
Copy link
Contributor

barkyq commented Feb 20, 2023

not so easy, afaict, to implement prefix matching in SQL when there is an unknown length array of strings to consider for each event, unlike pubkey/id which have just a single string for each event. I could be wrong though, not an SQL expert.

@barkyq
Copy link
Contributor

barkyq commented Feb 21, 2023

Wouldn't it be useful if clients could filter for events which match the tag name only?

If the intention of the note-writer is to make their event index-able via a specific "topic name", they can just put a ["t", "topic-name"] and then you can filter on that.

If you want to see which events have a specific tag (like e or r), you are out of luck.

@Giszmo
Copy link
Member

Giszmo commented Feb 21, 2023

The tag filters only match the second string and not the others.

The filter "#a":["b"] would match the event with tag ["a", "b", "c"].

@oren-z0
Copy link

oren-z0 commented Mar 13, 2023

@Giszmo Where can I find more information about the prefix filtering? Is this standardized?
I was thinking about the geohash tags, and prefix filter is critical for searching in a bounding box with a list of prefixes.

@Giszmo
Copy link
Member

Giszmo commented Mar 14, 2023

@oren-z0
Copy link

oren-z0 commented Mar 14, 2023

@Giszmo Ok, it talks only about ids and authors. We also need to extend this for #g tags, for similar reasons:

A prefix match is when the filter string is an exact string prefix of the event value. The use of prefixes allows for more compact filters where a large number of values are queried, and can provide some privacy for clients that may not want to disclose the exact authors or events they are searching for.

Do we need another NIP for that?

@Giszmo
Copy link
Member

Giszmo commented Mar 14, 2023

Yeah, probably. I'm not sure how many of the relays or clients support prefix queries.

@oren-z0
Copy link

oren-z0 commented Mar 14, 2023

@Giszmo Geohashes are encoded in base32, so a character like "*" could be used for prefix queries. For example, I could either search exactly "dqcjqcpew" or search a prefix "dqcjqcp*".

This "*"-format could be used as well for other tags that contain base32/base64/hex data, but I think each one should have its own NIP to explain why it is important (indexing irrelevant data for prefix-search might cost the relay operators significantly).

Tags that contain random texts might contain the "*" character, so this requires escaping the character and might not be backward compatible - but this is out of scope for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants