<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connection successful";
?>
This code demonstrates establishing a MySQL connection using the mysqli class. Replace with your actual database info when used.
source user
{
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 = gender
}
Replace placeholders with your actual database credentials and table structure.
Index Data
Run the following command in the terminal to build the index:
indexer -c /path/to/user.conf --all
Coreseek will read data from the database according to the config and build the index.
Search Implementation
The example below shows how to perform user data search with PHP calling Coreseek’s Sphinx API:
<?php
// Initialize Sphinx connection
require('sphinxapi.php');
$cl = new SphinxClient;
$cl->SetServer("localhost", 9312);
// Set search keyword
$keyword = "Zhang San";
$cl->SetMatchMode(SPH_MATCH_ANY);
$cl->Query($keyword);
// Get and print search results
$res = $cl->GetArrayResult();
print_r($res);
?>
This code includes the Sphinx API file, connects to the server, executes a keyword search, and outputs the results.