查找全文,不仅仅是查找题目。
下午好!有空简单写了一下,没有做优化,可能有更好的实现方法,希望能帮到您:
```dataviewjs
const pages = dv.pages()
const keywords = ["关键词1", "关键词2", "关键词3"]
const rows = []
for (const page of pages) {
const file = app.vault.getAbstractFileByPath(page.file.path)
const contents = await app.vault.read(file)
let check = true
for (const keyword of keywords) {
if (contents.includes(keyword) == false) {
check = false
}
}
if (check == true) {
rows.push([page.file.link])
}
}
dv.table(["Title"], rows)
```
文件多了的话速度就不行了吧。
是的,文件一多就卡了
感谢!确实可以实现。我想问一下,再此基础上能否实现排除具有特定几个关键词的功能。就是筛选出具有多个关键词的文件,再从中排除掉具有特定关键词的文件。
晚上好,可以的。因为我不是前端程序员,对 JS / TS 的函数式了解不多,没有用函数式的写法,可能有点长…… 见谅……
```dataviewjs
const inkeywords = ["要的关键词"]
const exkeywords = ["不要的关键词"]
const rows = []
for (const page of dv.pages()) {
const file = app.vault.getAbstractFileByPath(page.file.path)
const contents = await app.vault.read(file)
let check = true
for (const inkeyword of inkeywords) {
if (contents.includes(inkeyword) == false) {
check = false
break
}
}
if (check == true) {
for (const exkeyword of exkeywords) {
if (contents.includes(exkeyword) == true) {
check = false
break
}
}
if (check == true) {
rows.push([page.file.link])
}
}
}
dv.table(["Links"], rows)
```
1 个赞
完全满足我的需求了,谢谢