Skip to content

Conversation

leemhoon00
Copy link
Contributor

@leemhoon00 leemhoon00 commented Jan 17, 2024

I'm writing to report an inconsistency in the documentation regarding MySQL full-text search with the minus operator (-).

Incorrect Information

Page: https://www.prisma.io/docs/orm/prisma-client/queries/full-text-search#mysql
image

The statement that "The minus operator (-) excludes rows that contain a specific word" is not accurate.
According to MySQL's official documentation (https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html), the minus operator cannot be used by itself. It must be combined with other keywords or operators to form valid full-text search queries.
image

Testing and Results

Schema

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

datasource db {
  provider = "mysql"
  url      = "mysql://root:root@localhost:3306/temp"
}

model Post {
  id Int @id @default(autoincrement())
  content String

  @@fulltext([content])
}

Query Code

async function main() {
  const result1 = await prisma.post.findMany({
    where: {
      content: {
        search: '+dog -cat',
      },
    },
  });

  const result2 = await prisma.post.findMany({
    where: {
      content: {
        search: '-cat',
      },
    },
  });

  const result3 = await prisma.post.findMany({
    where: {
      content: {
        search: '-cat -pig',
      },
    },
  });

  console.log(result1);
  console.log(result2);
  console.log(result3);
}

Output

[ { id: 1, content: 'The quick brown fox jumps over the lazy dog' } ]
[]
[]

Copy link

vercel bot commented Jan 17, 2024

@leemhoon00 is attempting to deploy a commit to the Prisma Team on Vercel.

A member of the Team first needs to authorize it.

@jharrell jharrell merged commit e463235 into prisma:main Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants