Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/services/search/__tests__/query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,32 @@ describe('search – query', () => {
filters: [],
};
expect(requireOneFilter).toBeDefined();

const requestWithQSettings: query.GSearchRequest = {
q: 'test',
q_settings: {
mode: 'query_string',
default_operator: 'and',
},
};
expect(requestWithQSettings).toBeDefined();

const requestWithAdvanced: query.GSearchRequest = {
q: 'test',
advanced: true,
};
expect(requestWithAdvanced).toBeDefined();

// @ts-expect-error `q_settings` and `advanced` are mutually exclusive
const requestWithQSettingsAndAdvanced: query.GSearchRequest = {
q: 'test',
q_settings: {
mode: 'query_string' as const,
default_operator: 'and',
},
advanced: true,
};
expect(requestWithQSettingsAndAdvanced).toBeDefined();
});

test('Content Generic', async () => {
Expand Down
23 changes: 20 additions & 3 deletions src/services/search/service/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,44 @@ type InternalGSearchRequest = {
q?: string;
offset?: number;
limit?: number;
advanced?: boolean;
bypass_visible_to?: boolean;
result_format_version?: ResultFormatVersion;
filter_principal_sets?: string[];
filters?: GFilter[];
facets?: GFacet[];
boosts?: GBoost[];
sort?: GSort[];
q_settings?: OpenAPI.components['schemas']['GSearchRequestBodyV1']['q_settings'];
advanced?: OpenAPI.components['schemas']['GSearchRequestBodyV1']['advanced'];
};

/**
* `q_settings` and `advanced` are mutually exclusive.
* @see https://docs.globus.org/api/search/reference/post_query/#gsearchrequest
*/
type QSettingsOrAdvanced =
| {
q_settings?: InternalGSearchRequest['q_settings'];
advanced?: never;
}
| {
advanced?: InternalGSearchRequest['advanced'];
q_settings?: never;
};

/**
* You must provide either `q` or `filters`.
* @see https://docs.globus.org/api/search/reference/post_query/#gsearchrequest
*/
export type GSearchRequest =
export type GSearchRequest = (
| (Omit<InternalGSearchRequest, 'q'> & {
q: InternalGSearchRequest['q'];
})
| (Omit<InternalGSearchRequest, 'filters'> & {
filters: [GFilter, ...GFilter[]];
});
})
) &
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor tweaks; The original proposal was only intersecting with the second half of the GSearchRequest union and moved the properties back to InternalGSearchRequest to ensure it still reflects the comment/intent.

QSettingsOrAdvanced;

/**
* @param index_id The UUID of the index to query.
Expand Down
Loading