Documentation
¶
Index ¶
- Constants
- func TokensToTSVector(tokens []Token) []string
- type Comments
- type Data
- func (d *Data) ApproveSubmission(id int) error
- func (d *Data) DeleteComments(id int) error
- func (d *Data) DeleteEntry(id int) error
- func (s *Data) DeleteRelation(fromID, relID int) error
- func (d *Data) GetComments() ([]Comments, error)
- func (d *Data) GetEntry(id int) (Entry, error)
- func (d *Data) GetGlossaryWords(lang, initial string, offset, limit int) ([]GlossaryWord, int, error)
- func (d *Data) GetInitials(lang string) ([]string, error)
- func (d *Data) GetParentEntries(id int) ([]Entry, error)
- func (d *Data) GetPendingEntries(lang string, tags pq.StringArray, offset, limit int) ([]Entry, int, error)
- func (d *Data) GetStats() (Stats, error)
- func (d *Data) InsertComments(fromGUID, toGUID, comments string) error
- func (d *Data) InsertEntry(e Entry) (int, error)
- func (d *Data) InsertRelation(fromID, toID int, r Relation) (int, error)
- func (d *Data) InsertSubmissionEntry(e Entry) (int, error)
- func (d *Data) InsertSubmissionRelation(fromID, toID int, r Relation) (int, error)
- func (d *Data) RejectSubmission(id int) error
- func (d *Data) ReorderRelations(ids []int) error
- func (d *Data) Search(q Query) ([]Entry, int, error)
- func (d *Data) SearchAndLoadRelations(e []Entry, q Query) error
- func (d *Data) UpdateEntry(id int, e Entry) error
- func (d *Data) UpdateRelation(id int, r Relation) error
- type Entry
- type GlossaryWord
- type Lang
- type LangMap
- type Queries
- type Query
- type Relation
- type Stats
- type Token
- type Tokenizer
Constants ¶
const ( StatusPending = "pending" StatusEnabled = "enabled" StatusDisabled = "disabled" )
Variables ¶
This section is empty.
Functions ¶
func TokensToTSVector ¶
TokensToTSVector takes a list of tokens, de-duplicates them, and returns a Postgres tsvector string.
Types ¶
type Data ¶
type Data struct {
Langs LangMap
// contains filtered or unexported fields
}
Data represents the dictionary search interface.
func (*Data) ApproveSubmission ¶
ApproveSubmission approves a pending submission (entry, relations, related entries).
func (*Data) DeleteComments ¶
DeleteComments deletes a change suggestion from the public.
func (*Data) DeleteEntry ¶
DeleteEntry deletes a dictionary entry by its id.
func (*Data) DeleteRelation ¶
DeleteRelation deletes a dictionary entry by its id.
func (*Data) GetComments ¶
GetComments retrieves change submissions.
func (*Data) GetGlossaryWords ¶
func (d *Data) GetGlossaryWords(lang, initial string, offset, limit int) ([]GlossaryWord, int, error)
GetGlossaryWords gets words ordered by weight for a language to build a glossary.
func (*Data) GetInitials ¶
GetInitials gets the list of all unique initials (first character) across all the words for a given language.
func (*Data) GetParentEntries ¶
GetParentEntries returns the parent entries of an entry by its id.
func (*Data) GetPendingEntries ¶
func (d *Data) GetPendingEntries(lang string, tags pq.StringArray, offset, limit int) ([]Entry, int, error)
GetPendingEntries fetches entries based on the given condition.
func (*Data) InsertComments ¶
InsertComments inserts a change suggestion from the public.
func (*Data) InsertEntry ¶
InsertEntry inserts a new non-unique (content+lang) dictionary entry and returns its id.
func (*Data) InsertRelation ¶
InsertRelation adds a non-unique relation between to entries.
func (*Data) InsertSubmissionEntry ¶
InsertSubmissionEntry checks if a given content+lang exists and returns the existing ID. If it doesn't exist, a new entry is inserted and its ID is returned. This is used for accepting public submissions which are conntected to existing entries (if they exist).
func (*Data) InsertSubmissionRelation ¶
InsertRelation adds a relation between to entries only if a from_id+to_id+types relation doesn't already exist.
func (*Data) RejectSubmission ¶
RejectSubmission rejects a pending submission and deletes related pending entries.
func (*Data) ReorderRelations ¶
ReorderRelations updates the weights of the given relation IDs in the given order.
func (*Data) Search ¶
Search returns the entries filtered and paginated by a given Query along with the total number of matches in the database.
func (*Data) SearchAndLoadRelations ¶
SearchAndLoadRelations loads related entries into the given Entries.
func (*Data) UpdateEntry ¶
UpdateEntry updates a dictionary entry.
type Entry ¶
type Entry struct {
ID int `json:"id,omitempty" db:"id"`
GUID string `json:"guid" db:"guid"`
Weight float64 `json:"weight" db:"weight"`
Initial string `json:"initial" db:"initial"`
Lang string `json:"lang" db:"lang"`
Content string `json:"content" db:"content"`
Tokens string `json:"tokens" db:"tokens"`
Tags pq.StringArray `json:"tags" db:"tags"`
Phones pq.StringArray `json:"phones" db:"phones"`
Notes string `json:"notes" db:"notes"`
Status string `json:"status" db:"status"`
Relations []Entry `json:"relations,omitempty" db:"relations"`
Total int `json:"-" db:"total"`
CreatedAt null.Time `json:"created_at" db:"created_at"`
UpdatedAt null.Time `json:"updated_at" db:"updated_at"`
// Non-public fields for scanning relationship data and populating Relation.
FromID int `json:"-" db:"from_id"`
RelationID int `json:"-" db:"relation_id"`
RelationTypes pq.StringArray `json:"-" db:"relation_types"`
RelationTags pq.StringArray `json:"-" db:"relation_tags"`
RelationNotes string `json:"-" db:"relation_notes"`
RelationWeight float64 `json:"-" db:"relation_weight"`
RelationStatus string `json:"-" db:"relation_status"`
RelationCreatedAt null.Time `json:"-" db:"relation_created_at"`
RelationUpdatedAt null.Time `json:"-" db:"relation_updated_at"`
// RelationEntry encompasses an Entry with added fields that
// describes its relationship to other []Entry. This is only populated in
// []Entry in the Relations list.
Relation *Relation `json:"relation,omitempty"`
}
Entry represents a dictionary entry.
type GlossaryWord ¶
type GlossaryWord struct {
ID int `json:"id,omitempty" db:"id"`
Content string `json:"content" db:"content"`
Total int `json:"-" db:"total"`
}
GlossaryWord to read glosary content from db.
type Lang ¶
type Lang struct {
Name string `json:"name"`
Types map[string]string `json:"types"`
TokenizerName string `json:"tokenizer"`
TokenizerType string `json:"tokenizer_type"`
Tokenizer Tokenizer `json:"-"`
}
Lang represents a language's configuration.
type Queries ¶
type Queries struct {
Search *sqlx.Stmt `query:"search"`
SearchRelations *sqlx.Stmt `query:"search-relations"`
GetEntry *sqlx.Stmt `query:"get-entry"`
GetParentRelations *sqlx.Stmt `query:"get-parent-relations"`
GetInitials *sqlx.Stmt `query:"get-initials"`
GetGlossaryWords *sqlx.Stmt `query:"get-glossary-words"`
InsertEntry *sqlx.Stmt `query:"insert-entry"`
UpdateEntry *sqlx.Stmt `query:"update-entry"`
InsertRelation *sqlx.Stmt `query:"insert-relation"`
UpdateRelation *sqlx.Stmt `query:"update-relation"`
ReorderRelations *sqlx.Stmt `query:"reorder-relations"`
DeleteEntry *sqlx.Stmt `query:"delete-entry"`
DeleteRelation *sqlx.Stmt `query:"delete-relation"`
GetStats *sqlx.Stmt `query:"get-stats"`
GetPendingEntries *sqlx.Stmt `query:"get-pending-entries"`
InsertSubmissionEntry *sqlx.Stmt `query:"insert-submission-entry"`
InsertSubmissionRelation *sqlx.Stmt `query:"insert-submission-relation"`
InsertComments *sqlx.Stmt `query:"insert-comments"`
GetComments *sqlx.Stmt `query:"get-comments"`
DeleteComments *sqlx.Stmt `query:"delete-comments"`
ApproveSubmission *sqlx.Stmt `query:"approve-submission"`
RejectSubmission *sqlx.Stmt `query:"reject-submission"`
}
Queries contains prepared DB queries.
type Query ¶
type Query struct {
Query string `json:"query"`
FromLang string `json:"from_lang"`
ToLang string `json:"to_lang"`
Types []string `json:"types"`
Tags []string `json:"tags"`
Status string `json:"status"`
Offset int `json:"offset"`
Limit int `json:"limit"`
}
Query represents the parameters of a single search query.
type Relation ¶
type Relation struct {
ID int `json:"id,omitempty"`
Types pq.StringArray `json:"types"`
Tags pq.StringArray `json:"tags"`
Notes string `json:"notes"`
Weight float64 `json:"weight"`
Status string `json:"status"`
CreatedAt null.Time `json:"created_at"`
UpdatedAt null.Time `json:"updated_at"`
}
Relation represents the relationship between two IDs.
type Stats ¶
type Stats struct {
Entries int `json:"entries"`
Relations int `json:"relations"`
Languages map[string]int `json:"languages"`
}
Stats contains database statistics.
type Tokenizer ¶
type Tokenizer interface {
// Tokenize takes a string and tokenizes it into a list of tsvector tokens
// that can be stored in the database for fulltext search.
ToTokens(s string, lang string) ([]string, error)
// ToTSQuery takes a search string and returns a Postgres tsquery string,
// for example 'fat & cat`.
ToQuery(s string, lang string) (string, error)
}
Tokenizer represents a function that takes a string and returns a list of Postgres tsvector tokens.