search
HomeBackend DevelopmentPHP TutorialDetailed example explanation of PHP+Sphinx+Mysql development of search engine

When everyone hears about search engines, they will find it difficult to write and have no idea at all. In fact, PHP can also be used for search engine development, but PHP needs to be combined with sphinx and mysql to develop the search engine we want. I want to know about PHP How to carry out search engine development! Let’s take a look! !

First we download the Sphinx tool, download address official website download address: www.sphinxsearch.com, find sphinx-2.2.10-release-win64.zip, download this for 64-bit, unzip it to us Under the PHP running directory, it is convenient to view the results on subsequent web pages.

sphinx introduction:

Sphinx is the abbreviation of SQL Phrase Index (query phrase index). Sphinx is a full-text search engine based on SQL. The API interfaces it provides include :PHP, Python, Perl, Ruby, java, etc. At the same time, an engine plug-in SphinxSE is designed for MySQL, which is a distributed full-text retrieval system.
Advantages:
High-speed indexing can reach 10M/s
High-performance search (text data in 2-4G On average, the average response time for each retrieval is less than 0.1 seconds)
Can handle massive amounts of data (currently known to be able to process 100G of text data, and 100M of documents on a single CPU system)
Provides excellent correlation algorithm, composite ranking method based on phrase similarity and statistical BM2
Supports distributed search
Provide document fragment generation function
Can be used as a Mysql storage engine to provide search services
Support Boolean, phrase, word similarity and other search modes
Disadvantages:
Must have a primary key
The primary key must be an integer
Not responsible for data storage
The configuration is not flexible

The sphinx structure after decompression is as shown in the figure:


The following is our process For related configuration, see sphinx-min.conf.in in the picture, copy it to our bin directory for easy use and change the name to sphinx.conf,

Modify the content inside:

source src1
{
	type			= mysql

	sql_host		= localhost #主机地址
	sql_user		= root#帐号
	sql_pass		=     #密码
	sql_db			= sphinx  #数据库
	sql_port		= 3306	# 数据库端口 3306
	sql_query		= SELECT id, name, age FROM users #查询语句
	sql_attr_uint		= group_id
	sql_attr_timestamp	= date_added
	sql_query_pre = set names utf8   #数据库编码
}


index test1
{
	source			= src1
	path			= D:/myapaphe/www/sphinx/data #这个一定要配置
	charset_type = utf-8 #指定编码
	ngram_len = 1        #要找中文需指定为1.
	ngram_chars = U+3000..U+2FA1F
	
}

indexer
{
	mem_limit		= 128M
}
searchd
{
	listen			= 9312
	listen			= 9306:mysql41
	log			= D:\myapaphe\www\sphinx\log\searchd.log  #进程日志
	query_log		= D:\myapaphe\www\sphinx\log\query.log    #查询日志

	read_timeout		= 5
	max_children		= 30
	pid_file		= D:\myapaphe\www\sphinx\log\searchd.pid 
	seamless_rotate		= 1
	preopen_indexes		= 1
	unlink_old		= 1
	workers			= threads # for RT to work
	binlog_path		= D:\myapaphe\www\sphinx\data
}

The above must be configured, and the path must match your own path.

Next generate the query index:


Install searchd service:


Next load the configuration file:


##Start the service:


OK the previous configuration work and service startup have been completed. Now start the code:

Create test3.php under the api folder under sphinx and run test3.php

<?php 
require ( "sphinxapi.php" );
$s = new SphinxClient();
$s->SetServer(&#39;localhost&#39;,9312);
$result = $s->Query(&#39;高七&#39;);
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
print_r($result);


Garbled characters are because cmd defaults to gbk encoding. Let’s put it in the browser to view:


We see that sphinx does not find the complete result but returns the ID to us, allowing us to check the data based on the ID.

The following is a query time comparison:


The time I tested on more than 40,000 pieces of data was 0.001s. Let’s take a look at mysql How long does the query take:


We see that it takes 0.04s, there is not much data, and the result is not that obvious, but the gap of 0.039s is not small.

This completes the integration of sphinx, I hope it can help everyone.

related suggestion:

php Detailed explanation of calling existing search engines

php Function code to determine whether the visitor is a search engine spider

The above is the detailed content of Detailed example explanation of PHP+Sphinx+Mysql development of search engine. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何在 iPhone 和 iPad 上更改搜索引擎如何在 iPhone 和 iPad 上更改搜索引擎Apr 25, 2023 am 08:28 AM

在iPhone或iPad上的Safari、GoogleChrome或其他浏览器中更改搜索引擎非常简单。本教程将向您展示如何在iPhone和iPad上可用的四种不同网络浏览器上进行操作。如何更改iPhone或iPad上的Safari搜索引擎Safari是iOS和iPadOS上的默认网络浏览器,但您可能不喜欢这个搜索引擎。幸运的是,您可以使用以下步骤进行更改:在iPhone或iPad上,从主屏幕启动设置。向下滑动并从列表中点按Safari。在下一个菜单中,

Java开发:如何实现搜索引擎和全文检索功能Java开发:如何实现搜索引擎和全文检索功能Sep 21, 2023 pm 01:10 PM

Java开发:如何实现搜索引擎和全文检索功能,需要具体代码示例搜索引擎和全文检索是现代互联网时代的重要功能。它们不仅可以帮助用户快速找到想要的内容,还可以为网站和应用程序提供更好的用户体验。本文将介绍如何使用Java开发搜索引擎和全文检索功能,并提供一些具体的代码示例。使用Lucene库实现全文检索Lucene是一款开源的全文检索引擎库,由ApacheSo

PHP搜索引擎性能优化:Algolia的妙用之道PHP搜索引擎性能优化:Algolia的妙用之道Jul 23, 2023 pm 04:21 PM

PHP搜索引擎性能优化:Algolia的妙用之道随着互联网的发展和用户对搜索体验的要求不断提高,搜索引擎的性能优化变得至关重要。在PHP开发领域,Algolia是一个强大且易于集成的搜索引擎服务。本文将介绍Algolia的妙用之道以及如何通过Algolia来优化PHP搜索引擎的性能。Algolia介绍Algolia是一家基于SaaS模式的搜索引擎服务提供商,

人工智能搜索领域,谷歌微软展开对抗人工智能搜索领域,谷歌微软展开对抗Apr 08, 2023 am 11:31 AM

自去年年底推出以来,ChatGPT被看作对传统搜索信息方式的重大威胁。因为它是多样化的,可以回答人们的问题,编写论文或诗歌,甚至编写程序代码。对话式人工智能提供连贯答案的能力被认为是对谷歌搜索引擎的威胁,几十年来,谷歌一直是人们在互联网上搜索信息的标杆平台。OpenAI的ChatGPT可以定制用户提出的特定问题的答案,这可以节省浏览网站的时间。《纽约时报》12月发布的一份报告显示,ChatGPT一夜之间的成功迫使谷歌称其为“红色代码”,并开始应对人工智能聊天机器人对其搜索引擎业务造成的威胁。根据

PHP和Manticore Search开发:打造高效的搜索引擎PHP和Manticore Search开发:打造高效的搜索引擎Aug 07, 2023 am 09:45 AM

PHP和ManticoreSearch开发:打造高效的搜索引擎搜索引擎在现代互联网应用中起着非常重要的作用。为了实现高效和准确的搜索功能,我们需要选择合适的搜索引擎,并使用适当的开发工具进行开发。本文将介绍如何使用PHP和ManticoreSearch开发一个高效的搜索引擎。ManticoreSearch是一个强大的开源搜索引擎,它基于SphinxS

如何在PHP7.0中实现一个全文搜索引擎?如何在PHP7.0中实现一个全文搜索引擎?May 26, 2023 pm 04:51 PM

随着信息时代的不断发展,人们越来越依赖互联网来获取信息。而作为信息分享的平台之一,网页搜索引擎也在不断进化和完善。本文将介绍如何在PHP7.0中实现一个全文搜索引擎,帮助读者更好地利用PHP技术,快速构建高效率的搜索引擎。一、全文搜索引擎概述全文搜索即使用关键词或短语在整篇文档中进行搜索,以找到最匹配的结果。全文搜索引擎使用算法对文档进行索引,以加速搜索。在

使用PHP和Elasticsearch构建高效的搜索引擎使用PHP和Elasticsearch构建高效的搜索引擎Jul 09, 2023 pm 04:57 PM

使用PHP和Elasticsearch构建高效的搜索引擎引言:在当今互联网时代,搜索引擎是人们获取信息的首选工具。为了提供快速准确的搜索结果,开发人员需要构建高效的搜索引擎。本文将介绍如何使用PHP和Elasticsearch构建高效的搜索引擎,并给出相应的代码示例。一、什么是Elasticsearch?Elasticsearch是一个分布式的开源搜索和分析

构建强大的搜索引擎:PHP与Algolia的结合实践构建强大的搜索引擎:PHP与Algolia的结合实践Jul 22, 2023 pm 01:30 PM

构建强大的搜索引擎:PHP与Algolia的结合实践搜索引擎在当今互联网时代扮演着至关重要的角色,为用户提供快速、准确的搜索结果。而在实现强大的搜索功能时,PHP作为一种常用的编程语言,结合Algolia这个高性能的搜索服务,可以为网站或应用程序提供出色的搜索体验。本文将介绍如何使用PHP和Algolia构建强大的搜索引擎,并附上一些代码示例供读者参考。一、

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft