Skip to content

Commit

Permalink
OSCI-6310
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Stepanov <astepano@redhat.com>
  • Loading branch information
Andrei-Stepanov committed Feb 20, 2024
1 parent 66b801e commit 824aac7
Showing 1 changed file with 49 additions and 36 deletions.
85 changes: 49 additions & 36 deletions src/schema/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type QueryOptions = {
artTypes: string[] | undefined;
newerThen: string | undefined;
queryString: string | undefined;
isExtendedQs: boolean | undefined;
doDeepSearch: boolean | undefined;
paginationSize: number | undefined;
paginationFrom: number | undefined;
Expand All @@ -79,6 +80,7 @@ export const makeRequestParamsArtifacts = (
artTypes,
newerThen,
queryString,
isExtendedQs,
doDeepSearch,
paginationSize,
paginationFrom,
Expand All @@ -89,10 +91,6 @@ export const makeRequestParamsArtifacts = (
const paramSize = _.isUndefined(paginationSize)
? 10
: JSON.stringify(paginationSize);
const paramQueryString =
_.isUndefined(queryString) || _.isEmpty(queryString)
? '"*"'
: JSON.stringify(queryString);
const paramIndexNames = _.map(artTypes, (artType) => getIndexName(artType));

let requestBody: string;
Expand Down Expand Up @@ -129,6 +127,43 @@ export const makeRequestParamsArtifacts = (
},
`
}
let query = ''
if (!isExtendedQs) {
// Extended query
const qs = _.isUndefined(queryString) || _.isEmpty(queryString)
? "*"
: queryString;
const paramQueryString = JSON.stringify(qs);
query = `
{
"query_string": {
"query": ${paramQueryString},
"lenient": true,
"default_operator": "and",
"analyze_wildcard": true,
"allow_leading_wildcard": true,
"type" : "cross_fields"
}
}
`
} else {
// Simplified query
const qs = _.isUndefined(queryString) || _.isEmpty(queryString)
? ""
: queryString;
const paramQueryString = JSON.stringify(qs);
query = `
{
"multi_match": {
"query": ${paramQueryString},
"operator": "and",
"slop": 0,
"type": "bool_prefix",
"boost": 0
}
}
`
}

if (doDeepSearch) {
// Deep search query
Expand All @@ -143,16 +178,7 @@ export const makeRequestParamsArtifacts = (
"query": {
"bool": {
"must": [
{
"query_string": {
"query": ${paramQueryString},
"lenient": true,
"default_operator": "and",
"analyze_wildcard": true,
"allow_leading_wildcard": true,
"type" : "cross_fields"
}
}
${query}
],
"filter": [
${_.trimEnd(rangeFilterParam, ', \n')}
Expand All @@ -175,16 +201,7 @@ export const makeRequestParamsArtifacts = (
}
],
"must": [
{
"query_string": {
"query": ${paramQueryString},
"lenient": true,
"default_operator": "and",
"analyze_wildcard": true,
"allow_leading_wildcard": true,
"type" : "cross_fields"
}
}
${query}
]
}
}
Expand Down Expand Up @@ -234,16 +251,7 @@ export const makeRequestParamsArtifacts = (
}
],
"must": [
{
"query_string": {
"query": ${paramQueryString},
"lenient": true,
"default_operator": "and",
"analyze_wildcard": true,
"allow_leading_wildcard": true,
"type" : "cross_fields"
}
}
${query}
]
}
},
Expand Down Expand Up @@ -417,7 +425,7 @@ export const artifactChildren: GraphQLFieldConfig<any, any> = {
}
const requestParams: RequestParams.Search =
makeRequestParamsArtifactChildren(queryArgs);
log(' [i] run request: %s', printify(requestParams));
log(' [i] run request: %s', printify(requestParams.body));
let result: ApiResponse;
try {
result = await opensearchClient.client.search(requestParams);
Expand Down Expand Up @@ -650,6 +658,11 @@ export const getArtifacts: GraphQLFieldConfig<any, any> = {
type: GraphQLBoolean,
description: 'Look-up for artifacts, with chidlren match query string.',
},
isExtendedQs: {
type: GraphQLBoolean,
// https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-query-string-query.html
description: 'query string, using a parser with a strict syntax.'
},
paginationSize: {
type: GraphQLInt,
description: 'Number of results to return per page.',
Expand All @@ -671,7 +684,7 @@ export const getArtifacts: GraphQLFieldConfig<any, any> = {
}
const requestParams: RequestParams.Search =
makeRequestParamsArtifacts(queryOptions);
log(' [i] run request: %s', printify(requestParams));
log(' [i] run request for getArtifacts: %s', requestParams.body);
let result: ApiResponse;
try {
result = await opensearchClient.client.search(requestParams);
Expand Down

0 comments on commit 824aac7

Please sign in to comment.