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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mypolis.eu/directus-extension-custom-search

v0.4.0

Published

Override the Directus internal search system with a custom search filter - supports relationships

Readme

Custom Search for Directus

Overrides the built-in Directus search system with configurable filters per collection. Supports AND/OR groups, case variants, wildcard matching, relational/nested field search, and a search syntax with quoted phrases, negation, and automatic AND-based term splitting.

Search Syntax

The search box supports a simple syntax for precise queries:

| Syntax | Example | Behavior | | ---------------- | ------------ | --------------------------------------------- | | word | hello | Matches the term | | "exact phrase" | "john doe" | Treats quoted text as a literal, unsplit term |

Multiple terms are ANDed together — all must match for a result to appear.

For a config:

{
	"search_config": {
		"_or": [
			{"title": {"_contains": "$SEARCH"}},
			{"description": {"_contains": "$SEARCH"}}
		]
	}
}

Searching "john doe" urgent generates:

{
	"_and": [
		{
			"_or": [
				{"title": {"_contains": "john doe"}},
				{"description": {"_contains": "john doe"}}
			]
		},
		{
			"_or": [
				{"title": {"_contains": "urgent"}},
				{"description": {"_contains": "urgent"}}
			]
		}
	]
}

Quick Start

  1. Add an alias field to your collection (Data Model → your collection → Create Field → type: alias).
  2. Assign the Configure Search interface to that field.
  3. Build your filter using the filter builder. Use placeholders where the user's search term should go.
  4. Save and search from the collection's content page or API.

No alias field needed if you store the search_config in the collection's meta (see Collection Meta below).

Placeholders

Placeholders can be used as standalone values or embedded within larger strings (e.g. "prefix_$SEARCH_suffix"). When multiple placeholders appear in the same string, they are resolved independently.

| Placeholder | Behavior | Search "Hi" produces | | ------------------- | -------------------------- | ---------------------- | | $SEARCH | Raw search term, verbatim | Hi | | $SEARCH_LOWERCASE | Lowercased search term | hi | | $SEARCH_UPPERCASE | Uppercased search term | HI | | $SEARCH_WILDCARD | Wrapped with * wildcards | *Hi* |

$SEARCH_WILDCARD returns "" (empty string) when the search is empty, so filters like { "_contains": "$SEARCH_WILDCARD" } safely match nothing.

Example Configurations

Basic full-text search with status filter

{
	"search_config": {
		"_and": [
			{"status": {"_eq": "published"}},
			{
				"_or": [
					{"title": {"_contains": "$SEARCH"}},
					{"body": {"_contains": "$SEARCH"}},
					{"slug": {"_icontains": "$SEARCH_LOWERCASE"}}
				]
			}
		]
	}
}

Search across a relational (M2O) field

{
	"search_config": {
		"_or": [
			{"title": {"_contains": "$SEARCH"}},
			{
				"category": {
					"name": {"_contains": "$SEARCH"}
				}
			}
		]
	}
}

Exact match on a code field + wildcard on names

{
	"search_config": {
		"_or": [
			{"code": {"_eq": "$SEARCH_UPPERCASE"}},
			{"display_name": {"_contains": "$SEARCH_WILDCARD"}}
		]
	}
}

Collection Meta (Alternative Setup)

Instead of creating an alias field, you can store the search_config directly on the collection's meta object. The extension reads collection.meta.search_config first, falling back to field meta.options.search_config if not set.

Place this in the collection's meta JSON (via Directus settings or database):

{
	"search_config": {
		"_or": [
			{"title": {"_contains": "$SEARCH"}},
			{"description": {"_contains": "$SEARCH"}}
		]
	}
}

Automatic Fallback

If no search_config is found (neither in collection meta nor on any field), the extension auto-generates a _or filter across all string, text, and csv fields in the collection.

This means collections get multi-word search without any setup.

To opt-out of auto-generation for a collection, set on the collection meta:

{"search_auto": false}

When search_auto is false, the collection's built-in Directus search is left intact (query passes through unchanged).

Multiple Search Configs

You can place the Configure Search interface on multiple alias fields in the same collection. All found configs are merged with _or, so each config acts as an independent search scope.

Caching

Per-collection search configs are cached in memory for 5 minutes to avoid repeated schema reads on every API request. The cache is invalidated on server restart or after the TTL expires.