Overview

Fuse.js is a search engine written in JavaScript.

It is very useful as a search engine when building frontend-only applications.

This time, when implementing exact non-match search using Fuse.js, I needed to craft the query carefully, so here are my notes.

Advanced Search

Fuse.js supports various types of searches, including exact/partial match and partial non-match. These are described on the following page.

A Japanese translation is also available in the following article:

https://qiita.com/Sashimimochi/items/4972b3dc333c6e5fb866#Extended Search

However, for exact non-match search, the query needed some special handling.

Exact Non-Match Search

For example, to search for items where the label field does not contain the exact string "ๆ‚ชๅ…š" (villain), I was able to partially achieve this with the following query. It searches for items that "do not start with ๆ‚ชๅ…š" OR "do not end with ๆ‚ชๅ…š."

{
	"$or": [
		{
			"label": "!^ๆ‚ชๅ…š" # "does not start with ๆ‚ชๅ…š"
		},
		{
			"label": "!ๆ‚ชๅ…š$" # "does not end with ๆ‚ชๅ…š"
		}
	]
}

However, note that this query is not perfect -- it will also exclude items with values like "ๆ‚ชๅ…šใจๆ‚ชๅ…š" (villain and villain).

Summary

There may be some misunderstandings in my explanation, but I hope this serves as a useful reference.