mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-01 18:03:56 +02:00
minor refactoring, dedupe default on
This commit is contained in:
@@ -64,10 +64,10 @@ describe("Initialize", function(){
|
||||
index.encoder.normalize = encoder.normalize;
|
||||
expect(index.encoder).to.eql(encoder);
|
||||
expect(index.encoder.minlength).to.equal(1);
|
||||
expect(index.encoder.maxlength).to.equal(0);
|
||||
expect(index.encoder.maxlength).to.equal(1024);
|
||||
expect(index.encoder.rtl).to.equal(false);
|
||||
expect(index.encoder.numeric).to.equal(true);
|
||||
expect(index.encoder.dedupe).to.equal(false);
|
||||
expect(index.encoder.dedupe).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -82,8 +82,8 @@ describe("Add", function(){
|
||||
index.add(1, "FooBar");
|
||||
index.add(3, "Some 'short' content.");
|
||||
|
||||
expect(index.reg.keys()).to.have.members([0, 1, 2, 3]);
|
||||
expect(index.map.keys()).to.have.members(["foo", "bar", "foobar", "some", "short", "content"]);
|
||||
expect(Array.from(index.reg.keys())).to.have.members([0, 1, 2, 3]);
|
||||
expect(Array.from(index.map.keys())).to.have.members(["fo", "bar", "fobar", "some", "short", "content"]);
|
||||
expect(index.ctx.size).to.equal(0);
|
||||
expect(index.reg.size).to.equal(4);
|
||||
});
|
||||
@@ -97,12 +97,12 @@ describe("Add", function(){
|
||||
index.add(2, "T10030T10030");
|
||||
index.add(3, "1443-AB14345-1778");
|
||||
|
||||
expect(index.reg.keys()).to.have.members([0, 1, 2, 3]);
|
||||
expect(index.map.keys()).to.have.members([
|
||||
expect(Array.from(index.reg.keys())).to.have.members([0, 1, 2, 3]);
|
||||
expect(Array.from(index.map.keys())).to.have.members([
|
||||
"test", "123", "456", "789",
|
||||
"t", "100", "30",
|
||||
"t", "10", "30",
|
||||
// id 2 was already completely added, split: "t", "100", "30", "t", "100", "30"
|
||||
"144", "3", "ab", "143", "45", "177", "8"
|
||||
"14", "3", "ab", "143", "45", "17", "8"
|
||||
]);
|
||||
expect(index.ctx.size).to.equal(0);
|
||||
expect(index.reg.size).to.equal(4);
|
||||
|
@@ -10,7 +10,7 @@ const build_compact = env && env.includes(".compact");
|
||||
const build_esm = !env || env.startsWith("module");
|
||||
const Charset = _Charset || (await import("../src/charset.js")).default;
|
||||
|
||||
describe("Caching", function(){
|
||||
if(!build_light) describe("Caching", function(){
|
||||
|
||||
it("Should have been cached and sorted by popularity/latest", function(){
|
||||
|
||||
|
@@ -120,10 +120,10 @@ describe("Context", function(){
|
||||
index = new Index({ context: true });
|
||||
index.add(1, "1 A B C D 2 E F G H I 3 J K L");
|
||||
index.add(2, "A B C D E F G H I J 1 2 3 K L");
|
||||
result = result = index.search("1 2 3");
|
||||
result = index.search("1 2 3");
|
||||
expect(result[0]).to.equal(2);
|
||||
|
||||
index.search("1 2 3", { context: false });
|
||||
result = index.search("1 2 3", { context: false });
|
||||
expect(result[0]).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
@@ -31,9 +31,14 @@ describe("Encoder: Charset", function(){
|
||||
|
||||
it("Should have been encoded properly: Default", function(){
|
||||
|
||||
const index = new Index({ encoder: Charset.Default });
|
||||
let index = new Index({ encoder: Charset.Default });
|
||||
expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(
|
||||
["bjorn", "phillipp", "mayer"]
|
||||
["bjorn", "philip", "mayer"]
|
||||
);
|
||||
|
||||
index = new Index();
|
||||
expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(
|
||||
["bjorn", "philip", "mayer"]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -51,7 +56,7 @@ describe("Encoder: Charset", function(){
|
||||
|
||||
const index = new Index({ encoder: Charset.Normalize });
|
||||
expect(index.encoder.encode("Björn-Phillipp Mayer")).to.eql(
|
||||
index.encoder.encode("bjorn/phillipp mayer")
|
||||
index.encoder.encode("bjorn/philip mayer")
|
||||
);
|
||||
});
|
||||
|
||||
|
@@ -26,8 +26,8 @@ if(!build_light && !build_compact) describe("Keystore", function(){
|
||||
}
|
||||
|
||||
expect(index.map.size).to.equal(2);
|
||||
expect(index.map.get("foo")[0].length).to.equal(100);
|
||||
expect(index.ctx.get("foo").get("bar")[0].length).to.equal(100);
|
||||
expect(index.map.get("fo")[0].length).to.equal(100);
|
||||
expect(index.ctx.get("fo").get("bar")[0].length).to.equal(100);
|
||||
expect(index.reg.size).to.equal(100);
|
||||
|
||||
for(let i = 0; i < 100; i++){
|
||||
@@ -38,9 +38,9 @@ if(!build_light && !build_compact) describe("Keystore", function(){
|
||||
index.cleanup();
|
||||
expect(index.map.size).to.equal(1);
|
||||
|
||||
expect(index.map.get("foo")).to.be.undefined;
|
||||
expect(index.map.get("foobar")[0].length).to.equal(100);
|
||||
expect(index.ctx.get("foo")).to.be.undefined;
|
||||
expect(index.map.get("fo")).to.be.undefined;
|
||||
expect(index.map.get("fobar")[0].length).to.equal(100);
|
||||
expect(index.ctx.get("fo")).to.be.undefined;
|
||||
expect(index.reg.size).to.equal(100);
|
||||
|
||||
for(let i = 0; i < 50; i++){
|
||||
@@ -48,7 +48,7 @@ if(!build_light && !build_compact) describe("Keystore", function(){
|
||||
}
|
||||
|
||||
expect(index.map.size).to.equal(1);
|
||||
expect(index.map.get("foobar")[0].length).to.equal(50);
|
||||
expect(index.map.get("fobar")[0].length).to.equal(50);
|
||||
expect(index.reg.size).to.equal(50);
|
||||
|
||||
index.clear();
|
||||
@@ -76,8 +76,8 @@ if(!build_light && !build_compact) describe("Keystore", function(){
|
||||
index.add(1, "foo bar");
|
||||
index.add(2, "foo bar");
|
||||
|
||||
let foo = index.map.get("foo");
|
||||
let bar = index.ctx.get("foo").get("bar");
|
||||
let foo = index.map.get("fo");
|
||||
let bar = index.ctx.get("fo").get("bar");
|
||||
foo[0].length = 2**31 - 10;
|
||||
bar[0].length = 2**31 - 10;
|
||||
|
||||
@@ -85,10 +85,10 @@ if(!build_light && !build_compact) describe("Keystore", function(){
|
||||
index.add(i, "foo bar");
|
||||
}
|
||||
|
||||
expect(index.map.get("foo")[0].length).to.equal(2**31 + 10);
|
||||
expect(index.ctx.get("foo").get("bar")[0].length).to.equal(2**31 + 10);
|
||||
expect(index.map.get("fo")[0].length).to.equal(2**31 + 10);
|
||||
expect(index.ctx.get("fo").get("bar")[0].length).to.equal(2**31 + 10);
|
||||
//expect(index.reg.size).to.equal(2**31 + 1);
|
||||
expect(index.search("foo bar", 3)).to.eql([0, 1, 2]);
|
||||
expect(index.search("fo bar", 3)).to.eql([0, 1, 2]);
|
||||
|
||||
index.clear();
|
||||
|
||||
|
@@ -24,7 +24,7 @@ if(!build_light) describe("Export / Import", function(){
|
||||
index.add(2, "foobar foo bar");
|
||||
|
||||
expect(index.reg.size).to.equal(3);
|
||||
expect(index.map.size).to.equal(9);
|
||||
expect(index.map.size).to.equal(8);
|
||||
expect(index.search("foobar")).to.eql([2, 0, 1]);
|
||||
|
||||
const payload = new Map();
|
||||
@@ -34,7 +34,7 @@ if(!build_light) describe("Export / Import", function(){
|
||||
|
||||
expect(payload).to.eql(new Map([
|
||||
['1.reg', '[0,1,2]'],
|
||||
['1.map', '[["f",[[0,2],[1]]],["fo",[[0,2],[1]]],["foo",[[0,2],[1]]],["b",[[1],[0],[2]]],["ba",[[1],[0],[2]]],["bar",[[1],[0],[2]]],["foob",[[2],null,[0,1]]],["fooba",[[2],null,[0,1]]],["foobar",[[2],null,[0,1]]]]']
|
||||
['1.map', '[["f",[[0,2],[1]]],["fo",[[0,2],[1]]],["b",[[1],[0],[2]]],["ba",[[1],[0],[2]]],["bar",[[1],[0],[2]]],["fob",[[2],null,[0,1]]],["foba",[[2],null,[0,1]]],["fobar",[[2],null,[0,1]]]]']
|
||||
]));
|
||||
|
||||
index = new Index({
|
||||
@@ -46,7 +46,7 @@ if(!build_light) describe("Export / Import", function(){
|
||||
}
|
||||
|
||||
expect(index.reg.size).to.equal(3);
|
||||
expect(index.map.size).to.equal(9);
|
||||
expect(index.map.size).to.equal(8);
|
||||
expect(index.search("foobar")).to.eql([2, 0, 1]);
|
||||
});
|
||||
|
||||
@@ -72,8 +72,8 @@ if(!build_light) describe("Export / Import", function(){
|
||||
|
||||
expect(payload).to.eql(new Map([
|
||||
['1.reg', '[0,1,2]'],
|
||||
['1.map', '[["foo",[[0],[1,2]]],["bar",[[1],[0],[2]]],["foobar",[[2],null,[0,1]]]]'],
|
||||
['1.ctx', '[["foo",[["bar",[[0,1],[2]]]]],["foobar",[["bar",[null,[0]]],["foo",[[2],[1]]]]]]']
|
||||
['1.map', '[["fo",[[0],[1,2]]],["bar",[[1],[0],[2]]],["fobar",[[2],null,[0,1]]]]'],
|
||||
['1.ctx', '[["fo",[["bar",[[0,1],[2]]]]],["fobar",[["bar",[null,[0]]],["fo",[[2],[1]]]]]]']
|
||||
]));
|
||||
|
||||
index = new Index({
|
||||
|
Reference in New Issue
Block a user