尊龙凯时人生就是搏

ÔõÑùÔÚThinkPHP6ÖÐʹÓÃSphinx¾ÙÐÐÈ«ÎÄËÑË÷£¿

ÔÚÏÖ´úµÄweb¿ª·¢ÖУ¬ËÑË÷ÒýÇæÒѾ­³ÉΪÁËÒ»¸ö²»¿É»òȱµÄ²¿·Ö¡£ÓëÆäËüËÑË÷ÒýÇæÏà±È£¬sphinx ÊÇÒ»ÖÖרÃÅÓÃÀ´´¦ÀíÈ«ÎÄËÑË÷µÄЧÀÍ¡£ ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏêϸÏÈÈÝÔõÑùÔÚ thinkphp6 Öм¯³É sphinx ¾ÙÐÐÈ«ÎÄËÑË÷¡£

×°ÖÃ Sphinx

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚЧÀÍÆ÷ÉÏ×°Öà Sphinx¡£ÒÔÏÂÊÇÔÚ Ubuntu ϵͳÉÏ×°Öà Sphinx µÄʾÀýÏÂÁ

$ sudo apt-get update
$ sudo apt-get install sphinxsearch

µÇ¼ºó¸´ÖÆ

×°ÖÃÍê³Éºó£¬ÎÒÃÇÐèÒªÔÚ Sphinx ÉèÖÃÎļþÖÐÖ¸¶¨ÎÒÃÇÏ£ÍûËÑË÷µÄÊý¾ÝÔ´¡£ÔÚ Ubuntu ÖУ¬Sphinx ÉèÖÃÎļþµÄλÖÃͨ³£ÔÚ/etc/sphinxsearch/sphinx.conf¡£ Õâ¸öÎļþÖаüÀ¨ÁËÊý¾ÝÔ´ÐÅÏ¢ºÍÆäËüÓÐ¹Ø Sphinx µÄÉèÖÃÑ¡Ïî¡£ÎÒÃÇÐèҪƾ֤×Ô¼ºµÄÐèÒª¾ÙÐе÷½â¡£

ÉèÖÃ Sphinx Model

ÔÚ ThinkPHP6 ÖÐʹÓà Sphinx ¾ÙÐÐÈ«ÎÄËÑË÷ÓÐÁ½ÖÖ·½·¨£ºÊ¹Óà Sphinx Client ¾ÙÐÐËÑË÷£¬»òÊǼÌÐø SphinxqlTrait Àà½ç˵ Sphinx Model¡£ÕâÀïÎÒÃÇÏÈÈݵڶþÖÖÒªÁì¡£

Ê×ÏÈ£¬ÎÒÃÇÐèÒª½ç˵һ¸ö SphinxModel ¡£ÔÚ Model ÀàÖмÌÐø SphinxqlTrait£¬²¢½ç˵ $_table¡¢$_sphinx_index ºÍ $_sphinx_server ÊôÐÔ¡£ÕâÀ$_table Ö¸¶¨Á˱íÃû£¬$_sphinx_index Ö¸¶¨ÁË Sphinx Êý¾ÝÔ´ÖеÄË÷ÒýÃû³Æ£¬¶ø $_sphinx_server ÔòÊÇ Sphinx ЧÀÍÆ÷µÄÏà¹ØÐÅÏ¢¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

<?php
namespace appmodel;

use thinkmodelconcernSoftDelete;
use thinkmodelconcernTimestamp;
use thinkmodelSphinxqlTrait;

class Article extends     hinkModel
{
    use SphinxqlTrait;

    protected $table = 'article';
    protected $_sphinx_index = 'article';
    protected $_sphinx_server = [
        'host' => '127.0.0.1',
        'port' => 9312,
    ];
}

µÇ¼ºó¸´ÖÆ

ʵÏÖÈ«ÎÄËÑË÷

ÓÐÁË Sphinx Model ºó£¬ÎÒÃÇ¿ÉÒÔºÜÀû±ãµØ¾ÙÐÐÈ«ÎÄËÑË÷¡£ÏÂÃæÊÇÒ»¸öʹÓà Sphinx Model ¾ÙÐÐÒªº¦×ÖÅÌÎʵÄÀý×Ó£º

use appmodelArticle;

class Search
{
    public static function search($keyword)
    {
        $articles = Article::search($keyword)->select();

        return $articles;
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÊ×ÏÈÒýÈë appmodelArticle Ä£×Ó£¬È»ºóÔÚ search º¯ÊýÖÐʹÓà Article::search($keyword) ÒªÁì¾ÙÐÐÅÌÎÊ£¬Õâ¸öÒªÁìµÄ²ÎÊýÊÇËÑË÷µÄÒªº¦×Ö¡£×îºó£¬ÎÒÃÇ·µ»ØÅÌÎÊЧ¹û¡£

½áÓï

ÔÚÕâƪÎÄÕÂÖУ¬ÎÒÃÇÏÈÈÝÁËÔõÑùÔÚ ThinkPHP6 ÖÐʹÓà Sphinx ¾ÙÐÐÈ«ÎÄËÑË÷¡£ÎÒÃÇÊ×ÏÈ×°ÖÃÁË Sphinx ЧÀÍ£¬È»ºó½ç˵ÁËÒ»¸ö Sphinx Model£¬×îºóÎÒÃÇչʾÁËÔõÑùʹÓà Sphinx Model ¾ÙÐÐÈ«ÎÄËÑË÷¡£Õâ¸öÒªÁìÇáÓ¯Ò×ÐУ¬²¢ÇÒ¿ÉÒÔ×ÊÖúÎÒÃÇ´¦Àí´ó¹æÄ£µÄÈ«ÎÄËÑË÷ÐèÇó¡£Ï£Íû±¾ÎÄÄܸøÄã´øÀ´×ÊÖú¡£

ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖÐʹÓÃSphinx¾ÙÐÐÈ«ÎÄËÑË÷£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ