Skip to content

Commit 4d0377a

Browse files
committed
Refactor extractKeywordSearchColumns to avoid redundant function creation
1 parent b727d14 commit 4d0377a

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

libs/langchain-community/src/vectorstores/hanavector.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -624,31 +624,31 @@ export class HanaDB extends VectorStore {
624624
*/
625625
private extractKeywordSearchColumns(filter?: this["FilterType"]): string[] {
626626
const keywordColumns = new Set<string>();
627+
this.recurseFiltersHelper(keywordColumns, filter);
628+
return [...keywordColumns];
629+
}
630+
631+
private recurseFiltersHelper(keywordColumns: Set<string>, filterObj?: this["FilterType"], parentKey?: string): void {
632+
if (!filterObj || typeof filterObj !== "object") return;
627633

628-
const recurseFilters = (filterObj?: this["FilterType"], parentKey?: string): void => {
629-
if (!filterObj || typeof filterObj !== "object") return;
630-
631-
Object.entries(filterObj).forEach(([key, value]) => {
632-
if (key === CONTAINS_OPERATOR) {
633-
if (
634-
parentKey &&
635-
parentKey !== this.contentColumn &&
636-
!this.specificMetadataColumns.includes(parentKey)
637-
) {
638-
keywordColumns.add(parentKey);
639-
}
640-
} else if (key in LOGICAL_OPERATORS_TO_SQL) {
641-
// Assume it's an array of filters
642-
(value as this["FilterType"][]).forEach((subfilter) => recurseFilters(subfilter));
643-
} else if (typeof value === "object" && value !== null) {
644-
recurseFilters(value as this["FilterType"], key);
634+
Object.entries(filterObj).forEach(([key, value]) => {
635+
if (key === CONTAINS_OPERATOR) {
636+
if (
637+
parentKey &&
638+
parentKey !== this.contentColumn &&
639+
!this.specificMetadataColumns.includes(parentKey)
640+
) {
641+
keywordColumns.add(parentKey);
645642
}
646-
});
647-
};
648-
649-
recurseFilters(filter);
650-
return [...keywordColumns];
643+
} else if (key in LOGICAL_OPERATORS_TO_SQL) {
644+
// Assume it's an array of filters
645+
(value as this["FilterType"][]).forEach((subfilter) => this.recurseFiltersHelper(keywordColumns, subfilter));
646+
} else if (typeof value === "object" && value !== null) {
647+
this.recurseFiltersHelper(keywordColumns, value as this["FilterType"], key);
648+
}
649+
});
651650
}
651+
652652

653653
/**
654654
* Generate a SQL `WITH` clause to project metadata columns for keyword search.

0 commit comments

Comments
 (0)