[search] simplify tsvector generated expression and remove deletedAt condition #7561
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Because we can't create GIN indexes on primitive types and in this case both tsvector and deletedAt (date), we had to create an index on the tsvector only and had to make sure it wouldn't return results for deleted records.
To handle this, we added a CASE in the generated expression to generate an empty value if the row has been soft-deleted. This is a bit too complex and won't allow search on softDeleted records in the future.
What we want to do is to make sure deleted records are not returned by default by adding a WHERE clause in the search and still keep good performances by also adding a BTREE index on deletedAt column.
When this was implemented, soft-deleted was not handled properly but now typeorm query builder exclude soft deleted records by default which means the WHERE clause is not necessary. As for the BTREE index on deletedAt, this should be part on a broader effort to add it to all tables and can be added in a later PR.
This PR simply updates the complex tsVectorExpression to only return the expression regardless of the deletedAt column. Search won't return soft-deleted records as explained above and perfs will be improved in an upcoming version.
Test
tested locally with reset db + created a new workspace. Since the feature is not launched yet no more effort should be made.
Note
Some issues with optimistic rendering, we need to refresh once a record has been deleted otherwise it will still be returned by the search