doulu1867 2015-03-22 18:33
浏览 909

在MEDIUMTEXT上使用MySQL进行全字搜索

I know this question was discussed a lot of times. Anyway, I would like to figure out again.

Well, I have table "articles" contains these fields:

  • title (varchar 255)
  • keywords (varchar 255)
  • content_body_1 (mediumtext)
  • content_body_2 (mediumtext)

There is an index on "title" and "keywords". However, there is no index on MEDIUMTEXT fields.

I need to perform "whole word" search on all these fields. I am now doing this using REGEXP:

SELECT * FROM `articles` WHERE `content_body_1` REGEXP '[[:<:]]"keyword"[[:>:]]'

And so on. It's okay for 100 articles, but it's VERY slow (2-3 seconds) on 1000 articles. REGEXP does not use indexing in MySQL. What if I have 10000 articles? Is there any way for faster search by whole keyword?

How can I get that? Is FULLTEXT much faster? If yes - how can I design my database? And also what should I do with FULLTEXT limit of minimum characters to search?

Thanks.

  • 写回答

2条回答 默认 最新

  • douyi4544 2015-03-22 21:14
    关注

    Why are you using a regexp for a full text search? You could just as easily use the % character and it's probably much faster than doing a regex.

    SELECT * FROM articles WHERE content_body_1 LIKE '%keyword%'

    This will find any rows where your content_body_1 contains the keyword somewhere in it.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog