コード例 #1
0
        /// <summary>
        /// 原子操作索引
        /// </summary>
        /// <param name="collectionName">操作的集合(solr中的集体名称)</param>
        /// <param name="uniqueKeyName">主键名称(solr中的主键)</param>
        /// <param name="uniqueKeyValue">主键值(solr中的主键值)</param>
        /// <param name="setItem">需要操作的集体(key为字段名称,value为值)</param>
        /// <param name="operationType">操作类型</param>
        /// <returns>操作结果</returns>
        public IndexOperationResponse AtomOperateIndex(string collectionName, string uniqueKeyName, object uniqueKeyValue, Dictionary <string, object> setItem, IndexOperationType operationType = IndexOperationType.Update)
        {
            var docs = new List <SolrInputDocument>();
            var doc  = new SolrInputDocument();

            try
            {
                doc.Add(uniqueKeyName, new SolrInputField(uniqueKeyName, uniqueKeyValue));
                foreach (var item in setItem)
                {
                    var setOper = new Hashtable();
                    switch (operationType)
                    {
                    case IndexOperationType.Add:
                        setOper.Add("add", item.Value);
                        break;

                    case IndexOperationType.Update:
                        setOper.Add("set", item.Value);
                        break;

                    default:
                        setOper.Add("set", item.Value);
                        break;
                    }
                    doc.Add(item.Key, new SolrInputField(item.Key, setOper));
                    docs.Add(doc);
                }

                collectionName = string.IsNullOrEmpty(collectionName) ? searchConfig.Collection : collectionName;
                var result = updateOperations.Update(collectionName, "/update", new UpdateOptions()
                {
                    OptimizeOptions = optimizeOptions, Docs = docs
                });
                var header = binaryResponseHeaderParser.Parse(result);
                return(new IndexOperationResponse
                {
                    IsSuccess = header.Status == 0,
                    Message = string.Empty,
                    QTime = header.QTime,
                    Status = header.Status
                });
            }
            catch (Exception ex)
            {
                return(new IndexOperationResponse
                {
                    IsSuccess = false,
                    Message = ex.Message,
                    QTime = -1,
                    Status = -1
                });
            }
        }
コード例 #2
0
ファイル: SolrUpdate.cs プロジェクト: wtf-boy/Framework
        public IList <int> Update(DataTable objUpdateTable)
        {
            IList <int> list = new List <int>();
            List <SolrInputDocument> list2 = new List <SolrInputDocument>();

            foreach (DataRow dataRow in objUpdateTable.Rows)
            {
                SolrInputDocument solrInputDocument = new SolrInputDocument();
                foreach (DataColumn dataColumn in objUpdateTable.Columns)
                {
                    if (dataRow[dataColumn.ColumnName] != DBNull.Value)
                    {
                        solrInputDocument.Add(dataColumn.ColumnName, new SolrInputField(dataColumn.ColumnName, this.GetConvertValue(dataColumn.DataType, dataRow[dataColumn.ColumnName])));
                    }
                    else
                    {
                        solrInputDocument.Add(dataColumn.ColumnName, new SolrInputField(dataColumn.ColumnName, this.GetDefaultValue(dataColumn.DataType)));
                    }
                }
                list2.Add(solrInputDocument);
            }
            IList <int> result;

            if (list2.Count <= 0)
            {
                result = list;
            }
            else
            {
                CommitOptions value = default(CommitOptions);
                IObjectSerializer <SolrInputDocument> objectSerializer = new ObjectSerializerTable();
                ResponseHeader responseHeader = this.Update(new UpdateOptions
                {
                    Docs          = objectSerializer.Serialize(list2),
                    CommitOptions = new CommitOptions?(value)
                });
                if (responseHeader != null)
                {
                    list.Add(responseHeader.Status);
                    list.Add(responseHeader.QTime);
                    ConsoleHelper.WriteLine(string.Concat(new object[]
                    {
                        "更新Solr:",
                        this.SolrServerUrl,
                        "成功,状态:",
                        responseHeader.Status,
                        "执行时间:",
                        responseHeader.QTime
                    }), ConsoleColor.Yellow, "");
                }
                result = list;
            }
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// 创建索引
        /// </summary>
        public void InitIndex(object data)
        {
            var       docs = new List <SolrInputDocument>();
            DataTable list = data as DataTable;

            foreach (DataRow pro in list.Rows)
            {
                var model = new SolrInputDocument();

                PropertyInfo[] properites = typeof(IndexCustomerTagModel).GetProperties(); //得到实体类属性的集合
                //string[] dateFields = { "CreateDate" };
                string field = string.Empty;                                               //存储fieldname
                foreach (PropertyInfo propertyInfo in properites)                          //遍历数组
                {
                    object val = pro[propertyInfo.Name];
                    if (val != DBNull.Value)
                    {
                        model.Add(propertyInfo.Name, new SolrInputField(propertyInfo.Name, val));
                    }
                }
                docs.Add(model);
            }

            var result = updateOperations.Update("core1", "/update", new UpdateOptions()
            {
                Docs = docs, CommitOptions = commitOptions
            });
            var header = binaryResponseHeaderParser.Parse(result);

            System.Console.WriteLine(string.Format("Update Status:{0} QTime:{1}", header.Status, header.QTime));
            //System.Console.ReadLine();
        }
コード例 #4
0
ファイル: EasyNetSolrUtil.cs プロジェクト: wangz001/Funnycar
        /// <summary>
        /// 创建索引
        /// </summary>
        public static string Index()
        {
            var docs = new List <SolrInputDocument>();
            var doc  = new SolrInputDocument();

            doc.Add("id", new SolrInputField("id", "SOLR1000"));
            doc.Add("name", new SolrInputField("name", "Solr, the Enterprise Search Server"));
            doc.Add("features", new SolrInputField("features", new String[] { "Advanced Full-Text Search Capabilities using Lucene", "Optimized for High Volume Web Traffic", "Standards Based Open Interfaces - XML and HTTP", "Comprehensive HTML Administration Interfaces", "Scalability - Efficient Replication to other Solr Search Servers", "Flexible and Adaptable with XML configuration and Schema", "Good unicode support: h&#xE9;llo (hello with an accent over the e)" }));
            doc.Add("price", new SolrInputField("price", 0.0f));
            doc.Add("popularity", new SolrInputField("popularity", 10));
            doc.Add("inStock", new SolrInputField("inStock", true));
            doc.Add("incubationdate_dt", new SolrInputField("incubationdate_dt", new DateTime(2006, 1, 17, 0, 0, 0, DateTimeKind.Utc)));

            docs.Add(doc);

            var result = updateOperations.Update("collection1", "/update", new UpdateOptions()
            {
                OptimizeOptions = optimizeOptions, Docs = docs
            });
            var header = binaryResponseHeaderParser.Parse(result);

            return(string.Format("Update Status:{0} QTime:{1}", header.Status, header.QTime));
        }
コード例 #5
0
ファイル: EasyNetSolrUtil.cs プロジェクト: wangz001/Funnycar
        public static int NewTravelIndex(Travels travle)
        {
            var docs = new List <SolrInputDocument>();
            var doc  = new SolrInputDocument();

            doc.Add("id", new SolrInputField("id", "travels_" + travle.Id));  //索引中Id不能重复
            doc.Add("userid", new SolrInputField("userid", travle.UserId));
            doc.Add("TravelName", new SolrInputField("TravelName", travle.TravelName));
            doc.Add("CreateTime", new SolrInputField("CreateTime", travle.CreateTime));
            doc.Add("UpdateTime", new SolrInputField("UpdateTime", travle.UpdateTime));
            doc.Add("CoverImage", new SolrInputField("CoverImage", travle.CoverImage));
            docs.Add(doc);
            var result = updateOperations.Update(CoreName, "/update", new UpdateOptions()
            {
                OptimizeOptions = optimizeOptions, Docs = docs
            });
            var header = binaryResponseHeaderParser.Parse(result);

            return(header.Status); //返回状态码。0表示成功
        }
コード例 #6
0
        public IEnumerable <SolrInputDocument> Serialize(IEnumerable <Product> objs)
        {
            IList <SolrInputDocument> docs = new List <SolrInputDocument>();

            foreach (var obj in objs)
            {
                SolrInputDocument doc = new SolrInputDocument();

                doc.Add("id", new SolrInputField("id", obj.Id));
                if (!string.IsNullOrEmpty(obj.ProductName))
                {
                    doc.Add("ProductName", new SolrInputField("ProductName", obj.ProductName));
                }
                if (obj.ProductTypeId > 0)
                {
                    doc.Add("ProductTypeId", new SolrInputField("ProductTypeId", obj.ProductTypeId));
                }
                if (obj.ProductAttributeId > 0)
                {
                    doc.Add("ProductAttributeId", new SolrInputField("ProductAttributeId", obj.ProductAttributeId));
                }
                if (obj.Rank > 0)
                {
                    doc.Add("Rank", new SolrInputField("Rank", obj.Rank));
                }
                if (obj.EffectDate > DateTime.MinValue)
                {
                    doc.Add("EffectDate", new SolrInputField("EffectDate", obj.EffectDate));
                }
                if (obj.ExpireDate > DateTime.MinValue)
                {
                    doc.Add("ExpireDate", new SolrInputField("ExpireDate", obj.ExpireDate));
                }
                if (obj.Coords != null && obj.Coords.Length > 0)
                {
                    doc.Add("Coords", new SolrInputField("Coords", obj.Coords));
                }
                if (!string.IsNullOrEmpty(obj.ProductDescription))
                {
                    doc.Add("ProductDescription", new SolrInputField("ProductDescription", obj.ProductDescription));
                }
                if (obj.TourSpotName != null && obj.TourSpotName.Length > 0)
                {
                    doc.Add("TourSpotName", new SolrInputField("TourSpotName", obj.TourSpotName));
                }
                if (obj.SalesPrice > 0)
                {
                    doc.Add("SalesPrice", new SolrInputField("SalesPrice", obj.SalesPrice));
                }

                docs.Add(doc);
            }

            return(docs);
        }
コード例 #7
0
ファイル: EasyNetSolrUtil.cs プロジェクト: wangz001/Funnycar
        /// <summary>
        /// 创建或更新索引  travelpart
        /// </summary>
        /// <param name="parts"></param>
        /// <returns></returns>
        public static int NewTravelPartIndex(TravelParts parts)
        {
            var docs = new List <SolrInputDocument>();
            var doc  = new SolrInputDocument();

            doc.Add("id", new SolrInputField("id", "travelparts_" + parts.Id));
            doc.Add("TravelId", new SolrInputField("TravelId", parts.TravelId));
            doc.Add("UserId", new SolrInputField("UserId", parts.UserId));
            doc.Add("PartType", new SolrInputField("PartType", parts.PartType));
            doc.Add("Description", new SolrInputField("Description", parts.Description));
            doc.Add("PartUrl", new SolrInputField("PartUrl", parts.PartUrl));
            doc.Add("Longitude", new SolrInputField("Longitude", parts.Longitude));
            doc.Add("Latitude", new SolrInputField("Latitude", parts.Latitude));
            doc.Add("Height", new SolrInputField("Height", parts.Height));
            doc.Add("Area", new SolrInputField("Area", parts.Area));
            doc.Add("CreateTime", new SolrInputField("CreateTime", parts.CreateTime));
            docs.Add(doc);
            var result = updateOperations.Update(CoreName, "/update", new UpdateOptions()
            {
                OptimizeOptions = optimizeOptions, Docs = docs
            });
            var header = binaryResponseHeaderParser.Parse(result);

            return(header.Status); //返回状态码。0表示成功
        }