add new globalSearch resolver + update useSearchRecords hook (#10457)
# Context To enable search records sorting by ts_rank_cd / ts_rank, we have decided to add a new search resolver serving `GlobalSearchRecordDTO`. ----- - [x] Test to add - work in progress closes https://github.com/twentyhq/core-team-issues/issues/357
This commit is contained in:
@ -19,6 +19,7 @@ import { SearchResolverArgs } from 'src/engine/api/graphql/workspace-resolver-bu
|
||||
import { QUERY_MAX_RECORDS } from 'src/engine/api/graphql/graphql-query-runner/constants/query-max-records.constant';
|
||||
import { ObjectRecordsToGraphqlConnectionHelper } from 'src/engine/api/graphql/graphql-query-runner/helpers/object-records-to-graphql-connection.helper';
|
||||
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
|
||||
import { formatSearchTerms } from 'src/engine/core-modules/global-search/utils/format-search-terms';
|
||||
import { SEARCH_VECTOR_FIELD } from 'src/engine/metadata-modules/constants/search-vector-field.constants';
|
||||
import { formatResult } from 'src/engine/twenty-orm/utils/format-result.util';
|
||||
|
||||
@ -52,11 +53,11 @@ export class GraphqlQuerySearchResolverService extends GraphqlQueryBaseResolverS
|
||||
});
|
||||
}
|
||||
|
||||
const searchTerms = this.formatSearchTerms(
|
||||
const searchTerms = formatSearchTerms(
|
||||
executionArgs.args.searchInput,
|
||||
'and',
|
||||
);
|
||||
const searchTermsOr = this.formatSearchTerms(
|
||||
const searchTermsOr = formatSearchTerms(
|
||||
executionArgs.args.searchInput,
|
||||
'or',
|
||||
);
|
||||
@ -150,23 +151,6 @@ export class GraphqlQuerySearchResolverService extends GraphqlQueryBaseResolverS
|
||||
});
|
||||
}
|
||||
|
||||
private formatSearchTerms(
|
||||
searchTerm: string,
|
||||
operator: 'and' | 'or' = 'and',
|
||||
) {
|
||||
if (searchTerm === '') {
|
||||
return '';
|
||||
}
|
||||
const words = searchTerm.trim().split(/\s+/);
|
||||
const formattedWords = words.map((word) => {
|
||||
const escapedWord = word.replace(/[\\:'&|!()]/g, '\\$&');
|
||||
|
||||
return `${escapedWord}:*`;
|
||||
});
|
||||
|
||||
return formattedWords.join(` ${operator === 'and' ? '&' : '|'} `);
|
||||
}
|
||||
|
||||
async validate(
|
||||
_args: SearchResolverArgs,
|
||||
_options: WorkspaceQueryRunnerOptions,
|
||||
|
||||
Reference in New Issue
Block a user