public void OnItemClick(SearchInBookResultItemDataModel item) { _navigationService .UriFor <ReadPageViewModel>() .WithParam(vm => vm.BookId, item.BookId) .WithParam(vm => vm.TokenOffset, item.TokenId) .WithParam(vm => vm.CatalogId, CatalogId) .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel)) .Navigate(); }
public SearchInBookResultItemDataModel ToDataModel( BookSearchResult searchResult, string queryString, string bookId) { var query = BookSearch.PrepareQuery(queryString); var item = new SearchInBookResultItemDataModel(); if (searchResult.PreviousContext.Any()) { item.TokenId = searchResult.PreviousContext[0].ID; } else { item.TokenId = searchResult.SearchResult[0].ID; } item.BookId = bookId; var firstWord = query.First(); var lastWord = query.Last(); var firstToken = searchResult.SearchResult.First(); var lastToken = searchResult.SearchResult.Last(); var beforeWords = searchResult.PreviousContext.Select(r => r.Text).ToList(); var afterWords = searchResult.NextContext.Select(r => r.Text).ToList(); var intermediateWords = searchResult.SearchResult.Skip(1).Take(searchResult.SearchResult.Count - 2).Select(r => r.Text).ToList(); var firstWordIndex = firstToken.Text.IndexOf(firstWord, StringComparison.InvariantCultureIgnoreCase); beforeWords.Add(firstToken.Text.Substring(0, firstWordIndex)); intermediateWords.Insert(0, firstToken.Text.Substring(firstWordIndex, firstWord.Length)); var lastWordIndex = lastToken.Text.IndexOf(lastWord, StringComparison.InvariantCultureIgnoreCase); afterWords.Insert(0, lastToken.Text.Substring(lastWordIndex + lastWord.Length)); if (query.Count > 1) { intermediateWords.Add(lastToken.Text.Substring(lastWordIndex, lastWord.Length)); } item.TextBefore = string.Join(" ", beforeWords); item.SearchedText = string.Join(" ", intermediateWords); item.TextAfter = string.Join(" ", afterWords); return(item); }
private void UpdateText(SearchInBookResultItemDataModel newValue) { TextBefore.Text = newValue.TextBefore; TextAfter.Text = newValue.TextAfter; SearchedText.Text = newValue.SearchedText; }