随着自己电影网站资源逐渐增多,增加电影资源搜索服务成为必然。直接操作数据库的搜索,IO口请求增多减低了搜索性能。之前项目中有sphinx的使用基础,加之支持中文检索服务,最后决定采用基于sphinx的Coreseek搜索服务。
下载安装步骤【本人采用 linux环境下 4.1版本,系统支持mysql和xml数据源】:
coreseek下载地址,下载 coreseek-4.1-beta.tar.gz 包
解压gz包,tar zxvf coreseek-4.1-beta.tar.gz
编译安装 mmseg【中文分词包】
./bootstrap
./configure --prefix=/usr/local/mmseg3
make && make install
编译安装 coreseek
sh buildconf.sh #输出的warning信息可以忽略,如果出现error则需要解决
./configure --prefix=/usr/local/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg3/lib/ --with-mysql #with-mmseg-libs就是mmseg中文分词路径
make && make install
电影网站更新周期比较长,sphinx采用主索引+增量索引方式进行索引,最后合并两个索引文件。下面开始部署自己的搜索配置文件:
进入coreseek安装目录下的etc文件,新建或修改 .conf配置文件
配置source源
-
source movie
{
type = mysql
sql_host = localhost #mysql数据库host
sql_user = root #mysql用户
sql_pass = #mysql用户密码
sql_db = movie #movie
sql_port = 3306 # optional, default is 3306
sql_query_pre = SET NAMES utf8
#建立增量索引
sql_query_pre = REPLACE INTO movie_sph_counter SELECT 1, MAX(id) FROM movie
sql_query = SELECT id, UNIX_TIMESTAMP(cdate) AS date ,id AS movie_id ,name, year, type,status,sync_status FROM movie WHERE id#搜索返回字段
sql_attr_uint = movie_id
sql_attr_uint = year
sql_attr_uint = type
sql_attr_uint = date
sql_attr_uint = status
sql_attr_uint = sync_status
sql_field_string = name
sql_query_info_pre = SET NAMES utf8 #命令行查询时,设置正确的字符集
sql_query_info = SELECT * FROM movie WHERE id=$id #命令行查询时,从数据库读取原始数据信息
}#增量索引源
source delta : movie
{
sql_query_pre = SET NAMES utf8
sql_query = SELECT id, UNIX_TIMESTAMP(cdate) AS date ,id AS movie_id ,name , year, type ,status,sync_status FROM movie WHERE id>( SELECT max_movie_id FROM movie_sph_counter WHERE counter_id=1 )
sql_query_post_index = REPLACE INTO movie_sph_counter SELECT 1, MAX(id) FROM movie
} 配置索引
#index定义
index movie
{
source = movie #对应的source名称
path = /usr/local/coreseek/var/data/movie #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
html_strip = 0
#中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/
charset_dictpath = /usr/local/mmseg/etc/ #BSD、Linux环境下设置,/符号结尾 mmseg路径
charset_type = zh_cn.utf-8 #中文编码
}
index delta : movie
{
source = delta
path = /usr/local/coreseek/var/data/movie_delta #注意!!不要和主索引路径名称一样
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
html_strip = 0
charset_dictpath = /usr/local/mmseg/etc/
charset_type = zh_cn.utf-8
}配置搜索服务
#searchd服务定义
searchd
{
listen = 9312 #端口号,可以自己定义
read_timeout = 5
max_children = 30
max_matches = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old = 1
compat_sphinxql_magics=0
pid_file = /usr/local/coreseek/var/log/searchd_mysql.pid #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
log = /usr/local/coreseek/var/log/searchd_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
query_log = /usr/local/coreseek/var/log/query_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
binlog_path = #关闭binlog日志
}执行命令建立索引: /usr/local/coreseek/bin/indexer -c movie.conf --all
后台开启搜索服务运行:/usr/local/coreseek/bin/searchd -c movie.conf
建立定时任务,执行增量索引:/usr/local/coreseek/bin/indexer -c csft_movie.conf delta --rotate
建立定时任务,合并索引:/usr/local/coreseek/bin/indexer -c csft_movie.conf --merge movie delta --merge-dst-range deleted 0 0 --rotate
至此基于sphinx+mysql的搜索服务已经搭建完毕,接下来就是根据sphinxapi.php开发搜索接口代码……
第一次自己搭建sphinx搜索服务,最后测试网站搜索,速度杠杠的。
特此分享,希望对大家有所帮助

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
