尊龙凯时人生就是搏

ThinkPHP6ÖÐÔõÑù¾ÙÐзִÊËÑË÷²Ù×÷ £¿

Ëæ×Å»¥ÁªÍøÓ¦ÓõÄÒ»Ö±Éú³¤ £¬ËÑË÷ÒýÇæÒ²³ÉΪÁËÒ»Ñùƽ³£ÉúÑÄÖбز»¿ÉÉٵŤ¾ß £¬¶ø·Ö´ÊËÑË÷ÊÇËÑË÷ÒýÇæÖкÜÊÇÖ÷ÒªµÄÒ»ÖÖËÑË÷·½·¨¡£ÔÚʹÓÃthinkphp6¿ò¼Ü¿ª·¢ÏîĿʱ £¬ÎÒÃÇÒ²ÐèÒª¶Ô·Ö´ÊËÑË÷¾ÙÐÐÉîÈëÏàʶºÍÓ¦Óᣱ¾ÎĽ«ÏÈÈÝthinkphp6ÖÐÔõÑù¾ÙÐзִÊËÑË÷²Ù×÷¡£

Ò»¡¢·Ö´ÊËÑË÷¼ò½é

·Ö´ÊËÑË÷Êǽ«Óû§ÊäÈëµÄÒªº¦´Ê¾ÙÐÐÖ§½â £¬È»ºóÔÚÊý¾Ý¿âÖоÙÐÐÄ£ºýËÑË÷ £¬ÕÒµ½ÏàÇкϵļͼ¡£Ïà½ÏÓڹŰåµÄËÑË÷·½·¨ £¬·Ö´ÊËÑË÷¿ÉÒÔÔ½·¢¾«×¼µØÆ¥Åäµ½Óû§ËùÐèÒªµÄÄÚÈÝ £¬Ìá¸ßËÑË÷µÄ׼ȷÐÔºÍÓû§ÌåÑé¡£

¶þ¡¢·Ö´Ê²Ù×÷¹¤¾ß

ÔÚ¾ÙÐзִÊËÑË÷²Ù×÷Ç° £¬ÐèҪʹÓÃһЩ·Ö´Ê²Ù×÷¹¤¾ß £¬³£ÓõÄÓÐjieba·Ö´Ê¡¢sphinxÈ«ÎļìË÷¹¤¾ßµÈ¡£±¾ÎÄÒÔjieba·Ö´ÊΪÀý¾ÙÐÐ˵Ã÷¡£

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

ÏÂÔØjieba·Ö´Ê¿â

¿ÉÒÔÔÚjiebaµÄ¹Ù·½ÍøÕ¾ÉÏÏÂÔØÏà¹ØµÄ·Ö´Ê¿âÎļþ £¬Ò²¿ÉÒÔʹÓÃcomposerÖ±½ÓÔÚÏîÄ¿ÖÐÒýÈë¡£

ʹÓÃjieba·Ö´Ê

ÔÚʹÓÃjieba·Ö´ÊÇ° £¬ÐèÒªÏÈÒýÈëÏìÓ¦µÄÀà¿â£º

use     hinkFacadeConfig;
use     hinkacadeCache;
use xiaodiJiebaJieba;

Config::set('cache', ['type' => 'File']);
Jieba::init();

µÇ¼ºó¸´ÖÆ

¸Ã´úÂëƬ¶ÏʵÏÖÁ˶Ôjieba·Ö´Ê¹¤¾ßµÄ³õʼ»¯²Ù×÷ £¬²¢ÉèÖÃÁË»º´æÀàÐÍΪÎļþ»º´æ¡£È»ºó £¬ÎÒÃǾͿÉÒÔʹÓÃjieba·Ö´ÊÁË¡£

$seg_list = jiebaCutForSearch('·Ö´ÊËÑË÷¹¤¾ß');

µÇ¼ºó¸´ÖÆ

¸Ã´úÂëʵÏÖÁ˶ԡ°·Ö´ÊËÑË÷¹¤¾ß¡±Õâ¸ö×Ö·û´®¾ÙÐзִʲÙ×÷ £¬·µ»ØÒ»¸ö°üÀ¨·Ö´ÊЧ¹ûµÄÊý×é$seg_list¡£

Èý¡¢ThinkPHP6ÖзִÊËÑË÷ʵÏÖ

ÔÚʵÏÖ·Ö´ÊËÑË÷ʱ £¬ÎÒÃÇÐèÒª¶ÔThinkPHP6µÄQuery¹¤¾ß¾ÙÐвÙ×÷ £¬¿ÉÒÔʹÓÃÈçÏ´úÂëÀ©Õ¹ÅÌÎÊ£º

use     hinkdbQuery;

Query::macro('search', function ($keyword, $field) {
    $seg_list = jiebaCutForSearch($keyword);
    $where = [];
    foreach ($seg_list as $seg) {
        $where[] = [$field, 'like', '%' . $seg . '%'];
    }
    return $this->whereOr($where);
});

µÇ¼ºó¸´ÖÆ

¸Ã´úÂëʵÏÖÁËQuery¹¤¾ßµÄÀ©Õ¹²Ù×÷ £¬ÎüÊÕÁ½¸ö²ÎÊý£º$keywordΪҪº¦´Ê £¬$fieldΪÔÚÄÄЩ×Ö¶ÎÖоÙÐÐËÑË÷¡£Ê×ÏȽ«Òªº¦´Ê¾ÙÐзִÊ £¬È»ºó½«·Ö´ÊºóµÄЧ¹û×÷ΪÌõ¼þ¾ÙÐÐËÑË÷ £¬×îºó·µ»ØËÑË÷Ч¹û¡£

ÔÚÏÖʵʹÓÃÖÐ £¬¿ÉÒÔ¶ÔÄ£×Ó¾ÙÐÐÀ©Õ¹ £¬ÀýÈ磺

use     hinkModel;

class Article extends Model
{
    // ½ç˵ËÑË÷ÒªÁì
    public static function search($keyword)
    {
        return (new static())
            ->where('status', 1)
            ->search($keyword, 'title')
            ->order('create_time DESC');
    }
}

µÇ¼ºó¸´ÖÆ

ÕâÀïÎÒÃǶÔArticleÄ£×Ó¾ÙÐÐÀ©Õ¹ £¬½ç˵ÁËËÑË÷ÒªÁìsearch £¬ÎüÊÕÒ»¸ö²ÎÊý$keyword £¬Å²ÓÃQuery¹¤¾ßµÄsearchÒªÁì¾ÙÐÐËÑË÷¡£

ËÄ¡¢×ܽá

·Ö´ÊËÑË÷×÷ΪһÖÖºÜÊÇÖ÷ÒªµÄËÑË÷·½·¨ £¬±»ÆÕ±éÓ¦ÓÃÓÚÖÖÖÖ»¥ÁªÍøÓ¦ÓÃÖС£ÔÚʹÓÃThinkPHP6¿ª·¢ÏîĿʱ £¬ÎÒÃÇÒ²ÐèÒªÏàʶÔõÑùʹÓ÷ִÊËÑË÷ £¬¶ÔQuery¹¤¾ß¾ÙÐÐÀ©Õ¹ £¬Ìá¸ßËÑË÷µÄ׼ȷÐÔºÍÓû§ÌåÑé¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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