mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-26 19:38:48 +01:00
🎨 Support for opening file history on the doc tree https://github.com/siyuan-note/siyuan/issues/8448
This commit is contained in:
parent
772c809e31
commit
7bcc188c0a
1 changed files with 25 additions and 32 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue