store

package
v0.0.0-...-5c30f4a Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArtID

type ArtID int

type ArtList

type ArtList []ArtID

ArtList is a list of article IDs from a Store.

func (*ArtList) Days

func (arts *ArtList) Days() []string

func (ArtList) Intersection

func (arts ArtList) Intersection(other ArtList) ArtList

func (*ArtList) Pubs

func (arts *ArtList) Pubs() []string

func (ArtList) StringList

func (arts ArtList) StringList() string

func (ArtList) Subtract

func (arts ArtList) Subtract(other ArtList) ArtList

func (ArtList) Union

func (arts ArtList) Union(other ArtList) ArtList

type Article

type Article struct {
	ID           ArtID // id in local sqlite db
	CanonicalURL string
	URLs         []string
	Headline     string
	Authors      []Author
	// Content contains HTML, sanitised using a subset of tags
	Content string

	Published   string
	Updated     string
	Publication Publication
	// Hack for now: store keywords as strings to work around badger shortcomings
	// TODO: Restore full structure
	//	Keywords    []Keyword
	Keywords []string
	Section  string

	Tags []string

	// List of articles similar to this one.
	Similar []Match

	// a couple of tweet-specific bits
	Retweets   int
	Favourites int
	// resolved links
	Links []string

	// fudge fields
	Pub    string
	Byline string
}

func (*Article) AddTag

func (art *Article) AddTag(tag string) bool

func (*Article) BylineString

func (art *Article) BylineString() string

func (*Article) Day

func (art *Article) Day() string

func (*Article) FieldString

func (art *Article) FieldString(fieldName string) string

func (*Article) FormatContent

func (art *Article) FormatContent(highlightTerms string) string

TODO: this should be out in the gui layer TODO: this will screw up in assorted cases

eg a highlight term of "amp" will cause & escape codes to bork up.

func (*Article) FormattedPubDate

func (art *Article) FormattedPubDate(fmt string) string

func (*Article) GetURL

func (art *Article) GetURL(n int) string

fudge to get around go-qml non-support of []string

func (*Article) KeywordsString

func (art *Article) KeywordsString() string

func (*Article) LinksString

func (art *Article) LinksString() string

func (*Article) NumURLs

func (art *Article) NumURLs() int

fudge to get around go-qml non-support of []string

func (*Article) PlainTextContent

func (art *Article) PlainTextContent() string

func (*Article) PublishedTime

func (art *Article) PublishedTime() time.Time

func (*Article) RemoveTag

func (art *Article) RemoveTag(tag string) bool

func (*Article) TagsString

func (art *Article) TagsString() string

func (*Article) TextContent

func (art *Article) TextContent() template.HTML

func (*Article) URL

func (art *Article) URL() string

type Author

type Author struct {
	Name    string
	RelLink string
	Email   string
	Twitter string
}

type Batch

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

Batch is a helper for performing operations upon the store. TODO: - add logging for bad/partly bad articles - track articles we already had

func (*Batch) AddSimilar

func (batch *Batch) AddSimilar(id ArtID, matches []Match) error

func (*Batch) ClearSimilar

func (batch *Batch) ClearSimilar() error

func (*Batch) Commit

func (batch *Batch) Commit() error

func (*Batch) Rollback

func (batch *Batch) Rollback() error

type By

type By func(p1, p2 *Article) bool

func (By) Sort

func (by By) Sort(arts []*Article)

type Iter

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

func (*Iter) Cur

func (it *Iter) Cur() *Article

func (*Iter) Err

func (it *Iter) Err() error

func (*Iter) Next

func (it *Iter) Next() bool

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

type Match

type Match struct {
	ID    ArtID
	Score float32
}

type ProgressFn

type ProgressFn func(expected int, completed int)

type Publication

type Publication struct {
	// Code is a short, unique name (eg "mirror")
	Code string
	// Name is the 'pretty' name (eg "The Daily Mirror")
	Name   string
	Domain string
}

type SortOrder

type SortOrder int
const (
	Ascending SortOrder = iota
	Descending
)

type Stasher

type Stasher struct {
	Dest      *Store
	BatchSize int

	// StashedIDs contains IDs of successfully-stashed articles
	StashedIDs ArtList
	// contains filtered or unexported fields
}

Stasher is a helper for loading articles into a store. It batches up stashes, to improve indexing speed. TODO: - add logging for bad/partly bad articles - track articles we already had

func NewStasher

func NewStasher(dest *Store) *Stasher

func (*Stasher) Close

func (s *Stasher) Close() error

Flushes any batched articles Safe to call multiple times

func (*Stasher) Stash

func (s *Stasher) Stash(art *Article) error

Stash submits another article to the store. When the article is added (and it might be during a subsequent call - remember, articles are batched) it's ID field will be set.

type Store

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

Store is the core representation of our data set. Provides base methods for querying, tagging, whatever

func Create

func Create(dbFile string, dbug Logger, defaultLang string, loc *time.Location) (*Store, error)

Create creates a new database and index. Returns an error if already existant.

func New

func New(dbFile string, dbug Logger, defaultLang string, loc *time.Location) (*Store, error)

DEPRECATED - use Open() or Create() instead defaultLang is lang used when creating a new db (or updating an older version). Otherwise Lang set from existing DB.

func NewWithoutIndex

func NewWithoutIndex(dbFile string, dbug Logger, defaultLang string, loc *time.Location) (*Store, error)

NewWithoutIndex opens a store without a fulltext interface

func Open

func Open(dbFile string, dbug Logger, defaultLang string, loc *time.Location) (*Store, error)

Open an existing database & index. Returns error if non-existant.

func (*Store) AddTags

func (store *Store) AddTags(arts ArtList, tags []string) (ArtList, error)

func (*Store) AllArts

func (store *Store) AllArts() (ArtList, error)

standin - return IDs of all articles

func (*Store) BeginBatch

func (store *Store) BeginBatch() (*Batch, error)

func (*Store) Close

func (store *Store) Close()

func (*Store) DB

func (store *Store) DB() *sql.DB

TEMP - cheesy access to db directly

func (*Store) Delete

func (store *Store) Delete(arts ArtList, progress ProgressFn) error

Delete articles from the store (and index) if progress is non-nil, it'll be called at regularish intervals

func (*Store) Fetch

func (store *Store) Fetch(artIDs ...ArtID) ([]*Article, error)

func (*Store) FetchAll

func (store *Store) FetchAll() ([]*Article, error)

func (*Store) Filename

func (store *Store) Filename() string

Filename returns the filename of the .db file underlying this store

func (*Store) FindArt

func (store *Store) FindArt(urls []string) (ArtID, error)

func (*Store) IterateAllArts

func (store *Store) IterateAllArts() *Iter

func (*Store) IterateArts

func (store *Store) IterateArts(arts ...ArtID) *Iter

IterateArts returns an Iter which steps over each article in turn

func (*Store) IterateTaggedArts

func (store *Store) IterateTaggedArts() *Iter

func (*Store) Lang

func (store *Store) Lang() string

func (*Store) RemoveTags

func (store *Store) RemoveTags(arts ArtList, tags []string) (ArtList, error)

func (*Store) Search

func (store *Store) Search(queryString string) (ArtList, error)

search performs a search and returns the results XYZZY: add sort criteria

func (*Store) SetLang

func (store *Store) SetLang(lang string) error

set the default indexing language for this store NOTE: won't take effect unless index is deleted and rebuilt...

func (*Store) Sort

func (store *Store) Sort(artIDs ArtList, fieldName string, order SortOrder) (ArtList, error)

Sort an article list (by hitting the sqlite db)

func (*Store) Stash

func (store *Store) Stash(arts []*Article) error

func (*Store) TotalArts

func (store *Store) TotalArts() int
func (store *Store) UpdateLinks(arts ArtList) error

HACK - update all the links for the given articles

Jump to

Keyboard shortcuts

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