#software-engineering
## [Minisearch](<[lucaong/minisearch: Tiny and powerful JavaScript full-text search engine for browser and Node (github.com)](https://github.com/lucaong/minisearch)>)
```
pnpm install minisearch
```
```ts
import MiniSearch from 'minisearch'
// A collection of documents for our examples
const documents = [
{
id: 1,
title: 'Moby Dick',
text: 'Call me Ishmael. Some years ago...',
category: 'fiction'
},
{
id: 2,
title: 'Zen and the Art of Motorcycle Maintenance',
text: 'I can see by my watch...',
category: 'fiction'
},
{
id: 3,
title: 'Neuromancer',
text: 'The sky above the port was...',
category: 'fiction'
},
{
id: 4,
title: 'Zen and the Art of Archery',
text: 'At first sight it must seem...',
category: 'non-fiction'
},
// ...and more
]
let miniSearch = new MiniSearch({
fields: ['title', 'text'], // fields to index for full-text search
storeFields: ['title', 'category'] // fields to return with search results
})
// Index all documents
miniSearch.addAll(documents)
// Search with default options
let results = miniSearch.search('zen art motorcycle')
// => [
// { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258, match: { ... } },
// { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629, match: { ... } }
// ]
```
## [Fusejs](https://www.fusejs.io/demo.html)
```
pnpm install fuse.js
```
```ts
import Fuse from 'fuse.js'
const list = [
{
"title": "Old Man's War",
"author": {
"firstName": "John",
"lastName": "Scalzi"
}
},
...
]
const fuseOptions = {
keys: [
"title",
"author.firstName"
]
};
const fuse = new Fuse(list, fuseOptions);
// Change the pattern
const searchPattern = "David"
return fuse.search(searchPattern)
```
## [Orama](https://github.com/oramasearch/orama)
```
pnpm add @orama/orama
```
create schema
```ts
import { create, insert, remove, search, searchVector } from '@orama/orama'
const db = await create({
schema: {
name: 'string',
description: 'string',
price: 'number',
embedding: 'vector[1536]', // Vector size must be expressed during schema initialization
meta: {
rating: 'number',
},
},
})
```
add documents
```ts
await insert(db, {
name: 'Wireless Headphones',
description: 'Experience immersive sound quality with these noise-cancelling wireless headphones.',
price: 99.99,
embedding: [...],
meta: {
rating: 4.5,
},
})
await insert(db, {
name: 'Smart LED Bulb',
description: 'Control the lighting in your home with this energy-efficient smart LED bulb, compatible with most smart home systems.',
price: 24.99,
embedding: [...],
meta: {
rating: 4.3,
},
})
await insert(db, {
name: 'Portable Charger',
description: 'Never run out of power on-the-go with this compact and fast-charging portable charger for your devices.',
price: 29.99,
embedding: [...],
meta: {
rating: 3.6,
},
})
```
search
```ts
const searchResult = await search(db, {
term: 'headphones',
})
```