|
@@ -35,6 +35,7 @@ import (
|
|
"github.com/88250/lute/ast"
|
|
"github.com/88250/lute/ast"
|
|
"github.com/88250/lute/lex"
|
|
"github.com/88250/lute/lex"
|
|
"github.com/88250/lute/parse"
|
|
"github.com/88250/lute/parse"
|
|
|
|
+ "github.com/88250/vitess-sqlparser/sqlparser"
|
|
"github.com/jinzhu/copier"
|
|
"github.com/jinzhu/copier"
|
|
"github.com/siyuan-note/filelock"
|
|
"github.com/siyuan-note/filelock"
|
|
"github.com/siyuan-note/logging"
|
|
"github.com/siyuan-note/logging"
|
|
@@ -604,7 +605,7 @@ func buildTypeFilter(types map[string]bool) string {
|
|
func searchBySQL(stmt string, beforeLen, page int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
|
func searchBySQL(stmt string, beforeLen, page int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
|
stmt = gulu.Str.RemoveInvisible(stmt)
|
|
stmt = gulu.Str.RemoveInvisible(stmt)
|
|
stmt = strings.TrimSpace(stmt)
|
|
stmt = strings.TrimSpace(stmt)
|
|
- blocks := sql.SelectBlocksRawStmt(stmt, page, Conf.Search.Limit)
|
|
|
|
|
|
+ blocks := sql.SelectBlocksRawStmt(stmt, page, pageSize)
|
|
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
|
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
|
if 1 > len(ret) {
|
|
if 1 > len(ret) {
|
|
ret = []*Block{}
|
|
ret = []*Block{}
|
|
@@ -617,6 +618,7 @@ func searchBySQL(stmt string, beforeLen, page int) (ret []*Block, matchedBlockCo
|
|
} else {
|
|
} else {
|
|
stmt = strings.ReplaceAll(stmt, "select * ", "select COUNT(id) AS `matches`, COUNT(DISTINCT(root_id)) AS `docs` ")
|
|
stmt = strings.ReplaceAll(stmt, "select * ", "select COUNT(id) AS `matches`, COUNT(DISTINCT(root_id)) AS `docs` ")
|
|
}
|
|
}
|
|
|
|
+ stmt = removeLimitClause(stmt)
|
|
result, _ := sql.Query(stmt)
|
|
result, _ := sql.Query(stmt)
|
|
if 1 > len(ret) {
|
|
if 1 > len(ret) {
|
|
return
|
|
return
|
|
@@ -627,6 +629,23 @@ func searchBySQL(stmt string, beforeLen, page int) (ret []*Block, matchedBlockCo
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func removeLimitClause(stmt string) string {
|
|
|
|
+ parsedStmt, err := sqlparser.Parse(stmt)
|
|
|
|
+ if nil != err {
|
|
|
|
+ return stmt
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ switch parsedStmt.(type) {
|
|
|
|
+ case *sqlparser.Select:
|
|
|
|
+ slct := parsedStmt.(*sqlparser.Select)
|
|
|
|
+ if nil != slct.Limit {
|
|
|
|
+ slct.Limit = nil
|
|
|
|
+ }
|
|
|
|
+ stmt = sqlparser.String(slct)
|
|
|
|
+ }
|
|
|
|
+ return stmt
|
|
|
|
+}
|
|
|
|
+
|
|
func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []*Block) {
|
|
func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []*Block) {
|
|
keyword = gulu.Str.RemoveInvisible(keyword)
|
|
keyword = gulu.Str.RemoveInvisible(keyword)
|
|
|
|
|
|
@@ -748,7 +767,7 @@ func fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, orderBy strin
|
|
stmt += boxFilter + pathFilter
|
|
stmt += boxFilter + pathFilter
|
|
stmt += " " + orderBy
|
|
stmt += " " + orderBy
|
|
stmt += " LIMIT " + strconv.Itoa(pageSize) + " OFFSET " + strconv.Itoa((page-1)*pageSize)
|
|
stmt += " LIMIT " + strconv.Itoa(pageSize) + " OFFSET " + strconv.Itoa((page-1)*pageSize)
|
|
- blocks := sql.SelectBlocksRawStmt(stmt, page, Conf.Search.Limit)
|
|
|
|
|
|
+ blocks := sql.SelectBlocksRawStmt(stmt, page, pageSize)
|
|
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
|
ret = fromSQLBlocks(&blocks, "", beforeLen)
|
|
if 1 > len(ret) {
|
|
if 1 > len(ret) {
|
|
ret = []*Block{}
|
|
ret = []*Block{}
|