Пример #1
0
        private DataSet QueryResultsParseDataSet(string fields, NamedList namedList, string highlightFields, out long recordCount)
        {
            ObjectDeserializeTable <T> objectDeserializeTable = new ObjectDeserializeTable <T>(this._TableName, fields);
            ISolrResponseParser <NamedList, QueryResults <DataRow> > solrResponseParser = new BinaryQueryResultsParser <DataRow>(objectDeserializeTable);

            if (!string.IsNullOrWhiteSpace(highlightFields))
            {
                BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
                IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);
                objectDeserializeTable.Highlight = highlight;
            }
            QueryResults <DataRow> queryResults = solrResponseParser.Parse(namedList);

            recordCount = queryResults.NumFound;
            DataSet   dataSet   = new DataSet();
            DataTable dataTable = objectDeserializeTable.CreateDataTable();

            foreach (DataRow current in queryResults)
            {
                dataTable.Rows.Add(current.ItemArray);
            }
            dataSet.Tables.Add(dataTable);
            DataTable dataTable2 = new DataTable();

            dataTable2.TableName = "RecordCount";
            dataTable2.Columns.Add("RecordCount", typeof(long));
            DataRow dataRow = dataTable2.NewRow();

            dataRow["RecordCount"] = recordCount;
            dataTable2.Rows.Add(dataRow);
            dataSet.Tables.Add(dataTable2);
            return(dataSet);
        }
Пример #2
0
        public static DataSet ParserResultsDataSet <T>(this NamedList namedList, string fields, out long recordCount, string tableName = "") where T : class, new()
        {
            ObjectDeserializeTable <T> objectDeserializeTable = new ObjectDeserializeTable <T>(tableName, fields);
            ISolrResponseParser <NamedList, QueryResults <DataRow> > solrResponseParser = new BinaryQueryResultsParser <DataRow>(objectDeserializeTable);
            BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
            IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);

            objectDeserializeTable.Highlight = highlight;
            QueryResults <DataRow> queryResults = solrResponseParser.Parse(namedList);

            recordCount = queryResults.NumFound;
            DataSet   dataSet   = new DataSet();
            DataTable dataTable = objectDeserializeTable.CreateDataTable();

            foreach (DataRow current in queryResults)
            {
                dataTable.Rows.Add(current.ItemArray);
            }
            dataSet.Tables.Add(dataTable);
            DataTable dataTable2 = new DataTable();

            dataTable2.TableName = "RecordCount";
            dataTable2.Columns.Add("RecordCount", typeof(long));
            DataRow dataRow = dataTable2.NewRow();

            dataRow["RecordCount"] = recordCount;
            dataTable2.Rows.Add(dataRow);
            dataSet.Tables.Add(dataTable2);
            return(dataSet);
        }
Пример #3
0
 /// <summary>
 /// 搜索
 /// </summary>
 /// <typeparam name="T">返回的对象类型</typeparam>
 /// <param name="collectionName">搜索集合</param>
 /// <param name="condition">条件</param>
 /// <param name="deserializer">反序列化的对象</param>
 /// <returns>对应的结果集</returns>
 public QueryResponse <T> Query <T>(string collectionName, Dictionary <string, ICollection <string> > condition, ISolrObjectDeserializer <T> deserializer)
 {
     try
     {
         collectionName = string.IsNullOrEmpty(collectionName) ? searchConfig.Collection : collectionName;
         ISolrResponseParser <NamedList, QueryResults <T> > binaryQueryResultsParser = new BinaryQueryResultsParser <T>(deserializer);
         var result   = operations.Query(collectionName, "/select", null, condition);
         var header   = binaryResponseHeaderParser.Parse(result);
         var products = binaryQueryResultsParser.Parse(result);
         return(new QueryResponse <T>
         {
             IsSuccess = header.Status == 0,
             Message = string.Empty,
             QTime = header.QTime,
             Status = header.Status,
             Data = default(T),
             DataList = products.ToList()
         });
     }
     catch (Exception ex)
     {
         return(new QueryResponse <T>
         {
             IsSuccess = false,
             Message = ex.Message,
             QTime = -1,
             Status = -1,
             Data = default(T)
         });
     }
 }
Пример #4
0
        public int GetCount(string condition)
        {
            NamedList result = this.QueryLimit("*", condition, "", "", 0, 0, "", "");
            ISolrResponseParser <NamedList, QueryResults <NullResult> > solrResponseParser = new BinaryQueryResultsParser <NullResult>(new NullResultObjectDeserialize());
            QueryResults <NullResult> queryResults = solrResponseParser.Parse(result);

            return(Convert.ToInt32(queryResults.NumFound));
        }
Пример #5
0
        public static IEnumerable <T> ParserResults <T>(this NamedList namedList, string fields, out long recordCount, string tableName = "") where T : class, new()
        {
            ObjectDeserializeT <T> objectDeserializeT = new ObjectDeserializeT <T>(tableName, fields);
            ISolrResponseParser <NamedList, QueryResults <T> > solrResponseParser = new BinaryQueryResultsParser <T>(objectDeserializeT);
            BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
            IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);

            objectDeserializeT.Highlight = highlight;
            QueryResults <T> queryResults = solrResponseParser.Parse(namedList);

            recordCount = queryResults.NumFound;
            return(queryResults);
        }
Пример #6
0
        private IEnumerable <T> QueryResultsParseT(string fields, NamedList namedList, string highlightFields, out long recordCount)
        {
            ObjectDeserializeT <T> objectDeserializeT = new ObjectDeserializeT <T>(this._TableName, fields);
            ISolrResponseParser <NamedList, QueryResults <T> > solrResponseParser = new BinaryQueryResultsParser <T>(objectDeserializeT);

            if (!string.IsNullOrWhiteSpace(highlightFields))
            {
                BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
                IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);
                objectDeserializeT.Highlight = highlight;
            }
            QueryResults <T> queryResults = solrResponseParser.Parse(namedList);

            recordCount = queryResults.NumFound;
            return(queryResults);
        }
Пример #7
0
        public static FacetResult <T> ParserFacetResults <T>(this NamedList namedList, string fields, out long recordCount, string tableName = "") where T : class, new()
        {
            ObjectDeserializeT <T> objectDeserializeT = new ObjectDeserializeT <T>(tableName, fields);
            ISolrResponseParser <NamedList, QueryResults <T> > solrResponseParser = new BinaryQueryResultsParser <T>(objectDeserializeT);
            BinaryHighlightingParser binaryHighlightingParser = new BinaryHighlightingParser();
            IDictionary <string, IDictionary <string, IList <string> > > highlight = binaryHighlightingParser.Parse(namedList);

            objectDeserializeT.Highlight = highlight;
            QueryResults <T>        queryResults                      = solrResponseParser.Parse(namedList);
            BinaryFacetFieldsParser binaryFacetFieldsParser           = new BinaryFacetFieldsParser();
            IDictionary <string, IList <FacetField> >     dictionary  = binaryFacetFieldsParser.Parse(namedList);
            IDictionary <string, IList <FacetFieldInfo> > dictionary2 = new Dictionary <string, IList <FacetFieldInfo> >();

            if (dictionary != null && dictionary.Count > 0)
            {
                foreach (KeyValuePair <string, IList <FacetField> > current in dictionary)
                {
                    List <FacetFieldInfo> list = new List <FacetFieldInfo>();
                    foreach (FacetField current2 in current.Value)
                    {
                        list.Add(new FacetFieldInfo
                        {
                            Name  = current2.Name,
                            Count = current2.Count
                        });
                    }
                    dictionary2.Add(current.Key, list);
                }
            }
            FacetResult <T> facetResult = new FacetResult <T>();

            facetResult.Data  = queryResults;
            facetResult.Facet = dictionary2;
            recordCount       = queryResults.NumFound;
            return(facetResult);
        }