search.ts 1.0 KB

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