Browse Source

Feature/refactor search query of holdings search (#5333)

* Refactor search query

* Update changelog
pull/5338/head
Thomas Kaul 3 days ago
committed by GitHub
parent
commit
bd9aae6fec
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      CHANGELOG.md
  2. 2
      apps/api/src/app/portfolio/portfolio.controller.ts
  3. 10
      apps/api/src/app/portfolio/portfolio.service.ts

3
CHANGELOG.md

@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Extended the import functionality by tags
- Introduced fuzzy search for the accounts endpoint
- Introduced the fuzzy search for the accounts endpoint
- Refactored the fuzzy search for the holdings of the assistant
- Improved the language localization for Polish (`pl`)
- Improved the language localization for Spanish (`es`)

2
apps/api/src/app/portfolio/portfolio.controller.ts

@ -413,6 +413,7 @@ export class PortfolioController {
filterByAssetClasses,
filterByDataSource,
filterByHoldingType,
filterBySearchQuery,
filterBySymbol,
filterByTags
});
@ -421,7 +422,6 @@ export class PortfolioController {
dateRange,
filters,
impersonationId,
query: filterBySearchQuery,
userId: this.request.user.id
});

10
apps/api/src/app/portfolio/portfolio.service.ts

@ -292,13 +292,11 @@ export class PortfolioService {
dateRange,
filters,
impersonationId,
query,
userId
}: {
dateRange: DateRange;
filters?: Filter[];
impersonationId: string;
query?: string;
userId: string;
}) {
userId = await this.getUserId(impersonationId, userId);
@ -311,13 +309,17 @@ export class PortfolioService {
let holdings = Object.values(holdingsMap);
if (query) {
const searchQuery = filters.find(({ type }) => {
return type === 'SEARCH_QUERY';
})?.id;
if (searchQuery) {
const fuse = new Fuse(holdings, {
keys: ['isin', 'name', 'symbol'],
threshold: 0.3
});
holdings = fuse.search(query).map(({ item }) => {
holdings = fuse.search(searchQuery).map(({ item }) => {
return item;
});
}

Loading…
Cancel
Save