mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-14 00:16:13 +01:00
♻️ 重构 文件历史 查询 https://github.com/siyuan-note/siyuan/issues/6504
This commit is contained in:
parent
b0fe8b49ba
commit
24edac891e
4 changed files with 108 additions and 0 deletions
|
|
@ -360,6 +360,38 @@ func FullTextSearchHistory(query, box, op string, typ, page int) (ret []string,
|
|||
return
|
||||
}
|
||||
|
||||
func FullTextSearchHistoryItems(created, query, box, op string, typ int) (ret []*HistoryItem) {
|
||||
query = gulu.Str.RemoveInvisible(query)
|
||||
if "" != query {
|
||||
query = stringQuery(query)
|
||||
}
|
||||
|
||||
table := "histories_fts_case_insensitive"
|
||||
stmt := "SELECT * 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 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
|
||||
}
|
||||
|
||||
func GetNotebookHistory() (ret []*History, err error) {
|
||||
ret = []*History{}
|
||||
|
||||
|
|
@ -656,3 +688,22 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
func fromSQLHistories(sqlHistories []*sql.History) (ret []*HistoryItem) {
|
||||
if 1 > len(sqlHistories) {
|
||||
ret = []*HistoryItem{}
|
||||
return
|
||||
}
|
||||
|
||||
for _, sqlHistory := range sqlHistories {
|
||||
item := &HistoryItem{
|
||||
Title: sqlHistory.Title,
|
||||
Path: filepath.Join(util.HistoryDir, sqlHistory.Path),
|
||||
}
|
||||
if HistoryTypeAsset == sqlHistory.Type {
|
||||
item.Path = filepath.ToSlash(strings.TrimPrefix(item.Path, util.WorkspaceDir))
|
||||
}
|
||||
ret = append(ret, item)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue