Refactor and reorganize prefix index definitions

Removed redundant comments and restructured index definitions for improved clarity and maintainability. Added categorization and detailed documentation to better describe the purpose and usage of search indexes and metadata keys.
This commit is contained in:
2025-06-14 08:40:23 +01:00
parent e12fb03b03
commit 6a7ddb8aea

View File

@@ -8,8 +8,6 @@ const Len = 2
type I string
// the following enumerations are separate from the prefix value for simpler reference.
const (
// Event is the whole event stored in binary format
//
@@ -21,42 +19,46 @@ const (
// [ prefix ] [ configuration in JSON format ]
Config
// Id contains a truncated 8 byte hash of an event index
// Id contains a truncated 8 byte hash of an event index. This is the secondary key of an
// event, the primary key is the serial found in the Event.
//
// [ prefix ][ 8 bytes truncated hash of Id ][ 8 serial ]
Id
// FullIndex is an index designed to enable sorting and filtering of results found via
// other indexes.
// other indexes, without having to decode the event.
//
// [ prefix ][ 32 bytes full event ID ][ 8 bytes truncated hash of pubkey ][ 2 bytes kind ][ 8 bytes created_at timestamp ][ 8 serial ]
// [ prefix ][ 8 serial ][ 32 bytes full event ID ][ 8 bytes truncated hash of pubkey ][ 2 bytes kind ][ 8 bytes created_at timestamp ]
FullIndex
// ------------------------------------------------------------------------
//
// The following are search indexes. This first category are primarily for kind, pubkey and
// created_at timestamps. These compose a set of 3 primary indexes alone, two that combine
// with the timestamp, and a third that combines all three, covering every combination of
// these.
_
// Pubkey is an index for searching for events authored by a pubkey.
//
// [ prefix ][ 8 bytes truncated hash of pubkey ][ 8 serial ]
Pubkey
// PubkeyCreatedAt is a composite index that allows search by pubkey filtered by
// created_at.
// Kind is an index of event kind numbers.
//
// [ prefix ][ 8 bytes truncated hash of pubkey ][ 8 bytes created_at ][ 8 serial ]
PubkeyCreatedAt
// [ prefix ][ 2 bytes kind number ][ 8 serial ]
Kind
// CreatedAt is an index that allows search the timestamp on the event.
//
// [ prefix ][ created_at 8 bytes timestamp ][ 8 serial ]
CreatedAt
// FirstSeen is an index that records the timestamp of when the event was first seen.
// PubkeyCreatedAt is a composite index that allows search by pubkey filtered by
// created_at.
//
// [ prefix ][ 8 serial ][ 8 byte timestamp ]
FirstSeen
// Kind is an index of event kind numbers.
//
// [ prefix ][ 2 bytes kind number ][ 8 serial ]
Kind
// [ prefix ][ 8 bytes truncated hash of pubkey ][ 8 bytes created_at ][ 8 serial ]
PubkeyCreatedAt
// KindCreatedAt is an index of kind and created_at timestamp.
//
@@ -68,6 +70,18 @@ const (
// [ prefix ][ 2 bytes kind number ][ 8 bytes hash of pubkey ][ created_at 8 bytes timestamp ][ 8 bytes serial ]
KindPubkeyCreatedAt
// ------------------------------------------------------------------------
//
// The following are search indexes for tags, which are references to other categories,
// including events, replaceable event identities (d tags), public keys, hashtags, and
// arbitrary other kinds of keys including standard single letter and nonstandard word keys.
//
// Combining them with the previous set of 6 indexes involves using one query from the
// previous section according to the filter, and one or more of these tag indexes, to
// acquire a list of event serials from each query, and then intersecting the result sets
// from each one to yield the matches.
_
// TagA is an index of `a` tags, which contain kind, pubkey and hash of an arbitrary
// text, used to create an abstract reference for a multiplicity of replaceable event with a
// kind number. These labels also appear as `d` tags in inbound references, see
@@ -118,6 +132,9 @@ const (
// [ prefix ][ 8 byte hash of key ][ 8 byte hash of value ][ 8 serial ]
TagNonstandard
// ------------------------------------------------------------------------
_
// FulltextWord is a fulltext word index, the index contains the whole word. This will
// also be searchable via the use of annotations in the filter search as whole match for the
// word and any word containing the word (contains), and ^ prefix indicates a prefix match,
@@ -127,6 +144,17 @@ const (
// [ prefix ][ varint word len ][ full word ][ 4 bytes word position in content field ][ 8 serial ]
FulltextWord
// ------------------------------------------------------------------------
//
// The following keys are event metadata that are needed to enable other types of
// functionality such as garbage collection and metadata queries.
_
// FirstSeen is an index that records the timestamp of when the event was first seen.
//
// [ prefix ][ 8 serial ][ 8 byte timestamp ]
FirstSeen
// LastAccessed is an index that stores the last time the referenced event was returned
// in a result.
//