// Umbraco.Code.MapAll -Alias -Trashed private static void Map(ISearchResult source, SearchResultEntity target, MapperContext context) { target.Id = source.Id; target.Score = source.Score; // TODO: Properly map this (not aftermap) //get the icon if there is one target.Icon = source.Values.ContainsKey(UmbracoExamineIndex.IconFieldName) ? source.Values[UmbracoExamineIndex.IconFieldName] : "icon-document"; target.Name = source.Values.ContainsKey("nodeName") ? source.Values["nodeName"] : "[no name]"; if (source.Values.ContainsKey(UmbracoExamineIndex.NodeKeyFieldName)) { if (Guid.TryParse(source.Values[UmbracoExamineIndex.NodeKeyFieldName], out var key)) { target.Key = key; //need to set the UDI if (source.Values.ContainsKey(LuceneIndex.CategoryFieldName)) { switch (source.Values[LuceneIndex.CategoryFieldName]) { case IndexTypes.Member: target.Udi = new GuidUdi(Constants.UdiEntityType.Member, target.Key); break; case IndexTypes.Content: target.Udi = new GuidUdi(Constants.UdiEntityType.Document, target.Key); break; case IndexTypes.Media: target.Udi = new GuidUdi(Constants.UdiEntityType.Media, target.Key); break; } } } } if (source.Values.ContainsKey("parentID")) { if (int.TryParse(source.Values["parentID"], out var parentId)) { target.ParentId = parentId; } else { target.ParentId = -1; } } target.Path = source.Values.ContainsKey(UmbracoExamineIndex.IndexPathFieldName) ? source.Values[UmbracoExamineIndex.IndexPathFieldName] : ""; if (source.Values.ContainsKey(LuceneIndex.ItemTypeFieldName)) { target.AdditionalData.Add("contentType", source.Values[LuceneIndex.ItemTypeFieldName]); } }
public void SearchItems_MockedExternalServiceWith2Bicicletas_ReturnsResultWith2Bicicletas() { #region Arrange var mockedExternalServiceResult = new SearchResultEntity { results = new List <ItemResultEntity> { new ItemResultEntity(), new ItemResultEntity() } }; const string filter = "bicicleta"; var externalService = new Mock <IExternalService>(); string externalServiceResponseMessage = string.Empty; externalService.Setup(m => m.SearchItems(filter, null, null, ref externalServiceResponseMessage)) .Returns(mockedExternalServiceResult); var loggerService = new Mock <ILoggerService>(); var model = new ItemDomain(externalService.Object, loggerService.Object); #endregion #region Act string responseMessage = string.Empty; var searchResult = model.SearchItems(filter, null, null, ref responseMessage); #endregion #region Assert Assert.AreEqual(2, searchResult.results.Count); #endregion }
// Umbraco.Code.MapAll -Trashed -Alias -Score private static void Map(EntitySlim source, SearchResultEntity target, MapperContext context) { target.Icon = MapContentTypeIcon(source); target.Id = source.Id; target.Key = source.Key; target.Name = source.Name; target.ParentId = source.ParentId; target.Path = source.Path; target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key); if (target.Icon.IsNullOrWhiteSpace()) { if (source.NodeObjectType == Constants.ObjectTypes.Member) { target.Icon = Constants.Icons.Member; } else if (source.NodeObjectType == Constants.ObjectTypes.DataType) { target.Icon = Constants.Icons.DataType; } else if (source.NodeObjectType == Constants.ObjectTypes.DocumentType) { target.Icon = Constants.Icons.ContentType; } else if (source.NodeObjectType == Constants.ObjectTypes.MediaType) { target.Icon = Constants.Icons.MediaType; } else if (source.NodeObjectType == Constants.ObjectTypes.TemplateType) { target.Icon = Constants.Icons.Template; } } }
// Umbraco.Code.MapAll -Trashed -Alias -Score private static void Map(EntitySlim source, SearchResultEntity target, MapperContext context) { target.Icon = MapContentTypeIcon(source); target.Id = source.Id; target.Key = source.Key; target.Name = source.Name; target.ParentId = source.ParentId; target.Path = source.Path; target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key); if (target.Icon.IsNullOrWhiteSpace()) { if (source.NodeObjectType == Constants.ObjectTypes.Member) { target.Icon = "icon-user"; } else if (source.NodeObjectType == Constants.ObjectTypes.DataType) { target.Icon = "icon-autofill"; } else if (source.NodeObjectType == Constants.ObjectTypes.DocumentType) { target.Icon = "icon-item-arrangement"; } else if (source.NodeObjectType == Constants.ObjectTypes.MediaType) { target.Icon = "icon-thumbnails"; } else if (source.NodeObjectType == Constants.ObjectTypes.TemplateType) { target.Icon = "icon-newspaper-alt"; } } }
public void NavigateTo(SearchResultEntity clickedResult) { if (clickedResult.IsPage) { _mainWindowFunctions.OpenPage(clickedResult.Heading); } else { HyperlinkNavigation.NavigateTo(clickedResult.Url); } }
private void SaveSearchResults(string searchId, Dictionary <string, int> searchResults) { foreach (var key in searchResults.Keys) { var mi = new MessageIdentity().FromMessageString(key); var rank = searchResults[key]; SearchResultEntity entity = new SearchResultEntity(searchId, rank, mi); TableOperation insertOperation = TableOperation.InsertOrReplace(entity); _searchResultsTable.Execute(insertOperation); } }
/// <summary>検索処理</summary> /// <param name="parameter"></param> private void ExecuteSearch(object parameter) { Logger.Info(CLASS_NAME, "ExecuteSearch", $"start. SearchWord:[{SearchWord}]"); if (_model == null) { Logger.Fatal(CLASS_NAME, "ExecuteSearch", "_model is null"); return; } if (string.IsNullOrEmpty(SearchWord)) { Logger.Error(CLASS_NAME, "ExecuteSearch", "SearchWord is null or empty!"); return; } // dicのintはindex部分なので本文キャレット移動、stringは結果表示リストに使用する Dictionary <int, string> indexWordPairs = _model.SearchAllWordsInText(SearchWord, TextDocument.Text); if (UpdateSearchResultVisiblity(indexWordPairs) == false) { Logger.Error(CLASS_NAME, "ExecuteSearch", "UpdateSearchResultVisibility return false!"); return; } // 旧検索結果をクリアする SearchResult.Clear(); // 念のため昇順にソートしておく indexWordPairs.OrderBy(pair => pair.Key); SearchResultEntity[] searchResults = new SearchResultEntity[indexWordPairs.Count]; foreach (KeyValuePair <int, string> kvp in indexWordPairs) { SearchResult.Add( new SearchResultEntity() { Index = kvp.Key, DisplayWord = kvp.Value } ); } // 検索結果にハイライトをかける _model.ApplyHighlightToSearchResult(SearchWord); }
//public IActionResult Search(string q) //{ // return Search(q, 1); //} public IActionResult Search(string q, int p) { IExternalService externalService = new ExternalServiceMercadoLibre(); ILoggerService loggerService = new Log4NetLoggerService(); IItem model = new Item(externalService, loggerService); loggerService.Action("UserX", "VER CCOMO OBTENEMOS ESTO", System.Reflection.MethodBase.GetCurrentMethod().Name, DateTime.Now); SearchResultEntity searchResult = model.SearchItems(q, (p - 1) * _itemsPerPage, _itemsPerPage); if (searchResult != null && searchResult.results.Count > 0) { return(View(searchResult.results)); } else { return(null); } }
/// <summary>検索結果へのジャンプ処理</summary> /// <param name="parameter"></param> private void ExecuteJumpToSearchResult(object parameter) { Logger.Info(CLASS_NAME, "ExecuteJumpToSearchResult", "start"); SelectionChangedEventArgs args = parameter as SelectionChangedEventArgs; if (args == null) { Logger.Fatal(CLASS_NAME, "ExecuteJumpToSearchResult", "args is null!"); return; } if (args.AddedItems == null || args.AddedItems.Count < 0) { Logger.Fatal(CLASS_NAME, "ExecuteJumpToSearchResult", "AddedItems is null or empty!"); return; } SearchResultEntity searchResultEntity = args.AddedItems[0] as SearchResultEntity; if (searchResultEntity == null) { Logger.Fatal(CLASS_NAME, "ExecuteJumpToSearchResult", "searchResultEntity is null!"); return; } if (_model == null) { Logger.Fatal(CLASS_NAME, "ExecuteJumpToSearchResult", "_model is null"); return; } // キャレットの更新とFocusを行う if (_model.UpdateCaretOffset(searchResultEntity.Index) == false) { Logger.Error(CLASS_NAME, "ExecuteJumpToSearchResult", "UpdateCaretOffset return false!"); return; } }
public void SearchItems_MockedExternalServiceWith2Bicicletas_ReturnsResultWith2Bicicletas() { #region Arrange const string filter = "bicicleta"; const int totalItemCount = 22; const string idItem1 = "bici1"; const string titleItem1 = "SuperBici1"; const decimal priceItem1 = 50; const string thumbnailItem1 = "www.google.com"; const bool freeShippingItem1 = true; const string idItem2 = "bici2"; const string titleItem2 = "SuperBici2"; const decimal priceItem2 = 14123; const string thumbnailItem2 = "www.facebook.com"; const bool freeShippingItem2 = false; var mockedExternalServiceResult = new SearchResultEntity { paging = new PagingEntity { total = totalItemCount }, results = new List <ItemResultEntity> { new ItemResultEntity { id = idItem1, title = titleItem1, price = priceItem1, thumbnail = thumbnailItem1, shipping = new ShippingEntity { free_shipping = freeShippingItem1 } }, new ItemResultEntity { id = idItem2, title = titleItem2, price = priceItem2, thumbnail = thumbnailItem2, shipping = new ShippingEntity { free_shipping = freeShippingItem2 } } } }; var externalService = new Mock <IExternalService>(); string externalServiceResponseMessage = string.Empty; externalService.Setup(m => m.SearchItems(filter, null, null, ref externalServiceResponseMessage)) .Returns(mockedExternalServiceResult); var loggerService = new Mock <ILoggerService>(); ItemApplication.MapperReset(); var applicationItem = new ItemApplication(externalService.Object, loggerService.Object); #endregion #region Act string responseMessage = string.Empty; var searchResult = applicationItem.SearchItems(filter, null, null, ref responseMessage); #endregion #region Assert Assert.AreEqual(2, searchResult.Results.Count); Assert.AreEqual(idItem1, searchResult.Results.Where(i => i.Id == idItem1).First().Id); Assert.AreEqual(titleItem1, searchResult.Results.Where(i => i.Id == idItem1).First().Title); Assert.AreEqual(priceItem1, searchResult.Results.Where(i => i.Id == idItem1).First().Price); Assert.AreEqual(thumbnailItem1, searchResult.Results.Where(i => i.Id == idItem1).First().Thumbnail); Assert.AreEqual(freeShippingItem1, searchResult.Results.Where(i => i.Id == idItem1).First().FreeShipping); Assert.AreEqual(idItem2, searchResult.Results.Where(i => i.Id == idItem2).First().Id); Assert.AreEqual(titleItem2, searchResult.Results.Where(i => i.Id == idItem2).First().Title); Assert.AreEqual(priceItem2, searchResult.Results.Where(i => i.Id == idItem2).First().Price); Assert.AreEqual(thumbnailItem2, searchResult.Results.Where(i => i.Id == idItem2).First().Thumbnail); Assert.AreEqual(freeShippingItem2, searchResult.Results.Where(i => i.Id == idItem2).First().FreeShipping); #endregion }
// Umbraco.Code.MapAll -Alias -Trashed private static void Map(ISearchResult source, SearchResultEntity target, MapperContext context) { target.Id = source.Id; target.Score = source.Score; // TODO: Properly map this (not aftermap) //get the icon if there is one target.Icon = source.Values.ContainsKey(UmbracoExamineIndex.IconFieldName) ? source.Values[UmbracoExamineIndex.IconFieldName] : Constants.Icons.DefaultIcon; target.Name = source.Values.ContainsKey("nodeName") ? source.Values["nodeName"] : "[no name]"; var culture = context.GetCulture(); if (culture.IsNullOrWhiteSpace() == false) { target.Name = source.Values.ContainsKey($"nodeName_{culture}") ? source.Values[$"nodeName_{culture}"] : target.Name; } if (source.Values.TryGetValue(UmbracoExamineIndex.UmbracoFileFieldName, out var umbracoFile)) { if (umbracoFile != null) { target.Name = $"{target.Name} ({umbracoFile})"; } } if (source.Values.ContainsKey(UmbracoExamineIndex.NodeKeyFieldName)) { if (Guid.TryParse(source.Values[UmbracoExamineIndex.NodeKeyFieldName], out var key)) { target.Key = key; //need to set the UDI if (source.Values.ContainsKey(LuceneIndex.CategoryFieldName)) { switch (source.Values[LuceneIndex.CategoryFieldName]) { case IndexTypes.Member: target.Udi = new GuidUdi(Constants.UdiEntityType.Member, target.Key); break; case IndexTypes.Content: target.Udi = new GuidUdi(Constants.UdiEntityType.Document, target.Key); break; case IndexTypes.Media: target.Udi = new GuidUdi(Constants.UdiEntityType.Media, target.Key); break; } } } } if (source.Values.ContainsKey("parentID")) { if (int.TryParse(source.Values["parentID"], out var parentId)) { target.ParentId = parentId; } else { target.ParentId = -1; } } target.Path = source.Values.ContainsKey(UmbracoExamineIndex.IndexPathFieldName) ? source.Values[UmbracoExamineIndex.IndexPathFieldName] : ""; if (source.Values.ContainsKey(LuceneIndex.ItemTypeFieldName)) { target.AdditionalData.Add("contentType", source.Values[LuceneIndex.ItemTypeFieldName]); } }
private void AddIcon(SearchResultEntity searchResult) { searchResult.Icon = new WebIcon(); }