似乎Evernote的搜索语法不允许使用多个笔记本,但我仍想获取“笔记本1”或“笔记本2”中所有包含“ somesearch”的笔记。

我可以在一个笔记本中进行一次搜索:

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.findNotesMetadata(nFilter, 0, 50, rSpec).then(function(notesMetadataList) {
    console.log("Found " + notesMetadataList.notes.length + " notes.");
    console.log();
    console.log("Here are their titles: ");

    var titles = [];
    for (var i =0;i<notesMetadataList.notes.length;i++) {
      titles[i]=notesMetadataList.notes[i].title;
      console.log(titles[i]);
    }
  }).catch(function(err){
      console.log('Error:',err);
  });


但是我不知道如何在“ notebook 2”上进行第二次搜索,并将其标题附加到变量titles ...顺便说一句,我在node.js编程上还很新...

问候,

最佳答案

免责声明:未经测试

简短的答案是,您需要遍历笔记本,然后对结果进行汇总,然后再进行报告。我编辑了您的代码,并留下了一些指针注释。

// always put your imports first
const Evernote = require('evernote');

// default to const
const token = 'xxxxXXX';

const client = new Evernote.Client({token: token, sandbox: false});
const noteStore = client.getNoteStore();

// async await makes things cleaner
async function showTitles (noteBooks) {
  const queries = [];
  const rSpec = { includeTitle: true };
  // the of form of the for loop avoids i++
  for (const noteBook of noteBooks) {
    const nFilter = new Evernote.NoteStore.NoteFilter({
      words: `somesearch notebook:"${noteBook}"`,
      ascending: false
    });
    queries.push(noteStore.findNotesMetadata(nFilter, 0, 50, rSpec))
  }
  // run in parallel
  const results = await Promise.all(queries);
  let found = 0;
  let titles = [];
  for (const result of results) {
    found += result.notes.length;
    titles = titles.concat(results.notes.map(n => n.title));
  }
  console.log(`Found ${found} notes.

Here are their titles:
${titles.join('\n')}`);
}

showTitles(['notebook 1', 'notebook 2']).catch(function(err){
  console.log('Error:',err);
});

关于javascript - evernote api搜索+ nodejs:在两个笔记本中获取搜索结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49615753/

10-08 22:47