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.

Full-text-search not working when the query is multiple strings

See original GitHub issue

Bug description

Full-text-search not working when the query is multiple words, works fine when it’s a single word being passed into my Prisma query:


const results = await prisma.post.findMany({
      where: {
        body: {
          search: `post`, // works
        },
      },
    });

const results = await prisma.post.findMany({
      where: {
        body: {
          search: `second post`, // throws an error
        },
      },
    });

I get the following error:

PrismaClientUnknownRequestError3 [PrismaClientUnknownRequestError]: 
Invalid `prisma.post.findMany()` invocation:


  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42601"), message: "syntax error in tsquery: \"second post\"", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("tsquery.c"), line: Some(726), routine: Some("makepol") }) }) })
    at cb (/Users/m-abdelwahab/Desktop/full-text-search-demo/node_modules/@prisma/client/runtime/index.js:36067:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async handler (webpack-internal:///./pages/api/search.ts:11:21)
    at async Object.apiResolver (/Users/m-abdelwahab/Desktop/full-text-search-demo/node_modules/next/dist/server/api-utils.js:101:9)
    at async DevServer.handleApiRequest (/Users/m-abdelwahab/Desktop/full-text-search-demo/node_modules/next/dist/server/next-server.js:760:9)
    at async Object.fn (/Users/m-abdelwahab/Desktop/full-text-search-demo/node_modules/next/dist/server/next-server.js:651:37)
    at async Router.execute (/Users/m-abdelwahab/Desktop/full-text-search-demo/node_modules/next/dist/server/router.js:205:32)
    at async DevServer.run (/Users/m-abdelwahab/Desktop/full-text-search-demo/node_modules/next/dist/server/next-server.js:825:29)
    at async DevServer.handleRequest (/Users/m-abdelwahab/Desktop/full-text-search-demo/node_modules/next/dist/server/next-server.js:292:20) {
  clientVersion: '2.30.0'
}

Reproduction: https://github.com/m-abdelwahab/prisma-full-text-search

How to reproduce

Reproduction: https://github.com/m-abdelwahab/prisma-full-text-search

Clone repo, install dependencies, run seed script, go to http://localhost:3000 and try some queries

Maybe I’m doing something wrong that I’m not aware of

Expected behavior

Should work normally and return results that contain my query.

Prisma information

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["fullTextSearch"]
}

model Post {
  id     Int    @id @default(autoincrement())
  title  String @unique
  body   String
  status Status
}

enum Status {
  Draft
  Live
}

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v14.17.4

Prisma Version

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
m3haricommented, Oct 5, 2021

My workaround is to replace whitespace with underscore, it works for tabs, newline, and consecutive white spaces.

{
  search:query.replace(/[\s\n\t]/g, '_')
}
7reactions
matthewmuellercommented, Aug 31, 2021

The workaround today is to pre-process your queries, for example:

const results = await prisma.post.findMany({
  where: {
    body: {
      search: "second post".split(" ").join(" & "),
    },
  },
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

tsql - Use multiple words in FullText Search input string
I have basic stored procedure that performs a full text search against 3 columns in a table by passing in a ...
Read more >
SQL 2019 Full text search on multiple column with multiple ...
Hello,. I want to us full text search for cross column searching of multiple search values. For example there is a address table...
Read more >
Full text search on multiple unrelated fields - MongoDB
I want to be able to perform full text search on multiple fields , but i saw that mongo allows 1 text index...
Read more >
Full-text search index - Cypher Manual - Neo4j
The complete list of stop words for each analyzer is included in the result of the db.index.fulltext.listAvailableAnalyzers procedure. Full-text indexes:.
Read more >
Text Search | YouTrack Server Documentation - JetBrains
Enter multiple words to find issues that contain all of the specified words in any order. Use wildcards to expand the text search...
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