public IQueryable <SearchResultItem> Query <T>(IQueryable <SearchResultItem> queryable, SearchSettings settings = null) where T : SearchResultItem { if (settings.Enabled == null) { return(queryable); } if (string.IsNullOrEmpty(settings.WordToSearch) || string.IsNullOrWhiteSpace(settings.WordToSearch) || settings.Enabled.FirstOrDefault().ToLower() == "false") { return(queryable); } Dictionary <string, object> Fields = new Dictionary <string, object>(); foreach (var q in queryable) { foreach (var f in q.Fields) { if (f.Key != "_content" && f.Key != "content" && f.Value.ToString().Contains(settings.WordToSearch)) { var newValue = f.Value.ToString().Replace(settings.WordToSearch, string.Format("{0}{1}{2}", "<span style=\"background-color: #FFFF00\">", settings.WordToSearch, "</span>")); if (!Fields.ContainsKey(f.Key)) { Fields.Add(f.Key, newValue); } } } } _nativeCache.GetOrCreate <Dictionary <string, object> >("Highlight", Fields); return(queryable); }
private SearchUIModel GetResult(string search) { var model = _mvcContext.GetDataSourceItem <SearchSettingsModel>(); model.WordToSearch = search; _nativeCache.Delete("Highlight"); IQueryable <SearchResultItem> result = _searchService.Search <SearchResultItem>("master", model); var serachResultUI = new SearchUIModel { SearchModel = model, SearchResultItems = result, SearchResultCount = result.Count(), Facets = _nativeCache.GetOrCreate <List <FacetCategory> >("Category", null), HighlightResult = _nativeCache.GetOrCreate <Dictionary <string, object> >("Highlight", null) }; return(serachResultUI); }
public IQueryable <SearchResultItem> Query <T>(IQueryable <SearchResultItem> queryable, SearchSettings settings = null) where T : SearchResultItem { if (settings.Facets == null) { return(queryable); } foreach (var facet in settings.Facets) { queryable = queryable.FacetOn(x => x[facet], 1); _nativeCache.GetOrCreate <List <FacetCategory> >(facet, queryable.GetFacets().Categories); } return(queryable); }