/// <summary> /// Extracts searchable information from a given data object /// (including text parts, field values for search results preview and faceted search). /// </summary> /// <param name="data">The data item to collect searchable information from.</param> /// <param name="skipInheritedInterfaces">When <value>true</value>, the inherited properties will not be processed.</param> public void CrawlData(IData data, bool skipInheritedInterfaces = false) { var interfaceType = data.DataSourceId.InterfaceType; var fields = DataTypeSearchReflectionHelper.GetSearchableFields(interfaceType); foreach (var field in fields) { var propertyInfo = field.Key; if (skipInheritedInterfaces && propertyInfo.DeclaringType != interfaceType) { continue; } var fieldProcessor = DataTypeSearchReflectionHelper.GetDataFieldProcessor(propertyInfo); object value = propertyInfo.GetValue(data); if (value == null) { continue; } var attr = field.Value; // Text indexing if (attr.IndexText) { var textParts = fieldProcessor.GetTextParts(value); if (textParts != null) { _textParts.AddRange(textParts); } } // Field previewing if (attr.Previewable) { var indexValue = fieldProcessor.GetIndexValue(value); if (indexValue != null) { _fieldValues.Add(new KeyValuePair <string, object>( fieldProcessor.GetDocumentFieldName(propertyInfo), indexValue)); } } // Faceted fields if (attr.Faceted) { string[] facetValues = fieldProcessor.GetFacetValues(value); if (facetValues != null && facetValues.Length > 0) { _facetFieldValues.Add(new KeyValuePair <string, string[]>( fieldProcessor.GetDocumentFieldName(propertyInfo), facetValues)); } } } }
/// <summary> /// Extracts searchable information from a given data object /// (including text parts, field values for search results preview and faceted search). /// </summary> /// <param name="data">The data item to collect searchable information from.</param> /// <param name="skipInheritedInterfaces">When <value>true</value>, the inherited properties will not be processed.</param> public void CrawlData(IData data, bool skipInheritedInterfaces = false) { var interfaceType = data.DataSourceId.InterfaceType; var fields = DataTypeSearchReflectionHelper.GetSearchableFields(interfaceType); if (data is IPage page) { _currentPage = page; } foreach (var field in fields) { var propertyInfo = field.Key; if (skipInheritedInterfaces && propertyInfo.DeclaringType != interfaceType) { continue; } var fieldProcessor = DataTypeSearchReflectionHelper.GetDataFieldProcessor(propertyInfo); object value = propertyInfo.GetValue(data); if (value == null) { continue; } var attr = field.Value; // Text indexing if (attr.IndexText) { var textParts = fieldProcessor.GetTextParts(value); if (textParts != null) { _textParts.AddRange(textParts.SelectMany(ProcessXhtml)); } } // Field previewing if (attr.Previewable) { var indexValue = fieldProcessor.GetIndexValue(value); if (indexValue != null) { _fieldValues.Add(new KeyValuePair <string, object>( fieldProcessor.GetDocumentFieldName(propertyInfo), indexValue)); } } // Faceted fields if (attr.Faceted) { string[] facetValues = fieldProcessor.GetFacetValues(value); if (facetValues != null && facetValues.Length > 0) { _facetFieldValues.Add(new KeyValuePair <string, string[]>( fieldProcessor.GetDocumentFieldName(propertyInfo), facetValues)); } } } _extensions?.ForEach(e => { try { e.Populate(this, data); } catch (Exception ex) when(!(ex is ThreadAbortException)) { Log.LogError(nameof(SearchDocumentBuilder), ex); } }); }