Ejemplo n.º 1
0
        private Note ReadFromStorage()
        {
            var result = NoteStorage.GetExisting(NoteId);

            Check.DoEnsureLambda(result != null, () => $"Note {NoteId} does not exist");

            return(result);
        }
Ejemplo n.º 2
0
        public void ExecuteSearch()
        {
            if (PageNumber < 1)
            {
                PageNumber = 1;
            }
            else if (PageNumber > MaxPageCount)
            {
                PageNumber = MaxPageCount;
            }

            var maxResults = MaxPageCount * DefaultResultsPerPage;

            var headers = NoteStorage.SearchInPeriod(
                // ReSharper disable once RedundantArgumentDefaultValue
                PeriodStart, PeriodEnd, Query, maxResults + 1, SearchableDocumentTime.LastUpdate);

            if (_deletedNote != null)
            {
                headers.Remove(_deletedNote);
            }
            else if (headers.Any() && headers.Count > maxResults)
            {
                headers.RemoveAt(headers.Count - 1);
            }

            TotalPageCount = (int)Math.Ceiling((double)headers.Count / DefaultResultsPerPage);

            var headersPage = headers
                              .Skip((PageNumber - 1) * DefaultResultsPerPage)
                              .Take(DefaultResultsPerPage)
                              .ToList();

            SearchResultPage = headersPage
                               .Select(h => NoteStorage.GetExisting(h.Id))
                               .Where(x => x != null)
                               .ToList();

            if (headersPage.Count > SearchResultPage.Count)
            {
                Log.Warn("Fulltext index out of sync: rebuild it");
            }
        }
Ejemplo n.º 3
0
        public void LoadLatest()
        {
            var resultCount = MaxNumberOfNotesInRecentList;

            if (_changedNote != null && _changeIsDeletion)
            {
                ++resultCount;
            }

            // ReSharper disable once RedundantArgumentDefaultValue
            var lastHeaders = NoteStorage.GetTopInPeriod(null, DateTime.Now, resultCount, SearchableDocumentTime.LastUpdate);

            LastUpdatedNotes = lastHeaders.Select(h => NoteStorage.GetExisting(h.Id)).Where(x => x != null).ToList();

            if (lastHeaders.Count > LastUpdatedNotes.Count)
            {
                Log.WarnFormat("Fulltext index out of sync: rebuild it");
            }

            // FT index is updated asynchronously, so when we've just created new note it may not be returned
            if (_changedNote != null)
            {
                if (!_changeIsDeletion && !LastUpdatedNotes.Contains(_changedNote))
                {
                    LastUpdatedNotes.Insert(0, _changedNote);
                }
                else if (_changeIsDeletion && LastUpdatedNotes.Contains(_changedNote))
                {
                    LastUpdatedNotes.Remove(_changedNote);
                }
            }

            if (LastUpdatedNotes.Count > MaxNumberOfNotesInRecentList)
            {
                LastUpdatedNotes.RemoveAt(LastUpdatedNotes.Count - 1);
            }
        }