Searching notes and note metadata
Search Basics
Performing a basic search of a user’s Evernote account involves three steps:
- An instance of
NoteFilter - A call to
NoteStore.findNotesMetadata - A subsequent call to
NoteStore.getNotefor any notes that match the search.
NoteFilter offers several members that can be populated depending on the type of results you’re looking for:
words— send a text-based search query (e.g.,“notebook:foo tag:bar”).notebooksGuid— restrict the search results to a single notebook identified using it’sNotebook.guidvalue.tagGuids— limit your search results to only those notes that are assigned these tags (represented as a collection ofTag.guidstrings).inactive— marking this member astruewill return only inactive notes (notes in the Trash, in other words). If left asfalse— the default value — only active notes will be returned.
filter = NoteStore.NoteFilter()
filter.words = "created:month-3"
filter.notebookGuid = "SomeNotebookGuidHere"
filter.tagGuids = ["tagGuid1","tagGuid2"]NoteStore.findNotesMetadata takes five parameters, in this order:
- A valid auth token (a developer token will also work here)
- An instance of
NoteFilter - The offset, or index of the first result within all possible results. This is used for retrieving a large number of results using successive calls to
findNotes. - The number of notes to be retrieved in this request. If there are fewer matching notes than requested, all matching notes will be returned.
- An instance of
NotesMetadataResultSpec, which allows the user to define which information should be returned for each matching note. Essentially, this object's members are all boolean values (see the linked page for more details).
If we wanted to retrieve the titles of the 100 newest notes in an account, our code might look like this:
filter = NoteStore.NoteFilter()
filter.ascending = False
spec = NoteStore.NotesMetadataResultSpec()
spec.includeTitle = True
ourNoteList = noteStore.findNotesMetadata(authToken, filter, 0, 100, spec)As you can see, we create an instance of NoteFilter and set the ascending member to False (so the results are returned in descending order), set our offset to 0 and our limit to 100. If this query results in less than 100 notes, all matching notes will be returned. By setting includeTitle to True in our instance of NotesMetadataResultSpec (and leaving the remaining values as False), we ensure that unnecessary data isn't returned.
findNotesMetadata returns a type we haven’t yet seen: NotesMetadataList. Feel free to peruse the documentation for this type if you want to learn about everything it contains. In this example, we want to see which notes are returned — those can be find by querying NotesMetadataList.notes:
filter = NoteStore.NoteFilter()
filter.ascending = False
spec = NoteStore.NotesMetadataResultSpec()
spec.includeTitle = True
ourNoteList = noteStore.findNotesMetadata(authToken, filter, 0, 100, spec)
for note in ourNoteList.notes:
print "%s :: %s" % (note.guid, note.title)When run, that code will echo the GUID and title of each matching note to the console.
Downloading entire notes
After using NoteStore.findNotesMetadata to identify which note or notes you'd like to download in their entirety, you can call NoteStore.getNote, which returns an instance of Types.Note, for each note to download the note body, attached files (Resources), and recognition information.
filter = NoteStore.NoteFilter()
filter.ascending = False
spec = NoteStore.NotesMetadataResultSpec()
spec.includeTitle = True
ourNoteList = noteStore.findNotesMetadata(authToken, filter, 0, 100, spec)
wholeNotes = []
for note in ourNoteList.notes:
wholeNote = noteStore.getNote(authToken, note.guid, True)
print "Content length: %d" % wholeNote.contentLength
wholeNotes.append(wholeNote)