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

@brainnit/adonisjs-scout

v0.3.3

Published

Adonis Scout provides a driver based solution for searching your Lucid models, just like Laravel Scout.

Downloads

65

Readme

AdonisJs Scout

Adonis Scout provides a driver based solution for searching your Lucid models, heavily inspired by Laravel Scout and Scout Elasticsearch Driver.

Instalation

Use npm or yarn to install the package:

npm -i @brainnit/adonisjs-scout
# or
yarn add @brainnit/adonisjs-scout

Add Scout to the list of service providers at start/app.js:

const providers = [
  // ...
  '@brainnit/adonisjs-scout/providers/ScoutProvider',
  '@brainnit/adonisjs-scout/providers/IndexKeeperProvider'
];

Setup

Copy config/index.js to your app config folder and name it scout.js. Don't forget to setup your environment variables.

You may also need to install extra dependencies depending on the search engine driver you will be using. For instance, to use Elasticsearch you will need:

npm i --save elasticsearch bodybuilder
# or
yarn add elasticsearch bodybuilder

Usage

Add @provider:Searchable trait to your models and define only the methods you want to override to change default behaviour:

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model');

class User extends Model {
  static get traits () {
    return ['@provider:Searchable']
  }
}

module.exports = Users

Afterwards, create your first IndexKeeper and run the following commands to create/delete indexes on your application:

# if you want to create your indexes
adonis scout:up
# or this if you want to drop indexes
adonis scout:down

Search Rules

A search rule is a class that describes how a search query will be executed and allow you to build complex and reusable searches with the support of the Builder instance.

To create a search rule use the following command:

adonis make:searchableRule MySearchRule

In the file app/Models/SearchableRules/MySearchRule.js you will find a class definition:

'use strict'

/** @type {typeof import('@brainnit/adonisjs-scout/src/SearchRule')} */
const SearchRule = use('Scout/SearchRule')

class MySearchRule extends SearchRule {
  buildQuery () {
    return {
      'must': {
        'match': {
          'name': this.builder.query
        }
      }
    }
  }
}

module.exports = MySearchRule

To tell Scout about what search rules your model supports, just add the following method:

  /**
   * Specify what search rules the model supports.
   * 
   * The return value(s) must always class namespaces that will be
   * resolved by IoC Container.
   *
   * @static
   * 
   * @method searchableRules
   * 
   * @return {Array|String} ES6 Class
   */
  static searchableRules () {
    return ['App/Models/SearchRules/MySearchRule']
  }

Backlog

  • Move index create/update operations off from indexing methods (Elasticsearch)
  • Add commands (make:scout:searchableModel, make:scout:searchRule, make:scout:indexKeeper)
  • Document all error codes
  • Add setup instructions
  • Add badges for npm version, build status, coverals
  • Add license scan
  • Add better wiki/docs

What else? Please open an Issue for suggestions.