monolieta-search

Search library for browser and Node.js

Usage no npm install needed!

<script type="module">
  import monolietaSearch from 'https://cdn.skypack.dev/monolieta-search';
</script>

README

monolieta-search Coverage Status

Monolieta-Search

Search library for browser and Node.js

Getting started

Install monolieta-search using yarn or npm

yarn add monolieta-search
npm install monolieta-search

Usage

import { Search } from "monolieta-search";

const client = new Search();
client.index("001", "The Lord of the Rings");
client.index("002", "The Hobbit");

client.search("the hobbit"); // ["002", "001"]

Setting

Name Type Default Description
caseSensitive boolean false
exactWordStrategy boolean false
ignoreAccent boolean true
stopWord Object null
unorderedDocument boolean true

Case sensitive

const client = new Search({
    caseSensitive: true,
});

client.index("001", "The Lord of the Rings");
client.index("002", "The Hobbit");

client.search("hobbit"); // []
client.search("Hobbit"); // ["002"]

Exact word strategy

const client = new Search({
    exactWordStrategy: true,
});

client.index("001", "The Lord of the Rings");
client.index("002", "The Hobbit");

client.search("o"); // []
client.search("Rings"); // ["001"]

Ignore accent

const client = new Search({
    ignoreAccent: false,
});

client.index("001", "Parásitos");
client.index("002", "Déjame salir");
client.index("003", "El Tiburón");

client.search("Tiburon"); // []
client.search("Tiburón"); // ["003"]

Stop word

const client = new Search({
    stopWord: {
        the: true,
    },
});

client.index("001", "The Lord of the Rings");
client.index("002", "The Hobbit");

client.search("the"); // []
client.search("the hobbit"); // ["002"]

Unordered document

const client = new Search({
    unorderedDocument: false,
});

client.index("001", "The Lord of the Rings");
client.index("002", "The Hobbit");

client.search("the"); // ["001", "002"]
client.search("the hobbit"); // ["002", "001"]

License

This project is licensed under the MIT License.