MCPcopy Index your code
hub / github.com/cjinhuo/text-search-engine

github.com/cjinhuo/text-search-engine @1.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.2.0 ↗ · + Follow
84 symbols 207 edges 60 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README
<h2>Text Search Engine</h2>

A text search engine that supports mixed Chinese and English fuzzy search

Overview

中文 README

A dynamic programming-based text search engine that supports mixed Chinese and English fuzzy search, returning the highest-weight matching results.

Who use it?

Online Demo

Check out this online demo if you are interested.

online-demo

Installation

npm i text-search-engine

Supported Environments

Supports both Node.js and Web environments.

Usage

search

Pure English Search

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') Match result: nonode

Pure Chinese Search

import { search } from 'text-search-engine'

const source = '地表最强前端监控平台'

search(source, 'jk') // [[6, 7]]
search(source, 'qianduapt') // [[4, 5],[8, 9]]

search('地表最强前端监控平台', 'qianduapt') Match result: 地表最强前端监控平台

Mixed Chinese and English Search

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') Match result: Node.js 最强监控平台 V9

Space-separated Search

Adding spaces makes each term independent. Each term starts matching from the beginning, and matched terms will be removed, so the next term starts matching from the beginning and ignores previously matched terms.

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') Match result: Node.js 最强监控平台 V9

Sort of Backtracking

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]])

highlightMatches

This API is used for quickly validating text match highlights. It returns ANSI escape codes that can be output using console.log in both Web and Node.js environments to see the highlighted text.

import { highlightMatches } from 'text-search-engine'
console.log(highlightMatches('Node.js 最强监控平台 V9', 'nodev9'))

The console will output: Node.js 最强监控平台 V9

options

mergeSpaces

Default: 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]])

Performance

Time Complexity Space Complexity
Best O(M(source)) O(M(source))
Worst O(M(source) * N(target)) O(M(source) * N(target))

📞 contact

welcome to raise issue, you can contact me on wx or email if you have some good suggestion(notes: text-search-engine) * wx:cjinhuo * email: cjinhuo@qq.com

Extension points exported contracts — how you extend this code

SourceMappingData (Interface)
(no doc)
packages/text-search-engine/src/types.ts
Window (Interface)
(no doc)
app/online-demo/src/global.d.ts
SearchOption (Interface)
(no doc)
packages/text-search-engine/src/types.ts
IconParkIconAttributes (Interface)
(no doc)
app/online-demo/src/vite-env.d.ts
SearchOptionWithPinyin (Interface)
(no doc)
packages/text-search-engine/src/types.ts
IntrinsicElements (Interface)
(no doc)
app/online-demo/src/vite-env.d.ts
ILightedFuncProps (Interface)
(no doc)
app/online-demo/src/components/LightedText/index.tsx
Iprops (Interface)
(no doc)
app/online-demo/src/components/showTip/index.tsx

Core symbols most depended-on inside this repo

search
called by 16
packages/text-search-engine/src/exports.ts
extractBoundaryMapping
called by 5
packages/text-search-engine/src/boundary.ts
getBasicOutput
called by 4
utils/rollup/src/output.js
getBasicPlugins
called by 4
utils/rollup/src/common.js
getDirName
called by 4
utils/rollup/src/utils.js
searchSentenceByBoundaryMapping
called by 3
packages/text-search-engine/src/search.ts
isEmptyString
called by 2
packages/text-search-engine/src/utils.ts
mergeSpacesWithRanges
called by 2
packages/text-search-engine/src/utils.ts

Shape

Function 59
Interface 15
Method 6
Class 2
Enum 2

Languages

TypeScript100%

Modules by API surface

app/online-demo/src/shared/storeUtil.ts8 symbols
packages/text-search-engine/src/utils.ts6 symbols
app/online-demo/src/shared/utils.ts6 symbols
packages/text-search-engine/src/search.ts5 symbols
utils/rollup/bin/index.js4 symbols
packages/text-search-engine/src/exports.ts4 symbols
app/online-demo/src/hooks/useNotification.ts4 symbols
packages/text-search-engine/src/types.ts3 symbols
app/online-demo/src/components/SnackTip/index.tsx3 symbols
app/online-demo/src/components/ListSearch/index.tsx3 symbols
packages/text-search-engine/src/boundary.ts2 symbols
app/online-demo/src/vite-env.d.ts2 symbols

For agents

$ claude mcp add text-search-engine \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page