Documentation
¶
Overview ¶
Package sru implements a minimal SRU (Search/Retrieve via URL) 1.2 server. Supports operations: explain, searchRetrieve. CQL support is minimal: free-text terms and index=value queries.
Index ¶
Constants ¶
const ( Version = "1.2" NS = "http://www.loc.gov/zing/srw/" DiagNS = "http://www.loc.gov/zing/srw/diagnostic/" DefaultMaxRecs = 100 // Standard record schema identifiers. SchemaDC = "info:srw/schema/1/dc-v1.1" SchemaMARCXML = "info:srw/schema/1/marcxml-v1.1" SchemaMODS = "info:srw/schema/1/mods-v3.6" )
const ( DiagGeneralSystemError = "info:srw/diagnostic/1/1" DiagUnsupportedOperation = "info:srw/diagnostic/1/4" DiagUnsupportedVersion = "info:srw/diagnostic/1/5" DiagQuerySyntaxError = "info:srw/diagnostic/1/10" DiagUnsupportedIndex = "info:srw/diagnostic/1/16" DiagUnknownSchemaForRetrieval = "info:srw/diagnostic/1/66" )
Standard SRU diagnostic URIs.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(cfg ServerConfig) http.Handler
Handler returns an http.Handler that implements the SRU protocol.
Types ¶
type Index ¶
type Index struct {
CQLName string
Title string
Field string // internal field name for filtering; empty = free text query
}
Index maps a CQL index name to an internal field name.
type Schema ¶
type Schema struct {
Name string // short name, e.g. "oai_dc"
Identifier string // URI, e.g. "info:srw/schema/1/dc-v1.1"
Title string
}
Schema describes a supported record schema.
type SearchFunc ¶
type SearchFunc func(ctx context.Context, index, value string, offset, size int) (*SearchResult, error)
SearchFunc is the callback the app provides. It receives the parsed CQL query and pagination params, and returns encoded records. The index and value come from CQL parsing. Index is empty for free-text (serverChoice). Offset is 0-based. Size is the maximum number of records to return.
type SearchResult ¶
type SearchResult struct {
Total int
Records [][]byte // each entry is an encoded record (e.g. OAI-DC XML)
}
SearchResult is what the search callback returns to the SRU handler.
type ServerConfig ¶
type ServerConfig struct {
Database string // database name for explain
Title string // human-readable title for explain
Indexes []Index // supported CQL indexes
Schemas []Schema // supported record schemas
Search SearchFunc
}
ServerConfig configures an SRU endpoint.