<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// 接続を作成します
$conn = new mysqli($servername, $username, $password, $dbname);
// 接続が成功しているかどうかを確認してください
if ($conn-> connect_error){
die( "接続失敗:"。$ conn-> connect_error);
}
エコー「接続された接続」。
?>上記のコードは、MySQLIクラスを使用してMySQL接続を確立することを示しています。使用するときは、対応するデータベース情報に置き換えてください。
ソースユーザー
{
type = mysql
sql_host = localhost
sql_user = your_username
sql_pass = your_password
sql_db = your_database
sql_port = 3306
sql_query = select id、username、email、age、gender from user_table
sql_attr_uint = age
SQL_ATTR_UINT =性別
}
構成は、実際のデータベースアカウントとテーブル構造に置き換える必要があります。
インデックスデータは、コマンドラインで次のコマンドを実行することで完了します。
Indenser -C/Path/to/user.conf -all
CoreSeekはデータベースデータを読み取り、構成に基づいてインデックスを作成します。
検索実装次の例では、PHPを使用してCoreeekのSphinx APIを呼び出してユーザー検索を実行する方法を示しています。
<?php
// 初期化Sphinx接続する
require('sphinxapi.php');
$cl = new SphinxClient;
$cl->SetServer( "LocalHost"、9312);
//検索キーワードを設定します$ keyword = "zhang san";
$ cl-> setMatchMode(sph_match_any);
$ cl-> query($ keyword);
//検索結果を得るして出力します$ res = $ cl-> getArrayResult();
print_r($ res);
?>コードは、Sphinx APIファイルを導入し、接続を確立し、キーワード検索を実行し、最後に結果を出力します。