clientside search
1.0.0
“为什么现在我们没有像Lucene一样体面的客户端(浏览器)搜索引擎?”
该库为浏览器和Node.js提供类似Lucene的全文搜索功能。
该搜索引擎使用多种高级算法来提供大量文档集合的强大而有效的搜索。使用的算法包括用于称重和排名的TF-IDF,模糊匹配的BK-Tree,相关性评分的BM25以及用于测量搜索词之间的编辑距离的Damerau-Levenshtein距离。搜索引擎支持多种语言,并使用Stemming和StopWord删除来提高其效率。它还支持与文档相关的元数据的存储和检索。您可以在客户端和服务器端从文本语料库和元数据中生成索引。您也可以在客户端和服务器端补充水合(重复使用预先生成的)索引。
我想使用一个类似Lucene的索引,该索引使用TF-IDF矢量化,BM25和BKTREE排名以及客户端的滚雪球。
我想在客户端或服务器端生成搜索索引(并在客户端或服务器端重新保存/重新使用它)。状态信息应小且压缩。
全文搜索应快速有效,不会导致很多假阳性或假阴性。
搜索引擎应该能够在可能与每个文档关联的元数据中重新搜索和搜索。
搜索引擎应该能够删除/更新其索引文档。
状态应有水合。
en , de , fr , es , ja8 KiB nano尺寸(ESM,Gizpped,基本库)yarn add clientside-searchnpm install clientside-search import { SearchEngine } from 'clientside-search'
import en from 'clientside-search/en'
// create a new instance of a search engine
const searchEngine = new SearchEngine ( en )
// add some text
const docId1 = searchEngine . addDocument ( 'The quick brown fox jumps over the lazy dog' )
// you can also add UTF8 text, and metadata
const docId2 = searchEngine . addDocument ( 'The quick brown fox jumps over the fence ✅' , {
// metadata with index_ prefix will be indexed for search
index_title : 'Fence' ,
date : new Date ( ) ,
author : 'John Doe' ,
} )
/**
* {
* id:
* score: 1.34,
* metadata: { title: 'Fence', date: '2023-07-12 ...', author: 'John Doe' }
* }
*/
const searchResult = searchEngine . search ( 'Fence' )
// if you want to persist the index state,
// hydratedState is a JSON string that you can persist
const hydratedState = searchEngine . hydrateState ( )
// PLEASE NOTE: The hydrated state does NOT contain the original input text
// It contains an optimized representation of the search index
// However, metadata is kept 1:1
// you can re-hydrate from that state anywhere,
// on the server or the client:
const hydratedEngine = SearchEngine . fromHydratedState ( hydratedState , en )
// equals: searchResult
const searchResultFromHydated = hydratedEngine . search ( 'Fence' ) const { SearchEngine } = require ( 'clientside-search' )
const { en } = require ( 'clientside-search/en' )
// same API like ESM variant