最近要做一个全文搜索功能,不知道这块思路和技术这块怎么样?
最近要做全文搜索功能,用户输入框输入关键字,可以搜索到匹配该关键字的文章。
支持对文章内容匹配和文章标题匹配。想问下实现起来复杂么?
有哪些比较好的解决方案?
开发语言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

AI Hentai Generator
Generate AI Hentai for free.

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 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

The page is blank after PHP connects to MySQL, and the reason why die() function fails. When learning the connection between PHP and MySQL database, you often encounter some confusing things...

CMS stands for Content Management System. It is a software application or platform that enables users to create, manage, and modify digital content without requiring advanced technical knowledge. CMS allows users to easily create and organize content
