search.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import type {
  2. IDataWithMeta,
  3. IDataWithRequiredMeta,
  4. IPageHasId,
  5. } from '@growi/core';
  6. export type IPageSearchMeta = {
  7. bookmarkCount?: number;
  8. elasticSearchResult?: {
  9. snippet?: string | null;
  10. highlightedPath?: string | null;
  11. };
  12. };
  13. export const isIPageSearchMeta = (meta: any): meta is IPageSearchMeta => {
  14. return meta != null && 'elasticSearchResult' in meta;
  15. };
  16. export type ISearchResultMeta = {
  17. took?: number;
  18. total: number;
  19. hitsCount: number;
  20. };
  21. export type ISearchResultData = {
  22. _id: string;
  23. _score: number;
  24. _source: any;
  25. _highlight: any;
  26. };
  27. export type ISearchResult<T> = IDataWithRequiredMeta<T[], ISearchResultMeta>;
  28. export type IPageWithSearchMeta = IDataWithMeta<IPageHasId, IPageSearchMeta>;
  29. export type IFormattedSearchResult = IDataWithRequiredMeta<
  30. IPageWithSearchMeta[],
  31. ISearchResultMeta
  32. >;
  33. export const SORT_AXIS = {
  34. RELATION_SCORE: 'relationScore',
  35. CREATED_AT: 'createdAt',
  36. UPDATED_AT: 'updatedAt',
  37. } as const;
  38. export type SORT_AXIS = (typeof SORT_AXIS)[keyof typeof SORT_AXIS];
  39. export const SORT_ORDER = {
  40. DESC: 'desc',
  41. ASC: 'asc',
  42. } as const;
  43. export type SORT_ORDER = (typeof SORT_ORDER)[keyof typeof SORT_ORDER];