Evernote\Client::findNotesWithSearch PHP Method

findNotesWithSearch() public method

Searches for notes
public findNotesWithSearch ( $noteSearch, Evernote\Model\Notebook $notebook = null, integer $scope, integer $sortOrder, integer $maxResults = 20 ) : array | boolean
$noteSearch
$notebook Evernote\Model\Notebook
$scope integer
$sortOrder integer
$maxResults integer
return array | boolean
    public function findNotesWithSearch($noteSearch, Notebook $notebook = null, $scope = 0, $sortOrder = 0, $maxResults = 20)
    {
        if (!$noteSearch instanceof Search) {
            $noteSearch = new Search($noteSearch);
        }
        // App notebook scope is internally just an "all" search, because we don't a priori know where the app
        // notebook is. There's some room for a fast path in this flow if we have a saved linked record to a
        // linked app notebook, but that case is likely rare enough to prevent complexifying this code for.
        if ($this->isFlagSet($scope, self::SEARCH_SCOPE_APP_NOTEBOOK)) {
            $scope = self::SEARCH_SCOPE_ALL;
        }
        // Validate the scope and sort arguments.
        if (null !== $notebook && $scope != self::SEARCH_SCOPE_NONE) {
            $scope = self::SEARCH_SCOPE_NONE;
        } elseif (null === $notebook && $scope == self::SEARCH_SCOPE_NONE) {
            $scope = self::SEARCH_SCOPE_DEFAULT;
        }
        $requiresLocalMerge = false;
        if ($scope != self::SEARCH_SCOPE_NONE) {
            // Check for multiple scopes. Because linked scope can subsume multiple linked notebooks, that *always* triggers
            // the multiple scopes. If not, then both personal and business must be set together.
            if ($this->isFlagSet($scope, self::SEARCH_SCOPE_PERSONAL) && $this->isFlagSet($scope, self::SEARCH_SCOPE_BUSINESS) || $this->isFlagSet($scope, self::SEARCH_SCOPE_PERSONAL_LINKED)) {
                // If we're asked for multiple scopes, relevance is not longer supportable (since we
                // don't know how to combine relevance on the client), so default to updated date,
                // which is probably the closest proxy to relevance.
                if ($this->isFlagSet($sortOrder, self::SORT_ORDER_RELEVANCE)) {
                    $sortOrder = self::SORT_ORDER_RECENTLY_UPDATED;
                }
                $requiresLocalMerge = true;
            }
        }
        $resultSpec = new NotesMetadataResultSpec();
        $resultSpec->includeNotebookGuid = true;
        $resultSpec->includeTitle = true;
        $resultSpec->includeCreated = true;
        $resultSpec->includeUpdated = true;
        $resultSpec->includeUpdateSequenceNum = true;
        $noteFilter = new NoteFilter();
        $noteFilter->words = $noteSearch->getSearchString();
        if ($this->isFlagSet($sortOrder, self::SORT_ORDER_TITLE)) {
            $noteFilter->order = NoteSortOrder::TITLE;
        } elseif ($this->isFlagSet($sortOrder, self::SORT_ORDER_RECENTLY_CREATED)) {
            $noteFilter->order = NoteSortOrder::CREATED;
        } elseif ($this->isFlagSet($sortOrder, self::SORT_ORDER_RECENTLY_UPDATED)) {
            $noteFilter->order = NoteSortOrder::UPDATED;
        } elseif ($this->isFlagSet($sortOrder, self::SORT_ORDER_RELEVANCE)) {
            $noteFilter->order = NoteSortOrder::RELEVANCE;
        }
        // "Normal" sort is ascending for titles, and descending for dates and relevance.
        $sortAscending = $this->isFlagSet($sortOrder, self::SORT_ORDER_TITLE);
        if ($this->isFlagSet($sortOrder, self::SORT_ORDER_REVERSE)) {
            $sortAscending = !$sortAscending;
        }
        $noteFilter->ascending = $sortAscending;
        if (null !== $notebook) {
            $noteFilter->notebookGuid = $notebook->guid;
        }
        // Set up context.
        $context = new \stdClass();
        $context->scopeNotebook = $notebook;
        $context->scope = $scope;
        $context->sortOrder = $sortOrder;
        $context->noteFilter = $noteFilter;
        $context->resultSpec = $resultSpec;
        $context->maxResults = $maxResults;
        $context->findMetadataResults = array();
        $context->requiresLocalMerge = $requiresLocalMerge;
        $context->sortAscending = $sortAscending;
        // If we have a scope notebook, we already know what notebook the results will appear in.
        // If we don't have a scope notebook, then we need to query for all the notebooks to determine
        // where to search.
        if (null === $context->scopeNotebook) {
            return $this->findNotes_listNotebooksWithContext($context);
        }
        // Go directly to the next step.
        return $this->findNotes_findInPersonalScopeWithContext($context);
    }