private BulkDescriptor ToElasticSearchDocs(IEnumerable <ValueSet> docs, string indexTarget) { var descriptor = new BulkDescriptor(); foreach (var d in docs) { try { var indexingNodeDataArgs = new IndexingItemEventArgs(this, d); OnTransformingIndexValues(indexingNodeDataArgs); if (!indexingNodeDataArgs.Cancel) { //this is just a dictionary var ad = new Document { ["Id"] = d.Id, [FormatFieldName(LuceneIndex.ItemIdFieldName)] = d.Id, [FormatFieldName(LuceneIndex.ItemTypeFieldName)] = d.ItemType, [FormatFieldName(LuceneIndex.CategoryFieldName)] = d.Category }; foreach (var i in d.Values) { if (i.Value.Count > 0) { ad[FormatFieldName(i.Key)] = i.Value.Count == 1 ? i.Value[0] : i.Value; } } var docArgs = new DocumentWritingEventArgs(d, ad); OnDocumentWriting(docArgs); descriptor.Index <Document>(op => op.Index(indexTarget).Document(ad).Id(d.Id)); } } catch (Exception e) { } } return(descriptor); }
private void IndexerComponent_TransformingIndexValues(object sender, IndexingItemEventArgs e) { if (int.TryParse(e.ValueSet.Id, out var nodeId)) { switch (e.ValueSet.ItemType) { case "article": using (var umbracoContext = umbracoContextFactory.EnsureUmbracoContext()) { var contentNode = umbracoContext.UmbracoContext.Content.GetById(nodeId); if (contentNode != null) { var articleDate = contentNode.Value <DateTime>("articleDate"); e.ValueSet.Set("articleDate", articleDate.Date.Ticks); } } break; } } }
private void IndexProviderTransformingIndexValues(object sender, IndexingItemEventArgs e) { if (e.ValueSet.Category != IndexTypes.Content) { return; } var combinedFields = new StringBuilder(); foreach (var fieldValues in e.ValueSet.Values) { var values = fieldValues.Value.Where(value => value != null); foreach (var value in values) { combinedFields.AppendLine(value.ToString()); } } e.ValueSet.TryAdd("combinedField", combinedFields.ToString()); }
protected override void OnTransformingIndexValues(IndexingItemEventArgs e) { base.OnTransformingIndexValues(e); var updatedValues = e.ValueSet.Values.ToDictionary(x => x.Key, x => (IEnumerable <object>)x.Value); //ensure special __Path field var path = e.ValueSet.GetValue("path"); if (path != null) { updatedValues[UmbracoExamineFieldNames.IndexPathFieldName] = path.Yield(); } //icon if (e.ValueSet.Values.TryGetValue("icon", out var icon) && e.ValueSet.Values.ContainsKey(UmbracoExamineFieldNames.IconFieldName) == false) { updatedValues[UmbracoExamineFieldNames.IconFieldName] = icon; } e.SetValues(updatedValues); }
private void IndexerComponent_TransformingIndexvalues(object sender, IndexingItemEventArgs e) { if (int.TryParse(e.ValueSet.Id, out var nodeId)) { switch (e.ValueSet.ItemType) { case "blogPost": using (var umbracoContext = _umbracoContextFactory.EnsureUmbracoContext()) { var contentNode = umbracoContext.UmbracoContext.Content.GetById(nodeId); if (contentNode != null) { var categories = contentNode.Value <IEnumerable <string> >("category"); if (categories != null) { e.ValueSet.Set("searchableCategories", string.Join(",", categories)); } } } break; } } }
private void IndexProviderTransformingIndexValues(object sender, IndexingItemEventArgs e) { if (e.Index.Name != "ExternalIndex") { return; } if (e.ValueSet.Category != IndexTypes.Content) { return; } if (!_fullTextConfig.IsFullTextIndexingEnabled()) { _logger.Debug <AddFullTextItemsToIndex>("FullTextIndexing is not enabled"); return; } // check if contentType is allowed var nodeTypeAlias = e.ValueSet.GetValue("__NodeTypeAlias"); if (nodeTypeAlias != null && _fullTextConfig.GetDisallowedContentTypeAliases().Contains(nodeTypeAlias.ToString())) { _logger.Debug <AddFullTextItemsToIndex>("{nodeTypeAlias} is disallowed by DisallowedContentTypeAliases - {disallowedContentTypeAliases}", nodeTypeAlias.ToString(), string.Join(",", _fullTextConfig.GetDisallowedContentTypeAliases())); return; } // check if there is a template var templateId = e.ValueSet.GetValue("templateID"); if (templateId == null || templateId.ToString() == "0") { _logger.Debug <AddFullTextItemsToIndex>("Template Id is 0 or null"); return; } // set path value var currentPath = e.ValueSet.GetValue("path"); if (currentPath != null) { var pathFieldName = _fullTextConfig.GetPathFieldName(); e.ValueSet.TryAdd(pathFieldName, currentPath.ToString().Replace(",", " ")); } // convert id to int, so we can get it from the content cache if (!int.TryParse(e.ValueSet.Id, out int id)) { return; } using (_profilingLogger.DebugDuration <AddFullTextItemsToIndex>("Attempt to fulltext index for node " + id, "Completed fulltext index for node " + id)) { var cacheItems = _cacheService.GetFromCache(id); if (cacheItems == null || !cacheItems.Any()) { return; } foreach (var item in cacheItems) { var fieldName = _fullTextConfig.GetFullTextFieldName(); if (item.Culture != "") { fieldName += "_" + item.Culture; } e.ValueSet.TryAdd(fieldName, item.Text); } } }
public static void MakeUdisSearchable(this IndexingItemEventArgs e, string key) { IndexUdis(e, key); }
public static void MakeCsvSearchable(this IndexingItemEventArgs e, string key) { IndexCsv(e, key); }
/// <summary> /// Adds a new <c>hideFromSearch</c> field to the valueset indicating whether the node should be hidden /// (excluded) from search results. /// /// The <paramref name="ignoreIds"/> parameter can be used to specify areas of the website that should /// automatically be hidden from search results. This is done by checking whether at least one of the IDs the /// <paramref name="ignoreIds"/> parameter is part of the <c>path</c> field of the valueset for the current node. /// </summary> /// <param name="e"></param> /// <param name="ignoreIds">The IDs for which it self and it's descendants should be hidden.</param> public static void AddHideFromSearch(this IndexingItemEventArgs e, params int[] ignoreIds) { AddHideFromSearch(e, new HashSet <int>(ignoreIds)); }
/// <summary> /// Adds a new <c>hideFromSearch</c> field to the valueset indicating whether the node should be hidden /// (excluded) from search results. /// /// The <paramref name="ignoreId"/> parameter can be used to specify an area of the website that should /// automatically be hidden from search results. This is done by checking whether the ID of the /// <paramref name="ignoreId"/> parameter is part of the <c>path</c> field of the valueset for the current node. /// </summary> /// <param name="e"></param> /// <param name="ignoreId">The ID for which the node itself and it's descendants should be hidden.</param> public static void AddHideFromSearch(this IndexingItemEventArgs e, int ignoreId) { AddHideFromSearch(e, new HashSet <int> { ignoreId }); }
/// <summary> /// Adds a new <c>hideFromSearch</c> field to the valueset indicating whether the node should be hidden (excluded) from search results. /// </summary> /// <param name="e"></param> public static void AddHideFromSearch(this IndexingItemEventArgs e) { AddHideFromSearch(e, default(HashSet <int>)); }
/// <summary> /// Attemps to get the first string value of a field with the specified <paramref name="key"/>. /// </summary> /// <param name="e"></param> /// <param name="key">The key of the field.</param> /// <param name="value">When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param> /// <returns><c>true</c> if the value set contains a field with the specified key; otherwise, <c>false</c>.</returns> public static bool TryGetString(this IndexingItemEventArgs e, string key, out string value) { value = e.ValueSet.Values.TryGetValue(key, out List <object> values) ? values.FirstOrDefault() as string : null; return(value != null); }
/// <summary> /// Adds a searchable version of the date value in the field with the specified <paramref name="key"/>. /// /// The searchable value will be added in a new field using the <c>_range</c> prefix for the key (at it enables /// a ranged query) and the value will be formatted using <c>yyyyMMddHHmm00000</c>. /// </summary> /// <param name="e"></param> /// <param name="key">The key of the field.</param> public static void IndexDate(this IndexingItemEventArgs e, string key) { IndexDate(e, key, "yyyyMMddHHmm00000"); }
private void AddGroups(IndexingItemEventArgs e) { var groups = memberService.GetAllRoles(int.Parse(e.ValueSet.Id)).Aggregate("", (list, group) => string.IsNullOrEmpty(list) ? group : $"{list} {group}"); e.ValueSet.Add(Constants.Members.Groups, groups); }
/// <summary> /// Raises the <see cref="E:TransformingIndexValues"/> event. /// </summary> /// <param name="e">The <see cref="IndexingItemEventArgs"/> instance containing the event data.</param> protected virtual void OnTransformingIndexValues(IndexingItemEventArgs e) { TransformingIndexValues?.Invoke(this, e); }