protected string GetResultCultureValueWithFallback(ISearchResult searchResult, string property) { var retVal = searchResult.GetValues(property + "_" + this.Culture).FirstOrDefault(); if (retVal == null && this.Culture != defaultCulture) { retVal = searchResult.GetValues(property + "_" + defaultCulture).FirstOrDefault(); } if (retVal == null && this.Culture != defaultCulture) { retVal = this.GetResultValue(searchResult, property); } return(retVal); }
private IResourceItem BuildResource(ISearchResult searchResult) { var resourceType = searchResult.GetValues("__NodeTypeAlias").FirstOrDefault(); var item = ResourceFactoryProvider.GetResourceFactory(resourceType, this.Umbraco, this.Services.ContentService, this.CultureName).BuildResource(searchResult); return(item); }
/// <summary> /// Get multiple values for a particular field in the results /// </summary> public static IEnumerable <T> Values <T>(this ISearchResult result, string field) { var values = result.GetValues(field); return(values .Select(x => ConvertValue <T>(x)) .Where(x => x != null)); }
public string GetTitle(ISearchResult result) { var title = string.Empty; var props = _search.TitleProperties.SelectMany(x => new string[] { $"{x}_{_search.Culture}", x }); foreach (var prop in props) { title = result.GetValues(prop).FirstOrDefault(); if (!title.IsNullOrWhiteSpace()) { break; } } return(title); }
/// <summary> /// Converts the specified <paramref name="result"/> into an instance of <see cref="IPublishedContent"/>. /// /// The method will look at the <c>__IndexType</c> to determine the type of the result, and then use the /// relevant published cache (eg. content or media) to lookup the <see cref="IPublishedContent"/> equivalent of /// <paramref name="result"/>. /// </summary> /// <param name="result">The result to look up.</param> /// <returns>An instance of <see cref="IPublishedContent"/>.</returns> protected virtual IPublishedContent GetPublishedContentFromResult(ISearchResult result) { string indexType = result.GetValues("__IndexType").FirstOrDefault(); switch (indexType) { case "content": return(_umbracoContextAccessor.UmbracoContext.Content.GetById(int.Parse(result.Id))); case "media": case "pdf": return(_umbracoContextAccessor.UmbracoContext.Media.GetById(int.Parse(result.Id))); default: return(null); } }
public string GetSummary(ISearchResult result) { var summary = string.Empty; var props = _search.SummaryProperties.Concat(_search.BodyProperties).SelectMany(x => new string[] { $"{x}_{_search.Culture}", x }); foreach (var prop in props) { summary = result.GetValues(prop).FirstOrDefault(); if (summary.IsNullOrWhiteSpace()) { continue; } summary = SummarizeText(summary); break; } return(summary); }
/// <summary> /// Returns a <see cref="DateTime"/> value parsed from the property with specified /// <paramref name="propertyAlias"/>. If the property doesn't have a value, or it's value cannot be parsed, /// the <c>createDate</c> property is used instead. /// </summary> /// <param name="result">The search result.</param> /// <param name="propertyAlias">The alias of the property holding the <see cref="DateTime"/>.</param> /// <param name="logger">A reference to the current logger.</param> /// <returns>The sort value as an instance of <see cref="DateTime"/>.</returns> public static DateTime GetSortValueByDateTime(ISearchResult result, string propertyAlias, ILogger logger) { // Get the first string value from the result string value = result.GetValues(propertyAlias)?.FirstOrDefault(); // If we don't have a value, fall back to the item's creation date if (string.IsNullOrWhiteSpace(value)) { return(GetCreateDate(result)); } // Attempt to parse the value into a DateTime if (DateTime.TryParseExact(value, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dt)) { return(dt); } // If we reach this point, the value was not in a recognized format, so we write a warning to the log and fall back to the create date logger.Warn(typeof(SearchUtils), $"Error trying to convert to DateTime for ISearchResult with id: {result.Id} and propertyAlias: {propertyAlias}"); return(GetCreateDate(result)); }
protected bool GetResultBooleanValue(ISearchResult searchResult, string property) { return(searchResult.GetValues(property).FirstOrDefault() == "1"); }
protected string GetResultValue(ISearchResult searchResult, string property) { return(searchResult.GetValues(property).FirstOrDefault()); }
private string GetProviderName(ISearchResult result) { return(ResourceFactoryProvider.GetResourceFactoryName(result.GetValues("__NodeTypeAlias").FirstOrDefault())); }
/// <summary> /// Returns the creation date of the specified <paramref name="result"/>, or <see cref="DateTime.MinValue"/> if a creation date could not be determined. /// </summary> /// <param name="result">The result.</param> /// <returns>An instance of <see cref="DateTime"/> representing the creation date.</returns> public static DateTime GetCreateDate(ISearchResult result) { string createdDate = result.GetValues("createDate")?.FirstOrDefault(); return(createdDate == null ? DateTime.MinValue : new DateTime(long.Parse(createdDate))); }
private IResourceItemBase BuildResourceListItem(ISearchResult searchResult) { if (searchResult == null) { return(null); } int.TryParse(searchResult.Id, out int id); var category = this.GetNodeContentTypeAlias(id); var icon = this.GetIcon(searchResult); var providerName = this.GetResultCultureValueWithFallback(searchResult, "providerName"); var serviceName = this.GetResultCultureValueWithFallback(searchResult, "serviceName"); if (string.IsNullOrEmpty(serviceName)) { if (string.IsNullOrEmpty(providerName)) { serviceName = this.GetResultCultureValueWithFallback(searchResult, "nodeName"); } else { serviceName = providerName; providerName = null; } } if (!string.IsNullOrEmpty(providerName) && serviceName.StartsWith(providerName, StringComparison.InvariantCultureIgnoreCase)) { providerName = string.Empty; } var shortDescription = this.GetResultCultureValueWithFallback(searchResult, "shortDescription"); var classificationType = this.GetSingleNodeName(this.GetResultValue(searchResult, "classificationType")); var region = this.GetRegions(searchResult); var address = this.GetResultValue(searchResult, "streetAddress"); var city = this.GetResultValue(searchResult, "city"); var stateList = this.GetResultValue(searchResult, "state"); var state = stateList != null?JsonConvert.DeserializeObject <string[]>(stateList) : new string[] { }; var zip = this.GetResultValue(searchResult, "zip"); var mapInfo = this.GetMapInfo(searchResult, "map"); var tags = this.GetNodesName(searchResult.GetValues("tags").FirstOrDefault()); var options = searchResult.Values.Where(x => x.Value == "1").Where(x => x.Key != "needsTranslation" && x.Key != "sortOrder").Select(x => x.Key.ToLowerInvariant()).ToList(); var openingHours = this.GetOpeningTimes(searchResult); var specialHours = this.GetResultCultureValueWithFallback(searchResult, "specialHours"); var openInfo = this.OpenInfo(openingHours); if (!string.IsNullOrEmpty(specialHours)) { options.Add("seniorhours"); } var statusList = this.GetResultCultureValueWithFallback(searchResult, "status"); var status = statusList != null?JsonConvert.DeserializeObject <string[]>(statusList) : new string[] { }; var statusVal = status.Length > 0 ? status[0] : string.Empty; var open = !string.Equals(statusVal, "Temporarily Closed", StringComparison.InvariantCultureIgnoreCase) && !string.Equals(statusVal, "Permanently Closed", StringComparison.InvariantCultureIgnoreCase); return(new SocialServiceResourceListItem() { Id = id, Name = serviceName, ProviderAddLoc = providerName, Region = region, Category = category, ClassificationType = classificationType, Description = shortDescription, Address = address, City = city, State = state.Length > 0 ? state[0] : null, Zip = zip, Tags = tags, Options = options.ToArray(), IsOpen = open, Icon = icon, Lat = mapInfo?.Lat, Lng = mapInfo?.Lng, OpenInfo = openInfo }); }