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

directus-extension-searchsync-2

v1.0.0

Published

Simple Directus extension that sync content with remote search engine (eg. Meilisearch, ElasticSearch, Algolia).

Downloads

9

Readme

Simple search engine indexer

Inspired by the dimitrov-adrian/directus-extension-searchsync, rewritten in TypeScript, supporting Directus 10.

Supported engines

  • ✅ MeiliSearch
  • 🚧 ElasticSearch (coming soon)
  • 🚧 Algolia (coming soon)

CLI Commands

Usage: npx directus extension:searchsync <subdommand>

Subcommands:

  • index - Reindex all documents from configuration

Configuration

The extension uses cosmiconfig for configuration loader with searchsync block or if EXTENSION_SEARCHSYNC_CONFIG_PATH is set will try to use the file.

So, configuration should comes from one of next files:

  • package.json "searchsync":{...}
  • .searchsyncrc
  • .searchsyncrc.json
  • .searchsyncrc.yaml
  • .searchsyncrc.yml
  • .searchsyncrc.js
  • .searchsyncrc.cjs
  • searchsync.config.js
  • searchsync.config.cjs

Environment variables

References

  • server: object Holds configuration for the search engine
  • batchLimit: number Batch limit when performing index/reindex (defaults to 100)
  • reindexOnStart: boolean Performs full reindex of all documents upon Directus starts
  • collections: object Indexing data definition
  • collections.<collection>.filter: object The filter query in format like Directus on which item must match to be indexed (check Filter Rules )
  • collections.<collection>.fields: array<string> Fields that will be indexed in Directus format
  • collections.<collection>.transform: function (Could be defined only if config file is .js) A callback to return transformed/formatted data for indexing.
  • collections.<collection>.indexName: string Force collection name when storing in search index
  • collections.<collection>.collectionField: string If set, such field with value of the collection name will be added to the indexed document. Useful with conjuction with the indexName option

Examples

.searchsyncrc.json

{
  "server": {
    "type": "meilisearch",
    "host": "http://search:7700/myindex",
    "key": "the-private-key"
  },
  "batchLimit": 100,
  "reindexOnStart": false,
  "collections": {
    "products": {
      "filter": {
        "status": "published",
        "stock": "inStock"
      },
      "fields": [
        "title",
        "image.id",
        "category.title",
        "brand.title",
        "tags",
        "description",
        "price",
        "rating"
      ]
    },
    "posts": {
      "indexName": "blog_posts",
      "collectionField": "_collection",

      "filter": {
        "status": "published"
      },
      "fields": ["title", "teaser", "body", "thumbnail.id"]
    }
  }
}

.searchsyncrc.js

const config = {
  server: {
    type: "meilisearch",
    host: "http://search:7700",
    key: "the-private-key",
  },
  reindexOnStart: false,
  batchLimit: 100,
  collections: {
    pages: {
      filter: {
        status: "published",
      },
      fields: ["title", "teaser", "body", "thumbnail.id"],
      transform: (item, { flattenObject, striptags }) => {
        return {
          ...flattenObject(item),
          body: striptags(item.body),
          someCustomValue: "Hello World!",
        };
      },
    },
  },
};

// Use as object.
module.exports = config;
Collection transformation callback description
/**
 * @param {Object} item
 * @param {{striptags, flattenObject, objectMap}} utils
 * @param {String} collectionName
 * @returns {Object}
 */
function (item, { striptags, flattenObject, objectMap }, collectionName) {
	return item
}

Search engines config references

Meilisearch
{
  "type": "meilisearch",
  "host": "http://search:7700",
  "key": "the-private-key"
}
Algolia (coming soon)
{
  "type": "algolia",
  "appId": "Application-Id",
  "key": "secret-api-key"
}
ElasticSearch (coming soon)

New typeless behaviour, use collection names as index name.

{
  "type": "elasticsearch",
  "host": "http://search:9200/"
}

Use Authentification.

{
  "type": "elasticsearch",
  "host": "http://search:9200/",
  "username": "elastic",
  "password": "somepassword"
}

Ignore ssl-certificate-error.

{
  "type": "elasticsearch",
  "host": "http://search:9200/",
  "ignore_cert": true
}
ElasticSearch for 5.x and 6.x (coming soon)

Old type behaviour, use collection names as types.

{
  "type": "elasticsearch_legacy",
  "host": "http://search:9200/projectindex"
}