1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-02 02:12:46 +02:00

ADD suggestions

This commit is contained in:
Thomas Wilkerling
2018-03-27 19:16:15 +02:00
parent 2b5d9ceed7
commit aae24b5e3b
8 changed files with 267 additions and 110 deletions

View File

@@ -3,8 +3,8 @@
<head>
<meta charset="utf-8">
<title>Matching Test</title>
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.min.js"></script><!--<script src="../flexsearch.js"></script>-->
<script src="https://rawgit.com/nextapps-de/bulksearch/master/bulksearch.min.js"></script>
<script src="https://rawgit.com/nextapps-de/flexsearch/master/flexsearch.min.js"></script>
<script src="https://rawgit.com/nextapps-de/bulksearch/master/bulksearch.min.js"></script><!--<script src="../bulksearch.js"></script>-->
<script src="https://cdn.rawgit.com/weixsong/elasticlunr.js/master/example/elasticlunr.min.js"></script>
<script src="https://unpkg.com/lunr@2.1.6/lunr.js"></script>
<script src="https://cdn.rawgit.com/kbrsh/wade/master/dist/wade.min.js"></script>
@@ -44,7 +44,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<th>bm25</th>
</tr>
<tr id="test-1">
<td style="width: 200px">"without breach of modesty"</td>
<td style="width: 200px"></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -56,7 +56,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-2">
<td>"went softly stream"</td>
<td></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -68,7 +68,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-3">
<td>"princes of the ambition"</td>
<td></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -80,7 +80,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-4">
<td>"five-thousand leagues"</td>
<td></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -92,7 +92,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-5">
<td>"i already observed"</td>
<td></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -104,7 +104,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-6">
<td>"let a of his"</td>
<td></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -116,7 +116,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-7">
<td>"take that to the rocks"</td>
<td></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -128,7 +128,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-8">
<td>"bignes of splaknuk"</td>
<td></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -140,7 +140,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-9">
<td>"matematikal musikal instruments"</td>
<td></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -152,7 +152,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-10">
<td>"matical sical strument"</td>
<td></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -164,7 +164,37 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
<td>wait ...</td>
</tr>
<tr id="test-11">
<td>"lalkon the camberlayhn"</td>
<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>
</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>
</tr>
<tr>
<td colspan="10">
<br>
Contextual Search Test:
</td>
</tr>
<tr id="test-13">
<td style="width: 200px"></td>
<td>wait ...</td>
<td>wait ...</td>
<td>wait ...</td>
@@ -207,6 +237,12 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
}
}
data.push('zero one two three four five six seven eight nine ten.');
data.push('zero one two three four five six seven eight nine ten.');
data.push('four two zero one three ten five seven eight six nine.');
data.push('zero one two three four five six seven eight nine ten.');
data.push('zero one two three four five six seven eight nine ten.');
tmp = null;
new_data = null;
text_data = null;
@@ -225,10 +261,14 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
bulksearch = new BulkSearch({
type: 'short', // this type specifies the maximum bitlength of assigned IDs!
encode: 'advanced',
encode: 'extra',
multi: true,
suggest:true,
filter: true,
stemmer: true,
async: false,
cache: false
cache: false,
worker: false
});
console.time('bulksearch');
@@ -246,6 +286,7 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
mode: 'strict',
threshold: 5,
depth: 3,
suggest:true,
filter: true,
stemmer: true,
async: false,
@@ -376,12 +417,14 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
do_test('test-3', 'princes of the ambition', [72, 408]);
do_test('test-4', 'five-thousand leagues', [2]);
do_test('test-5', 'i already observed', [458, 346]);
do_test('test-6', 'let a of his', [50]);
do_test('test-7', 'take that to the rocks', [175]);
do_test('test-8', 'bignes of splaknuk', [146]);
do_test('test-9', 'matematikal musikal instruments', [267]);
do_test('test-10', 'matical sical strument', [267]);
do_test('test-11', 'lalkon the camberlayhn', [99]);
do_test('test-6', 'disgust the bigness', [175]);
do_test('test-7', 'bignes of splaknuk', [146]);
do_test('test-8', 'matematikal musikal instruments', [267]);
do_test('test-9', 'composition of minerals gums juices vegetables', [303]);
do_test('test-10', 'lalkon the camberlayhn', [99]);
do_test('test-11', 'to be at all this is', [184]);
do_test('test-12', 'matical sical strument', [267]);
do_test('test-13', 'zero one three ten', [504]);
// ---------------------------------------
@@ -389,6 +432,8 @@ var text_data = "LIBRARY OF THE FUTURE (R) First Edition Ver. 4.02 Gulliver's Tr
var nodes = document.getElementById(id).getElementsByTagName('td');
nodes[0].innerHTML = query;
for(var i = 1; i < nodes.length; i++){
var results;

View File

@@ -884,7 +884,7 @@ describe('Context', function(){
});
// ------------------------------------------------------------------------
// Encoding Tests
// Tokenizer Tests
// ------------------------------------------------------------------------
describe('Options', function(){
@@ -991,6 +991,7 @@ describe('Relevance', function(){
expect(index.search("1 3 4")).to.have.members([0]);
expect(index.search("1 5 3 4")).to.have.members([0]);
expect(index.search("1 3 4 7")).to.have.lengthOf(0);
expect(index.search("one")).to.have.members([1, 2]);
expect(index.search("one three")).to.have.members([1, 2]);
expect(index.search("three one")).to.have.members([1, 2]);
@@ -998,6 +999,33 @@ describe('Relevance', function(){
});
});
// ------------------------------------------------------------------------
// Suggestion Tests
// ------------------------------------------------------------------------
describe('Suggestion', function(){
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);
});
});
// ------------------------------------------------------------------------
// Feature Tests
// ------------------------------------------------------------------------
@@ -1029,9 +1057,8 @@ describe('Add Matchers', function(){
}).addMatcher({
'8': 'f'
});
flexsearch_forward.add(0, "12345678");
}).add(0, "12345678");
expect(flexsearch_forward.search("12345678")).to.include(0);
expect(flexsearch_forward.search("abcd")).to.include(0);
@@ -1152,5 +1179,5 @@ describe('Chaining', function(){
function test_encoder(str){
return str = '-[' + str.toUpperCase() + ']-';
return '-[' + str.toUpperCase() + ']-';
}