search.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import type { IDataWithMeta, IPageHasId } from '@growi/core';
  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 ISearchResultData = {
  21. _id: string
  22. _score: number
  23. _source: any
  24. _highlight: any
  25. }
  26. export type ISearchResult<T> = ISearchResultMeta & {
  27. data: T[],
  28. }
  29. export type IPageWithSearchMeta = IDataWithMeta<IPageHasId, IPageSearchMeta>;
  30. export type IFormattedSearchResult = ISearchResultMeta & {
  31. data: IPageWithSearchMeta[],
  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];