/// <summary> /// Returns the textual representation of the specified <paramref name="obj"/>. /// </summary> /// <param name="obj">The object to convert to text.</param> /// <param name="indexingHelper">The current <see cref="IIndexingHelper"/> instance.</param> /// <returns>The textual representation.</returns> public static string GetSearchableText(this ISearchableTextHelper obj, IIndexingHelper indexingHelper) { if (obj == null) { return(string.Empty); } StringBuilder sb = new StringBuilder(); using (TextWriter writer = new StringWriter(sb)) obj.WriteSearchableText(indexingHelper, writer); return(sb.ToString()); }
/// <summary> /// Adds a textual representation of the block list value from property with the specified <paramref name="key"/>. /// </summary> /// <param name="e"></param> /// <param name="logger">The logger to be used for logging errors.</param> /// <param name="indexingHelper">The indexing helper to be used for getting a textual representation of block list values.</param> /// <param name="content">The content item holding the block list value.</param> /// <param name="key">The key (or alias) of the property holding the block list value.</param> /// <param name="newKey">If specified, the value of this parameter will be used for the key of the new field added to the valueset.</param> /// <param name="newKeySuffix">If specified, and <paramref name="newKey"/> is not also specified, the value of this parameter will be appended to <paramref name="key"/>, and used for the key of the new field added to the valueset.</param> public static void IndexBlockList(this IndexingItemEventArgs e, ILogger logger, IIndexingHelper indexingHelper, IPublishedContent content, string key, string newKey = null, string newKeySuffix = null) { // Validate the content and the property if (content == null || !content.HasProperty(key)) { return; } // Get the block list BlockListModel blockList = content.Value <BlockListModel>(key); if (blockList == null) { return; } // Determine the new key newKey = newKey ?? $"{key}{newKeySuffix ?? "_search"}"; // Get the searchable text via the indexing helper try { string text = indexingHelper.GetSearchableText(blockList); if (!string.IsNullOrWhiteSpace(text)) { e.ValueSet.TryAdd(newKey, text); } } catch (Exception ex) { logger.Error(typeof(ExamineIndexingExtensions), ex, "Failed indexing block list in property {Property} on page with ID {Id}.", key, content.Id); } }
/// <summary> /// Adds a textual representation of the block list value from property with the specified <paramref name="key"/>. /// </summary> /// <param name="e"></param> /// <param name="logger">The logger to be used for logging errors.</param> /// <param name="indexingHelper">The indexing helper to be used for getting a textual representation of block list values.</param> /// <param name="umbracoContext">An Umbraco context used for looking up the corresponding content item of the current result.</param> /// <param name="key">The key (or alias) of the property holding the block list value.</param> /// <param name="newKey">If specified, the value of this parameter will be used for the key of the new field added to the valueset.</param> /// <param name="newKeySuffix">If specified, and <paramref name="newKey"/> is not also specified, the value of this parameter will be appended to <paramref name="key"/>, and used for the key of the new field added to the valueset.</param> public static void IndexBlockList(this IndexingItemEventArgs e, ILogger logger, IIndexingHelper indexingHelper, UmbracoContext umbracoContext, string key, string newKey = null, string newKeySuffix = null) { // The ID is numeric, but stored as a string, so we need to parse it if (!int.TryParse(e.ValueSet.Id, out int id)) { return; } // Look up the content node in the content cache IPublishedContent content = umbracoContext.Content.GetById(id); // Call the method overload to handle the rest IndexBlockList(e, logger, indexingHelper, content, key, newKey, newKeySuffix); }