diff --git a/kernel/model/history.go b/kernel/model/history.go index 5de549ff0..c845b1696 100644 --- a/kernel/model/history.go +++ b/kernel/model/history.go @@ -322,26 +322,7 @@ func FullTextSearchHistory(query, box, op string, typ, page int) (ret []string, table := "histories_fts_case_insensitive" stmt := "SELECT DISTINCT created FROM " + table + " WHERE " - if "" != query { - stmt += table + " MATCH '{title content}:(" + query + ")'" - } else { - stmt += "1=1" - } - - if HistoryTypeDocName == typ { - stmt = strings.ReplaceAll(stmt, "{title content}", "{title}") - } - - if HistoryTypeDocName == typ || HistoryTypeDoc == typ { - if "all" != op { - stmt += " AND op = '" + op + "'" - } - stmt += " AND path LIKE '%/" + box + "/%' AND path LIKE '%.sy'" - } else if HistoryTypeDocID == typ { - stmt += " AND id = '" + query + "'" - } else if HistoryTypeAsset == typ { - stmt += " AND path LIKE '%/assets/%'" - } + stmt += buildSearchHistoryQueryFilter(query, op, box, table, typ) countStmt := strings.ReplaceAll(stmt, "SELECT DISTINCT created", "SELECT COUNT(DISTINCT created) AS total") stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(pageSize) + " OFFSET " + strconv.Itoa(offset) result, err := sql.QueryHistory(stmt) @@ -374,29 +355,41 @@ func FullTextSearchHistoryItems(created, query, box, op string, typ int) (ret [] table := "histories_fts_case_insensitive" stmt := "SELECT * FROM " + table + " WHERE " + stmt += buildSearchHistoryQueryFilter(query, op, box, table, typ) + stmt += " AND created = '" + created + "' ORDER BY created DESC LIMIT " + fmt.Sprintf("%d", Conf.Search.Limit) + sqlHistories := sql.SelectHistoriesRawStmt(stmt) + ret = fromSQLHistories(sqlHistories) + return +} + +func buildSearchHistoryQueryFilter(query, op, box, table string, typ int) (stmt string) { if "" != query { - stmt += table + " MATCH '{title content}:(" + query + ")'" + switch typ { + case HistoryTypeDocName: + stmt += table + " MATCH '{title}:(" + query + ")'" + case HistoryTypeDoc: + stmt += table + " MATCH '{title content}:(" + query + ")'" + case HistoryTypeDocID: + stmt += table + " id = '" + query + "'" + case HistoryTypeAsset: + stmt += table + " MATCH '{title content}:(" + query + ")'" + } } else { stmt += "1=1" } - if HistoryTypeDocName == typ { - stmt = strings.ReplaceAll(stmt, "{title content}", "{title}") - } - - if HistoryTypeDocName == typ || HistoryTypeDoc == typ { + if HistoryTypeDocName == typ || HistoryTypeDoc == typ || HistoryTypeDocID == typ { if "all" != op { stmt += " AND op = '" + op + "'" } - stmt += " AND path LIKE '%/" + box + "/%' AND path LIKE '%.sy'" - } else if HistoryTypeDocID == typ { - stmt += " AND id = '" + query + "'" + if HistoryTypeDocName == typ || HistoryTypeDoc == typ { + stmt += " AND path LIKE '%/" + box + "/%' AND path LIKE '%.sy'" + } else if HistoryTypeDocID == typ { + stmt += " AND id = '" + query + "'" + } } else if HistoryTypeAsset == typ { stmt += " AND path LIKE '%/assets/%'" } - stmt += " AND created = '" + created + "' ORDER BY created DESC LIMIT " + fmt.Sprintf("%d", Conf.Search.Limit) - sqlHistories := sql.SelectHistoriesRawStmt(stmt) - ret = fromSQLHistories(sqlHistories) return }