fulltext-search-kit
- A utility library for full-text search in TypeScript.
- I have no intention of removing this package until npm ceases to exist.
Features
- Full-text search functionality
- Supports multiple search requirements
- Handles special character removal
- Optimized for Korean text
- Supports 초성 (initial consonant) search in Korean
- Supports mixed search terms like ‘한ㄱㅇ’ (partially composed + initials)
- Highlights matched search terms
Live Demo
Installation
You can install the library using npm:
npm install fulltext-search-kitor using yarn:
yarn add fulltext-search-kitUsage
Importing the Library
To use the latest full-text search functionality:
import { fullTextSearch, getFullTextSearchHighlights } from 'fulltext-search-kit';⚠️ Deprecated Notice
returnFullTextSearchFilteredDatawill be removed in version 3.0.0.
Please migrate tofullTextSearchandgetFullTextSearchHighlightsfor all new development.
Basic Example
const data = [
{ name: 'John Doe01012', age: 30, phoneNumber: '010-2345-7890' },
{ name: 'Jane Smith01023', age: 25, phoneNumber: '010-1234-5678' },
{ name: 'Alice Johnson01023', age: 35, phoneNumber: '010-5500-4455' },
];
const filteredData = fullTextSearch({
data,
searchRequirement: [
{ value: 'name', keywords: ['Jane'] },
{ value: 'phoneNumber', keywords: ['0101234'] },
],
});Highlight Example
const highlights = getFullTextSearchHighlights({
item: data[1],
searchRequirement: [
{ value: 'name', keywords: ['Jane'] },
{ value: 'phoneNumber', keywords: ['0101234'] },
],
});Korean Initials & Mixed Term Example
const filtered = fullTextSearch({
data,
searchRequirement: [
{ value: 'name', keywords: ['한ㄱㅇ'] }, // matches 한가영
],
});API
fullTextSearch
Filters an array of objects based on search requirements.
Parameters
data: Array<T>: The data to search through.searchRequirement: Array<{ value: string; keywords: string[] }>: The field names and search terms.
Returns
Array<T>: The filtered data.
getFullTextSearchHighlights
Returns the matched highlights from a specific item.
Parameters
item: T: The data item to check.searchRequirement: Array<{ value: string; keywords: string[] }>: The fields and search keywords.
Returns
Partial<Record<keyof T, string>>: Object with<mark>-tagged matched highlights.
Deprecated Functions
returnFullTextSearchFilteredData ⚠️ Deprecated
This function will be removed in v3.0.0.
Please migrate tofullTextSearch.
const filteredData = returnFullTextSearchFilteredData({
data,
searchRequirement: [
{ value: 'name' },
{ value: 'phoneNumber', removeCharacters: '-' },
],
searchFilterText: 'Jane',
});Internal Functions (For Contributors)
fullTextSearchCore: Low-level core functionescapeRegExp: Escapes RegExp special charscharacterPatternCheckerCore: Korean pattern generatorgetInitialsListWithSpaces: Extracts 초성 list with spacing logichighlightText: Internal highlighter engine
Changelog (v2.x → v3 Preview)
- ✅ Supports mixed search keywords like
한ㄱㅇ - ✅ Highlights matched values
- ✅
keywordsnow supports multiple per field - ✅
getFullTextSearchHighlightsfunction added - ⚠️
returnFullTextSearchFilteredDatamarked as deprecated
Contributing
- Contributions are welcome!
License
- This project is licensed under the MIT License - see the LICENSE file for details.
Author
ByungHyunWoo(KR)