Add contentReader to the typeAheadSearchResult

This commit is contained in:
Hongbo Wu
2023-04-20 10:00:56 +08:00
parent eff5d2aac7
commit 130677b50c
7 changed files with 18 additions and 6 deletions

View File

@ -635,7 +635,7 @@ export const searchAsYouType = async (
],
},
},
_source: ['title', 'slug', 'siteName'],
_source: ['title', 'slug', 'siteName', 'pageType'],
size,
},
})

View File

@ -2723,6 +2723,7 @@ export enum TypeaheadSearchErrorCode {
export type TypeaheadSearchItem = {
__typename?: 'TypeaheadSearchItem';
contentReader: ContentReader;
id: Scalars['ID'];
siteName?: Maybe<Scalars['String']>;
slug: Scalars['String'];
@ -5720,6 +5721,7 @@ export type TypeaheadSearchErrorResolvers<ContextType = ResolverContext, ParentT
};
export type TypeaheadSearchItemResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['TypeaheadSearchItem'] = ResolversParentTypes['TypeaheadSearchItem']> = {
contentReader?: Resolver<ResolversTypes['ContentReader'], ParentType, ContextType>;
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
siteName?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
slug?: Resolver<ResolversTypes['String'], ParentType, ContextType>;

View File

@ -2080,6 +2080,7 @@ enum TypeaheadSearchErrorCode {
}
type TypeaheadSearchItem {
contentReader: ContentReader!
id: ID!
siteName: String
slug: String!

View File

@ -65,6 +65,7 @@ import {
SortParams,
TypeaheadSearchError,
TypeaheadSearchErrorCode,
TypeaheadSearchItem,
TypeaheadSearchSuccess,
UpdateReason,
UpdatesSinceError,
@ -993,7 +994,13 @@ export const typeaheadSearchResolver = authorized<
},
})
return { items: await searchAsYouType(claims.uid, query, first || undefined) }
const results = await searchAsYouType(claims.uid, query, first || undefined)
const items: TypeaheadSearchItem[] = results.map((r) => ({
...r,
contentReader: contentReaderForPageType(r.pageType),
}))
return { items }
})
export const updatesSinceResolver = authorized<

View File

@ -8,7 +8,6 @@ import { getPageByParam } from '../elastic/pages'
import {
Article,
ArticleHighlightsInput,
ContentReader,
Highlight,
HighlightType,
LinkShareInfo,

View File

@ -1854,6 +1854,7 @@ const schema = gql`
title: String!
slug: String!
siteName: String
contentReader: ContentReader!
}
union UpdatesSinceResult = UpdatesSinceSuccess | UpdatesSinceError

View File

@ -2,6 +2,7 @@ import * as chai from 'chai'
import { expect } from 'chai'
import chaiString from 'chai-string'
import 'mocha'
import sinon from 'sinon'
import { createPubSubClient } from '../../src/datalayer/pubsub'
import { refreshIndex } from '../../src/elastic'
import { addHighlightToPage } from '../../src/elastic/highlights'
@ -30,6 +31,8 @@ import {
UpdateReason,
UploadFileStatus,
} from '../../src/generated/graphql'
import * as createTask from '../../src/utils/createTask'
import * as uploads from '../../src/utils/uploads'
import { createTestUser, deleteTestUser } from '../db'
import {
createTestElasticPage,
@ -37,9 +40,6 @@ import {
graphqlRequest,
request,
} from '../util'
import sinon from 'sinon'
import * as createTask from '../../src/utils/createTask'
import * as uploads from '../../src/utils/uploads'
chai.use(chaiString)
@ -362,6 +362,7 @@ const typeaheadSearchQuery = (keyword: string) => {
id
slug
title
contentReader
}
}
... on TypeaheadSearchError {
@ -1105,6 +1106,7 @@ describe('Article API', () => {
expect(res.body.data.typeaheadSearch.items[2].id).to.eq(pages[2].id)
expect(res.body.data.typeaheadSearch.items[3].id).to.eq(pages[3].id)
expect(res.body.data.typeaheadSearch.items[4].id).to.eq(pages[4].id)
expect(res.body.data.typeaheadSearch.items[0].contentReader).to.eq('WEB')
})
})