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.



Comments
โฆ