Requirements: Add full-text search functions to the front-end, such as menus, chat messages, etc. There are many full-text search middleware on the backend, such as ElasticSearch, Lucene, Solr, SQL Server built-in, etc. How to achieve full-text search on the front-end without relying on the back-end interface?
Review:
Fuse.js Powerful, lightweight fuzzy search library, written in JavaScript without any dependencies.
Official Website:The hyperlink login is visible. Source:The hyperlink login is visible. Parameter configuration:The hyperlink login is visible.
This article uses Angular 19 + fuse.js to implement the full-text search function, and the rendering is as follows:
npm installation
Code:
Output:
[ { "item": { "title": "Right Ho Jeeves", "author": "P.D. Mans", "tags": ["fiction", "war"] }, "refIndex": 1, // index in the original list "score": 0.12282280261157906 }, { "item": { "title": "Old Man's War fiction", "author": "John X", "tags": ["war"] }, "refIndex": 0, "score": 0.3807307877431757 }
] Remark:The smaller the score is, the more accurate it is, that is, the higher the match.
Reference:The hyperlink login is visible. |