Exemplo n.º 1
0
        private void InitData()
        {
            try
            {
                RaoVatSQLAdapter raovat = new RaoVatSQLAdapter(new SqlDb(QT.Entities.Server.ConnectionStringCrawler));
                this.CboWebSiteID.DataSource    = raovat.GetTblWebSite();
                this.CboWebSiteID.ValueMember   = "id";
                this.CboWebSiteID.DisplayMember = "domain";

                string Webdomain      = "raovat";
                string URLSolrConnect = "http://118.70.205.94:9104/solr/raovat";
                slr = SolrRaoVatDriver.GetDriver(null);

                this.LoadEventCheckRegex(new RichTextBox[] {
                    this.NoProductUrlRegexTextBox,
                    this.noVisitUrlsRegexTextBox,
                    this.ProductUrlsRegexTextBox,
                    this.visitUrlsRegexTextBox
                });

                this.LoadEventCheckXPaths(new RichTextBox[] {
                    this.PhoneSalerXPathsTextBox,
                    this.AddressXPathsTextBox,
                    this.AvaiableXPathsTextBox,
                    this.QualityXPathsTextBox,
                    this.ImageUrlsXPathsTextBox,
                    this.LastChangeXPathsTextBox,
                    this.PostDateXPathsTextBox,
                    this.PriceXPathsTextBox,
                    this.ProvinceXPathsTextBox,
                    this.UserNameXPathsTextBox,
                    this.TitleXPathsTextBox,
                    this.ContentXPathTextbox,
                    this.txtTagXPaths,
                    this.webCategoryXPathsTextBox,
                    this.txtLastEditXPaths
                });

                this.factoryMQ     = new ConnectionFactory();
                factoryMQ.UserName = QT.Entities.Server.RabbitMQ_User;
                factoryMQ.Password = QT.Entities.Server.RabbitMQ_Pass;
                factoryMQ.Protocol = Protocols.DefaultProtocol;
                factoryMQ.HostName = QT.Entities.Server.RabbitMQ_Host;
                factoryMQ.Port     = QT.Entities.Server.RabbitMQ_Port;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void btnRemoveSolr_Click(object sender, EventArgs e)
        {
            try
            {
                string Webdomain      = "raovat";
                string URLSolrConnect = "http://118.70.205.94:9104/solr/raovat";

                var    slr   = SolrRaoVatDriver.GetDriver(null);
                string query = "is_crawled:1 AND is_standard:1";
                bool   bOK   = slr.RunQuery(query);
                slr.Commit();
                MessageBox.Show("Sucsses!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        private void SyncProductMongoAndSolr(int iLimit)
        {
            int iCount = 0;

            while (!bPause)
            {
                try
                {
                    var                   slr     = SolrRaoVatDriver.GetDriver(SolrRaoVatDriver.GetInstance());
                    MongoDbRaoVat         mongoDb = new MongoDbRaoVat();
                    List <ProductSaleNew> lstKeywordNeedUpdate = mongoDb.GetListProductNeedUpdate(iLimit);
                    foreach (var item in lstKeywordNeedUpdate)
                    {
                        bool bDelData = false;

                        if (item.status != 1)
                        {
                            slr.DeleteByQuery(string.Format("_id:{0}", item._id));
                            bDelData = true;
                        }
                        else
                        {
                            if (item.category_ids.Contains(14))
                            {
                                bool bOK = slr.IndexItems(new List <ProductSaleNew>()
                                {
                                    item
                                });
                                bDelData = false;
                            }
                        }

                        long iOK = mongoDb.colProduct.UpdateOneAsync(Builders <BsonDocument> .Filter.Eq("_id", ObjectId.Parse(item._id))
                                                                     , Builders <BsonDocument> .Update.Set("is_solr_updated", true)
                                                                     .CurrentDate("solr_updated_at")).Result.ModifiedCount;

                        if (iOK > 0)
                        {
                            iCount++;
                            WriteLog(string.Format("PushToSolr {2} product {0}: {1}. Id:{3}", iCount
                                                   , item.name
                                                   , (bDelData) ? "Deleted" : "Updated"
                                                   , item._id));
                        }
                    }

                    WriteLog("SoftCommit");
                    slr.SoftCommit();
                    WriteLog("SoftCommit Sucess");

                    WriteLog("Sleep 5 s continute...");
                    Thread.Sleep(5000);
                }
                catch (ThreadAbortException threadAbortEx)
                {
                    return;
                }
                catch (Exception ex)
                {
                    WriteLog(string.Format("Exception:{0}", ex.Message));
                    log.ErrorFormat(ex.Message);
                    Thread.Sleep(1000);
                }
            }
        }