@nano-sql/plugin-fuzzy-search
Version:
Integrate Elastic Search style indexing in NanoSQL 2!
64 lines (55 loc) • 2 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.jsdelivr.net/npm/@nano-sql/core@2.3.2/dist/nano-sql.min.js"
integrity="sha256-sOydNXCPr6sSkdnlYvBmf4xA7vgdjA+mzMvlDKz3qFw=" crossorigin="anonymous"></script>
<script src="plugin-fuzzy-search.min.js"></script>
<title>Document</title>
</head>
<body>
<script>
function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 10; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
const { FuzzySearch, FuzzyUserSanitize, defaultTokenizer, stopWords } = window["@nano-sql/plugin-fuzzy-search"];
let rows = [];
const now = Date.now();
for (let i = 1; i < 10; i++) {
const time = new Date(now + (i * 1000));
rows.push({ name: makeid() });
}
nSQL().createDatabase({
plugins: [
FuzzySearch()
]
}).then(() => {
return nSQL().query("create table", {
name: "test",
model: {
"id:int": { pk: true, ai: true },
"name:string": {}
},
indexes: {
"name:string": { search: true }
}
}).exec();
}).then(() => {
return nSQL().selectTable("test").loadJS(rows);
}).then(() => {
return nSQL().query("select").limit(10).exec();
}).then((resultRows) => {
console.log(resultRows, nSQL());
nSQL().query("total").exec().then((rows) => {
console.log(rows);
})
});
</script>
</body>
</html>