database

package
v0.0.0-...-201777b Latest Latest
Warning

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

Go to latest
Published: May 31, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSearchOpts = &SearchOpts{
	Fields: allFields,
}

Functions

func DocMapping

func DocMapping() *mapping.DocumentMapping

DocMapping returns a bleve document mapping suitable to store this object and attaches it to a main index mapping.

func GetAll

func GetAll(idx bleve.Index, opts *SearchOpts) (*bleve.SearchResult, error)

GetAll fetches all records, according to the search options

func GetAllIDs

func GetAllIDs(idx bleve.Index, maxID int) map[int]bool

GetAllIDs will return a list of IDs of all strips that have been downloaded, up to maxID.

func GetLatestID

func GetLatestID(idx bleve.Index) int

GetLatestID returns the highest ID recorded in the database

func Open

func Open(path string) (bleve.Index, error)

Open returns a new database if none exists, or the existing one.

func SearchStr

func SearchStr(idx bleve.Index, queryStr string, opts *SearchOpts) (*bleve.SearchResult, error)

SearchStr will perform a string query on the datastore

func SetLogger

func SetLogger(l *zap.SugaredLogger)

SetLogger sets the logger for the package

Types

type SearchOpts

type SearchOpts struct {
	Fields     []string
	SortBy     []string
	MaxRecords int
}

func (SearchOpts) Apply

func (s SearchOpts) Apply(request *bleve.SearchRequest)

type XKCDStrip

type XKCDStrip struct {
	ID         int    `json:"id"`
	Title      string `json:"title"`
	Transcript string `json:"transcript"`
	Date       string `json:"date"`
	Img        string `json:"img"`
	Comment    string `json:"comment"`
}

XKCDStrip is the data structure we save to the index

func NewStrip

func NewStrip(w *download.WireXKCD) *XKCDStrip

NewStrip transforms what we got from the wire into a document we can index in bleve.

func NewStripFromDb

func NewStripFromDb(result *search.DocumentMatch) *XKCDStrip

NewStripFromDb returns an xkcd strip from data recovered from the database.

func (*XKCDStrip) BleveType

func (x *XKCDStrip) BleveType() string

BleveType implements the BleveClassifier interface

func (*XKCDStrip) Index

func (x *XKCDStrip) Index(idx bleve.Index) error

Index performs the indexing of this resource in a bleve index.

func (XKCDStrip) Summary

func (x XKCDStrip) Summary() string

Summary offers a formatted output.

func (XKCDStrip) URL

func (x XKCDStrip) URL() string

URL returns the full url of a strip

Jump to

Keyboard shortcuts

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