Skip to content

Commit 4f8b24b

Browse files
authored
Prevent undefined elements (#33)
* fix(lyra): filters results by defined values * chore(lyra): improves variables readability
1 parent a0e6885 commit 4f8b24b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/lyra/src/lyra.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,23 @@ export class Lyra<TSchema extends PropertiesSchema = PropertiesSchema> {
113113
const results: RetrievedDoc<TSchema>[] = Array.from({
114114
length: limit,
115115
});
116-
let totalResults = 0;
116+
let count = 0;
117117

118118
const timeStart = getNanosecondsTime();
119119

120120
let i = 0;
121121
let j = 0;
122122

123-
for (const token of tokens) {
123+
for (const term of tokens) {
124124
for (const index of indices) {
125125
const documentIDs = await this.getDocumentIDsFromSearch({
126126
...params,
127-
index: index,
128-
term: token,
129-
exact: exact,
127+
index,
128+
term,
129+
exact,
130130
});
131131

132-
totalResults += documentIDs.size;
132+
count += documentIDs.size;
133133

134134
if (i >= limit) {
135135
break;
@@ -154,10 +154,12 @@ export class Lyra<TSchema extends PropertiesSchema = PropertiesSchema> {
154154
}
155155
}
156156

157+
const hits = results.filter(Boolean);
158+
157159
return {
158160
elapsed: formatNanoseconds(getNanosecondsTime() - timeStart),
159-
hits: results,
160-
count: totalResults,
161+
hits,
162+
count,
161163
};
162164
}
163165

0 commit comments

Comments
 (0)