IssueRaiser

Postgres Full-Text Search Index is not used

### Bug description Current FTS appear to not use defined GIN or GIST index Recommended GIN index in doc is also not working ``` ERROR: data type text has no default operator class for access method "gin" HINT: You must specify an operator class for the index or define a default operator class for the data type. ``` As far as I know it should be something like this since body is of type `String` in schema ```sql CREATE INDEX IF NOT EXISTS "post_body_index" ON "Posts" USING GIN (to_tsvector('english', "body")); -- Or/And CREATE INDEX IF NOT EXISTS "post_body_index" ON "Posts" USING GIST (to_tsvector('english', "body")); ``` And request should be something like this ```sql SELECT "public"."Posts".* FROM "public"."Posts" WHERE to_tsvector('english', "public"."Posts"."body") @@ to_tsquery('test | test'); ``` `english` in `to_tsvector` could be another language so it should be dynamic from @prisma/client There is also a concatenation problem when you do ```ts const result = await prisma.posts.findMany({ where: { status: 'Draft', OR: [ { body: { search: 'cat & dog' }}, { anotherField: { search: 'test | test' }} ] }, }) ``` Where the `body` and `anotherField` get concatenated in sql ```sql SELECT "public"."Posts".* FROM "public"."Posts" WHERE to_tsvector("public"."Posts"."body"|| ' ' ||"public"."Posts"."anotherField") @@ to_tsquery($1) ``` instead of ```sql SELECT "public"."Posts".* FROM "public"."Posts" WHERE to_tsvector('english', "publ

Posted by AzSiAz on Aug 26, 2021, 5:07 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

github (Other)

Postgres Full-Text Search Index is not used

AzSiAzAug 26, 2021, 5:07 PM

### Bug description Current FTS appear to not use defined GIN or GIST index Recommended GIN index in doc is also not working ``` ERROR: data type text has no default operator class for access method "gin" HINT: You must specify an operator class for the index or define a default operator class for the data type. ``` As far as I know it should be something like this since body is of type `String` in schema ```sql CREATE INDEX IF NOT EXISTS "post_body_index" ON "Posts" USING GIN (to_tsvector('english', "body")); -- Or/And CREATE INDEX IF NOT EXISTS "post_body_index" ON "Posts" USING GIST (to_tsvector('english', "body")); ``` And request should be something like this ```sql SELECT "public"."Posts".* FROM "public"."Posts" WHERE to_tsvector('english', "public"."Posts"."body") @@ to_tsquery('test | test'); ``` `english` in `to_tsvector` could be another language so it should be dynamic from @prisma/client There is also a concatenation problem when you do ```ts const result = await prisma.posts.findMany({ where: { status: 'Draft', OR: [ { body: { search: 'cat & dog' }}, { anotherField: { search: 'test | test' }} ] }, }) ``` Where the `body` and `anotherField` get concatenated in sql ```sql SELECT "public"."Posts".* FROM "public"."Posts" WHERE to_tsvector("public"."Posts"."body"|| ' ' ||"public"."Posts"."anotherField") @@ to_tsquery($1) ``` instead of ```sql SELECT "public"."Posts".* FROM "public"."Posts" WHERE to_tsvector('english', "publ

Comments (0)

No comments yet. Start the discussion.

Comment on this issue