跳轉到內容
View in the app

A better way to browse. Learn more.

PHP論壇人

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

安裝 Sphinx CJK 中文搜尋

精選回覆

發表於

-------------------------
 安裝套件、依賴包
-------------------------

安裝java
apt-get install default-jdk


java -version
顯示已安裝 openjdk version "17.0.11" 2024-04-16

 

瀏覽目前安裝的python3版本

python3 --version

得知已安裝 Python 3.11.2

 

 

安裝 python-devel

apt install aptitude

aptitude install python3-dev

 


瀏覽目前的glibc版本

ldd --version

得知已安裝 ldd (Debian GLIBC 2.36-9+deb12u7) 2.36

目前的glibc版本 2.36,應該不用更新

 


安裝gcc
apt-get install gcc

 

安裝Jpype1
pip3 install --break-system-packages Jpype1

 


安裝 libpq 15.6
apt-get install libpq5

apt-get install libpq-dev

 


pip安裝sphinx,也許需要相關的依賴包
pip3.11 install --break-system-packages sphinx

 

 

---------------------------------------
下載Sphinx二進制包 & make編譯
---------------------------------------

Sphinx官網下載
http://sphinxsearch.com/downloads

安裝 Sphinx 3.0.1
http://sphinxsearch.com/downloads/sphinx-3.0.1-7fec4f6-linux-amd64.tar.gz/thankyou.html


Sphinx版本太新,會有更多的錯誤


下載後,上傳到自己的伺服器,放在 /usr/local/ 目錄

cd /usr/local/

tar zxf sphinx-3.0.1-7fec4f6-linux-amd64.tar.gz


將sphinx-3.0.1目錄,重新命名為sphinx目錄
mv sphinx-3.0.1-7fec4f6-linux-amd64 sphinx

 

開始編譯

cd /usr/local/sphinx/api/libsphinxclient

./configure --enable-id64 --prefix=/usr/local/sphinx

make && make install

 

 

---------------------------------------
在 /usr/local/sphinx/ 建立目錄
---------------------------------------

建立目錄

mkdir /usr/local/sphinx/log

mkdir /usr/local/sphinx/data

 


---------------------------------------
 配置vBulletin論壇的config.php
---------------------------------------

vi /var/www/域名.com/core/includes/config.php

在論壇根目錄/core/includes/config.php 檔案的底部,加入以下的內容 
$config['Misc']['sphinx_host']    = '127.0.0.1';
$config['Misc']['sphinx_port']    = '9306';
$config['Misc']['sphinx_path']    = '/usr/local/sphinx'; //no trailing slash
$config['Misc']['sphinx_config']    = $config['Misc']['sphinx_path'] . '/etc/vbulletin-sphinx.php';


ESC儲存並離開
:wq

 

 

---------------------------------------
上傳 vbulletin-sphinx.php
---------------------------------------

要再修改 vbulletin-sphinx.php,因此這裡可以下載到 vbulletin-sphinx.php

vbulletin-sphinx.php


然後,vbulletin-sphinx.php 上傳到 /usr/local/sphinx/etc/ 目錄

 

 

---------------------------------------
上傳 sphinxsearchfiles 文件夾
---------------------------------------

使用SFTP將 sphinxsearchfiles 整個資料夾與其中的檔案,上傳到 /var/www/域名.com/

在vBulletin 6.0 論壇程式.zip 的 do_not_upload 資料夾中,可找到 sphinxsearchfiles 資料夾

 

 

sphinxsearchfiles整個資料夾上傳後,更改網站目錄與檔案的擁有人/群組

chown -R www-data:www-data /var/www/域名.com

cd /var/www/域名.com/

 

瀏覽 sphinxsearchfiles 目錄是否改為 www-data:www-data
ls -l

 

 

-----------------------------------------------------
將 vbulletin-sphinx.php 文件設置為可執行文件
-----------------------------------------------------

設置為可執行文件
chmod +x /usr/local/sphinx/etc/vbulletin-sphinx.php

 

 


---------------------------------------
修改 vbulletin-sphinx.php
---------------------------------------

修改 vbulletin-sphinx.php

vi /usr/local/sphinx/etc/vbulletin-sphinx.php

修改為手搓LNMPPHP路徑
#!/usr/bin/php -q


更改為你論壇的情況
$myforumroot = '/var/www/域名.com';

$charsetTablesFolder = '/var/www/域名.com/sphinxsearchfiles';

$charsetTablesPrefix = 'sphinxcharsets_cjk.txt';

我是用mariadb,如果你是安裝mysql,就要修改為mysql
type    = mariadb

listen    = {$config['Misc']['sphinx_port']}:mysql41 這個不用改


注意:只建議安裝 Sphinx 3.0.1,Sphinx其他的版本在下面執行會有其他錯誤

 

ESC保存並離開
:wq

 


----------------------------
啟動服務(daemon)
----------------------------

cd /usr/local/sphinx/

/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/vbulletin-sphinx.php


忽略有關 vbulletin disk 索引的警告,一旦運行索引器就會建立

 

如果Sphinx版本太新 (sphinx-3.7.1),會有更多的錯誤

因為vbulletin-sphinx.php基本還是舊版PHP修改來的

 


----------------------------
測試sphinx是否運行
----------------------------

ps ax | grep search[d]


如果正常運行,則顯示 /usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/vbulletin-sphinx.php 類似的消息

 

 


------------------------------------
論壇後台打開Sphinx中文搜尋
------------------------------------

論壇後台 -> 設置 -> 選項 -> 消息搜索選項 -> 

啟用搜索引擎 -> 是

搜索索引字的最小長度 -> 2

-> 保存

 

 

論壇後台 -> 設置 ->搜索類型

選擇搜索執行 -> Sphinx搜索

-> 進行

 

 

論壇後台 -> 維護 -> 清除系統緩存

論壇後台 -> 維護 -> 一般更新工具 -> 重建搜索索引 -> 你確定要清空搜索索引? -> 是


論壇後台 -> 維護 -> 一般更新工具 -> 重建搜索索引 -> 要索引的內容類型 -> 所有 -> 重建搜索索引

 

 

------------------------------------
開機時,將自動啟動Sphinx
------------------------------------

網上找到開機啟動Sphinx腳本


寫一個sphinx.sh

cd /usr/local/bin

vi sphinx.sh

 

將下面幾行複製貼上

#!/bin/sh

appName="Sphinx"

stop(){
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/vbulletin-sphinx.php --stop > /dev/null 2>&1
        ret=$?
        if [ $ret -eq 0 ]; then
            action $"Stoping $appName: " /bin/true
        else
            action $"Stoping $appName: " /bin/false
        fi
    return $ret
}  


start(){
/usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/vbulletin-sphinx.php > /dev/null 2>&1
        ret=$?
        if [ $ret -eq 0 ]; then
            action $"Starting $appName: " /bin/true
        else
            action $"Starting $appName: " /bin/false
        fi
    return $ret
}


case $1 in
    restart)
    stop
    start
    ;; 

    stop)
    stop
    ;;

    start)
    start
    ;; 
esac

exit 0


ESC儲存並離開
:wq

 


-----------------------------------------------------
sphinx.sh修改為可執行權限
-----------------------------------------------------

chmod +x /usr/local/bin/sphinx.sh

 

 

-----------------------------------------------------
修改rc.local,開機啟動Sphinx
-----------------------------------------------------

前面寫過 rc.local 教學,為了Debian Linux 改用 iptables 防火牆 (開機啟動firewall.sh)

 

修改rc.local
vi /etc/rc.local


將這一行複製貼上到最下面
/usr/local/bin/sphinx.sh start

 

 

ESC儲存並離開
:wq

 

 

重開機
reboot

 


測試sphinx是否運行
ps ax | grep search[d]

 


回到論壇

已經可搜尋2個字的中文字

 

本文章最後於,由Jack編輯

建立帳號或登入後發表意見

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.