Skip to content

Commit

Permalink
Merge pull request #47 from terwer/dev
Browse files Browse the repository at this point in the history
feat:#42 修复查询列表重复问题
  • Loading branch information
terwer authored Sep 1, 2022
2 parents a7fc1fd + 97ea279 commit 7437eb1
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/siyuan/siYuanApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,25 +334,29 @@ async function getHPathByID(blockId: string) {
* 分页获取根文档
* @param page 页码
* @param pagesize 数目
*
* select root_id,content from blocks WHERE id IN (
* SELECT DISTINCT parent_id
* FROM blocks
* WHERE 1 = 1
* AND ((content LIKE '%token%') OR (tag LIKE '%token%'))
*
* select DISTINCT b2.root_id,b2.parent_id,b2.content from blocks b2
* WHERE 1==1
* AND b2.id IN (
* SELECT DISTINCT b1.id
* FROM blocks b1
* WHERE 1 = 1
* AND b1.parent_id=''
* AND ((b1.content LIKE '%jdbc%') OR (b1.tag LIKE '%jdbc%'))
* ORDER BY b1.created DESC LIMIT 0, 10
* )
* AND parent_id = ''
* ORDER BY created DESC LIMIT 0, 10
*/
async function getRootBlocks(page: number, pagesize: number, keyword: string) {
let stmt = `select root_id,content from blocks WHERE id IN (
SELECT DISTINCT parent_id
FROM blocks
WHERE 1 = 1
AND ((content LIKE '%${keyword}%') OR (tag LIKE '%${keyword}%'))
)
AND parent_id = ''
ORDER BY created DESC LIMIT ${page}, ${pagesize}`
let stmt = `select DISTINCT b2.root_id,b2.parent_id,b2.content from blocks b2
WHERE 1==1
AND b2.id IN (
SELECT DISTINCT b1.id
FROM blocks b1
WHERE 1 = 1
AND b1.parent_id=''
AND ((b1.content LIKE '%${keyword}%') OR (b1.tag LIKE '%${keyword}%'))
ORDER BY b1.created DESC LIMIT ${page}, ${pagesize}
)`
let data = await sql(stmt)
return data
}
Expand Down

1 comment on commit 7437eb1

@vercel
Copy link

@vercel vercel bot commented on 7437eb1 Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.