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

express-search

v1.0.3

Published

Super simple search plugin for express, with rich features

Downloads

24

Readme

Stories in Ready Build Status Code Climate Test Coverage

install: npm install express-search

#express-search

A beautifully bootstrapped elasticsearch search middleware for express v4.x.

Allows you to do searches like Pictures of "Cute Puppies" Or Recipies by @MarthaStewart

For example, if you want searches that MUST contain the phrase "Puppies" and you'd prefer them to be wearing hats: "Puppies" wearing hats would return results containing documents that contain "puppies", and try to find documents where the puppies are wearing hats.

If you want to find a person/place you can use mention style tags: @hansolo will return documents where hansolo is mentioned

If you want to search only documents with certain tags you can use hash tags in your search: #music top 10 will return documents with the tag "music, and look for a "top 10" document

You can string them together to make concise yet powerful searches: #music by @paulsimmon "You Can Call Me Al" Will try to find documents tagged "music", where "paulsimmon" is mentioned, and the phrase "You Can Call Me Al" is found.

##Setting Up an End Point

Set up is super simple. You just have to:

  • Provide connection settings for ElasticSearch.
  • Set Index and Type to search.
  • Configure pagination(default page size).
  • Configure Fields to search
    • Fields for general search
    • Fields for tag serach
    • Fields for mentions
  • Fields to return
  • Configure default sorting(optional)
    • Field to sort by
    • Sort order(ascending/descending)

Setup connection settings:

var expressSearch=require('express-search');
var express=require('express');

var app=express();

var config={
    'hosts':['localhost:9200']
    //'log':'trace' //handy for debugging
}

expressSearch.connect(configs);

Now you can use the expressSearch object to create multiple routes:

var mySearch={
   index: "myIndex",
   type: "someType",
   tags: ['tags','twitter.tags'], //fields for tag search
   mentions: ['authors','editors'], //fields for mention search
   fields: ['title','description'], //fields for general search
   projection: ['title','description','authors','editors','tags'], //fields to return in results. ['*'] for all fields
   pageSize: 10, //default page size
   sort: 'desc',
   sortBy: 'createDate'
};

app.use('/api/search/',expressSearch.setup(mySearch));

Now to use it:

curl http://localhost/api/search?q=music

You can use the expressSearch object to setup as many search endpoints are you desire.

##Using the end point Express-Search generates a GET end point at whichever route you configure.

There are several parameters you can pass via query string:

  • q (String)
    • the text to search(including mentions/tags/phrases)
  • page(Number)
    • page number starting from 0
  • pageSize(Number)
    • Overwrite default page size
  • sort(String)
    • Either "asc" or "desc"
    • Overwrites default
  • sortBy(String)
    • Set field to sort by
    • Overwrites default

##Batteries Not Included! Express-Search will not index documents for you! You should either index them yourself or use a river plugin. This plugin will not handle configuring a mapping for your documents. This plugin simply handles search.