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

react-solr-connector

v1.1.1

Published

A simple React component which provides access to a Solr server

Downloads

63

Readme

react-solr-connector

A React component which provides access to a Solr server. Suitable for use in simple React apps which do not make use of a state management framework like Redux. Since the component uses the Solr JSON API, only versions from 5 onward are supported (and I have only tested with 6.0.0).

Installation

Install the module with npm:

npm install --save react-solr-connector

Using the component

The module exports one default object, SolrConnector. This should be used to wrap your application components:

import SolrConnector from 'react-solr-connector';
...
<SolrConnector searchParams={searchParams}>
  <MyApp/>
</SolrConnector>

SolrConnector injects a solrConnector prop into all of its immediate children. This is an object with the structure:

{
  searchParams,
  busy,
  response,
  error
}

SolrConnector is passed a prop called searchParams (which is also copied into the injected solrConnector prop). If searchParams contains a non-empty query then the search is performed asynchronously and busy is set to true (this could be used to indicate to the user that a search is in progress, for example by displaying a spinner). response is null until a response from Solr is received, at which point it is set to the value of the response object from Solr (including the responseHeader, the main response object, and any facets, highlighting objects, etc.) busy is also set to false. If an error occurs, the error property is set (to a descriptive string) instead of the response property. A search is performed when the component first mounts, and thereafter any time it receives new props.

searchParams must have the following properties as a minimum:

{
  solrSearchUrl,
  query
}

Where query is the user-entered query string and solrSearchUrl is a Solr search endpoint, e.g.:

http://localhost:8983/solr/techproducts/select

If you are serving the app from a different host then you will have to enable CORS on Solr, or use a proxy service.

Optional properties for doSearch are:

{
  offset,
  limit,
  filter,
  fetchFields,
  facet,
  highlightParams
}

Most of these correspond exactly with properties in the Solr JSON API. The exceptions are fetchFields, which corresponds to the Solr fields (which is not a very clear name in my opinion) and highlightParams. In fact, highlightParams can contain any of the "traditional" Solr params that the JSON API does not currently support, but highlighting is the most obvious application.

Running tests

If you have cloned the react-solr-connector GitHub repository, you can run the jest tests with the following commands:

$ npm install
$ npm tests

Running the demo

To run the simple demo, install Solr 6 and start it with the techproducts example:

$ bin/solr start -e techproducts

then start the Webpack demo server:

$ npm start

and point your browser at http://localhost:8080/demo/index.html.