Skip to content

Commit

Permalink
Merge pull request #524 from connection-2023/feature/#517/search-after
Browse files Browse the repository at this point in the history
Refactor(#517): 누락된 searchAfter추가 및 any 속성 제거 완료
  • Loading branch information
Kimsoo0119 authored Jun 6, 2024
2 parents 7ba0e78 + bed2843 commit a2addab
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/search/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ import { DateUtils } from '@src/common/utils/date.utils';
import { plainToClass, plainToInstance } from 'class-transformer';
import { th } from 'date-fns/locale';
import { PopularSearchTermDto } from '../dtos/response/popular-search-term.dto';
import {
SearchHit,
SearchHitsMetadata,
} from '@elastic/elasticsearch/lib/api/types';

@Injectable()
export class SearchService {
Expand Down Expand Up @@ -931,13 +935,17 @@ export class SearchService {
}

generateESResponse<T, K extends string>(
hits: any,
hits: SearchHitsMetadata,
key: K,
): PaginatedResponse<T, K> {
const totalItemCount =
typeof hits.total === 'object' ? hits.total.value : 0;

const items =
totalItemCount > 0 ? hits.hits.map((hit: any) => hit._source) : [];
hits.hits?.map((hit: SearchHit<T>) => ({
...hit._source,
searchAfter: hit.sort,
})) || [];

return {
totalItemCount,
Expand Down

0 comments on commit a2addab

Please sign in to comment.