搜索
首页后端开发php教程php sphinx搜寻分词 windows7

php sphinx搜索分词 windows7

本地开发环境

1.下载coreseek词库,下载地址:http://www.coreseek.cn/products-install/install_on_windows/

coreseek3.2.14通用版php 5.4.3

?

2.下载好后,再环境变量里配置:

打开cmd#->CD c:\usr\local\coreseek-3.2.14-win32#->SET PATH=%CD%\bin;%PATH%

?

3.在项目录目下添加一个sphinx.conf文件(名字随自己定),关联查询product与product_type表

#MySQL数据源配置,详情请查看:http://www.coreseek.cn/products-install/mysql/#请先将var/test/documents.sql导入数据库,并配置好以下的MySQL用户密码数据库#源定义#sql_attr_uint#sql_attr_bool    #sql_attr_bigint     #sql_attr_timestamp   时间行#sql_attr_str2ordinal  字符串行#sql_attr_float   浮点型#sql_attr_multi  source mysql{    type                     = mysql    sql_host                 = 192.168.8.229    sql_user                 = feiyang    sql_pass                 = 123456    sql_db                   = feiyang_prd    sql_port                 = 3306    sql_query_pre            = SET NAMES utf8    sql_query                = SELECT SQL_NO_CACHE `product`.`ID` * CAST(1 AS SIGNED) + 0 AS `ID`, `product`.`MinPrice` AS `MinPrice`, `product`.`ProductTypeid` AS `product_type_id`, UNIX_TIMESTAMP(`product`.`ShowStartTime`) AS date_added , `product`.`WebTitle` AS `WebTitle`, `product`.`SubTitle` AS `SubTitle`, `product`.`AddressNames` AS `AddressNames`, `product_type`.`Title` AS `product_type_title` FROM `product` LEFT OUTER JOIN `product_type` ON `product_type`.`ID` = `product`.`ProductTypeid` where `product`.`ShowStatus` = 1 GROUP BY `product`.`ID` ORDER BY NULL         #sql_query第一列<span style="font-size: 1em; line-height: 1.5;">ID</span><span style="font-size: 1em; line-height: 1.5;">需为整数</span>         #WebTitle、SubTitle, ProductType表中title作为字符串/文本字段,被全文索引    sql_attr_uint            = sphinx_internal_id           #从SQL读取到的值必须为整数    sql_attr_uint            = class_crc    sql_attr_uint            = Sort    sql_attr_uint            = ShowStatus    sql_attr_float           = MinPrice    sql_attr_timestamp       = date_added #从SQL读取到的值必须为整数,作为时间属性    sql_attr_str2ordinal     = WebTitle_sort    sql_attr_str2ordinal     = SubTitle_sort    sql_attr_str2ordinal     = AddressNames_sort    sql_attr_str2ordinal     = StartCity_sort    sql_attr_str2ordinal     = ToTraffic_sort    sql_attr_str2ordinal     = BackTraffic_sort    sql_attr_str2ordinal     = Notes_sort        sql_query_info_pre       = SET NAMES utf8                                        #命令行查询时,设置正确的字符集    sql_query_info           = SELECT * FROM product WHERE `ID` = (($id - 0) / 1) #命令行查询时,从数据库读取原始数据信息}#index定义index mysql{    source            = mysql             #对应的source名称    path              = E:/projects/test_php/data/product #索引路径,请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    docinfo           = extern    mlock             = 0    morphology        = none    min_word_len      = 1    ngram_len         = 1   #1为搜索中文    html_strip        = 0    #charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾    charset_dictpath  = D:/coreseek/etc/                             #Windows环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...    charset_type      = utf-8    charset_table     = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F    ngram_chars      = U+3000..U+2FA1F}#全局index定义indexer{    mem_limit            = 128M}#searchd服务定义searchd{    listen              = 9312    read_timeout        = 5    max_children        = 30    max_matches         = 1000   # seamless_rotate    = 0  #windows下启动必须注释掉这行    preopen_indexes     = 0    unlink_old          = 1    pid_file            = ../log/searchd_mysql.pid  #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    log                 = ../log/searchd_mysql.log        #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    query_log           = ../log/query_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...}

?

4.生成索引,启动搜索

cmd下面运行下面代码:#-> indexer --config  config/sphinx.conf --all  #生成索引#-> searchd --config config/sphinx.conf  启动搜索

?

?

5.php里的配置

$cl = new SphinxClient ();$cl->SetServer ( '127.0.0.1', 9312);$cl->SetMatchMode ( SPH_MATCH_ANY );  //SPH_MATCH_ALL, 匹配所有查询词(默认模式); SPH_MATCH_ANY, 匹配查询词中的任意一个; SPH_MATCH_EXTENDED2, 支持特殊运算符查询  $cl->SetConnectTimeout ( 3 );$cl->SetArrayResult ( true );$weights = array('WebTitle'=>10, 'SubTitle'=>9, 'AddressNames'=>8, 'product_type_title'=>7);$cl->SetFieldWeights($weights);$cl->SetMaxQueryTime(10);   //最大搜索时间$res = $cl->Query ( $_GET['keyword'], "*" );  //"*"全部索引, 在conf文件中,会配置多个索引文件// 从名称为index的sphinx索引查询“电影票”$sp->SetGroupBy('item_id',SPH_GROUP_ATTR,'s_order desc');$sp->SetFilter('city_id','1');$sp->SetFilter('cat_id',array(1));$sp->SetLimit(0,10,1000);$sp->AddQuery('电影票','index');$sp->ResetFilters();//重置筛选条件$sp->SetGroupBy('item_id', SPH_GROUPBY_ATTR, 's_order desc');$sp->setFilter('city_id', '2');$sp->setFilter('cat_id', array(2));$sp->setLimits(0, 20, 1000);$sp->AddQuery('温泉', 'index');$sp->ResetFilters();// 重置筛选条件$sp->ResetGroupBy();//重置分组$results = $sp->RunQuries();

?

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
高流量网站的PHP性能调整高流量网站的PHP性能调整May 14, 2025 am 12:13 AM

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

PHP中的依赖注入:初学者的代码示例PHP中的依赖注入:初学者的代码示例May 14, 2025 am 12:08 AM

你应该关心DependencyInjection(DI),因为它能让你的代码更清晰、更易维护。1)DI通过解耦类,使其更模块化,2)提高了测试的便捷性和代码的灵活性,3)使用DI容器可以管理复杂的依赖关系,但要注意性能影响和循环依赖问题,4)最佳实践是依赖于抽象接口,实现松散耦合。

PHP性能:是否可以优化应用程序?PHP性能:是否可以优化应用程序?May 14, 2025 am 12:04 AM

是的,优化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)优化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,并避免使用

PHP性能优化:最终指南PHP性能优化:最终指南May 14, 2025 am 12:02 AM

theKeyStrategiestosiminificallyBoostphpapplicationPermenCeare:1)useOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)优化AtabaseInteractionswithPreparedStateTemtStatementStatementSandProperIndexing,3)配置

PHP依赖注入容器:快速启动PHP依赖注入容器:快速启动May 13, 2025 am 12:11 AM

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

PHP中的依赖注入与服务定位器PHP中的依赖注入与服务定位器May 13, 2025 am 12:10 AM

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

PHP性能优化策略。PHP性能优化策略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

PHP电子邮件验证:确保正确发送电子邮件PHP电子邮件验证:确保正确发送电子邮件May 13, 2025 am 12:06 AM

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器