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

@sefaria/search

v0.9.9

Published

repo for querying and processing queries to the Sefaria search API

Downloads

11

Readme

Sefaria Search Javascript Library

With this library, you can query and process query results from the Sefaria search API.

Sefaria is an open-source site which hosts a large online library of Jewish texts and source sheets. See Sefaria's site here and Sefaria's main repo here

Installation

npm install @sefaria/search

Usage

The library contains two main classes which will be discussed below

Search

Search is the most important class in the library. It allows you to query the Sefaria search API, process results and build datastructures to make it easier to filter results

You can import the Search class using

import { Search } from '@sefaria/search';

constructor

(apiHost, searchIndexText, searchIndexSheet) => null
  • apiHost: the Sefaria server you want to point your API requests to. Usually, this will be https://www.sefaria.org

  • searchIndexText: the index for texts in your Elasticsearch database. Usually, this will be text

  • searchIndexSheet: the index for source sheets in your Elasticsearch database. Usually, this will be sheet


execute_query

({
  query: string,
  type: oneOf("text", "sheet"),
  field: string, // which field do you want to query? usually either "exact", "naive_lemmatizer" or "content"
  exact: boolean, // if query is an exact query
  start: int, // pagination start
  size: int, // page size
  applied_filters: array[string], // list of filters you've applied
  appliedFilterAggTypes: array[string], // list of fields each filter is filtering on. must be same size as `filters` usually fields are either "path", "group" or "tags"
  aggregationsToUpdate: array[string], // list of fields to aggregate on. usually "path", "group" or "tags"
  sort_type: string, // how to sort. either "sort" or "score"  
}) => returns Elasticsearch result list (see here for more details: https://www.elastic.co/guide/en/elasticsearch/reference/6.1/_the_search_api.html)

The only required parameters are query and type. Default values are available for the rest of the fields from SearchState.metadataByType (see below)


SearchState

SearchState allows you to save many search related properties to keep track of them. For example, SearchState saves the current search results, sort settings and applied filters


constructor

({
  type: oneOf("text", "sheet"),
  appliedFilters: array[string], // list of filters you've applied
  appliedFilterAggTypes: array[string], // list of fields each filter is filtering on. must be same size as `filters` 
  availableFilters: array[FilterNode], // all available filters for current query. FilterNode is a class defined in the module
  filterRegistry: object(filterName -> FilterNode), // convenience object for accessing FilterNodes more quickly 
  filtersValid: boolean, // are `availableFilters` still valid or do they need to be refetched
  field: string, // which field do you want to query? usually either "exact", "naive_lemmatizer" or "content"
  sortType: string, // how to sort. either "sort" or "score"  
  isLoadingTail: boolean, // for infinite load, are we loading next page
  isLoading: boolean, // is API request pending
  results: array[result], // array of result objects for current results that have been loaded
  numResults: int, // number of results in total. not necessarily the same as `results.length`
  currPage: int,  // current page loaded
}) => null

only parameter required is type


metadataByType

object with default values for SearchState depending on the query type (either text or sheet)

Running Code While Developing

This module is not part of a stand alone app. As such, it is helpful to be able for the apps to account for changes made in this repo without having to push to npm every time a change is made.

Web

For web, npm link can be used. From within the Sefaria-Search-JS folder, run npm link (might require sudo). Then, from within Sefaria-Project, run npm link @sefaria/search.
As of this writing, Sefaria-Project does not load search.js as an npm module. The code is duplicated within Sefaria-Project, and ideally this will change in the near future.

Apps

Unfortunately, the metro server we use does not currently support symlinking (see issues and PR below): https://github.com/facebook/metro/issues/286
https://github.com/facebook/metro/issues/1
https://github.com/facebook/metro/pull/257

Currently, the options we found are to either push each change to npm and install, or to bundle the package as a .tgz and install.

To package:
From within the Sefaria-Search-JS directory:

npm pack
cp sefaria-search-<version>.tgz ~
cd <path-to-app-directory>
npm install ~/sefaria-search<version>.tgz

Unfortunately, I've found that the metro server will cache the package and may not reflect the changes without restarting and dumping cache. To do this, restart the metro server with: react-native start --resetCache

Dumping the cache can be a bit expensive. It might be worthwhile to just push changes to npm...