Home > Backend Development > PHP Tutorial > Use PHP and coreseek to implement accurate medical knowledge search function

Use PHP and coreseek to implement accurate medical knowledge search function

PHPz
Release: 2023-08-07 15:36:02
Original
748 people have browsed it

Use PHP and coreseek to implement accurate medical knowledge search function

Use PHP and coreseek to implement an accurate medical knowledge search function

Abstract: This article introduces how to use PHP and coreseek search engines to implement an accurate medical knowledge search function. By building the management interface and search interface, and configuring coreseek, developers can easily implement an efficient and flexible medical knowledge search system.

Keywords: PHP, coreseek, medical knowledge search, search engine

Introduction: With the rapid development of the Internet, people's demand for medical knowledge is getting higher and higher. In order to meet the needs of users, we hope to develop an efficient and flexible medical knowledge search system. Among the many search engines, coreseek is a very popular choice. This article will introduce how to use PHP and coreseek to implement an accurate medical knowledge search function.

Part One: Building the Management Interface

First, we need to build a management interface so that administrators can easily add, edit, and delete medical knowledge data. We can use PHP to develop a simple management interface, including the following functions:

  1. Add medical knowledge: Administrators can add the title, content and other information of medical knowledge on the management interface.
  2. Edit medical knowledge: Administrators can edit existing medical knowledge on the management interface.
  3. Delete medical knowledge: Administrators can delete existing medical knowledge on the management interface.

The following is a simple PHP code example to implement the above functions:

<?php
// 连接数据库
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "medical_knowledge";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("连接失败:" . $conn->connect_error);
}

// 添加医疗知识
if (isset($_POST['add'])) {
    $title = $_POST['title'];
    $content = $_POST['content'];
    
    $sql = "INSERT INTO knowledge (title, content) VALUES ('$title', '$content')";
    if ($conn->query($sql) === TRUE) {
        echo "添加成功!";
    } else {
        echo "添加失败:" . $conn->error;
    }
}

// 编辑医疗知识
if (isset($_POST['edit'])) {
    $id = $_POST['id'];
    $title = $_POST['title'];
    $content = $_POST['content'];
    
    $sql = "UPDATE knowledge SET title='$title', content='$content' WHERE id=$id";
    if ($conn->query($sql) === TRUE) {
        echo "编辑成功!";
    } else {
        echo "编辑失败:" . $conn->error;
    }
}

// 删除医疗知识
if (isset($_GET['delete'])) {
    $id = $_GET['delete'];
    
    $sql = "DELETE FROM knowledge WHERE id=$id";
    if ($conn->query($sql) === TRUE) {
        echo "删除成功!";
    } else {
        echo "删除失败:" . $conn->error;
    }
}

// 查询医疗知识
$sql = "SELECT * FROM knowledge";
$result = $conn->query($sql);
?>

<!-- 管理界面 HTML -->
<!DOCTYPE html>
<html>
<head>
    <title>医疗知识管理</title>
</head>
<body>
    <h1>医疗知识管理</h1>

    <!-- 添加医疗知识表单 -->
    <h2>添加医疗知识</h2>
    <form action="" method="POST">
        标题:<input type="text" name="title"><br>
        内容:<textarea name="content"></textarea><br>
        <input type="submit" name="add" value="添加">
    </form>

    <!-- 编辑医疗知识表单 -->
    <h2>编辑医疗知识</h2>
    <form action="" method="POST">
        <?php while($row = $result->fetch_assoc()): ?>
        ID:<input type="text" name="id" value="<?php echo $row['id']; ?>"><br>
        标题:<input type="text" name="title" value="<?php echo $row['title']; ?>"><br>
        内容:<textarea name="content"><?php echo $row['content']; ?></textarea><br>
        <input type="submit" name="edit" value="编辑">
        <a href="?delete=<?php echo $row['id']; ?>">删除</a><br>
        <?php endwhile; ?>
    </form>
</body>
</html>

<?php
// 关闭数据库连接
$conn->close();
?>
Copy after login

Part 2: Build the search interface

Set the medical settings in the administrator After obtaining the knowledge, we need to develop a search interface so that users can search for relevant medical knowledge by keywords. We can also use PHP to develop a simple search interface, including the following functions:

  1. Search medical knowledge: Users can enter keywords on the search interface and search by clicking the search button.
  2. Display search results: The search results will be displayed on the search interface in the form of a list, including matching titles and content.

The following is a simple PHP code example to implement the above functionality:

<?php
// 连接数据库
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "medical_knowledge";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("连接失败:" . $conn->connect_error);
}

// 搜索医疗知识
if (isset($_GET['search'])) {
    $keyword = $_GET['keyword'];
    
    // 调用coreseek搜索引擎
    $searchCmd = "/usr/local/coreseek/bin/search -i index -c /usr/local/coreseek/etc/csft.conf -q "$keyword" -n 0,20";
    exec($searchCmd, $output);
    
    // 显示搜索结果
    echo "<h2>搜索结果</h2>";
    foreach ($output as $result) {
        $resultArray = explode("    ", $result);
        $title = $resultArray[0];
        $content = $resultArray[1];
        
        echo "<h3>$title</h3>";
        echo "<p>$content</p>";
    }
}
?>

<!-- 搜索界面 HTML -->
<!DOCTYPE html>
<html>
<head>
    <title>医疗知识搜索</title>
</head>
<body>
    <h1>医疗知识搜索</h1>

    <!-- 搜索表单 -->
    <form action="" method="GET">
        <input type="text" name="keyword">
        <input type="submit" name="search" value="搜索">
    </form>
</body>
</html>

<?php
// 关闭数据库连接
$conn->close();
?>
Copy after login

Part 3: Configuring coreseek

In order to make coreseek and PHP work properly , we need to do some configuration first. First, we need to create the coreseek configuration file /usr/local/coreseek/etc/csft.conf and add the following content to the file:

source medical_knowledge
{
    type                    = mysql
    sql_host                = localhost
    sql_user                = username
    sql_pass                = password
    sql_db                  = medical_knowledge
    sql_port                = 3306

    sql_query               = SELECT id, title, content FROM knowledge
    sql_attr_uint           = id
    sql_attr_str2ordinal    = title
    sql_attr_str2ordinal    = content
}

index index
{
    source                  = medical_knowledge
    path                    = /usr/local/coreseek/var/data/medical_knowledge
    min_word_len            = 1
    min_prefix_len          = 1
    enable_star             = 1
}

searchd
{
    listen                  = 9312
    log                     = /usr/local/coreseek/var/log/searchd.log
    query_log               = /usr/local/coreseek/var/log/query.log
    read_timeout            = 5
    max_children            = 30
    pid_file                = /usr/local/coreseek/var/log/searchd.pid
    seamless_rotate         = 0
    preopen_indexes         = 0
    unlink_old              = 1
}
Copy after login

Then, we need to create An index to facilitate matching searches. Open the terminal and run the following command:

$ /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --all
Copy after login

Finally, we need to start the coreseek search service. Run the following command in the terminal:

$ /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft.conf
Copy after login

Conclusion: Through the above steps, we successfully implemented an accurate medical knowledge search function using PHP and coreseek. Administrators can add, edit and delete medical knowledge through the management interface, and users can search for relevant medical knowledge through the search interface. By configuring coreseek's indexing and search services, we implemented an efficient and flexible medical knowledge search system.

The above is the detailed content of Use PHP and coreseek to implement accurate medical knowledge search function. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template