Skip to content

Commit

Permalink
feat(lyra): improves search speed by pre-generating final array of re…
Browse files Browse the repository at this point in the history
…sults
  • Loading branch information
micheleriva committed May 28, 2022
1 parent 25ce67a commit 2860ca0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/lyra/src/lyra.ts
Expand Up @@ -73,12 +73,12 @@ export class Lyra {
const tokens = tokenize(params.term).values();
const indices = this.getIndices(params.properties);
const { limit = 10, offset = 0 } = params;
const results: object[] = [];
const results: object[] = new Array({ length: limit });
let totalResults = 0;

const timeStart = getNanosecondsTime();

let i = limit;
let i = 0;
let j = 0;

for (const token of tokens) {
Expand All @@ -91,7 +91,7 @@ export class Lyra {

totalResults += documentIDs.size;

if (i <= 0) {
if (i >= limit) {
break;
}

Expand All @@ -102,13 +102,13 @@ export class Lyra {
continue;
}

if (i <= 0) {
if (i >= limit) {
break;
}

const fullDoc = this.docs.get(id);
results.push({ id, ...fullDoc });
i--;
results[i] = { id, ...fullDoc };
i++;
}
}
}
Expand Down

0 comments on commit 2860ca0

Please sign in to comment.