public IList <FacetField> Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var facetCountsNamedList = (NamedList)result.Get("facet_counts");

            if (facetCountsNamedList == null)
            {
                return(null);
            }

            var facetQueriesNamedList = (NamedList)facetCountsNamedList.Get("facet_queries");

            if (facetQueriesNamedList == null)
            {
                return(null);
            }

            var facetFieldsResult = new List <FacetField>(facetQueriesNamedList.Count);

            for (var i = 0; i < facetQueriesNamedList.Count; i++)
            {
                facetFieldsResult.Add(new FacetField()
                {
                    Name = facetQueriesNamedList.GetName(i), Count = Convert.ToInt32(facetQueriesNamedList.GetVal(i))
                });
            }

            return(facetFieldsResult);
        }
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="result">名称对象集合</param>
        /// <returns>查询结果</returns>
        public QueryResults <T> Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var queryResults     = new QueryResults <T>();
            var solrDocumentList = (SolrDocumentList)result.Get("response");

            if (solrDocumentList == null)
            {
                return(null);
            }

            queryResults.NumFound = solrDocumentList.NumFound;
            queryResults.MaxScore = solrDocumentList.MaxScore;

            var docs = objectDeserialize.Deserialize(solrDocumentList);

            foreach (T doc in docs)
            {
                queryResults.Add(doc);
            }

            return(queryResults);
        }
Ejemplo n.º 3
0
        public IDictionary <string, FacetRange> Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var facetCountsNamedList = (NamedList)result.Get("facet_counts");

            if (facetCountsNamedList == null)
            {
                return(null);
            }

            var facetRangesNamedList = (NamedList)facetCountsNamedList.Get("facet_ranges");

            if (facetRangesNamedList == null)
            {
                return(null);
            }

            var facetRangesResult = new Dictionary <string, FacetRange>(facetRangesNamedList.Count);

            for (var i = 0; i < facetRangesNamedList.Count; i++)
            {
                var fieldName  = facetRangesNamedList.GetName(i);
                var fieldValue = (NamedList)facetRangesNamedList.GetVal(i);

                if (!facetRangesResult.ContainsKey(fieldName))
                {
                    facetRangesResult.Add(fieldName, new FacetRange()
                    {
                        Start = fieldValue.Get("start"), End = fieldValue.Get("end"), Gap = fieldValue.Get("gap")
                    });
                }

                var countsNamedList = (NamedList)fieldValue.Get("counts");

                if (countsNamedList != null)
                {
                    facetRangesResult[fieldName].Counts = new List <FacetField>(countsNamedList.Count);

                    for (var j = 0; j < countsNamedList.Count; j++)
                    {
                        facetRangesResult[fieldName].Counts.Add(new FacetField()
                        {
                            Name = countsNamedList.GetName(j), Count = Convert.ToInt32(countsNamedList.GetVal(j))
                        });
                    }
                }
            }

            return(facetRangesResult);
        }
Ejemplo n.º 4
0
        private IEnumerable <GroupResultInfo <T> > QueryGroupResultsParseT(string fields, NamedList namedList, string highlightFields, out int matchesCount)
        {
            ObjectDeserializeT <T> objectDeserializeT = new ObjectDeserializeT <T>(this._TableName, fields);

            matchesCount = 0;
            ISolrResponseParser <NamedList, IList <GroupQueryResults <T> > > solrResponseParser = new BinaryGroupQueryResultsParser <T>(objectDeserializeT);

            if (!string.IsNullOrWhiteSpace(highlightFields))
            {
                BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
                IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);
                objectDeserializeT.Highlight = highlight;
            }
            List <GroupResultInfo <T> >        list  = new List <GroupResultInfo <T> >();
            IList <GroupQueryResults <T> >     list2 = solrResponseParser.Parse(namedList);
            IEnumerable <GroupResultInfo <T> > result;

            if (list2 == null || list2.Count == 0)
            {
                result = list;
            }
            else
            {
                NamedList namedList2 = (NamedList)namedList.Get("grouped");
                int       num        = 0;
                foreach (GroupQueryResults <T> current in list2)
                {
                    matchesCount = current.Matches;
                    NamedList namedList3 = (NamedList)namedList2.GetVal(num);
                    object    obj        = namedList3.Get("ngroups");
                    if (obj != null)
                    {
                        matchesCount = Convert.ToInt32(obj);
                    }
                    foreach (GroupQueryResult <T> current2 in current.Groups)
                    {
                        list.Add(new GroupResultInfo <T>
                        {
                            Data         = current2.QueryResults,
                            RecordCount  = current2.QueryResults.NumFound,
                            MatchesCount = current.Matches,
                            GroupValue   = current2.GroupValue
                        });
                    }
                    num++;
                }
                result = list;
            }
            return(result);
        }
        public IDictionary <string, IDictionary <string, IList <string> > > Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var highlightingNamedList = (NamedList)result.Get("highlighting");

            if (highlightingNamedList == null)
            {
                return(null);
            }

            var highlightingResult = new Dictionary <string, IDictionary <string, IList <string> > >(highlightingNamedList.Count);

            for (var i = 0; i < highlightingNamedList.Count; i++)
            {
                var itemName      = highlightingNamedList.GetName(i);
                var itemNamedList = (NamedList)highlightingNamedList.GetVal(i);

                if (!highlightingResult.ContainsKey(itemName))
                {
                    highlightingResult[itemName] = new Dictionary <string, IList <string> >(itemNamedList.Count);
                }

                for (var j = 0; j < itemNamedList.Count; j++)
                {
                    var hlItemName      = itemNamedList.GetName(j);
                    var hlItemArrayList = (ArrayList)itemNamedList.GetVal(j);

                    if (!highlightingResult[itemName].ContainsKey(hlItemName))
                    {
                        highlightingResult[itemName][hlItemName] = new List <string>();
                    }

                    if (hlItemArrayList != null)
                    {
                        foreach (object obj in hlItemArrayList)
                        {
                            highlightingResult[itemName][hlItemName].Add(obj.ToString());
                        }
                    }
                }
            }

            return(highlightingResult);
        }
Ejemplo n.º 6
0
        public IDictionary <string, IList <FacetField> > Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var facetCountsNamedList = (NamedList)result.Get("facet_counts");

            if (facetCountsNamedList == null)
            {
                return(null);
            }

            var facetFieldsNamedList = (NamedList)facetCountsNamedList.Get("facet_fields");

            if (facetFieldsNamedList == null)
            {
                return(null);
            }

            var facetFieldsResult = new Dictionary <string, IList <FacetField> >(facetFieldsNamedList.Count);

            for (var i = 0; i < facetFieldsNamedList.Count; i++)
            {
                var fieldName = facetFieldsNamedList.GetName(i);

                if (!facetFieldsResult.ContainsKey(fieldName))
                {
                    facetFieldsResult.Add(fieldName, new List <FacetField>());
                }

                var fieldCountNamedList = (NamedList)facetFieldsNamedList.GetVal(i);

                if (fieldCountNamedList != null)
                {
                    for (var j = 0; j < fieldCountNamedList.Count; j++)
                    {
                        facetFieldsResult[fieldName].Add(new FacetField()
                        {
                            Name = fieldCountNamedList.GetName(j), Count = Convert.ToInt32(fieldCountNamedList.GetVal(j))
                        });
                    }
                }
            }

            return(facetFieldsResult);
        }
        public IList <GroupQueryResults <T> > Parse(NamedList result)
        {
            if (result == null)
            {
                return(null);
            }

            var groupedNamedList = (NamedList)result.Get("grouped");

            if (groupedNamedList == null)
            {
                return(null);
            }

            var queryResults = new List <GroupQueryResults <T> >(groupedNamedList.Count);

            for (var i = 0; i < groupedNamedList.Count; i++)
            {
                var groupName  = groupedNamedList.GetName(i);
                var groupValue = (NamedList)groupedNamedList.GetVal(i);

                var groupQueryResults = new GroupQueryResults <T>()
                {
                    GroupName = groupName
                };

                if (groupValue != null)
                {
                    groupQueryResults.Matches = Convert.ToInt32(groupValue.Get("matches"));

                    var groupsList = (ArrayList)groupValue.Get("groups");

                    if (groupsList != null)
                    {
                        groupQueryResults.Groups = new List <GroupQueryResult <T> >(groupsList.Count);

                        for (var j = 0; j < groupsList.Count; j++)
                        {
                            var groupNamedList = (NamedList)groupsList[j];

                            var groupQueryResult = new GroupQueryResult <T>()
                            {
                                GroupValue = groupNamedList.Get("groupValue").ToString()
                            };
                            var solrDocumentList = (SolrDocumentList)groupNamedList.Get("doclist");

                            if (solrDocumentList != null)
                            {
                                groupQueryResult.QueryResults = new QueryResults <T>()
                                {
                                    NumFound = solrDocumentList.NumFound, MaxScore = solrDocumentList.MaxScore
                                };

                                var docs = objectDeserialize.Deserialize(solrDocumentList);

                                foreach (T doc in docs)
                                {
                                    groupQueryResult.QueryResults.Add(doc);
                                }
                            }

                            groupQueryResults.Groups.Add(groupQueryResult);
                        }
                    }
                }

                queryResults.Add(groupQueryResults);
            }

            return(queryResults);
        }