void doUpdate() { this.Invoke((MethodInvoker) delegate { this.laMess1.Text = String.Format("Start download List company"); }); DBTool.CompanyDataTable dtCom = new DBTool.CompanyDataTable(); DBToolTableAdapters.CompanyTableAdapter adtCom = new DBToolTableAdapters.CompanyTableAdapter(); adtCom.Connection.ConnectionString = QT.Entities.Server.ConnectionString; DBTool2.Product_SolrDataTable dtProduct = new DBTool2.Product_SolrDataTable(); DBTool2TableAdapters.Product_SolrTableAdapter adtProduct = new DBTool2TableAdapters.Product_SolrTableAdapter(); adtProduct.Connection.ConnectionString = QT.Entities.Server.ConnectionString; adtCom.FillBy_WebsiteCoSanPham(dtCom); int x = 0; foreach (DBTool.CompanyRow drCom in dtCom) { x++; this.Invoke((MethodInvoker) delegate { this.laMess1.Text = String.Format("Update {1}/{2} Company {0} ", drCom.Domain.ToString(), x, dtCom.Count); }); try { adtProduct.FillBy_Company(dtProduct, drCom.ID); } catch (Exception) { } SolrDriver.DeleteByCompanyId(drCom.ID); int count = 0; List <SolrProductItem> ls = new List <SolrProductItem>(); for (int i = 0; i < dtProduct.Rows.Count; i++) { DataRow dr = dtProduct.Rows[i]; try { SolrProductItem item = new SolrProductItem { Id = QT.Entities.Common.Obj2Int64(dr["ID"]), Price = QT.Entities.Common.Obj2Int(dr["Price"]), Warranty = QT.Entities.Common.Obj2Int(dr["Warranty"]), Status = QT.Entities.Common.Obj2Int(dr["Status"]), Company = QT.Entities.Common.Obj2Int64(dr["Company"]), LastUpdate = QT.Entities.Common.ObjectToDataTime(dr["LastUpdate"]), Summary = dr["Summary"].ToString(), Description = "", ProductId = QT.Entities.Common.Obj2Int(dr["ProductID"]), ProductType = 2, Name = dr["Name"].ToString(), NameFT = dr["NameFT"].ToString(), DetailUrl = dr["DetailUrl"].ToString(), ImagePath = dr["ImagePath"].ToString(), CategoryId = QT.Entities.Common.Obj2Int(dr["CategoryID"]), ContentFT = dr["ContentFT"].ToString() + " " + Tools.removeHTML(dr["ProductContent"].ToString()), ViewCount = QT.Entities.Common.Obj2Int(dr["ViewCount"]), AddPosition = QT.Entities.Common.Obj2Int(dr["AddPosition"]) }; ls.Add(item); count++; } catch (Exception) { } if (count == 1000) { try { SolrDriver.IndexProducts(ls); SolrDriver.Commit(); count = 0; ls = new List <SolrProductItem>(); this.Invoke((MethodInvoker) delegate { this.laMess1.Text = String.Format("Update solr {0}/{1} Company {2}", i, dtProduct.Rows.Count, drCom.Domain.ToString()); }); } catch (Exception) { } } } try { SolrDriver.IndexProducts(ls); SolrDriver.Commit(); this.Invoke((MethodInvoker) delegate { this.laMess1.Text = String.Format("Update Finish Company {0} ", drCom.Domain.ToString()); }); } catch (Exception) { } adtCom.UpdateQuery_LastUpdateSolr(DateTime.Now, drCom.ID); } //var products = SolrDriver.SearchProducts(SolrDriver.SortCategory.SortByPriceIncrease, 1, 20, 100000, 10000000, "may tinh", // "c100,x430"); dtProduct.Dispose(); dtCom.Dispose(); adtProduct.Dispose(); adtCom.Dispose(); }
public static bool DoUpdateSolrIndex(int categoryID, string connProductString, string solrUrl) { DBTool.CompanyDataTable dtCom = new DBTool.CompanyDataTable(); DBToolTableAdapters.CompanyTableAdapter adtCom = new DBToolTableAdapters.CompanyTableAdapter(); adtCom.Connection.ConnectionString = connProductString; DBTool2.Product_SolrDataTable dtProduct = new DBTool2.Product_SolrDataTable(); DBTool2TableAdapters.Product_SolrTableAdapter adtProduct = new DBTool2TableAdapters.Product_SolrTableAdapter(); adtProduct.Connection.ConnectionString = connProductString; adtCom.FillBy_WebsiteCoSanPham(dtCom); SolrDriver.Init(solrUrl); int x = 0; foreach (DBTool.CompanyRow drCom in dtCom) { x++; try { adtProduct.FillBy_CompanyAndCategory(dtProduct, drCom.ID, categoryID); } catch (Exception) { } SolrDriver.DeleteByCompanyId(drCom.ID); int count = 0; List <SolrProductItem> ls = new List <SolrProductItem>(); for (int i = 0; i < dtProduct.Rows.Count; i++) { DataRow dr = dtProduct.Rows[i]; try { SolrProductItem item = new SolrProductItem { Id = QT.Entities.Common.Obj2Int64(dr["ID"]), Price = QT.Entities.Common.Obj2Int(dr["Price"]), Warranty = QT.Entities.Common.Obj2Int(dr["Warranty"]), Status = QT.Entities.Common.Obj2Int(dr["Status"]), Company = QT.Entities.Common.Obj2Int64(dr["Company"]), LastUpdate = QT.Entities.Common.ObjectToDataTime(dr["LastUpdate"]), Summary = dr["Summary"].ToString(), Description = "", ProductId = QT.Entities.Common.Obj2Int(dr["ProductID"]), ProductType = 2, Name = dr["Name"].ToString(), NameFT = dr["NameFT"].ToString(), DetailUrl = dr["DetailUrl"].ToString(), ImagePath = dr["ImagePath"].ToString(), CategoryId = QT.Entities.Common.Obj2Int(dr["CategoryID"]), ContentFT = dr["ContentFT"].ToString() + " " + Tools.removeHTML(dr["ProductContent"].ToString()), ViewCount = QT.Entities.Common.Obj2Int(dr["ViewCount"]), AddPosition = QT.Entities.Common.Obj2Int(dr["AddPosition"]), StringFilterFields = new Dictionary <string, object>(), DoubleFilterFields = new Dictionary <string, object>(), DateTimeFilterFields = new Dictionary <string, object>(), IntFilterFields = new Dictionary <string, object>() }; for (int exIndex = 1; exIndex <= 10; exIndex++) { string filterPropertyName = QT.Entities.Common.Obj2String(dr["EX" + exIndex]); string filterPropertyValue = QT.Entities.Common.Obj2String(dr["EXVALUE" + exIndex]); if (!string.IsNullOrEmpty(filterPropertyName) && !string.IsNullOrEmpty(filterPropertyValue)) { try { if (filterPropertyValue.StartsWith("number:")) { double filterDoubleValue; string filterIDAndValue = filterPropertyValue.Substring(7); string filterValueID = filterIDAndValue.Substring(0, filterIDAndValue.IndexOf(":")); string filterValue = filterIDAndValue.Length > filterValueID.Length + 1 ? filterIDAndValue.Substring(filterValueID.Length + 1) : ""; item.IntFilterFields.Add(filterPropertyName + "_id", filterValueID); if (Double.TryParse(filterValue, out filterDoubleValue)) { item.DoubleFilterFields.Add(filterPropertyName, filterDoubleValue); } } else { string filterValueID = filterPropertyValue.Substring(0, filterPropertyValue.IndexOf(":")); string filterValue = filterPropertyValue.Length > filterValueID.Length + 1 ? filterPropertyValue.Substring(filterValueID.Length + 1) : ""; item.IntFilterFields.Add(filterPropertyName + "_id", filterValueID); item.StringFilterFields.Add(filterPropertyName, filterValue); } } catch (Exception ex) { throw ex; } } } ls.Add(item); count++; } catch (Exception oex) { } if (count == 1000) { try { SolrDriver.IndexProducts(ls); SolrDriver.Commit(); count = 0; ls = new List <SolrProductItem>(); } catch (Exception) { } } } try { SolrDriver.IndexProducts(ls); SolrDriver.Commit(); } catch (Exception) { } adtCom.UpdateQuery_LastUpdateSolr(DateTime.Now, drCom.ID); } //var products = SolrDriver.SearchProducts(SolrDriver.SortCategory.SortByPriceIncrease, 1, 20, 100000, 10000000, "may tinh", // "c100,x430"); dtProduct.Dispose(); dtCom.Dispose(); adtProduct.Dispose(); adtCom.Dispose(); return(true); }