Exemple #1
0
        public void ReIndex()
        {
            writerInUse = true;
            using (var repository = new TradelrRepository())
            {
                // get subdomains
                var subdomains = repository.GetSubDomains();
                foreach (var subdomain in subdomains)
                {
                    // index contacts
                    writer = CreateWriter(LuceneIndexType.CONTACTS, subdomain.name);
                    if (writer != null)
                    {
                        var contacts = repository.GetAllContacts(subdomain.id);
                        foreach (var contact in contacts)
                        {
                            try
                            {
                                var action = new ContactItem(contact);
                                var doc    = IndexContact(action);
                                writer.AddDocument(doc);
                            }
                            catch (Exception ex)
                            {
                                Syslog.Write(ex);
                            }
                        }
                        writer.Optimize();
                        CloseWriter();
                    }

                    // index products
                    writer = CreateWriter(LuceneIndexType.PRODUCTS, subdomain.name);
                    if (writer != null)
                    {
                        var products = repository.GetProducts(subdomain.id);
                        foreach (var product in products)
                        {
                            try
                            {
                                var action = new ProductItem(product);
                                var doc    = IndexProduct(action);
                                writer.AddDocument(doc);
                            }
                            catch (Exception ex)
                            {
                                Syslog.Write(ex);
                            }
                        }

                        writer.Optimize();
                        CloseWriter();
                    }


                    // orders
                    writer = CreateWriter(LuceneIndexType.TRANSACTION, subdomain.name);
                    if (writer != null)
                    {
                        MASTERsubdomain subdomain1 = subdomain;
                        var             orders     = repository.GetOrders().Where(x => x.user1.organisation1.subdomain == subdomain1.id);
                        foreach (var order in orders)
                        {
                            try
                            {
                                var acttion = new TransactionItem(order);
                                var doc     = IndexTransaction(acttion);
                                writer.AddDocument(doc);
                            }
                            catch (Exception ex)
                            {
                                Syslog.Write("Lucene index error: order ID =" + order.id);
                                Syslog.Write(ex);
                            }
                        }

                        writer.Optimize();
                        CloseWriter();
                    }
                }
            }
            writerInUse = false;
        }