flexsearch
flexsearch copied to clipboard
Results not unique across pages when searching documents
Minimum test case:
it("Should have unique results across pages (documents)", function(){
var index = new FlexSearch({
doc: {
id: "id",
field: ["title", "text"],
},
});
var documents = [
{title: "aaa", text: "qqq"},
{title: "bbb", text: "aaa"},
{title: "ccc", text: "aaa"},
{title: "ddd", text: "aaa"},
]
documents.forEach(function(doc, i) {
doc.id = i;
index.add(doc);
});
var first = index.search('aaa', {limit: 2, page: true});
expect(first.next).to.not.equal(null);
expect(first.result).to.have.lengthOf(2);
var second = index.search('aaa', {limit: 2, page: first.next});
expect(second.result).to.have.lengthOf(2);
var firstHits = first.result.map(function(each) { return each.id })
var secondHits = second.result.map(function(each) { return each.id })
var overlaps = firstHits.filter(function(each) { return secondHits.includes(each) })
expect(overlaps).to.have.lengthOf(0);
});
This fails against the master branch (76dc7a8).
The first page contains:
[ { title: 'aaa', text: 'qqq', id: 0 },
{ title: 'bbb', text: 'aaa', id: 1 } ]
The second page contains:
[ { title: 'aaa', text: 'qqq', id: 0 },
{ title: 'ccc', text: 'aaa', id: 2 } ]
The document with id: 0 appears in both pages.
I'm not familiar with the codebase so this might be off, but this conditional in intersect() seems to be returning too early when the second page is requested:
https://github.com/nextapps-de/flexsearch/blob/76dc7a87e5351a35575f4a1464200fe57a29f610/flexsearch.js#L3443-L3446
When I tried commenting out that conditional, the second page had only one result though, so there's something else going on.