fix(server): return empty summary field value (#12517)

close AF-2658

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **Tests**
  - Added new test cases and snapshots to enhance coverage for search results involving empty or missing fields like summary, title, and ref_doc_id.
  - Verified consistent handling of empty string values and absence of fields across different search providers.

- **Bug Fixes**
  - Improved handling of empty string values for specific fields by converting them to null to ensure consistent search result formatting.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fengmk2
2025-05-27 04:42:54 +00:00
parent 3676f3b769
commit 382c237dac
10 changed files with 459 additions and 1 deletions
@@ -138,3 +138,35 @@ Generated by [AVA](https://avajs.dev).
},
},
}
## should return empty nodes when docId not exists
> Snapshot 1
{
workspace: {
search: {
nodes: [],
pagination: {
count: 0,
hasMore: false,
nextCursor: null,
},
},
},
}
## should empty doc summary string when doc exists but no summary
> Snapshot 1
[
{
fields: {
summary: [
'',
],
},
highlights: null,
},
]
@@ -276,3 +276,87 @@ e2e('should return empty results when search not match any docs', async t => {
t.snapshot(result);
});
e2e('should return empty nodes when docId not exists', async t => {
const owner = await app.signup();
const workspace = await app.create(Mockers.Workspace, {
owner,
});
const result = await app.gql({
query: indexerSearchQuery,
variables: {
id: workspace.id,
input: {
table: SearchTable.doc,
query: {
type: SearchQueryType.match,
field: 'docId',
match: 'not-exists-doc-id',
},
options: {
fields: ['summary'],
pagination: {
limit: 1,
},
},
},
},
});
t.snapshot(result);
});
e2e(
'should empty doc summary string when doc exists but no summary',
async t => {
const owner = await app.signup();
const workspace = await app.create(Mockers.Workspace, {
owner,
});
const indexerService = app.get(IndexerService);
await indexerService.write(
SearchTable.doc,
[
{
docId: 'doc-1-without-summary',
workspaceId: workspace.id,
title: 'test1',
summary: '',
createdByUserId: owner.id,
updatedByUserId: owner.id,
createdAt: new Date('2025-04-22T00:00:00.000Z'),
updatedAt: new Date('2025-04-22T00:00:00.000Z'),
},
],
{
refresh: true,
}
);
const result = await app.gql({
query: indexerSearchQuery,
variables: {
id: workspace.id,
input: {
table: SearchTable.doc,
query: {
type: SearchQueryType.match,
field: 'docId',
match: 'doc-1-without-summary',
},
options: {
fields: ['summary'],
pagination: {
limit: 1,
},
},
},
},
});
t.snapshot(result.workspace.search.nodes);
}
);