search.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { IDataWithMeta, IPageHasId } from './page';
  2. export type IPageSearchMeta = {
  3. bookmarkCount?: number,
  4. elasticSearchResult?: {
  5. snippet?: string | null;
  6. highlightedPath?: string | null;
  7. };
  8. }
  9. // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
  10. export const isIPageSearchMeta = (meta: any): meta is IPageSearchMeta => {
  11. return meta != null && 'elasticSearchResult' in meta;
  12. };
  13. export type ISearchResultMeta = {
  14. meta: {
  15. took?: number
  16. total: number
  17. hitsCount: number
  18. },
  19. }
  20. export type ISearchResult<T> = ISearchResultMeta & {
  21. data: T[],
  22. }
  23. export type IPageWithSearchMeta = IDataWithMeta<IPageHasId, IPageSearchMeta>;
  24. export type IFormattedSearchResult = ISearchResultMeta & {
  25. data: IPageWithSearchMeta[],
  26. }
  27. export const SORT_AXIS = {
  28. RELATION_SCORE: 'relationScore',
  29. CREATED_AT: 'createdAt',
  30. UPDATED_AT: 'updatedAt',
  31. } as const;
  32. export type SORT_AXIS = typeof SORT_AXIS[keyof typeof SORT_AXIS];
  33. export const SORT_ORDER = {
  34. DESC: 'desc',
  35. ASC: 'asc',
  36. } as const;
  37. export type SORT_ORDER = typeof SORT_ORDER[keyof typeof SORT_ORDER];