Skip to content

Commit

Permalink
update readme and benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ts-thomas committed Jun 10, 2021
1 parent 9b4654b commit 86a5dfe
Show file tree
Hide file tree
Showing 27 changed files with 939 additions and 836 deletions.
800 changes: 286 additions & 514 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"flexsearch-match", "flexsearch-memory", "flexsearch-score",
"flexsearch-speed"
]:[
/*"flexsearch-0.6.2",*/ "flexsearch-0.6.3", "flexsearch-0.7.0",
/*"flexsearch-0.6.2", "flexsearch-0.6.3",*/ "minisearch", "flexsearch-0.7.0",
"bm25", "bulksearch", "elasticlunr",
"fuzzysearch", "js-search", "jsii",
"fuse", "lunr", "wade"
Expand Down
196 changes: 6 additions & 190 deletions bench/match.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,196 +18,12 @@ <h4>Indexed Text: "Gulliver's Travels" (Swift Jonathan 1726)</h4>
<hr>
<div id="container">
<table>
<tr>
<th style="width: 200px"><b>Query</b></th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
</tr>
<tr id="test-1">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-2">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-3">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-4">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-5">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-6">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-7">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-8">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-9">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-10">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-11">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<tr id="test-12">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
<!--
<tr>
<td colspan="11">
<br>
Contextual Search Test:
</td>
</tr>
<tr id="test-13">
<td> </td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
</tr>
-->
<thead>
<tr style="font-weight: bold">
<td style="width: 200px">Query</td>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<hr>
Expand Down
68 changes: 36 additions & 32 deletions bench/match.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { text_data as data } from "../demo/data/gulliver.js";
import { text_data } from "../demo/data/gulliver.js";

const headers = document.getElementsByTagName("th");
const iframe = document.getElementsByTagName("iframe")[0];
const encode = false;
const lib = encode ? [
Expand All @@ -12,7 +11,7 @@ const lib = encode ? [
/*"flexsearch-0.6.2", "flexsearch-0.6.3",*/ "flexsearch-0.7.0-match",
"bm25", "bulksearch-match", "elasticlunr",
"fuzzysearch", "js-search", "jsii",
"fuse-match", "lunr", "wade"
"minisearch-match", "fuse-match", "lunr", "wade"
];

let promise;
Expand All @@ -28,9 +27,31 @@ window.onmessage = function(event){
}
};

window.data = data;
window.data = text_data;

//iframe.src = "test/" + lib[0].toLowerCase() + "/?query=gulliver" + (encode ? "&encode=true" : "") + "#match";
const tpl_td = document.createElement("td");
tpl_td.appendChild(document.createTextNode(""))

const root_head = document.getElementsByTagName("thead")[0].firstElementChild,
root_body = document.getElementsByTagName("tbody")[0];

const tpl_tr = document.createElement("tr");

for(let i = 0; i < lib.length + 1; i++){ // amount of libs + 1 for first row

tpl_tr.appendChild(tpl_td.cloneNode(true));
}

for(let i = 0; i < 12; i++){ // amount of tests + 1 for first row

const tr = tpl_tr.cloneNode(true);
tr.id = "test-" + (i + 1);

root_body.appendChild(tr);
root_head.appendChild(tpl_td.cloneNode(true));
}

const headers = root_head.getElementsByTagName("td");

// -----------------------------------------------------------

Expand All @@ -46,7 +67,6 @@ await do_test("test-9", "composition of minerals gums juices vegetables", [1676,
await do_test("test-10", "general camberlayhn", [520]);
await do_test("test-11", "the end defeat", [2209]);
await do_test("test-12", "fast chief", [1275]);
//await do_test("test-13", "zero one three ten", [2721, 2720, 2722]);

// ---------------------------------------

Expand All @@ -57,33 +77,25 @@ async function do_test(id, query, ref){

for(let i = 0, current; i < lib.length; i++){

current = lib[i];
headers[i + 1].firstChild.nodeValue = current.replace("-0.7.0", "").replace("-match", "");
current = lib[i].replace("-0.7.0", "").replace("-match", "");
headers[i + 1].firstChild.nodeValue = current;

const node = nodes[i + 1];
const style = node.style;

node.firstChild.nodeValue = "run ...";

let results = await new Promise(function(resolve){

promise = resolve;
iframe.src = "test/" + current + //(id === "test-13" && current === "flexsearch-0.7.0-match" ? "flexsearch-0.7.0-context" : current) +
"/?query=" + decodeURI(query) + (encode ? "&encode=true" : "") + "#match";
iframe.src = "test/" + lib[i] + "/?query=" + decodeURI(query) + (encode ? "&encode=true" : "") + "#match";
});

if(results.length){

switch(current){

// case "flexsearch":
// break;
//
// case "bulksearch":
// break;
//
// case "fuse":
// break;

case "elasticlunr":
results = results.map(val => val.ref);
break;

case "lunr":
results = results.map(val => val.ref);
break;
Expand All @@ -93,26 +105,18 @@ async function do_test(id, query, ref){
break;

case "js-search":
results = results.map(val => val.id);
break;

case "minisearch":
case "jsii":
results = results.map(val => val.id);
break;

case "bm25":
results = results.map(val => val.id);
break;

case "fuzzysearch":
results = results.map(val => data.indexOf(val));
results = results.map(val => text_data.indexOf(val));
break;
}
}

const node = nodes[lib.indexOf(current) + 1];
const style = node.style;

for(let a = 0; a < ref.length; a++){

const current = ref[a];
Expand Down
51 changes: 51 additions & 0 deletions bench/test/bulksearch-match/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Benchmark</title>
</head>
<body>
<h2>Benchmark: bulksearch-0.1.3</h2><hr/>
<h4>Indexed Text: "Gulliver's Travels" (Swift Jonathan 1726)</h4>
<div id="result" style="white-space: pre; font-family: Monospaced, monospace"></div>
<script src="https://cdn.jsdelivr.net/gh/nextapps-de/bulksearch@master/bulksearch.min.js"></script>
<script type="module">

import { suite } from "../../bench.js";

let lib;

suite["bulksearch"] = {

init: function(){

lib = new BulkSearch({

type: "short",
encode: 'extra',
multi: true
});
},
add: function(data){

for(let i = 0, len = data.length; i < len; i++){

lib.add(i, data[i]);
}
},
update: function(data){

for(let i = 0, len = data.length; i < len; i++){

lib.update(i, data[i]);
}
},
query: function(query){

return lib.search(query, { suggest: true });
}
};

</script>
</body>
</html>
Loading

0 comments on commit 86a5dfe

Please sign in to comment.