http://blog.anbutu.com/php/php-ext-trie-filter
Ãô¸Ð´Ê¹ýÂËÊÇÎÒ³¯³ÌÐòÔ±±ØÐë¾ß±¸µÄÒ»ÖÖÌØÊâ¼¼ÄÜ£¬Ëæ×ÅÃô¸Ð´ÊÔ½À´Ô½¶à£¬ÊÇʱºòд¸öÀ©Õ¹À´¿ìËٵĽøÐÐÃô¸Ð´Ê¼ì²âÁË
ʹÓÃ˵Ã÷
1. °²×° libdatrie
tar zxf libdatrie-0.2.4.tar.gz
cd libdatrie-0.2.4
./configure ¨Cprefix=/usr/local
make
make install
2. °²×° trie_filter À©Õ¹
tar zxf trie_filter-1.0.0.tar.gz
cd trie_filter-1.0.0
phpize
./configure ¨Cwith-php-config=/path/to/php-config
make
make install
¼ÇµÃÐÞ¸ÄÄãµÄ php.ini Îļþ£¬ÆôÓà trie_filter À©Õ¹¡£extension=trie_filter.so
3. Éú³É´ÊµäÔ¤´¦Àí¹¤¾ß£¨dpp.c ÔÚ trie_filter-1.0.0 ÀïÃ棩
gcc -O dpp dpp.c -ldatrie
4. Éú³ÉÃô¸Ð´Ê´Êµä
Ê×ÏÈÄãÐèÒª°ÑÐèÒª¼ì²âµÄÃô¸Ð´ÊдÈëµ½Ò»¸öÎı¾ÎļþÖУ¬Ã¿ÐÐÒ»¸öÃô¸Ð´Ê£¬È»ºóʹÓÃÉÏÒ»²½Éú³ÉµÄ dpp ³ÌÐò´¦ÀíÕâ¸öÎı¾ÎļþÀ´Éú³É´Êµä
./dpp txt_file_path dict_file_path
5. ʹÓÃÀ©Õ¹
À©Õ¹½Ó¿ÚºÜ¼òµ¥£¬Ö»ÓÐÁ½¸öº¯Êý£º
1) trie_filter_load($path_to_dict)
ÓÃÀ´ÔØÈë´Êµä£¬³É¹¦·µ»ØÒ»¸ö Trie_Filter ×ÊÔ´¾ä±ú£¬Ê§°Ü·µ»Ø NULL
2) trie_filter_search($trie, $text)
ÓÃÀ´¼ì²âÒ»¶ÎÎı¾ÖÐÊÇ·ñº¬ÓдʵäÖж¨ÒåµÄÃô¸Ð´Ê£¬$trie ÊÇÉÏÒ»¸öº¯Êý·µ»ØµÄ Trie Filter ¾ä±ú£¬$text ÊÇÓû¼ì²âµÄÎı¾
Èç¹û¼ì²âµ½Ãô¸Ð´ÊÔò·µ»ØÒ»¸öÊý×飬Êý×éµÚÒ»¸öÔªËØÖ¸³ö¼ì²âµ½µÄÃô¸Ð´ÊÔÚ $text ÖеÄÆ«ÒÆÁ¿£¬µÚ¶þ¸öÔªËØÖ¸³ö¸ÃÃô¸Ð´ÊµÄ³¤¶È(bytes)
Èç¹ûûÓмì²âµ½Ãô¸Ð´Ê£¬Ôò·µ»ØÒ»¸ö¿ÕÊý×é
À©Õ¹µÄËÙ¶ÈÔõôÑù
Ò»¸ö×Ö£¬ºÜ¿ì£¡À©Õ¹µÄ¼ì²âËã·¨»ùÓÚ Double Array Trie Tree£¬²éÕÒµ¥Ò»¹Ø¼ü×ÖµÄʱ¼ä¸´ÔÓ¶ÈΪ O(1)£¬²éÕÒÕû¶ÎÎı¾µÄʱ¼ä¸´ÔÓ¶ÈΪ O(n)£¬n ΪÎı¾µÄ³¤¶È£¬¶øÇÒ¼ì²âµÄËٶȲ»»áÒòΪÃô¸Ð´ÊµÄÔö¼Ó¶ø½µµÍ¡£
×¢ÒâÊÂÏî
1.
À©Õ¹°Ñ´ÊµäºÍÒª¼ì²âµÄÎı¾¶¼µ±×öƽ·²µÄ×Ö½ÚÁ÷´¦Àí£¬Òò´Ë¿ÉÒÔÎÞÊÓ×Ö·û¼¯µÄÎÊÌâ¡£µ«ÐèҪעÒâµÄÊǴʵäµÄ±àÂëÐèÒªºÍ¼ì²âÎı¾µÄ±àÂëÒ»Ö£¬ÀýÈç´ÊµäΪ
UTF-8 ±àÂë¶øÄãÐèÒª¼ì²âµÄÎı¾Îª GBK ±àÂ룬Õâ¾ÍÒªÇóÄãÔÚµ÷Óà trie_filter_search() º¯Êý֮ǰͨ¹ý iconv »òÕß
mb_xxx º¯Êýת»»Ò»Ï±àÂë
2. Ä¿Ç°Ö»ÔÚ linux + php-5.2 »·¾³Ï²âÊÔͨ¹ý£¬²»Ö§³Ö windows£¬Ò²Ã»ÓÐÖ§³ÖµÄ¼Æ»®
»¶Ó´ó¼Ò²âÊÔʹÓã¬Ìá³ö½¨Òé
ÍƼöÐÅÏ¢
- linuxÃüÁîѧϰ±Ê¼Ç£¨11£©£ºnlÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨5£©£ºrmÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨4£©£ºmkdirÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨1£©£ºlsÃüÁî
- ½«CentosµÄyumÔ´¸ü»»Îª¹úÄڵİ¢ÀïÔÆÔ´
- ʹÓÃNginxÌí¼Óheader·ÀÖ¹ÍøÒ³±»frame
- linuxϼÓËÙscp´«Êä´óÎļþµÄËÙ¶È
- linuxϵͳÉ϶ÔnginxÈÕÖ¾·Ö¸î´¦Àí
- lnmp/nginxϵͳÕæÕýÓÐЧµÄͼƬ·ÀµÁÁ´ÍêÕûÉèÖÃÏê½â
- Í»ÆÆÊ®Íò²¢·¢µÄNginxµÄÅäÖü°ÓÅ»¯
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- ²éÕÒ²¢É¾³ý.svnĿ¼Îļþ
- redis ÆßÖÖÊý¾ÝÀàÐ͵ÄʹÓó¡¾°
- linux ÏÂÎļþ¸´ÖƵ½windowsÏÂÂÒÂëµÄ½â¾ö°ì·¨
- nginx³öÏÖ502 upstream sent too big he....
- linuxÏÂsudoÅäÖÃÏê½â
- linuxÃüÁîѧϰ±Ê¼Ç£¨15£©£ºtailÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨14£©£ºheadÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨13£©£ºlessÃüÁî
- linuxÃüÁîѧϰ±Ê¼Ç£¨12£©£ºmoreÃüÁî
- ¼ÓÃÜËã·¨±È½Ï3DES AES RSA ECC MD5 SHA1µÈ
ÆÀÂÛ