fix: site scoped search not working for domain and hostname

* alter site_name_tsv to include hostname and domain
* add test cases
This commit is contained in:
Hongbo Wu
2023-10-26 22:10:35 +08:00
parent 4cbb696886
commit d480d53151
4 changed files with 105 additions and 2 deletions

View File

@ -338,7 +338,7 @@ const parseFieldFilter = (
}
}
const parseIds = (field: string, str?: string): string[] | undefined => {
const parseIds = (str?: string): string[] | undefined => {
if (str === undefined) {
return undefined
}
@ -500,7 +500,7 @@ export const parseSearchQuery = (query: string | undefined): SearchFilter => {
break
}
case 'includes': {
const ids = parseIds(keyword.keyword, keyword.value)
const ids = parseIds(keyword.value)
ids && result.ids.push(...ids)
break
}

View File

@ -1568,6 +1568,47 @@ describe('Article API', () => {
).to.eq(group.name)
})
})
context('when site:youtube.com is in the query', () => {
let items: LibraryItem[] = []
before(async () => {
keyword = 'site:youtube.com'
// Create some test items
items = await createLibraryItems(
[
{
user,
title: 'test title 1',
readableContent: '<p>test 1</p>',
slug: 'test slug 1',
originalUrl:
'https://www.youtube.com/watch?v=Omnivore',
itemType: PageType.Video,
},
{
user,
title: 'test title 2',
readableContent: '<p>test 2</p>',
slug: 'test slug 2',
originalUrl: `${url}/test2`,
},
],
user.id
)
})
after(async () => {
await deleteLibraryItems(items, user.id)
})
it('returns youtube videos', async () => {
const res = await graphqlRequest(query, authToken).expect(200)
expect(res.body.data.search.pageInfo.totalCount).to.eq(1)
expect(res.body.data.search.edges[0].node.id).to.eq(items[0].id)
})
})
})
describe('TypeaheadSearch API', () => {