mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-03 10:53:41 +02:00
v0.3.1
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<h2>Benchmark Comparison</h2>
|
||||
<button id="btn_start" onclick="start();" disabled>Start</button>
|
||||
<!--<button id="btn_start" onclick="start();" disabled>Start</button>-->
|
||||
<h4>Indexed Text: "Gulliver's Travels" (Swift Jonathan 1726)</h4>
|
||||
<hr>
|
||||
<div id="container"></div>
|
||||
@@ -370,15 +370,23 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
target.innerHTML = html;
|
||||
}
|
||||
|
||||
var is_mobile = navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/);
|
||||
|
||||
function init_tests(index, keys){
|
||||
|
||||
var key = keys[index];
|
||||
var test = tests[key];
|
||||
|
||||
tests[key].init();
|
||||
test.init();
|
||||
|
||||
if(is_mobile && (test.loops > 1)){
|
||||
|
||||
test.loops = (test.loops / 5) >> 0;
|
||||
}
|
||||
|
||||
for(var i = 0; i < text_data.length; i++){
|
||||
|
||||
tests[key].add(i, text_data[i]);
|
||||
test.add(i, text_data[i]);
|
||||
}
|
||||
|
||||
document.getElementById("test-" + key).textContent = "ready ...";
|
||||
@@ -389,24 +397,24 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
init_tests(index, keys);
|
||||
|
||||
}, 50);
|
||||
}, 100);
|
||||
}
|
||||
else{
|
||||
|
||||
/*
|
||||
window.start = function(){
|
||||
|
||||
start_tests(0, Object.keys(tests));
|
||||
};
|
||||
|
||||
document.getElementById("btn_start").disabled = false;
|
||||
*/
|
||||
|
||||
/*
|
||||
setTimeout(function(){
|
||||
|
||||
start_tests(0, keys);
|
||||
|
||||
}, 50);
|
||||
*/
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,9 +423,9 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
var queries = text_queries;
|
||||
var len = queries.length;
|
||||
var key = keys[index];
|
||||
var current = tests[key];
|
||||
var loops = current.loops;
|
||||
var query = current.query;
|
||||
var test = tests[key];
|
||||
var loops = test.loops;
|
||||
var query = test.query;
|
||||
|
||||
var start = Date.now();
|
||||
|
||||
@@ -435,7 +443,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
console.log(key + ":", duration);
|
||||
|
||||
document.getElementById("test-" + key).textContent = format_number((1000 / duration * loops + 0.5) >> 0) + " op/s";
|
||||
document.getElementById("test-" + key).textContent = /*format_number*/((1000 / duration * loops + 0.5) >> 0) + " op/s";
|
||||
|
||||
if(++index < keys.length){
|
||||
|
||||
@@ -443,7 +451,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
start_tests(index, keys);
|
||||
|
||||
}, 50);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,7 +461,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
init_tests(0, Object.keys(tests));
|
||||
|
||||
}, 50);
|
||||
}, 100);
|
||||
|
||||
function format_number(num){
|
||||
|
||||
@@ -462,7 +470,7 @@ Test rules: 1. no cache allowed, 2. no async allowed, 3. should return at least
|
||||
|
||||
// ---------------------------------------
|
||||
|
||||
window.tests = tests;
|
||||
//window.tests = tests;
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
116
test/test.js
116
test/test.js
@@ -513,18 +513,42 @@ if(env !== "light"){
|
||||
flexsearch_async.update(1, "foo");
|
||||
|
||||
expect(flexsearch_async.length).to.equal(3);
|
||||
expect(flexsearch_async.search("foo")).to.not.have.members([2, 1]);
|
||||
expect(flexsearch_async.search("bar")).to.not.include(0);
|
||||
expect(flexsearch_async.search("bar")).to.include(2);
|
||||
expect(flexsearch_async.search("foobar")).to.not.include(2);
|
||||
|
||||
flexsearch_async.search("foo").then(function(result){
|
||||
expect(result).to.not.have.members([2, 1]);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar").then(function(result){
|
||||
expect(result).to.not.include(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar").then(function(result){
|
||||
expect(result).to.include(2);
|
||||
});
|
||||
|
||||
flexsearch_async.search("foobar").then(function(result){
|
||||
expect(result).to.not.include(2);
|
||||
});
|
||||
|
||||
setTimeout(function(){
|
||||
|
||||
expect(flexsearch_async.length).to.equal(3);
|
||||
expect(flexsearch_async.search("foo")).to.have.members([2, 1]);
|
||||
expect(flexsearch_async.search("bar")).to.include(0);
|
||||
expect(flexsearch_async.search("bar")).to.not.include(2);
|
||||
expect(flexsearch_async.search("foobar")).to.include(2);
|
||||
|
||||
flexsearch_async.search("foo", function(result){
|
||||
expect(result).to.have.members([2, 1]);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar", function(result){
|
||||
expect(result).to.include(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar", function(result){
|
||||
expect(result).to.not.include(2);
|
||||
});
|
||||
|
||||
flexsearch_async.search("foobar", function(result){
|
||||
expect(result).to.include(2);
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
@@ -546,10 +570,22 @@ if(env !== "light"){
|
||||
setTimeout(function(){
|
||||
|
||||
expect(flexsearch_async.length).to.equal(3);
|
||||
expect(flexsearch_async.search("foo")).to.have.members([2, 1]);
|
||||
expect(flexsearch_async.search("bar")).to.include(0);
|
||||
expect(flexsearch_async.search("bar")).to.not.include(2);
|
||||
expect(flexsearch_async.search("foobar")).to.include(2);
|
||||
|
||||
flexsearch_async.search("foo").then(function(result){
|
||||
expect(result).to.have.members([2, 1]);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar").then(function(result){
|
||||
expect(result).to.include(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar").then(function(result){
|
||||
expect(result).to.not.include(2);
|
||||
});
|
||||
|
||||
flexsearch_async.search("foobar").then(function(result){
|
||||
expect(result).to.include(2);
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
@@ -570,9 +606,18 @@ if(env !== "light"){
|
||||
setTimeout(function(){
|
||||
|
||||
expect(flexsearch_async.length).to.equal(0);
|
||||
expect(flexsearch_async.search("foo")).to.have.lengthOf(0);
|
||||
expect(flexsearch_async.search("bar")).to.have.lengthOf(0);
|
||||
expect(flexsearch_async.search("foobar")).to.have.lengthOf(0);
|
||||
|
||||
flexsearch_async.search("foo", function(result){
|
||||
expect(result).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("bar", function(result){
|
||||
expect(result).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
flexsearch_async.search("foobar", function(result){
|
||||
expect(result).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
done();
|
||||
|
||||
@@ -767,6 +812,8 @@ if(env !== "light"){
|
||||
|
||||
it("Should have been removed from the index", function(done){
|
||||
|
||||
expect(flexsearch_worker.length).to.equal(3);
|
||||
|
||||
flexsearch_worker.remove(0);
|
||||
flexsearch_worker.remove(2);
|
||||
flexsearch_worker.remove(1);
|
||||
@@ -1039,28 +1086,31 @@ describe("Relevance", function(){
|
||||
// Suggestion Tests
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
describe("Suggestion", function(){
|
||||
if(env !== "light"){
|
||||
|
||||
it("Should have been suggested properly by relevance", function(){
|
||||
describe("Suggestion", function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
encode: "advanced",
|
||||
mode: "strict",
|
||||
suggest: true
|
||||
it("Should have been suggested properly by relevance", function(){
|
||||
|
||||
var index = new FlexSearch({
|
||||
encode: "advanced",
|
||||
mode: "strict",
|
||||
suggest: true
|
||||
});
|
||||
|
||||
index.add(0, "1 2 3 2 4 1 5 3");
|
||||
index.add(1, "zero one two three four five six seven eight nine ten");
|
||||
index.add(2, "four two zero one three ten five seven eight six nine");
|
||||
|
||||
expect(index.search("1 3 4 7")).to.have.members([0]);
|
||||
expect(index.search("1 3 9 7")).to.have.members([0]);
|
||||
expect(index.search("one foobar two")).to.have.members([1, 2]);
|
||||
expect(index.search("zero one foobar two foobar")).to.have.members([1, 2]);
|
||||
//TODO
|
||||
//expect(index.search("zero one foobar two foobar")[0]).to.equal(1);
|
||||
});
|
||||
|
||||
index.add(0, "1 2 3 2 4 1 5 3");
|
||||
index.add(1, "zero one two three four five six seven eight nine ten");
|
||||
index.add(2, "four two zero one three ten five seven eight six nine");
|
||||
|
||||
expect(index.search("1 3 4 7")).to.have.members([0]);
|
||||
expect(index.search("1 3 9 7")).to.have.members([0]);
|
||||
expect(index.search("one foobar two")).to.have.members([1, 2]);
|
||||
expect(index.search("zero one foobar two foobar")).to.have.members([1, 2]);
|
||||
//TODO
|
||||
//expect(index.search("zero one foobar two foobar")[0]).to.equal(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Feature Tests
|
||||
|
Reference in New Issue
Block a user