Skip to content

Commit

Permalink
修复模糊查询和工作流bug
Browse files Browse the repository at this point in the history
  • Loading branch information
weichaoduo committed Feb 23, 2020
1 parent a5c5f26 commit caa4ebd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 37 deletions.
55 changes: 33 additions & 22 deletions app/classes/IssueFilterLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use main\app\model\issue\IssueStatusModel;
use main\app\model\issue\IssueFilterModel;
use main\app\model\issue\IssueFollowModel;
use main\app\model\issue\IssueTypeModel;
use main\app\model\project\ProjectModuleModel;
use main\app\model\project\ReportProjectIssueModel;
use main\app\model\project\ReportSprintIssueModel;
Expand Down Expand Up @@ -161,21 +162,17 @@ public function getList($page = 1, $pageSize = 50)
if (strpos($versionStr, 'MariaDB') !== false) {
$versionNum = 0;
}
if ($versionNum < 5.70) {
// 使用LOCATE模糊搜索
if (strlen($search) < 10) {
$sql .= " AND ( LOCATE(:summary,`summary`)>0 OR pkey=:pkey)";
$params['pkey'] = $search;
$params['summary'] = $search;
} else {
$sql .= " AND LOCATE(:summary,`summary`)>0 ";
$params['summary'] = $search;
}

// 使用LOCATE模糊搜索
if (strlen($search) < 10) {
$sql .= " AND ( LOCATE(:summary,`summary`)>0 OR pkey=:pkey)";
$params['pkey'] = $search;
$params['summary'] = $search;
} else {
// 使用全文索引
$sql .= " AND MATCH (`summary`) AGAINST (:summary IN NATURAL LANGUAGE MODE) ";
$sql .= " AND LOCATE(:summary,`summary`)>0 ";
$params['summary'] = $search;
}

}
}

Expand Down Expand Up @@ -268,6 +265,26 @@ public function getList($page = 1, $pageSize = 50)
$sql .= " AND status=:status";
$params['status'] = $statusId;
}

// 事项类型
$typeId = null;
if (isset($_GET[urlencode('类型')])) {
$model = new IssueTypeModel();
$row = $model->getByName(urldecode($_GET[urlencode('类型')]));
if (isset($row['id'])) {
$typeId = $row['id'];
}
unset($row);
}
if (isset($_GET['type_id'])) {
$typeId = (int)$_GET['type_id'];
}

if ($typeId !== null) {
$sql .= " AND issue_type=:issue_type";
$params['issue_type'] = $typeId;
}

// 我未解决的
if ($sysFilter == 'my_unsolved') {
$params['assignee'] = UserAuth::getInstance()->getId();
Expand Down Expand Up @@ -508,14 +525,8 @@ public function getAdvQueryList($page = 1, $pageSize = 50)
$params[$field] = '%'.$value.'%';
break;
case 'like %...%':
if ($versionNum < 5.70) {
$sql .= " LOCATE(:$field,$field)>0 ";
$params[$field] = $value;
} else {
// 使用全文索引
$sql .= " MATCH ($field) AGAINST (:$field IN NATURAL LANGUAGE MODE) ";
$params[$field] = $value;
}
$sql .= " LOCATE(:$field,$field)>0 ";
$params[$field] = $value;
break;
case 'is null':
case 'is not null':
Expand Down Expand Up @@ -564,8 +575,8 @@ public function getAdvQueryList($page = 1, $pageSize = 50)
try {
// 获取总数
$sqlCount = "SELECT count(*) as cc FROM {$table} " . $sql;
//echo $sqlCount;
//print_r($params);
// echo $sqlCount;
// print_r($params);
$count = $model->db->getOne($sqlCount, $params);
$fields = '*';
$sql = "SELECT {$fields} FROM {$table} " . $sql;
Expand Down
25 changes: 13 additions & 12 deletions app/classes/SearchLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public static function getProjectByKeyword($keyword = 0, $page = 1, $pageSize =
$model = new ProjectModel();
$table = $model->getTable();
$field = "*";
if (self::$mysqlVersion < 5.70) {
//if (self::$mysqlVersion < 5.70) {
// 使用LOCATE模糊搜索
$where = "WHERE locate(:keyword,name) > 0 OR locate(:keyword,`key`) > 0 ";
} else {
//} else {
// 使用全文索引
$where =" WHERE MATCH (`name`) AGAINST (:keyword IN NATURAL LANGUAGE MODE) ";
}
// $where =" WHERE MATCH (`name`) AGAINST (:keyword IN NATURAL LANGUAGE MODE) ";
//}

$params['keyword'] = $keyword;

Expand Down Expand Up @@ -145,13 +145,13 @@ public static function getIssueByKeywordWithNgram($keyword = 0, $page = 1, $page

$issueModel = new IssueModel();
$table = $issueModel->getTable();
if (self::$mysqlVersion < 5.70) {
//if (self::$mysqlVersion < 5.70) {
// 使用LOCATE模糊搜索
$where = "WHERE locate(:keyword,`summary`) > 0 ";
} else {
//} else {
// 使用全文索引
$where =" WHERE MATCH (`summary`) AGAINST (:keyword IN NATURAL LANGUAGE MODE) ";
}
// $where =" WHERE MATCH (`summary`) AGAINST (:keyword IN NATURAL LANGUAGE MODE) ";
//}

$params['keyword'] = $keyword;
$sql = "SELECT * FROM {$table} {$where} {$limitSql}";
Expand All @@ -171,17 +171,18 @@ public static function getIssueCountByKeywordWithNgram($keyword)
$model = new IssueModel();
$table = $model->getTable();

if (self::$mysqlVersion < 5.70) {
//if (self::$mysqlVersion < 5.70) {
// 使用LOCATE模糊搜索
$where = "WHERE locate(:keyword,`summary`) > 0 ";
} else {
//} else {
// 使用全文索引
$where =" WHERE MATCH (`summary`) AGAINST (:keyword IN NATURAL LANGUAGE MODE) ";
}
// $where =" WHERE MATCH (`summary`) AGAINST (:keyword IN NATURAL LANGUAGE MODE) ";
//}
$params['keyword'] = $keyword;

$params['keyword'] = $keyword;
$sqlCount = "SELECT count(*) as cc FROM {$table} " . $where;
//echo $sqlCount;
$count = $model->db->getOne($sqlCount, $params);
return (int)$count;
}
Expand Down
2 changes: 1 addition & 1 deletion app/view/twig/admin/workflow_edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<script type="text/javascript">
var $Workflow = null;
var workflow_data = {{workflow['data']}};
var workflow_data = {{workflow['data']|raw}};
$(function() {
$('#btn_add_states').on('click', function () {
Expand Down
2 changes: 1 addition & 1 deletion app/view/twig/admin/workflow_view.twig
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<script type="text/javascript">
var $Workflow = null;
var workflow_data = {{data}};
var workflow_data = {{data|raw}};
$(function() {
Expand Down
1 change: 0 additions & 1 deletion php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ max_execution_time = 30

[Redis]
extension = redis.so

0 comments on commit caa4ebd

Please sign in to comment.