fixes on search (#11955)
In this PR - enable search by email - search with ' ' (spaces) string and special characters do not throw entry error closes https://github.com/twentyhq/twenty/issues/11447 & https://github.com/twentyhq/core-team-issues/issues/860
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { getLogoUrlFromDomainName } from 'twenty-shared/utils';
|
||||
import { Brackets, ObjectLiteral } from 'typeorm';
|
||||
@ -96,7 +97,7 @@ export class SearchService {
|
||||
...(imageIdentifierField ? [imageIdentifierField] : []),
|
||||
].map((field) => `"${field}"`);
|
||||
|
||||
const searchQuery = searchTerms
|
||||
const searchQuery = isNonEmptyString(searchTerms)
|
||||
? queryBuilder
|
||||
.select(fieldsToSelect)
|
||||
.addSelect(
|
||||
|
||||
@ -2,12 +2,12 @@ export const formatSearchTerms = (
|
||||
searchTerm: string,
|
||||
operator: 'and' | 'or' = 'and',
|
||||
) => {
|
||||
if (searchTerm === '') {
|
||||
if (searchTerm.trim() === '') {
|
||||
return '';
|
||||
}
|
||||
const words = searchTerm.trim().split(/\s+/);
|
||||
const formattedWords = words.map((word) => {
|
||||
const escapedWord = word.replace(/[\\:'&|!()]/g, '\\$&');
|
||||
const escapedWord = word.replace(/[\\:'&|!()@<>]/g, '\\$&');
|
||||
|
||||
return `${escapedWord}:*`;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user