Skip to content

Commit

Permalink
fix: Fix document counts. (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda authored Jan 10, 2023
1 parent 86118a5 commit 390fafe
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 131 deletions.
1 change: 1 addition & 0 deletions src/methods/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export async function create<S extends PropertiesSchema>(properties: Configurati
defaultLanguage,
schema: properties.schema,
docs: {},
docsCount: 0,
index: {},
hooks: properties.hooks || {},
edge: properties.edge ?? false,
Expand Down
1 change: 1 addition & 0 deletions src/methods/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function insert<S extends PropertiesSchema>(
assertDocSchema(doc, lyra.schema);

lyra.docs[id] = doc;
lyra.docsCount++;
recursiveradixInsertion(lyra, doc, id, config, undefined, lyra.components?.tokenizer as TokenizerConfigExec);
trackInsertion(lyra);

Expand Down
1 change: 1 addition & 0 deletions src/methods/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function load<S extends PropertiesSchema>(

lyra.index = index;
lyra.docs = docs;
lyra.docsCount = Object.keys(docs).length;
lyra.schema = schema;
lyra.frequencies = frequencies;
lyra.tokenOccurrencies = tokenOccurrencies;
Expand Down
1 change: 1 addition & 0 deletions src/methods/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function remove<S extends PropertiesSchema>(lyra: Lyra<S>, docID: s
}

lyra.docs[docID] = undefined;
lyra.docsCount--;

return true;
}
3 changes: 1 addition & 2 deletions src/methods/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export async function search<S extends PropertiesSchema>(
const results: RetrievedDoc<S>[] = Array.from({
length: limit,
});
const N = lyra.docsCount;

const timeStart = getNanosecondsTime();
// uniqueDocsIDs contains unique document IDs for all the tokens in all the indices.
Expand Down Expand Up @@ -139,8 +140,6 @@ export async function search<S extends PropertiesSchema>(
docsIntersection[index] = [];
}

const N = Object.keys(lyra.docs).length;

// Now it's time to loop over all the indices and get the documents IDs for every single term
const indexesLength = indices.length;
for (let i = 0; i < indexesLength; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface Lyra<S extends PropertiesSchema> extends Data<S> {
hooks: Hooks;
components?: Components;
frequencies: FrequencyMap;
docsCount: number;
}

type ResolveTypes<TType> = TType extends "string"
Expand Down
Loading

0 comments on commit 390fafe

Please sign in to comment.