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