MYSQL中的中文模糊搜索除了使用全文索引外还有什么办法呢?
环 境:winxp
语 言:php5.49
数据库:musql5.6
LEVER:一个初学PHP和MYSQL的小粉
数据量:30万左右,不会超过50万。
就是这样的一个网站,就是这样的一个水平的我,却在这几天被一个难题难死了。
因为我之前的这个站是用asp+mssql搭建的,一直在托管的服务器上跑的还行,某一天想把数据库放到阿里云上,查了一下报价,发现mysql的价格比mssql的价格便宜近10倍多,这才认识到为什么开源软件这么受欢迎了,好吧,我也改一下数据库,顺便学习一下早就想学的PHP,说干就干,装PHP装mysql,中间碰到的这个苦难就不说了,改写起来还算顺利,有一些弱智的问题也得到了网友的热情回答,还算顺利,但是直到昨天,我在改写原来MSsql里面的全文索引语句为PHP的全文索引语句时,无意中看到,MSSQL居然不支持中文的全文索引,于是我感到无比的挫败感,这该怎么办呢?这么好的数据库却有这么一个难题,于是想对于一个如此成熟的数据库,同时全文索引又是一个常用功能,那么网上的解决方案一定是现成的,好吧,我开始了百度,这下才发现,很难找到像样的资料可以轻松解决此问题,很多解决方案是那么那么的晦涩难懂。对于我这样的水平的人,看完都不容易更不要说执行了,尝试了其中一种Sphinx+CoreSeek4.1的方案,连安装调试都过不去,可以找到的资料也是很少很少,唉。。。愁人的
所以,我就想问问大家,为什么你们都不需要解决中文模糊搜索过程中全文索引的建立和使用问题吗?这不是一个很普遍的应用吗?
再或者,请你们帮我分析一下,对于这样一个30万左右的数据库,一共10个字段,想对其中5个字段实现模糊搜索,是通过spnix/coreseek建立中文的全文索引的搜索速度快,还是直接使用like 汉字关键词%的速度快呢?或者慢的话又能慢多少呢?
我现在没有这方面的经验,所以一直在纠结,要是二者没有显著性差别,我觉得为这个搭建一个spnix/coreseek环境是不是有些太那个了呢?而且还那么那么那么那么难搭建的,真心懊恼,不知道咋办了,请帮我一下好吗?谢谢大家。
回复内容:
环 境:winxp
语 言:php5.49
数据库:musql5.6
LEVER:一个初学PHP和MYSQL的小粉
数据量:30万左右,不会超过50万。
就是这样的一个网站,就是这样的一个水平的我,却在这几天被一个难题难死了。
因为我之前的这个站是用asp+mssql搭建的,一直在托管的服务器上跑的还行,某一天想把数据库放到阿里云上,查了一下报价,发现mysql的价格比mssql的价格便宜近10倍多,这才认识到为什么开源软件这么受欢迎了,好吧,我也改一下数据库,顺便学习一下早就想学的PHP,说干就干,装PHP装mysql,中间碰到的这个苦难就不说了,改写起来还算顺利,有一些弱智的问题也得到了网友的热情回答,还算顺利,但是直到昨天,我在改写原来MSsql里面的全文索引语句为PHP的全文索引语句时,无意中看到,MSSQL居然不支持中文的全文索引,于是我感到无比的挫败感,这该怎么办呢?这么好的数据库却有这么一个难题,于是想对于一个如此成熟的数据库,同时全文索引又是一个常用功能,那么网上的解决方案一定是现成的,好吧,我开始了百度,这下才发现,很难找到像样的资料可以轻松解决此问题,很多解决方案是那么那么的晦涩难懂。对于我这样的水平的人,看完都不容易更不要说执行了,尝试了其中一种Sphinx+CoreSeek4.1的方案,连安装调试都过不去,可以找到的资料也是很少很少,唉。。。愁人的
所以,我就想问问大家,为什么你们都不需要解决中文模糊搜索过程中全文索引的建立和使用问题吗?这不是一个很普遍的应用吗?
再或者,请你们帮我分析一下,对于这样一个30万左右的数据库,一共10个字段,想对其中5个字段实现模糊搜索,是通过spnix/coreseek建立中文的全文索引的搜索速度快,还是直接使用like 汉字关键词%的速度快呢?或者慢的话又能慢多少呢?
我现在没有这方面的经验,所以一直在纠结,要是二者没有显著性差别,我觉得为这个搭建一个spnix/coreseek环境是不是有些太那个了呢?而且还那么那么那么那么难搭建的,真心懊恼,不知道咋办了,请帮我一下好吗?谢谢大家。
mysql5.7 支持中文分词 全文索引
你既然用阿里云了,那就尝试他们的【开放搜索】服务看看
或者你觉得拥抱开源,也可以尝试在linux下配置segmentfault.com在用或曾经用过的http://www.xunsearch.com/,个人感觉相对还是比较简单的,而且性能比mysql全文索引要强
coreseek,sphinx拿来用研究试试
表引擎建议使用MySQL5.6.4后的InnoDB,是支持中文索引的.简易中文分词SCWS提供有PECL扩展以及中文词典,PHP使用起来很方便:
http://www.xunsearch.com/scws/docs.php#instscws
比如要实现对自己博客的所有文章进行全文搜索:
show variables like '%ft_min%' 可见默认值:
MyISAM: ft_min_word_len=4
InnoDB: innodb_ft_min_token_size=3
把单词最小单词长度设为1,这样就能索引和查找只有一个字符的关键词了:
执行 set global innodb_ft_min_token_size=1;
返回 Variable 'innodb_ft_min_token_size' is a read only variable
所以只能在my.cnf的[mysqld]下配置:
<code>ft_min_word_len=1 innodb_ft_min_token_size=1 </code>
<code>建表: CREATE TABLE `articles` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(200) NOT NULL DEFAULT '', `content` text, `article_fc` text, PRIMARY KEY (`id`), FULLTEXT (`article_fc`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci; 或者后期添加FULLTEXT: ALTER TABLE `articles` ADD FULLTEXT (`article_fc`); INSERT INTO `articles`(`title`, `content`, `article_fc`) VALUES ('标题1', '中国人民银行', '中国 人民 银行 中国人民银行'); INSERT INTO `articles`(`title`, `content`, `article_fc`) VALUES ('标题2', '中华民族伟大复兴', '中华 民族 伟大 复兴 中华民族'); SELECT * FROM articles WHERE MATCH(article_fc) AGAINST('中国 复兴');</code>
如果只是查询表单自动完成呢
有没有树型存储结构来存放拼音对应的单词
建议选用第三方专用搜索引擎
ElasticSearch

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.
