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

minor refactoring to align with the documentation

This commit is contained in:
Thomas Wilkerling
2025-03-30 21:57:37 +02:00
parent bdfddd5509
commit 40f17691bf
118 changed files with 870 additions and 816 deletions

View File

@@ -12,7 +12,7 @@ const Charset = _Charset || (await import("../src/charset.js")).default;
describe("Context", function(){
it("Should have been added properly to the context", function(){
it("Should have been added properly to the context (bidirectional enabled)", function(){
let index = new Index({
tokenize: "strict",
@@ -26,13 +26,20 @@ describe("Context", function(){
expect(index.reg.size).to.equal(1);
expect(index.search("zero one")).to.include(0);
expect(index.search("zero two")).to.include(0);
// breaks the context chain:
expect(index.search("zero three").length).to.equal(0);
expect(index.search("zero three", { suggest: true })).to.include(0);
// breaks the context chain:
expect(index.search("three seven").length).to.equal(0);
expect(index.search("three seven", { suggest: true })).to.include(0);
expect(index.search("three five seven")).to.include(0);
// bidirectional:
expect(index.search("eight six four")).to.include(0);
expect(index.search("seven five three")).to.include(0);
expect(index.search("three foobar seven").length).to.equal(0);
expect(index.search("three foobar seven", { suggest: true })).to.include(0);
expect(index.search("seven foobar three").length).to.equal(0);
expect(index.search("seven foobar three", { suggest: true })).to.include(0);
expect(index.search("eight ten")).to.include(0);
expect(index.search("ten nine seven eight six five three four two zero one")).to.include(0);
@@ -42,6 +49,7 @@ describe("Context", function(){
expect(index.search("1 5")).to.include(1);
expect(index.search("2 4 1")).to.include(1);
// disable bidirectional
index = new Index({
tokenize: "strict",
context: {
@@ -53,4 +61,41 @@ describe("Context", function(){
index.add(0, "zero one two three four five six seven eight nine ten");
expect(index.search("ten nine seven eight six five three four two zero one").length).to.equal(0);
});
it("Should have been added properly to the context when bidirectional was disabled", function(){
let index = new Index({
tokenize: "strict",
context: {
depth: 2,
bidirectional: false
}
});
index.add(1, "1 2 3 4 5 6 7 8 9");
expect(index.search("3 1").length).to.equal(0);
expect(index.search("4 3 2").length).to.equal(0);
});
it("Should have been added properly when dupes will break the context chain", function(){
const index = new Index({
context: {
depth: 2
}
});
index.add(1, "1 2 3 4 5 6 7 8 1 2 9");
expect(index.search("1 9")).to.include(1);
expect(index.search("1 2 9")).to.include(1);
expect(index.search("9 1 2")).to.include(1);
// todo shuffled chain:
//expect(index.search("1 3 9")).to.include(1);
expect(index.search("3 1 9")).to.include(1);
expect(index.search("9 1 3")).to.include(1);
// todo shuffled chain:
//expect(index.search("9 3 1")).to.include(1);
});
});

View File

@@ -43,7 +43,7 @@ describe("Encoder: Charset", function(){
const index = new Index({ encoder: Charset.Exact });
expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(
["Björn-Phillipp", "Mayer"]
["Björn", "Phillipp", "Mayer"]
);
});

View File

@@ -227,15 +227,31 @@ export default function(DB, DBClass){
// mount database to the index
//await db.mount(document);
//expect(document.index.get("primaryTitle").db).to.be.instanceof(db.constructor);
//document.clear();
//await document.clear();
// add test data
for(let i = 0; i < data.length; i++){
document.add(data[i]);
}
expect(document.index.get("primaryTitle").reg.size).to.equal(2);
expect(document.index.get("primaryTitle").map.size).to.equal(25);
expect(document.index.get("originalTitle").reg.size).to.equal(2);
expect(document.index.get("originalTitle").map.size).to.equal(25);
// tag pseudo indexes (persistent only)
expect(document.index.get("startYear").reg.size).to.equal(2);
expect(document.index.get("startYear").map.size).to.equal(0);
expect(document.index.get("genres").reg.size).to.equal(2);
expect(document.index.get("genres").map.size).to.equal(0);
expect(document.reg.size).to.equal(2);
expect(document.store.size).to.equal(2);
expect(document.tag.size).to.equal(2);
expect(document.tag.get("startYear").size).to.equal(2);
expect(document.tag.get("genres").size).to.equal(3);
// transfer changes in bulk
await document.commit();
//await new Promise(resolve => setTimeout(resolve, 200));
expect(document.index.get("primaryTitle").reg.size).to.equal(0);
expect(document.index.get("primaryTitle").map.size).to.equal(0);

View File

@@ -42,8 +42,8 @@ describe("Scoring", function(){
expect(index.search("1")).to.eql([0]);
expect(index.search("one")).to.eql([1, 2]);
expect(index.search("one two")).to.eql([2]); // 1: no bi-directional
expect(index.search("four one")).to.eql([1]); // 2: no bi-directional
expect(index.search("one two")).to.eql([1]); // 2 => no bi-directional
expect(index.search("four one")).to.eql([2]); // 1 => no bi-directional
index = new Index({
tokenize: "strict",