openalex

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package openalex is a thin HTTP client for api.openalex.org that resolves DOIs and runs cross-field search, mapping the returned Work records into coldp.Reference values.

LIFT-TO-SFLIB CANDIDATE. Every SFBorg tool that touches references wants this. Kept self-contained (no reach into hive-internal state, no singleton) so migration to sflib is a clean copy.

Polite pool etiquette: OpenAlex asks clients to identify themselves via User-Agent or a mailto=<email> query param. Identified requests land in a higher-priority pool. Callers thread the curator email through New(email); empty is legal (anonymous pool, slower).

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("openalex: work not found")

ErrNotFound is returned when OpenAlex has no work for the given DOI. Distinct from network failures so calling code can tell "DOI is bad" from "OpenAlex is down."

Functions

This section is empty.

Types

type Client

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

Client is concurrent-safe (net/http.Client is). One instance per process is plenty.

func New

func New(email string) *Client

New constructs a client with an explicit email for the polite pool.

func (*Client) ResolveDOI

func (c *Client) ResolveDOI(ctx context.Context, doi string) (*coldp.Reference, error)

ResolveDOI fetches the OpenAlex Work record for a DOI and maps it to a coldp.Reference. The DOI may be a bare identifier ("10.1234/abcd") or a full URL ("https://doi.org/10.1234/abcd"). Returns ErrNotFound on 404.

The returned Reference carries no ID; the caller assigns one before persisting. OpenAlex's own W-IDs aren't preserved into sfga; a curator wanting that linkage can add it to col__alternative_id.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, limit int) ([]coldp.Reference, error)

Search runs OpenAlex's cross-field search (title / abstract / author) and returns up to `limit` results mapped to coldp.Reference. Search is fuzzy — OpenAlex handles typos and word ordering itself.

Empty query returns nil rather than "everything"; callers filtering by name+year should compose a query string themselves.

Jump to

Keyboard shortcuts

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