search.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { IDataWithMeta, IPageHasId } from './page';
  2. export type IPageSearchMeta = {
  3. bookmarkCount?: number,
  4. elasticSearchResult?: {
  5. snippet?: string | null;
  6. highlightedPath?: string | null;
  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 ISearchResultMeta = {
  15. meta: {
  16. took?: number
  17. total: number
  18. hitsCount: number
  19. },
  20. }
  21. export type ISearchResult<T> = ISearchResultMeta & {
  22. data: T[],
  23. }
  24. export type IPageWithSearchMeta = IDataWithMeta<IPageHasId, IPageSearchMeta>;
  25. export type IFormattedSearchResult = ISearchResultMeta & {
  26. data: IPageWithSearchMeta[],
  27. }
  28. export const SORT_AXIS = {
  29. RELATION_SCORE: 'relationScore',
  30. CREATED_AT: 'createdAt',
  31. UPDATED_AT: 'updatedAt',
  32. } as const;
  33. export type SORT_AXIS = typeof SORT_AXIS[keyof typeof SORT_AXIS];
  34. export const SORT_ORDER = {
  35. DESC: 'desc',
  36. ASC: 'asc',
  37. } as const;
  38. export type SORT_ORDER = typeof SORT_ORDER[keyof typeof SORT_ORDER];