Skip to content

Commit

Permalink
feat: Add internal cache for Lyra.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda committed Mar 13, 2023
1 parent 2f65899 commit 6891569
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/methods/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export async function create<S extends Schema, I extends OpaqueIndex, D extends

const lyra = {
data: {},
caches: {},
schema,
tokenizer,
index,
Expand Down
12 changes: 9 additions & 3 deletions src/methods/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,15 @@ export async function search<S extends Schema, I extends OpaqueIndex, D extends
const tokens = lyra.tokenizer.tokenize(term, language);

// Get searchable string properties
let propertiesToSearch = await lyra.index.getSearchableProperties(index);
const propertiesToSearchWithTypes = await lyra.index.getSearchablePropertiesWithTypes(index);
propertiesToSearch = propertiesToSearch.filter((prop: string) => propertiesToSearchWithTypes[prop] === "string");
let propertiesToSearch = lyra.caches["propertiesToSearch"] as string[];
if (!propertiesToSearch) {
const propertiesToSearchWithTypes = await lyra.index.getSearchablePropertiesWithTypes(index);

propertiesToSearch = await lyra.index.getSearchableProperties(index);
propertiesToSearch = propertiesToSearch.filter((prop: string) => propertiesToSearchWithTypes[prop] === "string");

lyra.caches["propertiesToSearch"] = propertiesToSearch;
}

if (properties && properties !== "*") {
for (const prop of properties) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export type Lyra<S extends Schema, I extends OpaqueIndex, D extends OpaqueDocume
index: I;
docs: D;
};
caches: Record<string, unknown>;
[kInsertions]: number | undefined;
[kRemovals]: number | undefined;
};

0 comments on commit 6891569

Please sign in to comment.