core

package
v0.0.5-29 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SUBSCRIBE   = "subscribe"
	UNSUBSCRIBE = "unsubscribe"
	DEFAULT     = "default"
)
View Source
const COLLECTIONS_BY_FIRST_CONTENT_UNIT_CLAUSE = `
  and c.id = collection_first_content_unit_languages.collection_id
`

Filter collection to have language.

View Source
const CONTENT_UNIT_PERSON_RAV = `` /* 178-byte string literal not displayed */
View Source
const CONTENT_UNIT_SUGGESTER_NAME = "ContentUnitsSuggester"

Variables

View Source
var Suggesters = map[string]MakeSuggesterFunc{}

Functions

func CollectionsByFirstUnitLanguagesTableSql

func CollectionsByFirstUnitLanguagesTableSql(contentTypes []string, languages []string) string

func ContentTypesToContentIds

func ContentTypesToContentIds(contentTypes []string) []string

func FilterByLanguageSql

func FilterByLanguageSql(languages []string) string

Filter content unit to have language.

func RegisterSuggester

func RegisterSuggester(name string, makeFunc MakeSuggesterFunc)

func SplitContentItems

func SplitContentItems(contentItems []ContentItem, numLists int) [][]ContentItem

Types

type CollectionSuggester

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

func MakeCollectionSuggester

func MakeCollectionSuggester(db *sql.DB, contentType string) *CollectionSuggester

func (*CollectionSuggester) MarshalSpec

func (suggester *CollectionSuggester) MarshalSpec() (SuggesterSpec, error)

func (*CollectionSuggester) More

func (suggester *CollectionSuggester) More(request MoreRequest) ([]ContentItem, error)

func (*CollectionSuggester) UnmarshalSpec

func (suggester *CollectionSuggester) UnmarshalSpec(db *sql.DB, spec SuggesterSpec) error

type CompletionSuggester

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

Given slice of Suggesters will take the first one, if not enough suggestions will take the second one, ect... The OriginalOrder here is the index of the suggester, e.g., 0, 0, 0, 1, 1, 2, 2, 2, 2 (3 items from suggeter #0, 2 from #1, 4 from #4)

func MakeCompletionSuggester

func MakeCompletionSuggester(suggesters []Suggester) *CompletionSuggester

func (*CompletionSuggester) MarshalSpec

func (suggester *CompletionSuggester) MarshalSpec() (SuggesterSpec, error)

func (*CompletionSuggester) More

func (suggester *CompletionSuggester) More(request MoreRequest) ([]ContentItem, error)

func (*CompletionSuggester) UnmarshalSpec

func (suggester *CompletionSuggester) UnmarshalSpec(db *sql.DB, spec SuggesterSpec) error

type ContentItem

type ContentItem struct {
	UID           string    `json:"uid"`
	ContentType   string    `json:"content_type"`
	Date          time.Time `json:"date"`
	CreatedAt     time.Time `json:"created_at"`
	OriginalOrder []int64   `json:"original_order"`
	Suggester     string    `json:"suggester"`
}

func Merge

func Merge(r MoreRequest, suggestions [][]ContentItem) ([]ContentItem, error)

func Unsort

func Unsort(contentItems []ContentItem) []ContentItem

type ContentUnitsSuggester

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

func MakeContentUnitsSuggester

func MakeContentUnitsSuggester(db *sql.DB, contentTypes []string) *ContentUnitsSuggester

func (*ContentUnitsSuggester) MarshalSpec

func (suggester *ContentUnitsSuggester) MarshalSpec() (SuggesterSpec, error)

func (*ContentUnitsSuggester) More

func (suggester *ContentUnitsSuggester) More(request MoreRequest) ([]ContentItem, error)

func (*ContentUnitsSuggester) UnmarshalSpec

func (suggester *ContentUnitsSuggester) UnmarshalSpec(db *sql.DB, spec SuggesterSpec) error

type Feed

type Feed struct {
	Suggester Suggester
}

func MakeFeed

func MakeFeed(db *sql.DB) *Feed

func (*Feed) More

func (f *Feed) More(r MoreRequest) ([]ContentItem, error)

type MakeSuggesterFunc

type MakeSuggesterFunc func(db *sql.DB) Suggester

type MoreOptions

type MoreOptions struct {
	ContentTypes Subscriptions `json:"content_types" form:"content_type"`
	// Map from collection content type to Subscriptions.
	Collections map[string]Subscriptions `json:"collections" form:"collections"`

	Recommend Recommend      `json:"recommend" form:"recommend"`
	Spec      *SuggesterSpec `json:"spec,omitempty" form:"spec,omitempty"`

	Languages []string `json:"languages,omitempty" form:"languages,omitempty"`
	SkipUids  []string `json:"skip_uids"`
}

type MoreRequest

type MoreRequest struct {
	CurrentFeed []ContentItem `json:"current_feed" form:"current_feed"`
	MoreItems   int           `json:"more_items" form:"more_items"`
	Options     MoreOptions   `json:"options" form:"options"`
}

type Recommend

type Recommend struct {
	Uid string `json:"uid"`
}

type RoundRobinSuggester

type RoundRobinSuggester struct {
	Name       string
	Suggesters []Suggester
}

func MakeRoundRobinSuggester

func MakeRoundRobinSuggester(suggesters []Suggester) *RoundRobinSuggester

func (*RoundRobinSuggester) MarshalSpec

func (suggester *RoundRobinSuggester) MarshalSpec() (SuggesterSpec, error)

func (*RoundRobinSuggester) More

func (suggester *RoundRobinSuggester) More(request MoreRequest) ([]ContentItem, error)

func (*RoundRobinSuggester) UnmarshalSpec

func (suggester *RoundRobinSuggester) UnmarshalSpec(db *sql.DB, spec SuggesterSpec) error

type SortSuggester

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

Sort items by date and then by create at time.

func MakeSortSuggester

func MakeSortSuggester(suggester Suggester) *SortSuggester

func (*SortSuggester) MarshalSpec

func (suggester *SortSuggester) MarshalSpec() (SuggesterSpec, error)

func (*SortSuggester) More

func (suggester *SortSuggester) More(request MoreRequest) ([]ContentItem, error)

func (*SortSuggester) UnmarshalSpec

func (suggester *SortSuggester) UnmarshalSpec(db *sql.DB, spec SuggesterSpec) error

type Subscriptions

type Subscriptions map[string]string

Keys are content types or collection mids. Values are one of the constants: SUBSCRIBE, UNSUBSCRIBE, DEFAULT

type Suggester

type Suggester interface {
	More(request MoreRequest) ([]ContentItem, error)

	MarshalSpec() (SuggesterSpec, error)
	UnmarshalSpec(db *sql.DB, spec SuggesterSpec) error
}

func MakeSuggesterFromName

func MakeSuggesterFromName(db *sql.DB, name string) (Suggester, error)

type SuggesterSpec

type SuggesterSpec struct {
	Name         string           `json:"name,omitempty" form:"name,omitempty"`
	Args         []string         `json:"args,omitempty" form:"args,omitempty"`
	SecondArgs   []string         `json:"second_args,omitempty" form:"second_args,omitempty"`
	TimeSelector TimeSelectorEnum `json:"time_selector,omitempty" form:"time_selector,omitempty"`
	Specs        []SuggesterSpec  `json:"specs,omitempty" form:"specs,omitempty"`
}

type TimeSelectorEnum

type TimeSelectorEnum int

Defines time constrain for selecting content units / collection.

const (
	Last TimeSelectorEnum = iota
	Next
	Prev
	Rand
)

Jump to

Keyboard shortcuts

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