question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres Full-Text Search Index is not used

See original GitHub issue

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

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

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

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

SELECT "public"."Posts".*
FROM "public"."Posts" 
WHERE to_tsvector("public"."Posts"."body"|| ' ' ||"public"."Posts"."anotherField") @@ to_tsquery($1)

instead of

SELECT "public"."Posts".*
FROM "public"."Posts" 
WHERE to_tsvector('english', "public"."Posts"."body" || "public"."Posts"."anotherField") @@ to_tsquery($1)

This problem also prevent using GIN/GIST index with two field

How to reproduce

See bug description

Expected behavior

No response

Prisma information

full-text search exemple in doc https://www.prisma.io/docs/concepts/components/prisma-client/full-text-search

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v16.7.0

Prisma Version

prisma                : 2.30.0
@prisma/client        : 2.30.0
Current platform      : darwin-arm64
Query Engine (Binary) : query-engine 60b19f4a1de4fe95741da371b4c44a92f4d1adcb (at node_modules/@prisma/engines/query-engine-darwin-arm64)
Migration Engine      : migration-engine-cli 60b19f4a1de4fe95741da371b4c44a92f4d1adcb (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine  : introspection-core 60b19f4a1de4fe95741da371b4c44a92f4d1adcb (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary         : prisma-fmt 60b19f4a1de4fe95741da371b4c44a92f4d1adcb (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash  : 60b19f4a1de4fe95741da371b4c44a92f4d1adcb
Studio                : 0.422.0
Preview Features      : orderByRelation, selectRelationCount, orderByAggregateGroup, filterJson, referentialActions, fullTextSearch

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:12
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

12reactions
floelhoeffelcommented, Aug 3, 2022

Hello everyone 👋

We are starting design work to improve Prisma’s support for Full Text Search (FTS)!

If you would like to help, please tell us about your needs via a short FTS user research survey.

Thank you!

6reactions
joshribakoff-smcommented, Mar 14, 2022

🤷 I basically just want it to not be super slow, however that happens 😆 I created the feature request 😃 thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Indexing for full text search in PostgreSQL - Compose Articles
This article will give you an understanding of how PostgreSQL full text search indexing works under the hood and show you the steps...
Read more >
PostgreSQL GIN index not used when ts_query language is ...
I suggest a solution with partial expression indexes: CREATE TABLE search ( search_id serial PRIMARY KEY , language regconfig NOT NULL ...
Read more >
PostgreSQL full text search not using index after importing ...
I am trying to make PostgreSQL use an index for prefix searching using full text search. It works fine in general, but only...
Read more >
Documentation: 15: 12.2. Tables and Indexes - PostgreSQL
Practical use of text searching usually requires creating an index. ... s that were created with different text search configurations, and there would...
Read more >
Understanding PostgreSQL Full Text Search: 10 Critical Aspects
During a PostgreSQL Full Text search, Postgres will not include “stop ... After that, you can then generate a GIN index using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found