最近要做一个全文搜索功能,不知道这块思路和技术这块怎么样?
最近要做全文搜索功能,用户输入框输入关键字,可以搜索到匹配该关键字的文章。
支持对文章内容匹配和文章标题匹配。想问下实现起来复杂么?
有哪些比较好的解决方案?
开发语言php,数据库mysql
回复内容:
最近要做全文搜索功能,用户输入框输入关键字,可以搜索到匹配该关键字的文章。
支持对文章内容匹配和文章标题匹配。想问下实现起来复杂么?
有哪些比较好的解决方案?
开发语言php,数据库mysql
给楼主一个选择方案:http://www.xunsearch.com/site/usercase
也是开源的,同时也提供商业服务,如果时间充裕的话,可以考虑自主开发,否则选择开源方案吧,而且社区比较活跃的
sphinx的中文分词版coreseek。
http://www.coreseek.cn/
我觉得 elasticsearch 还是不错的,java写的 就是一个搜搜引擎 而且是分布式的 也可以做日志搜索
数据库实现的话可扩展性不高。数据量大起来了,性能会下降。
开源方案有很多,如lucene,需求简单的话写来来也很快。也可以使用基于lucene的solr(http://lucene.apache.org/solr/)
最最最方便,扩展性强的,建议使用阿里与的opensearch,简直太简单方便了。
开源中文搜索引擎XunSearch:
http://www.cloud-sun.com/view/product
http://www.xunsearch.com/doc/php/guide/start.installation
1.性能劲爆:XunSearch单库最多支持40亿条数据,在5亿网页大约1.5TB的数据中检索时间不超过1秒(非缓存).
2.简单易用:前端是使用脚本语言PHP编写的开发工具包.API简单清晰,开发难度极低,提供全中文的示例代码,文档,辅助脚本工具等.
3.功能丰富:除支持基础的自定义分词,字段检索,布尔搜索外,还直接支持用户急需的相关搜索,拼音搜索,搜索建议等专业功能.
XunSearch作者同时是中文分词SCWS(提供有PECL扩展和纯PHP实现以及完整中文词典)的作者马明练hightman.
http://www.xunsearch.com/scws/index.php
PHP驱动的segmentfault.com的站内搜索用的就是XunSearch.
XunSearch搜索建议和纠错(比如拼音搜索):
http://www.xunsearch.com/doc/php/guide/search.fix
或者你可以利用MySQL InnoDB/MyISAM内置的FullText全文索引字段类型,用PECL SCWS对文件内容和标题字段分词后存入一个FullText的分词字段比如article_fc text,FULLTEXT (article_fc)
,然后用户输入时用PECL SCWS分词后再用MATCH AGAINST语句进行全文搜索:
<code>SELECT * FROM articles WHERE MATCH(article_fc) AGAINST('word1 word2');</code>
article_fc字段所在的表也可以和标题正文所在的文章表分开,查出后连接文章表读出标题正文即可.甚至可以用SQLite里建一个分词表,把分词内容都存到SQLite中,减轻MySQL压力.因为SQLite也是支持全文检索的,而且全文检索是一个读操作,SQLite的读性能是非常好的.
更简单粗暴的是,既不依赖PHP SCWS分词,也不依赖MySQL(InnoDB/MyISAM)/SQLite/XunSearch全文检索,直接提示用户分开关键词输入,然后用SQL LIKE进行模糊查询,数据量不大的情况下是可行且简单的方案:
<code>SELECT * FROM articles WHERE content LIKE '%word1%' OR content LIKE '%word2%'; SELECT * FROM articles WHERE content REGEXP 'word1|word2';</code>
Solr,apache的一个项目

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

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database
