Documentation
¶
Index ¶
- Variables
- func CalculateUUID(time time.Time) (ulid.ULID, error)
- func DeleteDocument(docULIDSt string, db Repository) error
- func FetchAllDocuments(db Repository) (*[]Document, error)
- func FetchConfigFromDB(db Repository) (config.ServerConfig, error)
- func UpdateDocumentField(docULIDSt string, field string, newValue interface{}, db Repository) (int, error)
- func WriteConfigToDB(serverConfig config.ServerConfig, db Repository)
- type Dimension
- type DimensionValue
- type DimensionWithValues
- type Document
- func AddNewDocument(filePath string, fullText string, db Repository) (*Document, error)
- func FetchDocument(docULIDSt string, db Repository) (Document, int, error)
- func FetchDocumentFromPath(path string, db Repository) (Document, error)
- func FetchDocuments(docULIDSt []string, db Repository) ([]Document, int, error)
- func FetchFolder(folderName string, db Repository) ([]Document, error)
- func FetchNewestDocuments(numberOf int, db Repository) ([]Document, error)
- type DocumentDimension
- type DocumentMetadataUpdate
- type DocumentTag
- type DocumentTagsAndDimensions
- type DocumentWithTagsAndDimensions
- type EphemeralPostgresDB
- type Job
- type JobStatus
- type JobSummary
- type JobType
- type MemDB
- func (m *MemDB) AddDocumentToStory(documentID int, storyID int) error
- func (m *MemDB) AddStoryTag(storyID int, tagID int) error
- func (m *MemDB) AddTagToDocument(documentID int, tagID int) error
- func (m *MemDB) CancelJob(jobID ulid.ULID) error
- func (m *MemDB) Close() error
- func (m *MemDB) CompleteJob(jobID ulid.ULID, result string) error
- func (m *MemDB) ConvertStoryToTag(storyID int) error
- func (m *MemDB) ConvertTagToStory(tagID int) (*Story, error)
- func (m *MemDB) CreateJob(jobType JobType, message string) (*Job, error)
- func (m *MemDB) CreateSavedSearch(search *SavedSearch) error
- func (m *MemDB) CreateStory(story *Story) error
- func (m *MemDB) CreateTag(tag *Tag) error
- func (m *MemDB) DeleteDocument(ulidStr string) error
- func (m *MemDB) DeleteOldJobs(olderThan time.Duration) (int, error)
- func (m *MemDB) DeleteSavedSearch(id int) error
- func (m *MemDB) DeleteStory(id int) error
- func (m *MemDB) DeleteTag(id int) error
- func (m *MemDB) ExecuteSearch(parsed *ParsedSearch, page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (m *MemDB) GetActiveJobs() ([]Job, error)
- func (m *MemDB) GetAllDimensions() ([]Dimension, error)
- func (m *MemDB) GetAllDocuments() ([]Document, error)
- func (m *MemDB) GetAllSavedSearches() ([]SavedSearch, error)
- func (m *MemDB) GetAllStories() ([]Story, error)
- func (m *MemDB) GetAllTagAliases() ([]TagAliasEntry, error)
- func (m *MemDB) GetAllTags() ([]Tag, error)
- func (m *MemDB) GetArchivedDocuments(page, pageSize int) ([]Document, int, error)
- func (m *MemDB) GetConfig() (*config.ServerConfig, error)
- func (m *MemDB) GetDimensionByID(id int) (*Dimension, error)
- func (m *MemDB) GetDimensionByName(name string) (*Dimension, error)
- func (m *MemDB) GetDimensionValueByValue(dimensionID int, value string) (*DimensionValue, error)
- func (m *MemDB) GetDimensionValues(dimensionID int) ([]DimensionValue, error)
- func (m *MemDB) GetDocumentByHash(hash string) (*Document, error)
- func (m *MemDB) GetDocumentByID(id int) (*Document, error)
- func (m *MemDB) GetDocumentByPath(path string) (*Document, error)
- func (m *MemDB) GetDocumentByULID(ulidStr string) (*Document, error)
- func (m *MemDB) GetDocumentDimensions(documentID int) (map[string]DimensionValue, error)
- func (m *MemDB) GetDocumentsByFolder(folder string) ([]Document, error)
- func (m *MemDB) GetDocumentsByTag(tagID int, page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (m *MemDB) GetDocumentsWithoutStory(page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (m *MemDB) GetJob(jobID ulid.ULID) (*Job, error)
- func (m *MemDB) GetNewestDocuments(limit int) ([]Document, error)
- func (m *MemDB) GetNewestDocumentsWithPagination(page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (m *MemDB) GetRecentJobs(limit, offset int) ([]Job, error)
- func (m *MemDB) GetSavedSearchByID(id int) (*SavedSearch, error)
- func (m *MemDB) GetSchemaVersion() (string, error)
- func (m *MemDB) GetStoriesWithMeta() ([]StoryWithMeta, error)
- func (m *MemDB) GetStoryByID(id int) (*Story, error)
- func (m *MemDB) GetStoryByTagID(tagID int) (*Story, error)
- func (m *MemDB) GetStoryTags(storyID int) ([]Tag, error)
- func (m *MemDB) GetTagByID(id int) (*Tag, error)
- func (m *MemDB) GetTagByName(name string) (*Tag, error)
- func (m *MemDB) GetTagGroups() ([]string, error)
- func (m *MemDB) GetTagUsageCount(tagID int) (int, error)
- func (m *MemDB) GetTaggedDocuments(page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (m *MemDB) GetTagsForDocument(documentID int) ([]Tag, error)
- func (m *MemDB) GetTopTagsByUsage(limit int) ([]TagWithCount, error)
- func (m *MemDB) GetTopWords(limit int) ([]WordFrequency, error)
- func (m *MemDB) GetUntaggedDocuments(page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (m *MemDB) GetWordCloudMetadata() (*WordCloudMetadata, error)
- func (m *MemDB) InsertTagAlias(tagID int, aliasName string) error
- func (m *MemDB) RecalculateAllWordFrequencies() error
- func (m *MemDB) RecoverStuckJobs(stuckThreshold time.Duration) (int, error)
- func (m *MemDB) ReindexSearchDocuments() (int, error)
- func (m *MemDB) RemoveDocumentDimension(documentID int, dimensionID int) error
- func (m *MemDB) RemoveDocumentFromStory(documentID int, storyID int) error
- func (m *MemDB) RemoveStoryTag(storyID int, tagID int) error
- func (m *MemDB) RemoveTagFromDocument(documentID int, tagID int) error
- func (m *MemDB) SaveConfig(cfg *config.ServerConfig) error
- func (m *MemDB) SaveDocument(doc *Document) error
- func (m *MemDB) SearchDocuments(searchTerm string) ([]Document, error)
- func (m *MemDB) SetDocumentDimension(documentID int, dimensionID int, dimensionValueID int) error
- func (m *MemDB) UpdateDocumentArchiveStatus(ulidStr string, status *string, archivedAt *time.Time) error
- func (m *MemDB) UpdateDocumentDate(ulidStr string, date *time.Time) error
- func (m *MemDB) UpdateDocumentFolder(ulidStr string, folder string) error
- func (m *MemDB) UpdateDocumentFullText(ulidStr string, text string) error
- func (m *MemDB) UpdateDocumentMetadata(ulidStr string, meta DocumentMetadataUpdate) error
- func (m *MemDB) UpdateDocumentPath(ulidStr string, path string, folder string) error
- func (m *MemDB) UpdateDocumentURL(ulidStr string, url string) error
- func (m *MemDB) UpdateJobError(jobID ulid.ULID, errorMsg string) error
- func (m *MemDB) UpdateJobProgress(jobID ulid.ULID, progress int, currentStep string) error
- func (m *MemDB) UpdateJobStatus(jobID ulid.ULID, status JobStatus, message string) error
- func (m *MemDB) UpdateSavedSearch(search *SavedSearch) error
- func (m *MemDB) UpdateStory(story *Story) error
- func (m *MemDB) UpdateTag(tag *Tag) error
- func (m *MemDB) UpdateWordFrequencies(docID string) error
- type PGDB
- func (p *PGDB) AddDocumentToStory(documentID int, storyID int) error
- func (p *PGDB) AddStoryTag(storyID int, tagID int) error
- func (p *PGDB) AddTagToDocument(documentID int, tagID int) error
- func (p *PGDB) CancelJob(jobID ulid.ULID) error
- func (p *PGDB) Close() error
- func (p *PGDB) CompleteJob(jobID ulid.ULID, result string) error
- func (p *PGDB) ConvertStoryToTag(storyID int) error
- func (p *PGDB) ConvertTagToStory(tagID int) (*Story, error)
- func (p *PGDB) CreateJob(jobType JobType, message string) (*Job, error)
- func (p *PGDB) CreateSavedSearch(search *SavedSearch) error
- func (p *PGDB) CreateStory(story *Story) error
- func (p *PGDB) CreateTag(tag *Tag) error
- func (p *PGDB) DeleteDocument(ulidStr string) error
- func (p *PGDB) DeleteOldJobs(olderThan time.Duration) (int, error)
- func (p *PGDB) DeleteSavedSearch(id int) error
- func (p *PGDB) DeleteStory(id int) error
- func (p *PGDB) DeleteTag(id int) error
- func (p *PGDB) ExecuteSearch(parsed *ParsedSearch, page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (p *PGDB) GetActiveJobs() ([]Job, error)
- func (p *PGDB) GetAllDimensions() ([]Dimension, error)
- func (p *PGDB) GetAllDocuments() ([]Document, error)
- func (p *PGDB) GetAllSavedSearches() ([]SavedSearch, error)
- func (p *PGDB) GetAllStories() ([]Story, error)
- func (p *PGDB) GetAllTagAliases() ([]TagAliasEntry, error)
- func (p *PGDB) GetAllTags() ([]Tag, error)
- func (p *PGDB) GetArchivedDocuments(page, pageSize int) ([]Document, int, error)
- func (p *PGDB) GetConfig() (*config.ServerConfig, error)
- func (p *PGDB) GetDimensionByID(id int) (*Dimension, error)
- func (p *PGDB) GetDimensionByName(name string) (*Dimension, error)
- func (p *PGDB) GetDimensionValueByValue(dimensionID int, value string) (*DimensionValue, error)
- func (p *PGDB) GetDimensionValues(dimensionID int) ([]DimensionValue, error)
- func (p *PGDB) GetDocumentByHash(hash string) (*Document, error)
- func (p *PGDB) GetDocumentByID(id int) (*Document, error)
- func (p *PGDB) GetDocumentByPath(path string) (*Document, error)
- func (p *PGDB) GetDocumentByULID(ulidStr string) (*Document, error)
- func (p *PGDB) GetDocumentDimensions(documentID int) (map[string]DimensionValue, error)
- func (p *PGDB) GetDocumentsByFolder(folder string) ([]Document, error)
- func (p *PGDB) GetDocumentsByTag(tagID int, page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (p *PGDB) GetDocumentsWithoutStory(page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (p *PGDB) GetJob(jobID ulid.ULID) (*Job, error)
- func (p *PGDB) GetNewestDocuments(limit int) ([]Document, error)
- func (p *PGDB) GetNewestDocumentsWithPagination(page int, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (p *PGDB) GetRecentJobs(limit, offset int) ([]Job, error)
- func (p *PGDB) GetSavedSearchByID(id int) (*SavedSearch, error)
- func (p *PGDB) GetSchemaVersion() (string, error)
- func (p *PGDB) GetStoriesWithMeta() ([]StoryWithMeta, error)
- func (p *PGDB) GetStoryByID(id int) (*Story, error)
- func (p *PGDB) GetStoryByTagID(tagID int) (*Story, error)
- func (p *PGDB) GetStoryTags(storyID int) ([]Tag, error)
- func (p *PGDB) GetTagByID(id int) (*Tag, error)
- func (p *PGDB) GetTagByName(name string) (*Tag, error)
- func (p *PGDB) GetTagGroups() ([]string, error)
- func (p *PGDB) GetTagUsageCount(tagID int) (int, error)
- func (p *PGDB) GetTaggedDocuments(page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (p *PGDB) GetTagsForDocument(documentID int) ([]Tag, error)
- func (p *PGDB) GetTopTagsByUsage(limit int) ([]TagWithCount, error)
- func (p *PGDB) GetTopWords(limit int) ([]WordFrequency, error)
- func (p *PGDB) GetUntaggedDocuments(page, pageSize int, showHidden ...bool) ([]Document, int, error)
- func (p *PGDB) GetWordCloudMetadata() (*WordCloudMetadata, error)
- func (p *PGDB) InsertTagAlias(tagID int, aliasName string) error
- func (p *PGDB) RecalculateAllWordFrequencies() error
- func (p *PGDB) RecoverStuckJobs(stuckThreshold time.Duration) (int, error)
- func (p *PGDB) ReindexSearchDocuments() (int, error)
- func (p *PGDB) RemoveDocumentDimension(documentID int, dimensionID int) error
- func (p *PGDB) RemoveDocumentFromStory(documentID int, storyID int) error
- func (p *PGDB) RemoveStoryTag(storyID int, tagID int) error
- func (p *PGDB) RemoveTagFromDocument(documentID int, tagID int) error
- func (p *PGDB) SaveConfig(cfg *config.ServerConfig) error
- func (p *PGDB) SaveDocument(doc *Document) error
- func (p *PGDB) SearchDocuments(searchTerm string) ([]Document, error)
- func (p *PGDB) SetDocumentDimension(documentID int, dimensionID int, dimensionValueID int) error
- func (p *PGDB) UpdateDocumentArchiveStatus(ulidStr string, status *string, archivedAt *time.Time) error
- func (p *PGDB) UpdateDocumentDate(ulidStr string, date *time.Time) error
- func (p *PGDB) UpdateDocumentFolder(ulidStr string, folder string) error
- func (p *PGDB) UpdateDocumentFullText(ulidStr string, text string) error
- func (p *PGDB) UpdateDocumentMetadata(ulidStr string, meta DocumentMetadataUpdate) error
- func (p *PGDB) UpdateDocumentPath(ulidStr string, path string, folder string) error
- func (p *PGDB) UpdateDocumentURL(ulidStr string, url string) error
- func (p *PGDB) UpdateJobError(jobID ulid.ULID, errorMsg string) error
- func (p *PGDB) UpdateJobProgress(jobID ulid.ULID, progress int, currentStep string) error
- func (p *PGDB) UpdateJobStatus(jobID ulid.ULID, status JobStatus, message string) error
- func (p *PGDB) UpdateSavedSearch(search *SavedSearch) error
- func (p *PGDB) UpdateStory(story *Story) error
- func (p *PGDB) UpdateTag(tag *Tag) error
- func (p *PGDB) UpdateWordFrequencies(docID string) error
- type ParsedSearch
- type Repository
- type SavedSearch
- type SavedSearchWithCount
- type SearchResult
- type Story
- type StoryWithMeta
- type Tag
- type TagAliasEntry
- type TagWithCount
- type WordCloudMetadata
- type WordFrequency
- type WordTokenizer
Constants ¶
This section is empty.
Variables ¶
var Logger *slog.Logger
Logger is global since we will need it everywhere
Functions ¶
func CalculateUUID ¶
CalculateUUID for the incoming file
func DeleteDocument ¶
func DeleteDocument(docULIDSt string, db Repository) error
DeleteDocument fetches the requested document by ULID
func FetchAllDocuments ¶
func FetchAllDocuments(db Repository) (*[]Document, error)
FetchAllDocuments fetches all the documents in the database
func FetchConfigFromDB ¶
func FetchConfigFromDB(db Repository) (config.ServerConfig, error)
FetchConfigFromDB pulls the server config from the database
func UpdateDocumentField ¶
func UpdateDocumentField(docULIDSt string, field string, newValue interface{}, db Repository) (int, error)
UpdateDocumentField updates a single field in a document
func WriteConfigToDB ¶
func WriteConfigToDB(serverConfig config.ServerConfig, db Repository)
WriteConfigToDB writes the serverconfig to the database for later retrieval
Types ¶
type Dimension ¶
type Dimension struct {
ID int `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Description string `json:"description,omitempty"`
DimensionType string `json:"dimension_type"` // 'single' or 'multiple'
IsRequired bool `json:"is_required"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Dimension represents a structured metadata category (e.g., Person, Location)
type DimensionValue ¶
type DimensionValue struct {
ID int `json:"id"`
DimensionID int `json:"dimension_id"`
Value string `json:"value"`
DisplayName string `json:"display_name"`
Description string `json:"description,omitempty"`
Color string `json:"color"`
SortOrder int `json:"sort_order"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
DimensionValue represents an allowed value for a dimension
type DimensionWithValues ¶
type DimensionWithValues struct {
Dimension
Values []DimensionValue `json:"values"`
}
DimensionWithValues includes the dimension and its possible values
type Document ¶
type Document struct {
ID int `json:"id"`
Name string `json:"name"`
Path string `json:"path"` // full path to the file
IngressTime time.Time `json:"ingress_time"`
Folder string `json:"folder"`
Hash string `json:"hash"`
ULID ulid.ULID `json:"ulid"` // Have a smaller (than hash) id that can be used in URL's, hopefully speed things up
DocumentType string `json:"document_type"` // type of document (pdf, txt, etc)
FullText string `json:"full_text"`
URL string `json:"url"`
DocumentDate *time.Time `json:"document_date,omitempty"` // user-assigned document date (e.g. invoice date)
CreatedDate *time.Time `json:"created_date,omitempty"` // original creation date from source
UpdatedDate *time.Time `json:"updated_date,omitempty"` // original modification date from source
Author string `json:"author,omitempty"` // note author
SourceURL string `json:"source_url,omitempty"` // original source URL
Source string `json:"source,omitempty"` // source system (e.g. "evernote")
ArchiveStatus *string `json:"archive_status,omitempty"` // nil=active, "pending", "archived"
ArchivedAt *time.Time `json:"archived_at,omitempty"` // when archival began
}
Document is all of the document information stored in the database
func AddNewDocument ¶
func AddNewDocument(filePath string, fullText string, db Repository) (*Document, error)
AddNewDocument adds a new document to the database
func FetchDocument ¶
func FetchDocument(docULIDSt string, db Repository) (Document, int, error)
FetchDocument fetches the requested document by ULID
func FetchDocumentFromPath ¶
func FetchDocumentFromPath(path string, db Repository) (Document, error)
FetchDocumentFromPath fetches the document by document path
func FetchDocuments ¶
func FetchDocuments(docULIDSt []string, db Repository) ([]Document, int, error)
FetchDocuments fetches an array of documents // TODO: Not fucking needed?
func FetchFolder ¶
func FetchFolder(folderName string, db Repository) ([]Document, error)
FetchFolder grabs all of the documents contained in a folder
func FetchNewestDocuments ¶
func FetchNewestDocuments(numberOf int, db Repository) ([]Document, error)
FetchNewestDocuments fetches the documents that were added last
type DocumentDimension ¶
type DocumentDimension struct {
ID int `json:"id"`
DocumentID int `json:"document_id"`
DimensionID int `json:"dimension_id"`
DimensionValueID int `json:"dimension_value_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
DocumentDimension represents a dimension value assigned to a document
type DocumentMetadataUpdate ¶
type DocumentMetadataUpdate struct {
CreatedDate *time.Time `json:"created_date,omitempty"`
UpdatedDate *time.Time `json:"updated_date,omitempty"`
Author *string `json:"author,omitempty"`
SourceURL *string `json:"source_url,omitempty"`
Source *string `json:"source,omitempty"`
}
DocumentMetadataUpdate holds optional fields for bulk metadata update via API. Pointer fields are omitted from the update when nil.
type DocumentTag ¶
type DocumentTag struct {
DocumentID int `json:"document_id"`
TagID int `json:"tag_id"`
CreatedAt time.Time `json:"created_at"`
}
DocumentTag represents the many-to-many relationship between documents and tags
type DocumentTagsAndDimensions ¶
type DocumentTagsAndDimensions struct {
Tags []string `json:"tags"` // Free tags (no group)
TagGroups map[string]string `json:"tag_groups,omitempty"` // group_name -> tag_name (one per group)
}
DocumentTagsAndDimensions is a helper struct for JSON sidecar files
type DocumentWithTagsAndDimensions ¶
type DocumentWithTagsAndDimensions struct {
Document
Tags []Tag `json:"tags"`
Dimensions map[string]DimensionValue `json:"dimensions"` // dimension_name -> value
}
DocumentWithTagsAndDimensions extends Document with its tags and dimensions
type EphemeralPostgresDB ¶
type EphemeralPostgresDB struct {
*PGDB
// contains filtered or unexported fields
}
EphemeralPostgresDB wraps PGDB with an ephemeral PostgreSQL server for testing
type Job ¶
type Job struct {
ID ulid.ULID `json:"id"`
Type JobType `json:"type"`
Status JobStatus `json:"status"`
Progress int `json:"progress"` // 0-100
CurrentStep string `json:"currentStep"` // Human-readable current step
TotalSteps int `json:"totalSteps"` // Total number of steps
Message string `json:"message"` // Status message
Error string `json:"error,omitempty"` // Error message if failed
Result string `json:"result,omitempty"` // JSON result data
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
StartedAt *time.Time `json:"startedAt,omitempty"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
}
Job represents a background job or operation
type JobSummary ¶
type JobSummary struct {
FilesProcessed int `json:"filesProcessed"`
FilesTotal int `json:"filesTotal"`
BytesProcessed int64 `json:"bytesProcessed"`
Errors int `json:"errors"`
Details string `json:"details,omitempty"`
}
JobSummary provides summary statistics for a job
type MemDB ¶
type MemDB struct {
// contains filtered or unexported fields
}
MemDB is a pure in-memory Repository implementation for WASM demos and testing. It requires no external dependencies (no SQL driver, no CGo).
func (*MemDB) AddDocumentToStory ¶
func (*MemDB) ConvertStoryToTag ¶
func (*MemDB) CreateSavedSearch ¶
func (m *MemDB) CreateSavedSearch(search *SavedSearch) error
func (*MemDB) CreateStory ¶
func (*MemDB) DeleteDocument ¶
func (*MemDB) DeleteSavedSearch ¶
func (*MemDB) DeleteStory ¶
func (*MemDB) ExecuteSearch ¶
func (*MemDB) GetActiveJobs ¶
func (*MemDB) GetAllDimensions ¶
func (*MemDB) GetAllDocuments ¶
func (*MemDB) GetAllSavedSearches ¶
func (m *MemDB) GetAllSavedSearches() ([]SavedSearch, error)
func (*MemDB) GetAllStories ¶
func (*MemDB) GetAllTagAliases ¶
func (m *MemDB) GetAllTagAliases() ([]TagAliasEntry, error)
func (*MemDB) GetAllTags ¶
func (*MemDB) GetArchivedDocuments ¶
func (*MemDB) GetDimensionByName ¶
func (*MemDB) GetDimensionValueByValue ¶
func (m *MemDB) GetDimensionValueByValue(dimensionID int, value string) (*DimensionValue, error)
func (*MemDB) GetDimensionValues ¶
func (m *MemDB) GetDimensionValues(dimensionID int) ([]DimensionValue, error)
func (*MemDB) GetDocumentByULID ¶
func (*MemDB) GetDocumentDimensions ¶
func (m *MemDB) GetDocumentDimensions(documentID int) (map[string]DimensionValue, error)
func (*MemDB) GetDocumentsByFolder ¶
func (*MemDB) GetDocumentsByTag ¶
func (*MemDB) GetDocumentsWithoutStory ¶
func (*MemDB) GetNewestDocuments ¶
func (*MemDB) GetNewestDocumentsWithPagination ¶
func (*MemDB) GetSavedSearchByID ¶
func (m *MemDB) GetSavedSearchByID(id int) (*SavedSearch, error)
func (*MemDB) GetSchemaVersion ¶
func (*MemDB) GetStoriesWithMeta ¶
func (m *MemDB) GetStoriesWithMeta() ([]StoryWithMeta, error)
func (*MemDB) GetTagGroups ¶
func (*MemDB) GetTaggedDocuments ¶
func (*MemDB) GetTagsForDocument ¶
func (*MemDB) GetTopTagsByUsage ¶
func (m *MemDB) GetTopTagsByUsage(limit int) ([]TagWithCount, error)
func (*MemDB) GetTopWords ¶
func (m *MemDB) GetTopWords(limit int) ([]WordFrequency, error)
func (*MemDB) GetUntaggedDocuments ¶
func (*MemDB) GetWordCloudMetadata ¶
func (m *MemDB) GetWordCloudMetadata() (*WordCloudMetadata, error)
func (*MemDB) RecalculateAllWordFrequencies ¶
func (*MemDB) RecoverStuckJobs ¶
func (*MemDB) ReindexSearchDocuments ¶
func (*MemDB) RemoveDocumentDimension ¶
func (*MemDB) RemoveDocumentFromStory ¶
func (*MemDB) RemoveTagFromDocument ¶
func (*MemDB) SaveConfig ¶
func (m *MemDB) SaveConfig(cfg *config.ServerConfig) error
func (*MemDB) SaveDocument ¶
func (*MemDB) SearchDocuments ¶
func (*MemDB) SetDocumentDimension ¶
func (*MemDB) UpdateDocumentArchiveStatus ¶
func (*MemDB) UpdateDocumentDate ¶
func (*MemDB) UpdateDocumentFolder ¶
func (*MemDB) UpdateDocumentFullText ¶
func (*MemDB) UpdateDocumentMetadata ¶
func (m *MemDB) UpdateDocumentMetadata(ulidStr string, meta DocumentMetadataUpdate) error
func (*MemDB) UpdateDocumentPath ¶
func (*MemDB) UpdateDocumentURL ¶
func (*MemDB) UpdateJobError ¶
func (*MemDB) UpdateJobProgress ¶
func (*MemDB) UpdateJobStatus ¶
func (*MemDB) UpdateSavedSearch ¶
func (m *MemDB) UpdateSavedSearch(search *SavedSearch) error
func (*MemDB) UpdateStory ¶
func (*MemDB) UpdateWordFrequencies ¶
type PGDB ¶
type PGDB struct {
// contains filtered or unexported fields
}
PGDB implements Repository using database/sql with raw PostgreSQL SQL. For production it connects via lib/pq; for dev/testing via go-postgres ("pglike") which transparently translates PostgreSQL SQL to SQLite.
func NewRepository ¶
func NewRepository(cfg config.ServerConfig) *PGDB
NewRepository initializes the database based on configuration
func SetupEphemeralPostgresDatabase ¶
SetupEphemeralPostgresDatabase creates an ephemeral PostgreSQL instance
func (*PGDB) AddDocumentToStory ¶
AddDocumentToStory adds the story's tag (and all associated tags) to a document.
func (*PGDB) AddStoryTag ¶
AddStoryTag adds an associated tag to a story.
func (*PGDB) AddTagToDocument ¶
AddTagToDocument associates a tag with a document
func (*PGDB) CompleteJob ¶
CompleteJob marks a job as completed with optional result data
func (*PGDB) ConvertStoryToTag ¶
ConvertStoryToTag removes the story but keeps the tag and all document associations. Clears the tag's "Story" group.
func (*PGDB) ConvertTagToStory ¶
ConvertTagToStory creates a story from an existing tag. Sets the tag's group to "Story" and creates a story row linked to it.
func (*PGDB) CreateSavedSearch ¶
func (p *PGDB) CreateSavedSearch(search *SavedSearch) error
CreateSavedSearch creates a new saved search
func (*PGDB) CreateStory ¶
CreateStory creates a new story and its associated tag in a transaction. The tag is created with tag_group='Story' and name derived from the title.
func (*PGDB) DeleteDocument ¶
DeleteDocument deletes a document by ULID
func (*PGDB) DeleteOldJobs ¶
DeleteOldJobs deletes completed jobs older than the specified duration
func (*PGDB) DeleteSavedSearch ¶
DeleteSavedSearch deletes a saved search by ID
func (*PGDB) DeleteStory ¶
DeleteStory deletes a story and its associated tag (cascade cleans document_tags).
func (*PGDB) ExecuteSearch ¶
func (p *PGDB) ExecuteSearch(parsed *ParsedSearch, page, pageSize int, showHidden ...bool) ([]Document, int, error)
ExecuteSearch executes a parsed search query and returns paginated results
func (*PGDB) GetActiveJobs ¶
GetActiveJobs retrieves all running or pending jobs
func (*PGDB) GetAllDimensions ¶
GetAllDimensions returns all dimension definitions
func (*PGDB) GetAllDocuments ¶
GetAllDocuments retrieves all documents
func (*PGDB) GetAllSavedSearches ¶
func (p *PGDB) GetAllSavedSearches() ([]SavedSearch, error)
GetAllSavedSearches returns all saved searches sorted by sort_order
func (*PGDB) GetAllStories ¶
GetAllStories returns all stories ordered by start_date descending.
func (*PGDB) GetAllTagAliases ¶
func (p *PGDB) GetAllTagAliases() ([]TagAliasEntry, error)
GetAllTagAliases returns all tag aliases with resolved tag names
func (*PGDB) GetAllTags ¶
GetAllTags returns all tags sorted by group and sort_order Uses CASE WHEN workaround for NULLS FIRST (not yet supported by go-postgres)
func (*PGDB) GetArchivedDocuments ¶
GetArchivedDocuments returns paginated documents with non-null archive_status.
func (*PGDB) GetConfig ¶
func (p *PGDB) GetConfig() (*config.ServerConfig, error)
GetConfig retrieves server configuration
func (*PGDB) GetDimensionByID ¶
GetDimensionByID returns a dimension by its ID
func (*PGDB) GetDimensionByName ¶
GetDimensionByName returns a dimension by its name
func (*PGDB) GetDimensionValueByValue ¶
func (p *PGDB) GetDimensionValueByValue(dimensionID int, value string) (*DimensionValue, error)
GetDimensionValueByValue returns a dimension value by dimension ID and value string
func (*PGDB) GetDimensionValues ¶
func (p *PGDB) GetDimensionValues(dimensionID int) ([]DimensionValue, error)
GetDimensionValues returns all possible values for a dimension
func (*PGDB) GetDocumentByHash ¶
GetDocumentByHash retrieves a document by hash
func (*PGDB) GetDocumentByID ¶
GetDocumentByID retrieves a document by ID
func (*PGDB) GetDocumentByPath ¶
GetDocumentByPath retrieves a document by file path
func (*PGDB) GetDocumentByULID ¶
GetDocumentByULID retrieves a document by ULID
func (*PGDB) GetDocumentDimensions ¶
func (p *PGDB) GetDocumentDimensions(documentID int) (map[string]DimensionValue, error)
GetDocumentDimensions returns all dimension values assigned to a document
func (*PGDB) GetDocumentsByFolder ¶
GetDocumentsByFolder retrieves documents in a specific folder
func (*PGDB) GetDocumentsByTag ¶
func (p *PGDB) GetDocumentsByTag(tagID int, page, pageSize int, showHidden ...bool) ([]Document, int, error)
GetDocumentsByTag returns paginated documents that have a specific tag
func (*PGDB) GetDocumentsWithoutStory ¶
func (p *PGDB) GetDocumentsWithoutStory(page, pageSize int, showHidden ...bool) ([]Document, int, error)
GetDocumentsWithoutStory returns documents that don't belong to any story, paginated and ordered by newest first.
func (*PGDB) GetNewestDocuments ¶
GetNewestDocuments retrieves the newest documents
func (*PGDB) GetNewestDocumentsWithPagination ¶
func (p *PGDB) GetNewestDocumentsWithPagination(page int, pageSize int, showHidden ...bool) ([]Document, int, error)
GetNewestDocumentsWithPagination retrieves documents with pagination support
func (*PGDB) GetRecentJobs ¶
GetRecentJobs retrieves the most recent jobs with pagination
func (*PGDB) GetSavedSearchByID ¶
func (p *PGDB) GetSavedSearchByID(id int) (*SavedSearch, error)
GetSavedSearchByID returns a saved search by its ID
func (*PGDB) GetSchemaVersion ¶
GetSchemaVersion returns the latest applied migration version
func (*PGDB) GetStoriesWithMeta ¶
func (p *PGDB) GetStoriesWithMeta() ([]StoryWithMeta, error)
GetStoriesWithMeta returns all stories with their tags, associated tags, and document counts.
func (*PGDB) GetStoryByID ¶
GetStoryByID returns a story by its ID.
func (*PGDB) GetStoryByTagID ¶
GetStoryByTagID returns a story by its tag ID.
func (*PGDB) GetStoryTags ¶
GetStoryTags returns the associated tags for a story (from story_tags junction).
func (*PGDB) GetTagByID ¶
GetTagByID returns a tag by its ID
func (*PGDB) GetTagByName ¶
GetTagByName returns a tag by its name, falling back to alias lookup
func (*PGDB) GetTagGroups ¶
GetTagGroups returns all distinct tag group names
func (*PGDB) GetTagUsageCount ¶
GetTagUsageCount returns the number of documents using a specific tag
func (*PGDB) GetTaggedDocuments ¶
GetTaggedDocuments returns paginated documents that have at least one tag
func (*PGDB) GetTagsForDocument ¶
GetTagsForDocument returns all tags associated with a document
func (*PGDB) GetTopTagsByUsage ¶
func (p *PGDB) GetTopTagsByUsage(limit int) ([]TagWithCount, error)
GetTopTagsByUsage returns the most-used tags sorted by document count descending.
func (*PGDB) GetTopWords ¶
func (p *PGDB) GetTopWords(limit int) ([]WordFrequency, error)
GetTopWords retrieves the top N most frequent words
func (*PGDB) GetUntaggedDocuments ¶
func (p *PGDB) GetUntaggedDocuments(page, pageSize int, showHidden ...bool) ([]Document, int, error)
GetUntaggedDocuments returns paginated documents that have no tags
func (*PGDB) GetWordCloudMetadata ¶
func (p *PGDB) GetWordCloudMetadata() (*WordCloudMetadata, error)
GetWordCloudMetadata retrieves metadata about the word cloud
func (*PGDB) InsertTagAlias ¶
InsertTagAlias inserts a tag alias (does nothing on conflict)
func (*PGDB) RecalculateAllWordFrequencies ¶
RecalculateAllWordFrequencies performs a full recalculation of word frequencies
func (*PGDB) RecoverStuckJobs ¶
func (*PGDB) ReindexSearchDocuments ¶
ReindexSearchDocuments reindexes all documents for full-text search
func (*PGDB) RemoveDocumentDimension ¶
RemoveDocumentDimension removes a dimension value from a document
func (*PGDB) RemoveDocumentFromStory ¶
RemoveDocumentFromStory removes only the story tag from a document. Associated tags remain (they were applied upfront).
func (*PGDB) RemoveStoryTag ¶
RemoveStoryTag removes an associated tag from a story.
func (*PGDB) RemoveTagFromDocument ¶
RemoveTagFromDocument removes a tag association from a document
func (*PGDB) SaveConfig ¶
func (p *PGDB) SaveConfig(cfg *config.ServerConfig) error
SaveConfig saves server configuration
func (*PGDB) SaveDocument ¶
SaveDocument saves or updates a document
func (*PGDB) SearchDocuments ¶
SearchDocuments performs full-text search
func (*PGDB) SetDocumentDimension ¶
SetDocumentDimension sets a dimension value for a document (replaces existing)
func (*PGDB) UpdateDocumentArchiveStatus ¶
func (p *PGDB) UpdateDocumentArchiveStatus(ulidStr string, status *string, archivedAt *time.Time) error
UpdateDocumentArchiveStatus sets the archive_status and archived_at fields.
func (*PGDB) UpdateDocumentDate ¶
UpdateDocumentDate updates the document_date field of a document
func (*PGDB) UpdateDocumentFolder ¶
UpdateDocumentFolder updates the Folder field of a document
func (*PGDB) UpdateDocumentFullText ¶
UpdateDocumentFullText updates the full_text field of a document
func (*PGDB) UpdateDocumentMetadata ¶
func (p *PGDB) UpdateDocumentMetadata(ulidStr string, meta DocumentMetadataUpdate) error
UpdateDocumentMetadata updates multiple metadata fields in a single query. Only non-nil fields in the update struct are applied.
func (*PGDB) UpdateDocumentPath ¶
UpdateDocumentPath updates the path and folder fields of a document
func (*PGDB) UpdateDocumentURL ¶
UpdateDocumentURL updates the URL field of a document
func (*PGDB) UpdateJobError ¶
UpdateJobError updates a job with an error
func (*PGDB) UpdateJobProgress ¶
UpdateJobProgress updates the progress of a job
func (*PGDB) UpdateJobStatus ¶
UpdateJobStatus updates the status of a job
func (*PGDB) UpdateSavedSearch ¶
func (p *PGDB) UpdateSavedSearch(search *SavedSearch) error
UpdateSavedSearch updates an existing saved search
func (*PGDB) UpdateStory ¶
UpdateStory updates a story's title, description, dates, and syncs tag name/color.
func (*PGDB) UpdateTag ¶
UpdateTag updates an existing tag. If the name changed, the old name is saved as an alias so that .tags.json sidecars with the old name still resolve.
func (*PGDB) UpdateWordFrequencies ¶
UpdateWordFrequencies updates word frequencies after document ingestion
type ParsedSearch ¶
type ParsedSearch struct {
TextTerms string // Free text to search for
IncludeTags []string // Tags to include (prefixed with #)
ExcludeTags []string // Tags to exclude (prefixed with ~)
IsUntagged bool // Special: show only untagged documents
IsTagged bool // Special: show only tagged documents
IsAllDocs bool // Special: show all documents
AfterDate *time.Time // Filter: document_date >= this (inclusive)
BeforeDate *time.Time // Filter: document_date <= this (inclusive)
}
ParsedSearch represents a parsed search query
func ParseSearchQuery ¶
func ParseSearchQuery(query string) *ParsedSearch
ParseSearchQuery parses a unified search query string Syntax:
- text: full-text search terms
- #tagname: include documents with this tag
- ~tagname: exclude documents with this tag
- Special: "*" means all documents
- Special: "!untagged" means only untagged documents
Examples:
- "cancer" -> text search for "cancer"
- "#Invoice" -> documents with Invoice tag
- "~2025" -> documents without 2025 tag
- "cancer #Invoice ~Draft" -> text "cancer", has Invoice, no Draft
type Repository ¶
type Repository interface {
Close() error
SaveDocument(doc *Document) error
GetDocumentByID(id int) (*Document, error)
GetDocumentByULID(ulid string) (*Document, error)
GetDocumentByPath(path string) (*Document, error)
GetDocumentByHash(hash string) (*Document, error)
GetNewestDocuments(limit int) ([]Document, error)
GetNewestDocumentsWithPagination(page int, pageSize int, showHidden ...bool) ([]Document, int, error)
GetAllDocuments() ([]Document, error)
GetDocumentsByFolder(folder string) ([]Document, error)
DeleteDocument(ulid string) error
UpdateDocumentURL(ulid string, url string) error
UpdateDocumentPath(ulid string, path string, folder string) error
UpdateDocumentFolder(ulid string, folder string) error
UpdateDocumentDate(ulid string, date *time.Time) error
UpdateDocumentFullText(ulid string, text string) error
SaveConfig(config *config.ServerConfig) error
GetConfig() (*config.ServerConfig, error)
SearchDocuments(searchTerm string) ([]Document, error)
ReindexSearchDocuments() (int, error)
// Word cloud methods
GetTopWords(limit int) ([]WordFrequency, error)
GetWordCloudMetadata() (*WordCloudMetadata, error)
RecalculateAllWordFrequencies() error
UpdateWordFrequencies(docID string) error
// Job tracking methods
CreateJob(jobType JobType, message string) (*Job, error)
UpdateJobProgress(jobID ulid.ULID, progress int, currentStep string) error
UpdateJobStatus(jobID ulid.ULID, status JobStatus, message string) error
UpdateJobError(jobID ulid.ULID, errorMsg string) error
CompleteJob(jobID ulid.ULID, result string) error
GetJob(jobID ulid.ULID) (*Job, error)
GetRecentJobs(limit, offset int) ([]Job, error)
GetActiveJobs() ([]Job, error)
DeleteOldJobs(olderThan time.Duration) (int, error)
CancelJob(jobID ulid.ULID) error
RecoverStuckJobs(stuckThreshold time.Duration) (int, error)
// Tag methods
CreateTag(tag *Tag) error
GetAllTags() ([]Tag, error)
GetTagByID(id int) (*Tag, error)
GetTagByName(name string) (*Tag, error)
UpdateTag(tag *Tag) error
DeleteTag(id int) error
GetTagsForDocument(documentID int) ([]Tag, error)
AddTagToDocument(documentID int, tagID int) error
RemoveTagFromDocument(documentID int, tagID int) error
GetTagUsageCount(tagID int) (int, error)
GetTopTagsByUsage(limit int) ([]TagWithCount, error)
GetTagGroups() ([]string, error)
GetAllTagAliases() ([]TagAliasEntry, error)
InsertTagAlias(tagID int, aliasName string) error
// Dimension methods
GetAllDimensions() ([]Dimension, error)
GetDimensionByID(id int) (*Dimension, error)
GetDimensionByName(name string) (*Dimension, error)
GetDimensionValues(dimensionID int) ([]DimensionValue, error)
GetDimensionValueByValue(dimensionID int, value string) (*DimensionValue, error)
GetDocumentDimensions(documentID int) (map[string]DimensionValue, error)
SetDocumentDimension(documentID int, dimensionID int, dimensionValueID int) error
RemoveDocumentDimension(documentID int, dimensionID int) error
// Schema version
GetSchemaVersion() (string, error)
// Saved search methods
GetAllSavedSearches() ([]SavedSearch, error)
GetSavedSearchByID(id int) (*SavedSearch, error)
CreateSavedSearch(search *SavedSearch) error
UpdateSavedSearch(search *SavedSearch) error
DeleteSavedSearch(id int) error
// Search execution methods
GetDocumentsByTag(tagID int, page, pageSize int, showHidden ...bool) ([]Document, int, error)
GetUntaggedDocuments(page, pageSize int, showHidden ...bool) ([]Document, int, error)
GetTaggedDocuments(page, pageSize int, showHidden ...bool) ([]Document, int, error)
ExecuteSearch(parsed *ParsedSearch, page, pageSize int, showHidden ...bool) ([]Document, int, error)
// Story methods
CreateStory(story *Story) error
GetStoryByID(id int) (*Story, error)
GetAllStories() ([]Story, error)
GetStoriesWithMeta() ([]StoryWithMeta, error)
UpdateStory(story *Story) error
DeleteStory(id int) error
GetStoryByTagID(tagID int) (*Story, error)
GetStoryTags(storyID int) ([]Tag, error)
AddStoryTag(storyID int, tagID int) error
RemoveStoryTag(storyID int, tagID int) error
AddDocumentToStory(documentID int, storyID int) error
RemoveDocumentFromStory(documentID int, storyID int) error
GetDocumentsWithoutStory(page, pageSize int, showHidden ...bool) ([]Document, int, error)
UpdateDocumentMetadata(ulid string, meta DocumentMetadataUpdate) error
ConvertTagToStory(tagID int) (*Story, error)
ConvertStoryToTag(storyID int) error
// Archive methods
UpdateDocumentArchiveStatus(ulidStr string, status *string, archivedAt *time.Time) error
GetArchivedDocuments(page, pageSize int) ([]Document, int, error)
}
Repository defines database operations
type SavedSearch ¶
type SavedSearch struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Query string `json:"query"` // Unified search query (text #tag ~exclude)
Icon string `json:"icon"` // Emoji icon
SortOrder int `json:"sort_order"` // Display order
IsSystem bool `json:"is_system"` // True for built-in searches
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
SavedSearch represents a saved search query
type SavedSearchWithCount ¶
type SavedSearchWithCount struct {
SavedSearch
DocumentCount int `json:"document_count"`
}
SavedSearchWithCount includes the document count for display
type SearchResult ¶
SearchResult extends Document with search-related info
type Story ¶
type Story struct {
ID int `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
StartDate *time.Time `json:"start_date,omitempty"`
EndDate *time.Time `json:"end_date,omitempty"`
TagID int `json:"tag_id"` // references the story's own tag
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Story represents a grouping of documents (e.g. a house purchase, medical episode). Each story creates a tag with tag_group='Story', so a document belongs to at most one story.
type StoryWithMeta ¶
type StoryWithMeta struct {
Story
Tag Tag // The story's own tag (has color, name etc.)
AssociatedTags []Tag // Tags from story_tags junction
DocumentCount int
StartDateFmt string // Pre-formatted "2006-01-02" for templates (avoids *time.Time filter issues)
EndDateFmt string
}
StoryWithMeta includes the story's tag, associated tags, and document count for display.
type Tag ¶
type Tag struct {
ID int `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
Description string `json:"description,omitempty"`
TagGroup *string `json:"tag_group,omitempty"`
SortOrder int `json:"sort_order"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Tag represents a tag that can be applied to documents If TagGroup is nil/empty, it's a free tag (multiple allowed per document) If TagGroup has a value, only one tag from that group is allowed per document
type TagAliasEntry ¶
TagAliasEntry represents a tag alias with resolved tag name (for config export/import)
type TagWithCount ¶
TagWithCount includes the count of documents using this tag
type WordCloudMetadata ¶
type WordCloudMetadata struct {
LastCalculation time.Time `json:"lastCalculation"`
TotalDocsProcessed int `json:"totalDocsProcessed"`
TotalWordsIndexed int `json:"totalWordsIndexed"`
Version int `json:"version"`
}
WordCloudMetadata tracks word cloud calculation status
type WordFrequency ¶
type WordFrequency struct {
Word string `json:"word"`
Frequency int `json:"frequency"`
Updated time.Time `json:"updated"`
}
WordFrequency represents a word and its frequency count
type WordTokenizer ¶
type WordTokenizer struct {
// contains filtered or unexported fields
}
WordTokenizer handles text processing for word cloud
func NewWordTokenizer ¶
func NewWordTokenizer() *WordTokenizer
NewWordTokenizer creates a new word tokenizer
func (*WordTokenizer) TokenizeAndCount ¶
func (wt *WordTokenizer) TokenizeAndCount(text string) map[string]int
TokenizeAndCount extracts words from text and counts frequencies