index

package module
v0.0.0-...-09abe39 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: AGPL-3.0 Imports: 14 Imported by: 0

README

go.yarn.social/index

Build Status Go Report Card Go Reference

go.yarn.social/index is the Go library used by Yarn's search engine yarns and other components as a dependency.

Quick Start

TBD

License

go.yarn.social/index is licensed under the terms of the AGPLv3

Documentation

Index

Constants

View Source
const DefaultResultsPerPage = 10

Variables

View Source
var (
	SearchFields = []string{DefaultSearchField,
		"type", "text", "conv", "subject", "tags",
		"links", "mentions", "nick", "feed", "author",
	}

	DefaultSort = []string{"-created", "-_score", "-_id"}
)
View Source
var ErrBadConfiguration = errors.New("error: both path and memory options cannot be used")

Functions

func FileExists

func FileExists(name string) bool

func IsValidSearchField

func IsValidSearchField(f string) bool

func IsValidSearchType

func IsValidSearchType(t SearchType) bool

Types

type Config

type Config struct {
	Path   string
	Memory bool

	ResultsPerPage int
}

func NewDefaultConfig

func NewDefaultConfig() *Config

type ConfigOption

type ConfigOption func(cfg *Config) error

func WithMemory

func WithMemory() ConfigOption

func WithPath

func WithPath(p string) ConfigOption

func WithResultsPerPage

func WithResultsPerPage(resultsPerPage int) ConfigOption

type Entry

type Entry struct {
	Twt types.Twt

	Type    string    `json:"type"`
	Text    string    `json:"text"`
	Conv    string    `json:"conv"`
	Subject string    `json:"subject"`
	Created time.Time `json:"created"`

	Tags     []string `json:"tags"`
	Links    []string `json:"links"`
	Mentions []string `json:"mentions"`

	Nick   string `json:"nick"`
	Feed   string `json:"feed"`
	Author string `json:"author"`
	Avatar string `json:"avatar"`
}

func NewEntry

func NewEntry(twt types.Twt, info types.Info) Entry

type Indexer

type Indexer interface {
	Index(entry Entry) error
	Size() int64
	Search(qs string, opts ...SearchOption) (res *SearchResponse, err error)
}

func NewBleveIndexer

func NewBleveIndexer(opts ...ConfigOption) (Indexer, error)

type Result

type Result struct {
	Type    string
	Text    string
	Conv    string
	Subject string
	Created time.Time

	Tags     []string
	Links    []string
	Mentions []string

	Nick   string
	Feed   string
	Author string
	Avatar string
	// contains filtered or unexported fields
}

func NewResult

func NewResult(score float64, content string) *Result

func (Result) HTML

func (r Result) HTML() template.HTML

func (*Result) Score

func (r *Result) Score() float64

func (*Result) String

func (r *Result) String() string

type Results

type Results []Result

type SearchOption

type SearchOption func(opts *SearchOptions) error

func SetField

func SetField(f string) SearchOption

func SetPage

func SetPage(p int) SearchOption

func SetType

func SetType(t SearchType) SearchOption

func SortBy

func SortBy(sort []string) SearchOption

type SearchOptions

type SearchOptions struct {
	Type  SearchType
	Field string
	Page  int
	Sort  []string
}

func NewDefaultSearchOptions

func NewDefaultSearchOptions() *SearchOptions

type SearchResponse

type SearchResponse struct {
	Results Results
	Total   uint64
	Took    time.Duration
}

type SearchType

type SearchType string
const (
	SearchTypeQuery     SearchType = "qs"
	SearchTypeMatch     SearchType = "match"
	SearchTypeTerm      SearchType = "term"
	SearchTypeUndefined SearchType = ""
	DefaultSearchType              = SearchTypeMatch

	DefaultSearchField = "_all"
)

Jump to

Keyboard shortcuts

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