Example #1
0
 private void btnClearIndex_Click(object sender, EventArgs e)
 {
     if (LuceneIndex.ClearLuceneIndex())
     {
         MessageBox.Show("Search index was cleared successfully!");
     }
     else
     {
         MessageBox.Show("Index is locked and cannot be cleared, try again later or clear manually!");
     }
 }
        public override async Task RunAsync()
        {
            if (this.IsShuttingDown || this.Pause)
            {
                return;
            }

            LuceneIndex.ClearLuceneIndex();

            var productService = IoC.Container.GetInstance <IProductService>();
            var postService    = IoC.Container.GetInstance <IPostService>();

            foreach (var product in await productService.GetAllForLuceneIndex())
            {
                LuceneIndex.ClearLuceneIndexRecord(product.Id);
                LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
                {
                    ProductId     = product.Id,
                    Title         = product.Title,
                    Image         = product.Image,
                    Description   = product.Description.RemoveHtmlTags(),
                    Category      = "کالا‌ها",
                    SlugUrl       = product.SlugUrl,
                    Price         = product.Price.ToString(CultureInfo.InvariantCulture),
                    ProductStatus = product.ProductStatus.ToString()
                });
            }

            foreach (var post in await postService.GetAllForLuceneIndex())
            {
                LuceneIndex.ClearLucenePostIndexRecord(post.Id);
                LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
                {
                    PostId      = post.Id,
                    Title       = post.Title,
                    Image       = post.Image,
                    Description = post.Description.RemoveHtmlTags(),
                    Category    = post.Category,
                    SlugUrl     = post.SlugUrl
                });
            }
        }
        public virtual async Task <ActionResult> ReIndex()
        {
            LuceneIndex.ClearLuceneIndex();

            var productService = IoC.Container.GetInstance <IProductService>();
            var postService    = IoC.Container.GetInstance <IPostService>();

            foreach (var product in await productService.GetAllForLuceneIndex())
            {
                LuceneIndex.ClearLuceneIndexRecord(product.Id);
                LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
                {
                    ProductId     = product.Id,
                    Title         = product.Title,
                    Image         = product.Image,
                    Description   = product.Description.RemoveHtmlTags(),
                    Category      = "کالا‌ها",
                    SlugUrl       = product.SlugUrl,
                    Price         = product.Price.ToString(CultureInfo.InvariantCulture),
                    ProductStatus = product.ProductStatus.ToString()
                });
            }

            foreach (var post in await postService.GetAllForLuceneIndex())
            {
                LuceneIndex.ClearLucenePostIndexRecord(post.Id);
                LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
                {
                    PostId      = post.Id,
                    Title       = post.Title,
                    Image       = post.Image,
                    Description = post.Description.RemoveHtmlTags(),
                    Category    = post.Category,
                    SlugUrl     = post.SlugUrl
                });
            }
            return(Content("ReIndexing Complete."));
        }