Ejemplo n.º 1
0
        /// <summary>
        /// Parse highlighting snippets for each field.
        /// </summary>
        /// <param name="nodes"></param>
        /// <returns></returns>
        public HighlightedSnippets ParseHighlightingFields(IEnumerable <XElement> nodes)
        {
            var fields = new HighlightedSnippets();

            foreach (var field in nodes)
            {
                var fieldName = field.Attribute("name").Value;
                var snippets  = new List <string>();
                foreach (var str in field.Elements("str"))
                {
                    snippets.Add(str.Value);
                }
                fields.Add(fieldName, snippets);
            }
            return(fields);
        }
        /// <summary>
        /// Parse highlighting snippets for each field.
        /// </summary>
        /// <param name="nodes"></param>
        /// <returns></returns>
        public static HighlightedSnippets ParseHighlightingFields(IEnumerable <XElement> nodes)
        {
            var fields = new HighlightedSnippets();

            foreach (var field in nodes)
            {
                var fieldName = field.Attribute("name").Value;
                ICollection <string> snippets = field.Elements("str")
                                                .Select(str => str.Value)
                                                .ToList();
                if (snippets.Count == 0 && !string.IsNullOrEmpty(field.Value))
                {
                    snippets = new[] { field.Value }
                }
                ;
                fields.Add(fieldName, snippets);
            }
            return(fields);
        }
    }