elasticstore

package
v0.0.0-...-11d12e1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BOOKS_INDEX_NAME = "books"
)

Variables

This section is empty.

Functions

func RunMigrations

func RunMigrations(ctx context.Context, client *opensearchapi.Client, migrations []Migration) error

RunMigrations runs unfinished migrations in the order they are provided. It stops at the first error. Migrations that have already finished are skipped.

Migration functions should be idempotent: a process can stop after a migration succeeds but before its completion is recorded, causing that migration to run again on the next attempt.

func Setup

func Setup(ctx context.Context, client *opensearchapi.Client) error

Types

type BookIndex

type BookIndex struct {
	Name              string    `json:"name"`
	Description       string    `json:"description"`
	Rating            string    `json:"rating"`
	AuthorID          uuid.UUID `json:"authorId"`
	Tags              []int64   `json:"tags"`
	Chapters          int32     `json:"chapters"`
	Words             int32     `json:"words"`
	Slug              string    `json:"slug"`
	WordsPerChapter   int32     `json:"wordsPerChapter"`
	IsPubliclyVisible bool      `json:"isPubliclyVisible"`
	IsTrashed         bool      `json:"isTrashed"`
	CreatedAt         time.Time `json:"createdAt"`
	UpdatedAt         time.Time `json:"updatedAt"`

	Views          int64   `json:"views"`
	Popularity     float64 `json:"popularity"`
	ReadersCount   int64   `json:"readersCount"`
	ReviewsCount   int64   `json:"reviewsCount"`
	WeightedRating float64 `json:"weightedRating"`
}

func (*BookIndex) Normalize

func (c *BookIndex) Normalize()

type BoolQuery

type BoolQuery struct {
	Must    []Query `json:"must,omitempty"`
	MustNot []Query `json:"must_not,omitempty"`
	Should  []Query `json:"should,omitempty"`
}

type DateRangeQuery

type DateRangeQuery struct {
	Gte    string `json:"gte,omitempty"`
	Lte    string `json:"lte,omitempty"`
	Format string `json:"format,omitempty"`
}

type FieldValue

type FieldValue any

type HighlightField

type HighlightField struct {
	NumberOfFragments int `json:"number_of_fragments"`
}

type HighlightRequest

type HighlightRequest struct {
	PreTags  []string                  `json:"pre_tags"`
	PostTags []string                  `json:"post_tags"`
	Encoder  string                    `json:"encoder"`
	Fields   map[string]HighlightField `json:"fields"`
}

type Int32

type Int32 struct {
	Valid bool
	Int32 int32
}

type MatchQuery

type MatchQuery struct {
	Query     string  `json:"query"`
	Fuzziness string  `json:"fuzziness,omitempty"`
	Boost     float64 `json:"boost,omitempty"`
	Operator  string  `json:"operator,omitempty"`
}

type Migration

type Migration struct {
	Name string
	Run  func(context.Context, *opensearchapi.Client) error
}

Migration is a named, idempotent change to the OpenSearch store.

A migration is considered finished only after Run returns nil and its name has been recorded in OpenSearch. Names must be unique within a migration list and must not be changed after a migration has run.

type NumberRangeQuery

type NumberRangeQuery struct {
	Gt  *float64 `json:"gt,omitempty"`
	Gte *float64 `json:"gte,omitempty"`
	Lt  *float64 `json:"lt,omitempty"`
	Lte *float64 `json:"lte,omitempty"`
}

type Query

type Query struct {
	Term        map[string]TermQuery  `json:"term,omitempty"`
	Match       map[string]MatchQuery `json:"match,omitempty"`
	Bool        *BoolQuery            `json:"bool,omitempty"`
	QueryString *QueryStringQuery     `json:"query_string,omitempty"`
	Range       map[string]RangeQuery `json:"range,omitempty"`
}

type QueryStringQuery

type QueryStringQuery struct {
	Query string `json:"query"`
}

type Range

type Range struct {
	Min Int32
	Max Int32
}

func (Range) Has

func (r Range) Has() bool

type RangeQuery

type RangeQuery any

type SearchReqBody

type SearchReqBody struct {
	Highlight *HighlightRequest       `json:"highlight,omitempty"`
	Query     Query                   `json:"query"`
	From      int                     `json:"from,omitempty"`
	Size      int                     `json:"size,omitempty"`
	Sort      []map[string]SortOption `json:"sort,omitempty"`
}

type SearchRequest

type SearchRequest struct {
	Rating          string
	NumberFilters   map[string]*NumberRangeQuery
	DateFilters     map[string]DateRangeQuery
	Query           string
	Sort            SearchSort
	IncludeUsers    []string
	ExcludeUsers    []string
	IncludeTags     []int64
	ExcludeTags     []int64
	Words           Range
	Chapters        Range
	WordsPerChapter Range
	Page            int32
	PageSize        int32
	IncludeHidden   bool
}

type SearchResult

type SearchResult struct {
	Hits   []SearchRow
	TookMS int64
	Total  int64
}
func Search(
	ctx context.Context,
	client *opensearchapi.Client,
	req SearchRequest,
) (SearchResult, error)

type SearchRow

type SearchRow struct {
	BookIndex
	ID            int64
	NameHighlight string
}

type SearchSort

type SearchSort string
const (
	SearchSortChapters        SearchSort = "chapters"
	SearchSortWords           SearchSort = "words"
	SearchSortWordsPerChapter SearchSort = "words-per-chapter"
)

type SortOption

type SortOption struct {
	Order string `json:"order"`
}

type TermQuery

type TermQuery struct {
	Value FieldValue `json:"value"`
}

Jump to

Keyboard shortcuts

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