npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@internetarchive/search-service

v1.3.2

Published

A search service for the Internet Archive

Downloads

264

Readme

codecov

Internet Archive Search Service

A service for searching the Internet Archive.

Installation

npm install @internetarchive/search-service

Usage

Searching

import {
  SearchService,
  SearchType,
  SortParam,
  SortDirection
} from '@internetarchive/search-service';

const searchService = SearchService.default;
const dateSort = { field: 'date', direction: 'desc' };
const params = {
  query: 'collection:books AND title:(goody)',
  sort: [dateSort],
  rows: 25,
  fields: ['identifier', 'collection', 'title', 'creator']
};

const result = await searchService.search(params, SearchType.METADATA);
if (result.success) {
  const searchResponse = result.success;
  searchResponse.response.totalResults // => number -- total number of search results available to fetch
  searchResponse.response.returnedCount // => number -- how many search results are included in this response
  searchResponse.response.results // => Result[] array
  searchResponse.response.results[0].identifier // => 'some-item-identifier'
  searchResponse.response.results[0].title?.value // => 'some-item-title', or possibly undefined if no title exists on the item
}

Currently available search types are SearchType.METADATA and SearchType.FULLTEXT.

Search parameters

The params object passed as first argument to search calls can have the following properties:

query

The full search query, which may include Lucene syntax.

rows

The maximum number of search results to be retrieved per page.

page

Which page of results to retrieve, beginning from page 1. Each page is sized according to the rows parameter, so requesting { rows: 20, page: 3 } would retrieve results 41-60, etc.

fields

An array of metadata field names that should be present on the returned search results.

sort

An array of sorting parameters to apply to the results. The first array element specifies the primary sort, the second element the secondary sort, and so on. Each sorting parameter has the form

{ field: string, direction: 'asc' | 'desc' }

where field is the name of the column to sort on (e.g., title) and direction is whether to sort ascending or descending.

aggregations

An object specifying which aggregations to retrieve with the query. To retrieve no aggregations at all, this object should be { omit: true }. To retrieve aggregations for one or more keys, this object should resemble

{ simpleParams: ['subject', 'creator', /*...*/] }

To specify the number of buckets for individual aggregation types, the object should instead use the advancedParams property, resembling

{ advancedParams: [{ field: 'subject', size: 2 }, { field: 'creator', size: 4 }, /*...*/] }

However, these advanced aggregation parameters are not currently supported by the backend and may be removed at a later date.

aggregationsSize

The number of buckets to be returned for all aggregation types. This defaults to 6 (the number of facets displayed for each type in the search results sidebar), but can be overridden using this parameter to retrieve more/fewer buckets as needed.

pageType

A string indicating what type of page this data is being requested for. The search backend may use a different set of default parameters depending on the page type. This defaults to 'search_results', and currently only supports 'search_results' | 'collection_details', with more types to be added in the future.

pageTarget

Used in conjunction with pageType: 'collection_details' to specify the identifier of the collection to retrieve results for.

Search types

At present the only two types of search available are Metadata Search (SearchType.METADATA) and Full Text Search (SearchType.FULLTEXT). This will eventually be extended to support other types of search including TV captions and radio transcripts. Calls that do not specify a search type will default to Metadata Search.

Return values

Calls to SearchService#search will return a Promise that either resolves to a SearchResponse object or rejects with a SearchServiceError.

SearchResponse objects are structured similar to this example:

{
  rawResponse: {/*...*/}, // The raw JSON fetched from the server
  request: {
    clientParameters: {/*...*/}, // The original client parameters sent with the request
    finalizedParameters: {/*...*/} // The finalized request parameters as determined by the backend
  },
  responseHeader: {/*...*/}, // The header containing info about the response success/failure and processing time
  response: {
    totalResults: 12345, // The total number of search results matching the query
    returnedCount: 50, // The number of search results returned in this response
    results: [/*...*/], // The array of search results
    aggregations: {/*...*/}, // A record mapping aggregation names to Aggregation objects
    schema: {/*...*/} // The data schema to which the returned search results conform
  }
}

Fetch Metadata

As of v0.4.0, metadata fetching has been moved to the iaux-metadata-service package and is no longer included as part of the Search Service.

Development

Prerequisite

npm install

Testing

npm run test

Demo

npm run start

Linting

npm run format