|
@@ -730,7 +730,6 @@ function themeConfig($form)
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
function getPost($postId){
|
|
|
$db = Typecho_Db::get();
|
|
|
$post = $db->fetchRow($db->select()->from('table.contents')->where('cid = ?', $postId));
|
|
@@ -741,11 +740,92 @@ function getPost($postId){
|
|
|
else
|
|
|
{
|
|
|
return Typecho_Widget::widget('Widget_Abstract_Contents')->push($post);
|
|
|
-
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function logSearch($keyword, $category_id, $dataset_id) {
|
|
|
+ $db = Typecho_Db::get();
|
|
|
+ $request = Typecho_Request::getInstance();
|
|
|
|
|
|
+ $data = array(
|
|
|
+ 'keyword' => $keyword,
|
|
|
+ 'category_id' => $category_id ?: null,
|
|
|
+ 'dataset_id' => $dataset_id,
|
|
|
+ 'ip_address' => $request->getIp(),
|
|
|
+ 'user_agent' => $request->getServer('HTTP_USER_AGENT'),
|
|
|
+ 'referer' => $request->getServer('HTTP_REFERER')
|
|
|
+ );
|
|
|
+
|
|
|
+ try {
|
|
|
+ $db->query($db->insert('table.search_logs')->rows($data));
|
|
|
+ } catch (Exception $e) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+// 定义函数,接收 token, datasets, 和 keyword 作为参数
|
|
|
+function retrieveDatasetData($token, $datasets, $keyword)
|
|
|
+{
|
|
|
+ // 设置接口URL
|
|
|
+ $url = "http://8.217.82.148/v1/datasets/{$datasets}/retrieve";
|
|
|
+
|
|
|
+ // 请求体的内容 (JSON 数据)
|
|
|
+ $requestBody = [
|
|
|
+ 'query' => $keyword, // 用户传入的查询关键字
|
|
|
+ 'retrieval_model' => [
|
|
|
+ 'reranking_enable' => false,
|
|
|
+ 'reranking_mode' => null,
|
|
|
+ 'reranking_model' => [
|
|
|
+ 'reranking_provider_name' => '',
|
|
|
+ 'reranking_model_name' => ''
|
|
|
+ ],
|
|
|
+ 'weights' => null,
|
|
|
+ 'top_k' => 3,
|
|
|
+ 'score_threshold_enabled' => false,
|
|
|
+ 'score_threshold' => null
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 初始化CURL会话
|
|
|
+ $ch = curl_init();
|
|
|
+
|
|
|
+ // 设置CURL选项
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 设置返回的内容为字符串
|
|
|
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // 如果需要自动跟随重定向
|
|
|
+
|
|
|
+ // 设置请求头部,包含Authorization字段和Content-Type
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
+ 'Authorization: Bearer ' . $token,
|
|
|
+ 'Content-Type: application/json', // 设置Content-Type为JSON
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 设置POST请求方法并将请求体内容(JSON)作为POST数据发送
|
|
|
+ curl_setopt($ch, CURLOPT_POST, true);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestBody)); // 将请求体数据编码为JSON格式
|
|
|
+
|
|
|
+ // 执行请求并获取响应
|
|
|
+ $response = curl_exec($ch);
|
|
|
+
|
|
|
+ // 检查是否发生错误
|
|
|
+ if (curl_errno($ch)) {
|
|
|
+ echo 'cURL Error: ' . curl_error($ch);
|
|
|
+ return null; // 如果发生错误,返回 null
|
|
|
+ } else {
|
|
|
+ // 成功,处理返回的JSON数据
|
|
|
+ $data = json_decode($response, true);
|
|
|
+
|
|
|
+ // 关闭CURL会话
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+ // 返回响应数据
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
?>
|