Documentation
¶
Index ¶
- Variables
- func ComputeQueryHash(query string, limit int) [32]byte
- func NormalizeQuery(q string) string
- func ScanUUID(src any) (uuid.UUID, error)
- func UUIDToBytes(id uuid.UUID) []byte
- type AnalysisService
- type Collection
- type CollectionService
- type InquireOptions
- type InquireResult
- type OpenAlexAnalysisService
- func (s *OpenAlexAnalysisService) GetWorks(ctx context.Context, collectionID uuid.UUID, ids []string) ([]*models.Work, []string, error)
- func (s *OpenAlexAnalysisService) Inquire(ctx context.Context, query string, limit int, opts InquireOptions) (*InquireResult, error)
- func (s *OpenAlexAnalysisService) LoadAnalysis(ctx context.Context, collectionID uuid.UUID) (*models.Analysis, error)
- func (s *OpenAlexAnalysisService) QueryCategory(ctx context.Context, collectionID uuid.UUID, category string, limit int) ([]*models.Result, error)
- func (s *OpenAlexAnalysisService) Search(ctx context.Context, collectionID uuid.UUID, query string, limit int) (*models.Analysis, error)
- func (s *OpenAlexAnalysisService) StoreAnalysis(ctx context.Context, collectionID uuid.UUID, a *models.Analysis) error
- type SQLiteCollectionService
- func (s *SQLiteCollectionService) Create(ctx context.Context, col *Collection) error
- func (s *SQLiteCollectionService) Delete(ctx context.Context, id uuid.UUID) error
- func (s *SQLiteCollectionService) FindByHash(ctx context.Context, hash [32]byte) (*Collection, error)
- func (s *SQLiteCollectionService) FindByID(ctx context.Context, id uuid.UUID) (*Collection, error)
- func (s *SQLiteCollectionService) FindByName(ctx context.Context, name string) (*Collection, error)
- func (s *SQLiteCollectionService) List(ctx context.Context) ([]*Collection, error)
- func (s *SQLiteCollectionService) Resolve(ctx context.Context, target string) (*Collection, error)
- func (s *SQLiteCollectionService) UpdateName(ctx context.Context, id uuid.UUID, name *string) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCollectionNotFound is returned when a requested collection is not present in the store. ErrCollectionNotFound = errors.New("collection not found") // ErrCollectionExists is returned when attempting to create a collection with a duplicate name or query hash. ErrCollectionExists = errors.New("collection already exists") )
Functions ¶
func ComputeQueryHash ¶
ComputeQueryHash calculates a deterministic SHA-256 idempotency key for a query and limit.
func NormalizeQuery ¶
NormalizeQuery canonicalizes a search query: trims leading/trailing whitespace, transforms to lowercase, and collapses multiple consecutive spaces into a single space.
func ScanUUID ¶
ScanUUID parses a SQLite value (either []byte of length 16 or standard string) into a uuid.UUID.
func UUIDToBytes ¶
UUIDToBytes returns the raw 16-byte slice of a uuid.UUID for BLOB storage.
Types ¶
type AnalysisService ¶
type AnalysisService interface {
Inquire(ctx context.Context, query string, limit int, opts InquireOptions) (*InquireResult, error)
StoreAnalysis(ctx context.Context, collectionID uuid.UUID, a *models.Analysis) error
LoadAnalysis(ctx context.Context, collectionID uuid.UUID) (*models.Analysis, error)
QueryCategory(ctx context.Context, collectionID uuid.UUID, category string, limit int) ([]*models.Result, error)
Search(ctx context.Context, collectionID uuid.UUID, query string, limit int) (*models.Analysis, error)
GetWorks(ctx context.Context, collectionID uuid.UUID, ids []string) ([]*models.Work, []string, error)
}
AnalysisService defines operations for literature inquiry, graph algorithms, and analysis queries.
type Collection ¶
type Collection struct {
ID uuid.UUID `json:"id"`
QueryHash [32]byte `json:"query_hash"`
Query string `json:"query"`
ResultLimit int `json:"result_limit"`
Parameters []byte `json:"parameters,omitempty"`
Name *string `json:"name,omitempty"`
WorkCount int `json:"work_count"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Collection represents a bibliographic inquiry collection stored in the database.
type CollectionService ¶
type CollectionService interface {
FindByHash(ctx context.Context, hash [32]byte) (*Collection, error)
FindByID(ctx context.Context, id uuid.UUID) (*Collection, error)
FindByName(ctx context.Context, name string) (*Collection, error)
Resolve(ctx context.Context, target string) (*Collection, error)
List(ctx context.Context) ([]*Collection, error)
Create(ctx context.Context, col *Collection) error
UpdateName(ctx context.Context, id uuid.UUID, name *string) error
Delete(ctx context.Context, id uuid.UUID) error
}
CollectionService defines collection lifecycle and resolution operations.
type InquireOptions ¶
InquireOptions specifies optional configuration for storing inquiry results.
type InquireResult ¶
type InquireResult struct {
Collection *Collection
IsNew bool
// SeedCount is the number of works OpenAlex returned for the query. It is
// only set when the collection was newly fetched.
SeedCount int
}
InquireResult encapsulates the stored or matched collection and whether it was newly queried.
type OpenAlexAnalysisService ¶
type OpenAlexAnalysisService struct {
// contains filtered or unexported fields
}
OpenAlexAnalysisService coordinates literature fetching from OpenAlex, running SAP and Steiner algorithms, and managing analysis persistence via SQLite.
func NewAnalysisService ¶
func NewAnalysisService( db *sql.DB, openalexClient openalex.Client, ) *OpenAlexAnalysisService
NewAnalysisService creates a new OpenAlexAnalysisService backed by the provided sql.DB and openalex.Client.
func NewAnalysisServiceWithQueries ¶
func NewAnalysisServiceWithQueries( db *sql.DB, queries *repository.Queries, openalexClient openalex.Client, ) *OpenAlexAnalysisService
NewAnalysisServiceWithQueries creates a new OpenAlexAnalysisService with explicit *repository.Queries.
func (*OpenAlexAnalysisService) GetWorks ¶ added in v0.6.0
func (s *OpenAlexAnalysisService) GetWorks(ctx context.Context, collectionID uuid.UUID, ids []string) ([]*models.Work, []string, error)
GetWorks retrieves works belonging to a collection matching the provided IDs or labels. If ids is empty or nil, all works belonging to the collection are returned. Any requested ID that cannot be resolved is returned in the notFound slice.
func (*OpenAlexAnalysisService) Inquire ¶
func (s *OpenAlexAnalysisService) Inquire( ctx context.Context, query string, limit int, opts InquireOptions, ) (*InquireResult, error)
Inquire coordinates fetching literature from OpenAlex, running SAP algorithms, and storing the resulting analysis in SQLite with query idempotency support.
func (*OpenAlexAnalysisService) LoadAnalysis ¶
func (s *OpenAlexAnalysisService) LoadAnalysis(ctx context.Context, collectionID uuid.UUID) (*models.Analysis, error)
LoadAnalysis reconstructs the entire models.Analysis graph from the database for a collection.
func (*OpenAlexAnalysisService) QueryCategory ¶
func (s *OpenAlexAnalysisService) QueryCategory(ctx context.Context, collectionID uuid.UUID, category string, limit int) ([]*models.Result, error)
QueryCategory retrieves scored results for a category using indexed B-Tree ordering.
func (*OpenAlexAnalysisService) Search ¶
func (s *OpenAlexAnalysisService) Search(ctx context.Context, collectionID uuid.UUID, query string, limit int) (*models.Analysis, error)
Search executes a keyword graph search using SQLite FTS5 and pseudo-Steiner graph reduction.
func (*OpenAlexAnalysisService) StoreAnalysis ¶
func (s *OpenAlexAnalysisService) StoreAnalysis(ctx context.Context, collectionID uuid.UUID, a *models.Analysis) error
StoreAnalysis persists an analysis graph (works, scored nodes, links, and FTS5 entries) for a collection.
type SQLiteCollectionService ¶
type SQLiteCollectionService struct {
// contains filtered or unexported fields
}
SQLiteCollectionService implements CollectionService backed by repository.Queries.
func NewCollectionService ¶
func NewCollectionService(db repository.DBTX) *SQLiteCollectionService
NewCollectionService creates a *SQLiteCollectionService backed by the provided repository.DBTX.
func NewCollectionServiceWithQueries ¶
func NewCollectionServiceWithQueries(queries *repository.Queries) *SQLiteCollectionService
NewCollectionServiceWithQueries creates a *SQLiteCollectionService wrapping existing *repository.Queries.
func (*SQLiteCollectionService) Create ¶
func (s *SQLiteCollectionService) Create(ctx context.Context, col *Collection) error
Create inserts a new collection record into the database.
func (*SQLiteCollectionService) Delete ¶
Delete removes a collection and cascades to its nodes and links.
func (*SQLiteCollectionService) FindByHash ¶
func (s *SQLiteCollectionService) FindByHash(ctx context.Context, hash [32]byte) (*Collection, error)
FindByHash finds a collection matching the given query hash.
func (*SQLiteCollectionService) FindByID ¶
func (s *SQLiteCollectionService) FindByID(ctx context.Context, id uuid.UUID) (*Collection, error)
FindByID finds a collection by its UUID.
func (*SQLiteCollectionService) FindByName ¶
func (s *SQLiteCollectionService) FindByName(ctx context.Context, name string) (*Collection, error)
FindByName finds a collection by its human-friendly name alias.
func (*SQLiteCollectionService) List ¶
func (s *SQLiteCollectionService) List(ctx context.Context) ([]*Collection, error)
List returns all collections ordered by creation timestamp descending.
func (*SQLiteCollectionService) Resolve ¶
func (s *SQLiteCollectionService) Resolve(ctx context.Context, target string) (*Collection, error)
Resolve resolves a collection by target string. If target is empty, it returns the most recent collection. If target parses as a valid UUID, it queries by ID. If not found or if target is not a valid UUID, it queries by name alias.
func (*SQLiteCollectionService) UpdateName ¶
UpdateName updates the human-friendly name alias of an existing collection.