search

package
v0.0.0-...-72b4acb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2024 License: Apache-2.0, MIT Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MetricsMiddleware

func MetricsMiddleware(next echo.HandlerFunc) echo.HandlerFunc

MetricsMiddleware defines handler function for metrics middleware

func NormalizeLossyURL

func NormalizeLossyURL(raw string) string

aggressively normalizes URL, for search indexing and matching. it is possible the URL won't be directly functional after this normalization

Types

type ActorSearchParams

type ActorSearchParams struct {
	Query     string       `json:"q"`
	Typeahead bool         `json:"typeahead"`
	Follows   []syntax.DID `json:"follows"`
	Viewer    *syntax.DID  `json:"viewer"`
	Offset    int          `json:"offset"`
	Size      int          `json:"size"`
}

func (*ActorSearchParams) Filters

func (p *ActorSearchParams) Filters() []map[string]interface{}

Filters turns search params in to actual elasticsearch/opensearch filter DSL

type EsSearchHit

type EsSearchHit struct {
	Index  string          `json:"_index"`
	ID     string          `json:"_id"`
	Score  float64         `json:"_score"`
	Source json.RawMessage `json:"_source"`
}

type EsSearchHits

type EsSearchHits struct {
	Total struct {
		Value    int
		Relation string
	} `json:"total"`
	MaxScore float64       `json:"max_score"`
	Hits     []EsSearchHit `json:"hits"`
}

type EsSearchResponse

type EsSearchResponse struct {
	Took     int          `json:"took"`
	TimedOut bool         `json:"timed_out"`
	Hits     EsSearchHits `json:"hits"`
}

func DoSearchGeneric

func DoSearchGeneric(ctx context.Context, escli *es.Client, index, q string) (*EsSearchResponse, error)

helper to do a full-featured Lucene query parser (query_string) search, with all possible facets. Not safe to expose publicly.

func DoSearchPosts

func DoSearchPosts(ctx context.Context, dir identity.Directory, escli *es.Client, index string, params *PostSearchParams) (*EsSearchResponse, error)

func DoSearchProfiles

func DoSearchProfiles(ctx context.Context, dir identity.Directory, escli *es.Client, index string, params *ActorSearchParams) (*EsSearchResponse, error)

func DoSearchProfilesTypeahead

func DoSearchProfilesTypeahead(ctx context.Context, escli *es.Client, index string, params *ActorSearchParams) (*EsSearchResponse, error)

type HealthStatus

type HealthStatus struct {
	Service string `json:"service,const=palomar"`
	Status  string `json:"status"`
	Version string `json:"version"`
	Message string `json:"msg,omitempty"`
}

type Indexer

type Indexer struct {
	// contains filtered or unexported fields
}

func NewIndexer

func NewIndexer(db *gorm.DB, escli *es.Client, dir identity.Directory, config IndexerConfig) (*Indexer, error)

func (*Indexer) BulkIndexPageranks

func (idx *Indexer) BulkIndexPageranks(ctx context.Context, pagerankFile string) error

BulkIndexPageranks updates the pageranks for the DIDs in the Search Index from a CSV file.

func (*Indexer) BulkIndexPosts

func (idx *Indexer) BulkIndexPosts(ctx context.Context, postsFile string) error

BulkIndexPosts indexes posts from a CSV file.

func (*Indexer) BulkIndexProfiles

func (idx *Indexer) BulkIndexProfiles(ctx context.Context, profilesFile string) error

BulkIndexProfiles indexes profiles from a CSV file.

func (*Indexer) EnsureIndices

func (idx *Indexer) EnsureIndices(ctx context.Context) error

func (*Indexer) RunIndexer

func (idx *Indexer) RunIndexer(ctx context.Context) error

type IndexerConfig

type IndexerConfig struct {
	RelayHost           string
	ProfileIndex        string
	PostIndex           string
	Logger              *slog.Logger
	RelaySyncRateLimit  int
	IndexMaxConcurrency int
	DiscoverRepos       bool
	IndexingRateLimit   int
}

type LastSeq

type LastSeq struct {
	ID  uint `gorm:"primarykey"`
	Seq int64
}

type PagerankIndexJob

type PagerankIndexJob struct {
	// contains filtered or unexported fields
}

type PostDoc

type PostDoc struct {
	DocIndexTs        string   `json:"doc_index_ts"`
	DID               string   `json:"did"`
	RecordRkey        string   `json:"record_rkey"`
	RecordCID         string   `json:"record_cid"`
	CreatedAt         *string  `json:"created_at,omitempty"`
	Text              string   `json:"text"`
	TextJA            *string  `json:"text_ja,omitempty"`
	LangCode          []string `json:"lang_code,omitempty"`
	LangCodeIso2      []string `json:"lang_code_iso2,omitempty"`
	MentionDID        []string `json:"mention_did,omitempty"`
	EmbedATURI        *string  `json:"embed_aturi,omitempty"`
	ReplyRootATURI    *string  `json:"reply_root_aturi,omitempty"`
	EmbedImgCount     int      `json:"embed_img_count"`
	EmbedImgAltText   []string `json:"embed_img_alt_text,omitempty"`
	EmbedImgAltTextJA []string `json:"embed_img_alt_text_ja,omitempty"`
	SelfLabel         []string `json:"self_label,omitempty"`
	URL               []string `json:"url,omitempty"`
	Domain            []string `json:"domain,omitempty"`
	Tag               []string `json:"tag,omitempty"`
	Emoji             []string `json:"emoji,omitempty"`
}

func TransformPost

func TransformPost(post *appbsky.FeedPost, did syntax.DID, rkey, cid string) PostDoc

func (*PostDoc) DocId

func (d *PostDoc) DocId() string

Returns the search index document ID (`_id`) for this document.

This identifier should be URL safe and not contain a slash ("/").

type PostIndexJob

type PostIndexJob struct {
	// contains filtered or unexported fields
}

type PostSearchParams

type PostSearchParams struct {
	Query    string           `json:"q"`
	Sort     string           `json:"sort"`
	Author   *syntax.DID      `json:"author"`
	Since    *syntax.Datetime `json:"since"`
	Until    *syntax.Datetime `json:"until"`
	Mentions *syntax.DID      `json:"mentions"`
	Lang     *syntax.Language `json:"lang"`
	Domain   string           `json:"domain"`
	URL      string           `json:"url"`
	Tags     []string         `json:"tag"`
	Viewer   *syntax.DID      `json:"viewer"`
	Offset   int              `json:"offset"`
	Size     int              `json:"size"`
}

func ParsePostQuery

func ParsePostQuery(ctx context.Context, dir identity.Directory, raw string, viewer *syntax.DID) PostSearchParams

ParseQuery takes a query string and pulls out some facet patterns ("from:handle.net") as filters

func (*PostSearchParams) Filters

func (p *PostSearchParams) Filters() []map[string]interface{}

Filters turns search params in to actual elasticsearch/opensearch filter DSL

func (*PostSearchParams) Update

func (p *PostSearchParams) Update(other *PostSearchParams)

Merges params from another param object in to this one. Intended to meld parsed query with HTTP query params, so not all functionality is supported, and priority is with the "current" object

type PostSearchResult

type PostSearchResult struct {
	Tid  string     `json:"tid"`
	Cid  string     `json:"cid"`
	User UserResult `json:"user"`
	Post any        `json:"post"`
}

type ProfileDoc

type ProfileDoc struct {
	DocIndexTs  string   `json:"doc_index_ts"`
	DID         string   `json:"did"`
	RecordCID   string   `json:"record_cid"`
	Handle      string   `json:"handle"`
	DisplayName *string  `json:"display_name,omitempty"`
	Description *string  `json:"description,omitempty"`
	ImgAltText  []string `json:"img_alt_text,omitempty"`
	SelfLabel   []string `json:"self_label,omitempty"`
	URL         []string `json:"url,omitempty"`
	Domain      []string `json:"domain,omitempty"`
	Tag         []string `json:"tag,omitempty"`
	Emoji       []string `json:"emoji,omitempty"`
	HasAvatar   bool     `json:"has_avatar"`
	HasBanner   bool     `json:"has_banner"`
}

func TransformProfile

func TransformProfile(profile *appbsky.ActorProfile, ident *identity.Identity, cid string) ProfileDoc

func (*ProfileDoc) DocId

func (d *ProfileDoc) DocId() string

Returns the search index document ID (`_id`) for this document.

This identifier should be URL safe and not contain a slash ("/").

type ProfileIndexJob

type ProfileIndexJob struct {
	// contains filtered or unexported fields
}

type Server

type Server struct {
	Indexer *Indexer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(escli *es.Client, dir identity.Directory, config ServerConfig) (*Server, error)

func (*Server) EnsureIndices

func (s *Server) EnsureIndices(ctx context.Context) error

func (*Server) RunAPI

func (s *Server) RunAPI(listen string) error

func (*Server) RunMetrics

func (s *Server) RunMetrics(listen string) error

func (*Server) SearchPosts

func (*Server) SearchProfiles

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

type ServerConfig

type ServerConfig struct {
	Logger            *slog.Logger
	ProfileIndex      string
	PostIndex         string
	AtlantisAddresses []string
}

type UserResult

type UserResult struct {
	Did    string `json:"did"`
	Handle string `json:"handle"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL