-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search #7237
Conversation
packages/twenty-server/src/engine/twenty-orm/decorators/workspace-index.decorator.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR introduces comprehensive search functionality across the Twenty application, focusing on both frontend and backend implementations. Here are the key changes:
- Added new
search
GraphQL query and resolver for efficient full-text search - Implemented
TsVector
field type and GIN indexing for PostgreSQL full-text search - Created frontend hooks and utilities for search operations (
useSearchRecords
,useSearchRecordsQuery
) - Integrated feature flags for controlled rollout of search functionality
- Modified CommandMenu component to utilize new search capabilities
- Updated GraphQL schema and type definitions to support search operations
- Added migrations for new database structures supporting search features
30 file(s) reviewed, 13 comment(s)
Edit PR Review Bot Settings
packages/twenty-front/src/modules/object-record/hooks/useSearchRecords.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/object-record/hooks/useSearchRecordsQuery.ts
Outdated
Show resolved
Hide resolved
import { getSearchRecordsQueryResponseField } from '@/object-record/utils/getSearchRecordsQueryResponseField'; | ||
import { capitalize } from '~/utils/string/capitalize'; | ||
|
||
export type QueryCursorDirection = 'before' | 'after'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: QueryCursorDirection is defined but not used in this file. Consider removing if unnecessary.
...s/twenty-server/src/database/typeorm/metadata/migrations/1726848397026-addTypeOrmMetadata.ts
Show resolved
Hide resolved
...ase/typeorm/metadata/migrations/1727699709905-addIsCustomAddIsCustomColumnToIndexMetadata.ts
Outdated
Show resolved
Hide resolved
...enty-server/src/engine/api/graphql/workspace-query-builder/factories/search-query.factory.ts
Outdated
Show resolved
Hide resolved
...enty-server/src/engine/api/graphql/workspace-query-builder/factories/search-query.factory.ts
Outdated
Show resolved
Hide resolved
...erver/src/engine/api/graphql/workspace-resolver-builder/factories/search-resolver-factory.ts
Show resolved
Hide resolved
...erver/src/engine/api/graphql/workspace-resolver-builder/factories/search-resolver-factory.ts
Show resolved
Hide resolved
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; | ||
import { isCompositeFieldMetadataType } from 'src/engine/metadata-modules/field-metadata/utils/is-composite-field-metadata-type.util'; | ||
import { isRelationFieldMetadataType } from 'src/engine/utils/is-relation-field-metadata-type.util'; | ||
import { pascalCase } from 'src/utils/pascal-case'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Import order changed. Consider using a consistent import ordering strategy across the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great Job @ijreilly! I left a few comments and still need to test a bit locally. Can't wait to merge it 💪
...ase/typeorm/metadata/migrations/1727699709905-addIsCustomAddIsCustomColumnToIndexMetadata.ts
Outdated
Show resolved
Hide resolved
...ase/typeorm/metadata/migrations/1727699709905-addIsCustomAddIsCustomColumnToIndexMetadata.ts
Outdated
Show resolved
Hide resolved
...ase/typeorm/metadata/migrations/1727699709905-addIsCustomAddIsCustomColumnToIndexMetadata.ts
Outdated
Show resolved
Hide resolved
...es/twenty-server/src/engine/api/graphql/graphql-query-runner/graphql-query-runner.service.ts
Show resolved
Hide resolved
icon: 'IconUser', | ||
generatedType: 'STORED', | ||
asExpression: getTsVectorColumnExpressionFromFields([ | ||
{ name: NAME_FIELD_NAME, type: FieldMetadataType.TEXT }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use standardFieldId instead here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the util at this stage we cannot fetch fieldMetadata based on the standardFieldId, can we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not yet. Should be part of the refactoring of sync-metadata but we already started to use hashmap in some places with standard-id, nameSingular, namePlural, etc... as keys.
You can keep it as it is for now indeed
packages/twenty-server/src/engine/metadata-modules/index-metadata/index-metadata.entity.ts
Show resolved
Hide resolved
packages/twenty-front/src/modules/object-record/graphql/types/RecordGqlOperationFilter.ts
Outdated
Show resolved
Hide resolved
.../src/database/typeorm/metadata/migrations/1725893697807-addIndexTypeColumnToIndexMetadata.ts
Outdated
Show resolved
Hide resolved
packages/twenty-front/src/modules/object-record/cache/utils/getRecordsFromRecordConnection.ts
Outdated
Show resolved
Hide resolved
...c/engine/api/graphql/graphql-query-runner/resolvers/graphql-query-search-resolver.service.ts
Fixed
Show fixed
Hide fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there 💪
Also I noticed we were not querying search for custom objects on the FE, is it expected? Looks like the BE should be ready? LGTM if we want to do it in another PR 👍
.../src/database/typeorm/metadata/migrations/1725893697807-addIndexTypeColumnToIndexMetadata.ts
Outdated
Show resolved
Hide resolved
...c/engine/api/graphql/graphql-query-runner/resolvers/graphql-query-search-resolver.service.ts
Outdated
Show resolved
Hide resolved
...twenty-server/src/engine/api/graphql/workspace-schema-builder/utils/generate-fields.utils.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/metadata-modules/index-metadata/index-metadata.entity.ts
Show resolved
Hide resolved
isActive: false, | ||
isSystem: true, | ||
type: FieldMetadataType.TS_VECTOR, | ||
name: SEARCH_VECTOR_FIELD_NAME, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, maybe we can create an object then?
const SEARCH_VECTOR_FIELD = {
name: 'searchVector',
label: 'Search Vector',
...
}
not a strong requirement, up to you if you feel like those const are enough
...nty-server/src/engine/metadata-modules/utils/constants/search-vector-field-name.constants.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/twenty-orm/decorators/workspace-index.decorator.ts
Show resolved
Hide resolved
...rc/engine/workspace-manager/workspace-migration-runner/workspace-migration-runner.service.ts
Show resolved
Hide resolved
...twenty-server/src/engine/workspace-manager/workspace-sync-metadata/standard-objects/index.ts
Show resolved
Hide resolved
icon: 'IconUser', | ||
generatedType: 'STORED', | ||
asExpression: getTsVectorColumnExpressionFromFields([ | ||
{ name: NAME_FIELD_NAME, type: FieldMetadataType.TEXT }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not yet. Should be part of the refactoring of sync-metadata but we already started to use hashmap in some places with standard-id, nameSingular, namePlural, etc... as keys.
You can keep it as it is for now indeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!! Just left a few comments but LGTM 👏
.../src/database/typeorm/metadata/migrations/1725893697807-addIndexTypeColumnToIndexMetadata.ts
Outdated
Show resolved
Hide resolved
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TYPE metadata.INDEX_TYPES AS ENUM ('BTREE', 'GIN')`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realised but I think that's not the naming convention we follow currently.
We put the name of the table as well. Can you double check please? 🙏
} | ||
|
||
if (!args.searchInput) { | ||
return {} as IConnection<ObjectRecord>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to return this
return typeORMObjectRecordsParser.createConnection(
[],
objectMetadataItem.nameSingular,
0,
0,
[{ id: OrderByDirection.AscNullsFirst }],
false,
false,
);
Steps to test 1. Run metadata migrations 2. Run sync-metadata on your workspace 3. Enable the following feature flags: IS_SEARCH_ENABLED IS_QUERY_RUNNER_TWENTY_ORM_ENABLED IS_WORKSPACE_MIGRATED_FOR_SEARCH 4. Type Cmd + K and search anything
Steps to test
IS_SEARCH_ENABLED
IS_QUERY_RUNNER_TWENTY_ORM_ENABLED
IS_WORKSPACE_MIGRATED_FOR_SEARCH