You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js调用Evernote API:跨两个笔记本搜索指定内容

解决Evernote多笔记本OR搜索的问题

我完全懂你的困扰——Evernote的原生搜索语法确实不支持直接用OR同时指定多个笔记本进行查询。不过别担心,咱们可以通过代码层面的逻辑来绕开这个限制:分别搜索两个目标笔记本的内容,再合并结果就行。

先看看你现有的单笔记本搜索代码(我帮你补全了未完成的部分):

var token = 'xxxxXXX';
const Evernote = require('evernote');
const nFilter = new Evernote.NoteStore.NoteFilter({ 
  words: 'somesearch notebook:"notebook 1"', 
  ascending: false 
});
const rSpec = {};
rSpec.includeTitle = true;
var client = new Evernote.Client({token: token, sandbox: false});
var noteStore = client.getNoteStore();

// 执行单笔记本搜索
noteStore.findNotes(nFilter, 0, 100, rSpec, (err, notes) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log('找到的笔记:', notes.notes);
});

要实现多笔记本的OR搜索,咱们可以拆分两次搜索,再合并结果。这里额外做了去重处理(通过笔记的guid),避免出现理论上可能存在的重复项。

修改后的完整代码示例:

var token = 'xxxxXXX';
const Evernote = require('evernote');
const client = new Evernote.Client({token: token, sandbox: false});
const noteStore = client.getNoteStore();
const searchKeyword = 'somesearch';
const targetNotebooks = ['notebook 1', 'notebook 2'];
const rSpec = { includeTitle: true };

// 封装通用的笔记本搜索函数,返回Promise便于异步处理
const searchNotebook = (notebookName) => {
  const nFilter = new Evernote.NoteStore.NoteFilter({ 
    words: `${searchKeyword} notebook:"${notebookName}"`, 
    ascending: false 
  });
  return new Promise((resolve, reject) => {
    noteStore.findNotes(nFilter, 0, 100, rSpec, (err, notes) => {
      if (err) return reject(err);
      resolve(notes.notes);
    });
  });
};

// 并行搜索两个笔记本,合并结果并去重
Promise.all(targetNotebooks.map(searchNotebook))
  .then(results => {
    // 把两次搜索的结果数组合并成一个
    const allNotes = results.flat();
    // 通过guid去重,确保结果无重复
    const uniqueNotes = Array.from(new Map(allNotes.map(note => [note.guid, note])).values());
    console.log('合并后的笔记:', uniqueNotes);
  })
  .catch(err => {
    console.error('搜索出错:', err);
  });

代码说明:

  • 把搜索逻辑封装成searchNotebook函数,用Promise处理异步操作,这样可以通过Promise.all并行搜索两个笔记本,效率更高。
  • 用flat()方法把两次搜索的结果数组合并成一个数组。
  • 借助Map和笔记唯一标识guid做去重,确保最终结果里没有重复笔记(如果能确定两个笔记本无重复内容,这一步可以跳过)。
  • 保留了你原有代码的核心参数,比如includeTitle和分页范围(示例中是0到100条,你可以根据需求调整数量)。

这样就能实现你想要的「在notebook 1或notebook 2中搜索包含somesearch的所有笔记」的需求啦。

内容的提问来源于stack exchange,提问作者kurokirasama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:37:05