Internet Archive Search Service
A service for searching and retrieving metadata from the Internet Archive.
Installation
npm install @internetarchive/search-service
Usage
Searching
import {
SearchService,
SortParam,
SortDirection
} from '@internetarchive/search-service';
const searchService = SearchService.default;
const dateSort = new SortParam('date', 'desc')
const params = new SearchParams({
query: 'collection:books AND title:(goody)',
sort: [dateSort],
rows: 25,
start: 0,
fields: ['identifier', 'collection', 'title', 'creator']
});
const result = await searchService.performSearch(params);
if (result.success) {
const searchResponse = result.success;
searchResponse.response.numFound
searchResponse.response.docs
searchResponse.response.docs[0].identifier
}
Fetch Metadata
const metadataResponse: MetadataResponse = await searchService.fetchMetadata('some-identifier');
metadataResponse.metadata.identifier
metadataResponse.metadata.collection.value
metadataResponse.metadata.collection.values
Metadata Values
Internet Archive Metadata is expansive and nearly all metadata fields can be returned as either an array, string, or number.
The Search Service handles all of the possible variations in data formats and converts them to their appropriate types. For instance on date fields, like date
, it takes the string returned and converts it into a native javascript Date
value. Similarly for duration-type fields, like length
, it takes the duration, which can be seconds 324.34
or hh:mm:ss.ms
and converts them to a number
in seconds.
There are parsers for several different field types, like Number
, String
, Date
, and Duration
and others can be added for other field types.
See src/models/metadata-fields/field-types.ts
Usage
metadata.collection.value
metadata.collection.values
metadata.collection.rawValue
metadata.date.value
metadata.length.value
Development
Prerequisite
npm install
Testing
npm run test
Demo
npm run start
Linting
npm run format