IndexService.cs :  » Content-Management-Systems-CMS » Kooboo » Everest » CmsServices » Search » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » Kooboo 
Kooboo » Everest » CmsServices » Search » IndexService.cs
/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using Microsoft.Data.Extensions;

using Everest.Library;
using Everest.Library.Data;
using Everest.Library.Data.Entity;
using Everest.Library.HealthMonitor;

using Everest.CmsServices.Models;
using Everest.CmsServices.Services;

using Everest.Search;
namespace Everest.CmsServices.Search{
    public class IndexService
    {
        //const string SelectDeleted_SQL = "SELECT distinct ContentUUID FROM Cms_IndexTrigger WHERE [Action]=2";
        //const string SelectChanged_SQL = "SELECT TOP 1000 ContentUUID FROM Cms_IndexTrigger WHERE [Action]<>2 ORDER BY ChangedDate DESC";
        const string DeleteChanged_SQL = "DELETE FROM Cms_IndexTrigger WHERE {0}";
        //const string SelectAllCount = "SELECT COUNT(*) FROM Cms_IndexTrigger";
        /// <summary>
        /// build index. 
        /// </summary>
        public virtual void Indexing()
        {
            //could not use   IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
            IEverestCmsDataContext dataContext = EverestCmsEntities.CreateDataContext(false);

            try
            {
                var indexed = new List<Guid>();
                try
                {
                    using (IIndexer index = new LuceneIndexer())
                    {
                        index.Open(typeof(SearchedContent), CmsGlobal.IndexDirectory, "ContentUUID", new ContentConvertor(), false);

                        //delete
                        var deleteIndex = dataContext.Cms_IndexTrigger.Where(it => it.Action == 2).Select(it => it.ContentUUID).Distinct();
                        foreach (var item in deleteIndex)
                        {
                            try
                            {
                                DeleteDocument(dataContext, index, item);

                                indexed.Add(item);
                            }
                            catch (Exception e)
                            {
                                HealthMonitoringLogging.LogError(e);
                            }
                        }

                        //update
                        var textContentService = UnityManager.Resolve<TextContentService>();
                        var updateIndex = dataContext.Cms_IndexTrigger.Where(it => it.Action != 2).Select(it => it.ContentUUID).Distinct();
                        foreach (var item in updateIndex)
                        {
                            try
                            {
                                SearchedContent searchedContent = textContentService.GetContentForIndex(item);
                                if (searchedContent == null)
                                {
                                    DeleteDocument(dataContext, index, item);
                                }
                                else
                                {
                                    index.UpdateDocument(searchedContent);

                                }

                                indexed.Add(item);
                            }
                            catch (Exception e)
                            {
                                HealthMonitoringLogging.LogError(e);
                            }
                        }

                        index.Close();
                    }
                }
                finally
                {
                    DeleteChanged(dataContext, indexed);
                }
            }
            catch (Exception e)
            {
                HealthMonitoringLogging.LogError(e);
            }

        }

        private void DeleteDocument(IEverestCmsDataContext dataContext, IIndexer index, Guid contentUUID)
        {
            index.DeleteDocument(contentUUID.ToString());
        }
        private void DeleteChanged(IEverestCmsDataContext dataContext, IEnumerable<Guid> contentUUID)
        {
            StringBuilder stringBuilder = new StringBuilder("1 <> 1");
            foreach (var guid in contentUUID)
            {
                stringBuilder.AppendFormat(" OR ContentUUID = '{0}'", guid);
            }

            DbCommand dbCommand = dataContext.ObjectContext.CreateStoreCommand(string.Format(DeleteChanged_SQL, stringBuilder.ToString()));

            using (dbCommand.Connection.CreateConnectionScope())
            {
                dbCommand.ExecuteNonQuery();
            }
        }
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.