https://github.com/toastdriven/nanosearch
A tiny search engine.
https://github.com/toastdriven/nanosearch
engine ngram search
Last synced: about 2 months ago
JSON representation
A tiny search engine.
- Host: GitHub
- URL: https://github.com/toastdriven/nanosearch
- Owner: toastdriven
- License: bsd-3-clause
- Created: 2022-07-26T12:32:56.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-06T21:11:09.000Z (about 3 years ago)
- Last Synced: 2025-08-13T14:54:34.770Z (about 2 months ago)
- Topics: engine, ngram, search
- Language: JavaScript
- Homepage: https://toastdriven.github.io/nanosearch/
- Size: 2.41 MB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# `nanosearch`
A tiny search engine.
Suitable for in-browser use, this provides n-gram based search results.
## Quickstart
```js
import { SearchEngine } from '@toastdriven/nanosearch';// Create a search engine.
const engine = new SearchEngine();// Index some documents.
// First parameter is the unique document ID, second is the document text.
engine.add("abc", "The dog is a 'hot dog'.");
engine.add("def", "Dogs > Cats");
engine.add("ghi", "the quick brown fox jumps over the lazy dog");
engine.add("jkl", "Am I lazy, or just work smart?");// Then, you can let the user search on the engine...
let myDogResults = engine.search("my dog");
myDogResults.count(); // 3for(let res of myDogResults.iterator()) {
console.log(res.docId); // ex: "def"
console.log(res.score); // ex: 0.2727272727272727
}// ...including limiting results (to just one)...
let lazyResults = engine.search("lazy");
let topResult = lazyResults.at(0);
console.log(topResult);// ...or making pages of ten results!
let dogResults = engine.search("dogs");
let pageOne = dogResults.slice(0, 10);
let pageTwo = dogResults.slice(10, 20);
console.log(pageOne);
console.log(pageTwo);
```## Installation
`$ npm install @toastdriven/nanosearch`
## Requirements
* ES6 (or similar translation/polyfill)
## Tests
```shell
$ git clone git@github.com:toastdriven/nanosearch.git
$ cd nanosearch
$ npm install
$ npm test
```## Docs
```shell
$ git clone git@github.com:toastdriven/nanosearch.git
$ cd nanosearch
$ npm install
$ ./node_modules/.bin/jsdoc -r -d ~/Desktop/out --package package.json --readme README.md src
```## License
New BSD