中国語と英語の混合あいまい検索をサポートするテキスト検索エンジン
中文 お読みください
中国語と英語の混合ファジー検索をサポートする動的プログラミング ベースのテキスト検索エンジンで、最も重みの高い一致結果を返します。
ご興味がございましたら、このオンライン デモをご覧ください。
npm i text-search-engine
Node.js
とWeb
環境の両方をサポートします。
import { search } from 'text-search-engine'
const source = 'nonode'
search ( source , 'no' ) //[[0, 1]]
// Matches 'no', continuous characters have higher weight
search ( source , 'nod' ) // [[2, 4]]
search ( source , 'noe' ) // [[0, 1], [5, 5]]
search ( source , 'oo' ) // [[1, 1],[3, 3]]
search('nonode', 'noe')
一致結果:いいえうなずくe
import { search } from 'text-search-engine'
const source = '地表最强前端监控平台'
search ( source , 'jk' ) // [[6, 7]]
search ( source , 'qianduapt' ) // [[4, 5],[8, 9]]
search('地表最强前端监控平台', 'qianduapt')
一致結果: 地表最强フロントエンド监控平台
import { search } from 'text-search-engine'
search ( 'Node.js 最强监控平台 V9' , 'nodejk' ) //[[0, 3],[10, 11]]
const source_2 = 'a_nd你你的就是我的'
search ( source_2 , 'nd' ) //[[2, 3]]
// Matches '你你的'
search ( source_2 , 'nnd' ) //[[4, 6]]
// Matches 'a_'n'd你你的就'是我的'
search ( source_2 , 'nshwode' ) //[[2, 2],[8, 10]]
search('Node.js 最强监控平台 V9', 'nodejk')
一致結果:ノード.js の最强监控平台 V9
スペースを追加すると、各用語が独立します。各用語は先頭から照合を開始し、一致した用語は削除されるため、次の用語は先頭から照合を開始し、以前に一致した用語は無視されます。
const source_1 = 'Node.js 最强监控平台 V9'
search ( source_1 , 'jknode' ) // undefined
search ( source_1 , 'jk node' ) // [[10, 11],[0, 3]]
search('Node.js 最强监控平台 V9', 'jk node')
一致結果:ノード.js の最强监控平台 V9
const source_1 = 'zxhxo zhx'
search ( source_1 , 'zh' ) //[[6, 7]])
// Even though the weight of 'zh' is higher, but the next term 'o' is not matched, so hit the previous one
search ( source_1 , 'zho' ) //[[0, 0],[2, 2],[4, 4]])
この API は、テキスト一致ハイライトを迅速に検証するために使用されます。 Web 環境と Node.js 環境の両方で console.log を使用して出力できる ANSI エスケープ コードを返し、強調表示されたテキストを確認できます。
import { highlightMatches } from 'text-search-engine'
console . log ( highlightMatches ( 'Node.js 最强监控平台 V9' , 'nodev9' ) )
コンソールには次の出力が表示されます。ノード.js 最强监控平台V9
デフォルト: false
const source = 'chrome 应用商店'
search ( source , 'meyinyon' ) //[[4, 5], [7, 8]])
// would merge blank spaces between each index of the matched term
search ( source , 'meyinyon' , { mergeSpaces : true } ) //[[4, 8]])
デフォルト: undefined
const source = 'Node.js 最强监控平台 V8'
search ( source , 'nozjk' ) //[[0, 1], [8, 8], [10, 11]]
// When the strictnessCoefficient is 0.5 and nozjk is five characters long, Math.ceil(5 * 0.5) equals 3. If the match is less than or equal to 3 characters, it will return normally.
search ( source , 'nozjk' , { strictnessCoefficient : 0.5 } ) //[[0, 1], [8, 8], [10, 11]]
search ( source , 'nozjk' , { strictnessCoefficient : 0.4 } ) //undefined
CodeSandbox オンライン デモを見てみる
import { HighlightWithTarget } from 'text-search-engine/react'
function Test ( ) {
return < HighlightWithTarget source = 'Node.js 最强监控平台 V9' target = 'nodejk' / >
}
import { HighlightWithRanges } from 'text-search-engine/react'
import { search } from 'text-search-engine'
export default function DemoForHighlightWithTarget ( ) {
const ranges = search ( 'Node.js 最强监控平台 V9' , 'nodejk' )
return < HighlightWithRanges source = 'Node.js 最强监控平台 V9' hitRanges = { ranges } / >
}
時間計算量 | 空間の複雑さ | |
---|---|---|
最高 | O(M(ソース)) | O(M(ソース)) |
最悪 | O(M(ソース) * N(ターゲット)) | O(M(ソース) * N(ターゲット)) |
詳細については、投稿ガイドラインをご覧ください。
素晴らしい貢献者の皆様に心より感謝申し上げます❤️
ぜひ参加してPRを送ってください!
問題提起を歓迎します。何か良い提案がある場合は、wx または電子メールで私に連絡してください (注: text-search-engine)