Example #1
0
        /// <summary>
        /// Parses collapsed document.ids and their counts
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public ICollection <Group <T> > ParseGroup(IEnumerable <XElement> nodes)
        {
            var groups = new List <Group <T> >();

            foreach (var resultElement in nodes)
            {
                var groupName = resultElement.Attribute("name");

                if (groupName == null)
                {
                    continue;
                }

                var groupMatches = int.Parse(resultElement.Attribute("numFound").Value);
                var parsedDocs   = docParser.ParseResults(resultElement);

                groups.Add(new Group <T>()
                {
                    Documents  = parsedDocs,
                    GroupValue = groupName.Value,
                    NumFound   = groupMatches
                });
            }

            return(groups);
        }
Example #2
0
        public void Parse(XDocument xml, AbstractSolrQueryResults <T> results)
        {
            // IsNullOrEmpty part is needed to pass tests -- ptasz3k
            var resultNode = xml.Element("response").Elements("result").FirstOrDefault(e => String.IsNullOrEmpty((string)e.Attribute("name")) || (string)e.Attribute("name") == "response");

            //FIX BY klaas
            //If resultNode == null exit func
            //		This can occur when grouped results are returned
            if (resultNode == null)
            {
                return;
            }

            results.NumFound = Convert.ToInt32(resultNode.Attribute("numFound").Value);
            var maxScore = resultNode.Attribute("maxScore");

            if (maxScore != null)
            {
                results.MaxScore = double.Parse(maxScore.Value, CultureInfo.InvariantCulture.NumberFormat);
            }

            foreach (var result in docParser.ParseResults(resultNode))
            {
                results.Add(result);
            }
        }
        public void Parse(XDocument xml, SolrMoreLikeThisHandlerResults <T> results)
        {
            var resultNode = xml
                             .Element("response")
                             .Elements("result")
                             .FirstOrDefault(e => e.Attribute("name").Value == "match");

            results.Match = resultNode == null ?
                            default(T) :
                            docParser.ParseResults(resultNode).FirstOrDefault();
        }
Example #4
0
        /// <summary>
        /// Parses more-like-this results
        /// </summary>
        /// <param name="results"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public IDictionary <string, IList <T> > ParseMoreLikeThis(IEnumerable <T> results, XElement node)
        {
            var r       = new Dictionary <string, IList <T> >();
            var docRefs = node.Elements("result");

            foreach (var docRef in docRefs)
            {
                var docRefKey = docRef.Attribute("name").Value;
                r[docRefKey] = docParser.ParseResults(docRef);
            }
            return(r);
        }
Example #5
0
        public void Parse(XDocument xml, SolrQueryResults <T> results)
        {
            var resultNode = xml.Element("response").Element("result");

            results.NumFound = Convert.ToInt32(resultNode.Attribute("numFound").Value);
            var maxScore = resultNode.Attribute("maxScore");

            if (maxScore != null)
            {
                results.MaxScore = double.Parse(maxScore.Value, CultureInfo.InvariantCulture.NumberFormat);
            }

            foreach (var result in docParser.ParseResults(resultNode))
            {
                results.Add(result);
            }
        }
Example #6
0
 /// <summary>
 /// Parses collapsed document.ids and their counts
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public IEnumerable<Group<T>> ParseGroup(XElement node) {
     return
         from docNode in node.Elements("arr").Where(X.AttrEq("name", "groups")).Elements()
         let groupValueNode = docNode.Elements().FirstOrDefault(X.AttrEq("name", "groupValue"))
         where groupValueNode != null
         let groupValue = groupValueNode.Name == "null"
             ? "UNMATCHED"
             : //These are the results that do not match the grouping
             groupValueNode.Value
         let resultNode = docNode.Elements("result").First(X.AttrEq("name", "doclist"))
         let numFound = Convert.ToInt32(resultNode.Attribute("numFound").Value)
         let docs = docParser.ParseResults(resultNode).ToList()
         select new Group<T> {
             GroupValue = groupValue,
             Documents = docs,
             NumFound = numFound,
         };
 }
Example #7
0
        public void Parse(XDocument xml, AbstractSolrQueryResults <T> results)
        {
            var resultNode = GetMainResultNode(xml) ?? GetGroupResultNode(xml);

            if (resultNode == null)
            {
                return;
            }

            results.NumFound = Convert.ToInt32(resultNode.Attribute("numFound").Value);
            var maxScore = resultNode.Attribute("maxScore");

            if (maxScore != null)
            {
                results.MaxScore = double.Parse(maxScore.Value, CultureInfo.InvariantCulture.NumberFormat);
            }

            results.AddRange(docParser.ParseResults(resultNode));
        }
Example #8
0
 /// <summary>
 /// Parses collapsed document.ids and their counts
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public IEnumerable <Group <T> > ParseGroup(XElement node)
 {
     return
         (from docNode in node.XPathSelectElement("arr[@name='groups']").Elements()
          let groupValueNode = docNode.XPathSelectElements("*[@name='groupValue']").FirstOrDefault()
                               where groupValueNode != null
                               let groupValue = groupValueNode.Name == "null"
                              ? "UNMATCHED"
                              : //These are the results that do not match the grouping
                                                groupValueNode.Value
                                                let resultNode = docNode.XPathSelectElement("result[@name='doclist']")
                                                                 let numFound = Convert.ToInt32(resultNode.Attribute("numFound").Value)
                                                                                let docs = docParser.ParseResults(resultNode).ToList()
                                                                                           select new Group <T> {
         GroupValue = groupValue,
         Documents = docs,
         NumFound = numFound,
     });
 }