search.ts 1.0 KB

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