コード例 #1
0
        private void UpdateItems(IndexDataSource dataSource, string tableName, string primaryKeyName)
        {
            UpdateHealth();

            if (dataSource.UpdatedItems.Count < 1)
            {
                return;
            }

            string updateSql = "UPDATE " + tableName + " SET NeedsIndexing = 0 WHERE " + primaryKeyName + " IN (" + DataUtils.IntArrayToCommaString(dataSource.UpdatedItems.ToArray()) + ")";

            LogVerbose(updateSql);
            SqlCommand command = new SqlCommand();

            command.CommandText = updateSql;
            command.CommandType = System.Data.CommandType.Text;

            SqlExecutor.ExecuteNonQuery(LoginUser, command);
            LogVerbose(tableName + " Indexes Statuses UPdated");
        }
コード例 #2
0
        private void ProcessIndex(Organization organization, ReferenceType referenceType, bool isRebuilder)
        {
            if (IsStopped)
            {
                return;
            }
            string indexPath = string.Empty;
            string deletedIndexItemsFileName = string.Empty;
            string storedFields   = string.Empty;
            string tableName      = string.Empty;
            string primaryKeyName = string.Empty;

            IndexDataSource indexDataSource = null;
            int             maxRecords      = Settings.ReadInt("Max Records", 1000);

            switch (referenceType)
            {
            case ReferenceType.Tickets:
                indexPath = "\\Tickets";
                deletedIndexItemsFileName = "DeletedTickets.txt";
                storedFields    = "TicketID OrganizationID TicketNumber Name IsKnowledgeBase Status Severity DateModified DateCreated DateClosed SlaViolationDate SlaWarningDate";
                tableName       = "Tickets";
                primaryKeyName  = "TicketID";
                indexDataSource = new TicketIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            case ReferenceType.Wikis:
                indexPath = "\\Wikis";
                deletedIndexItemsFileName = "DeletedWikis.txt";
                storedFields    = "OrganizationID Creator Modifier";
                tableName       = "WikiArticles";
                primaryKeyName  = "ArticleID";
                indexDataSource = new WikiIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            case ReferenceType.Notes:
                indexPath = "\\Notes";
                deletedIndexItemsFileName = "DeletedNotes.txt";
                tableName       = "Notes";
                primaryKeyName  = "NoteID";
                indexDataSource = new NoteIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            case ReferenceType.ProductVersions:
                indexPath = "\\ProductVersions";
                deletedIndexItemsFileName = "DeletedProductVersions.txt";
                tableName       = "ProductVersions";
                primaryKeyName  = "ProductVersionID";
                indexDataSource = new ProductVersionIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            case ReferenceType.WaterCooler:
                indexPath = "\\WaterCooler";
                deletedIndexItemsFileName = "DeletedWaterCoolerMessages.txt";
                tableName       = "WatercoolerMsg";
                primaryKeyName  = "MessageID";
                indexDataSource = new WaterCoolerIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            case ReferenceType.Organizations:
                indexPath = "\\Customers";
                deletedIndexItemsFileName = "DeletedCustomers.txt";
                storedFields    = "Name JSON";
                tableName       = "Organizations";
                primaryKeyName  = "OrganizationID";
                indexDataSource = new CustomerIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            case ReferenceType.Contacts:
                indexPath = "\\Contacts";
                deletedIndexItemsFileName = "DeletedContacts.txt";
                storedFields    = "Name JSON";
                tableName       = "Users";
                primaryKeyName  = "UserID";
                indexDataSource = new ContactIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            case ReferenceType.Assets:
                indexPath = "\\Assets";
                deletedIndexItemsFileName = "DeletedAssets.txt";
                storedFields    = "Name JSON";
                tableName       = "Assets";
                primaryKeyName  = "AssetID";
                indexDataSource = new AssetIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            case ReferenceType.Products:
                indexPath = "\\Products";
                deletedIndexItemsFileName = "DeletedProducts.txt";
                storedFields    = "Name JSON";
                tableName       = "Products";
                primaryKeyName  = "ProductID";
                indexDataSource = new ProductIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            case ReferenceType.Tasks:
                indexPath = "\\Tasks";
                deletedIndexItemsFileName = "DeletedTasks.txt";
                storedFields    = "Name JSON";
                tableName       = "Tasks";
                primaryKeyName  = "TaskID";
                indexDataSource = new TaskIndexDataSource(LoginUser, maxRecords, organization.OrganizationID, tableName, isRebuilder, Logs);
                break;

            default:
                throw new System.ArgumentException("ReferenceType " + referenceType.ToString() + " is not supported by indexer.");
            }
            string root          = Settings.ReadString("Tickets Index Path", "c:\\Indexes");
            string mainIndexPath = Path.Combine(root, organization.OrganizationID.ToString() + indexPath);

            if (isRebuilder)
            {
                indexPath = "\\Rebuild" + indexPath;
            }
            string path = Path.Combine(Settings.ReadString("Tickets Index Path", "c:\\Indexes"), organization.OrganizationID.ToString() + indexPath);

            LogVerbose("Path: " + path);

            bool isNew = !System.IO.Directory.Exists(path);

            if (isNew)
            {
                Directory.CreateDirectory(path);
                LogVerbose("Creating path: " + path);
            }

            if (isRebuilder)
            {
                DeleteIndex(path);
            }

            try
            {
                if (!isRebuilder && !organization.IsRebuildingIndex)
                {
                    RemoveOldIndexItems(LoginUser, path, organization, referenceType, deletedIndexItemsFileName);
                }
            }
            catch (Exception ex)
            {
                Logs.WriteException(ex);
                ExceptionLogs.LogException(LoginUser, ex, "Indexer.RemoveOldIndexItems - " + referenceType.ToString() + " - " + organization.OrganizationID.ToString());
            }

            string noiseFile = Path.Combine(root, "noise.dat");

            if (!File.Exists(noiseFile))
            {
                File.Create(noiseFile).Dispose();
            }

            Options options = new Options();

            options.TextFlags     = TextFlags.dtsoTfRecognizeDates;
            options.NoiseWordFile = noiseFile;
            options.Save();
            LogVerbose("Processing " + tableName);
            using (IndexJob job = new IndexJob())
            {
                job.DataSourceToIndex = indexDataSource;

                job.IndexPath           = path;
                job.ActionCreate        = isNew || isRebuilder;
                job.ActionAdd           = true;
                job.CreateRelativePaths = false;
                job.StoredFields        = Server.Tokenize(storedFields);
                job.IndexingFlags       = IndexingFlags.dtsAlwaysAdd;
                //string tempPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "TempIndexFiles" + indexPath);
                //if (!Directory.Exists(tempPath)) Directory.CreateDirectory(tempPath);
                //job.TempFileDir = tempPath;
                bool doCompress = false;
                if (_threadPosition % 2 == 0 && (DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday))
                {
                    IndexInfo info = new IndexInfo();
                    info = IndexJob.GetIndexInfo(path);
                    LogVerbose("Info - Doc Count:" + info.DocCount.ToString());
                    LogVerbose("Info - Obsolete:" + info.ObsoleteCount.ToString());

                    doCompress = (info.ObsoleteCount / info.DocCount) > 0.2;
                    if (doCompress)
                    {
                        job.ActionCompress = true;
                        job.ActionVerify   = true;
                        LogVerbose("Compressing");
                    }
                }

                try
                {
                    job.ExecuteInThread();

                    // Monitor the job execution thread as it progresses
                    IndexProgressInfo status = new IndexProgressInfo();
                    while (job.IsThreadDone(1000, status) == false)
                    {
                        if (IsStopped)
                        {
                            job.AbortThread();
                        }
                    }
                }
                catch (Exception ex)
                {
                    ExceptionLogs.LogException(LoginUser, ex, "Index Job Processor - " + referenceType.ToString() + " - " + organization.OrganizationID.ToString());
                    Logs.WriteException(ex);
                    throw;
                }

                if (doCompress)
                {
                    IndexInfo info = new IndexInfo();
                    info = IndexJob.GetIndexInfo(path);
                    LogVerbose("Compressed");
                    LogVerbose("Info - Doc Count:" + info.DocCount.ToString());
                    LogVerbose("Info - Obsolete:" + info.ObsoleteCount.ToString());
                }

                if (!IsStopped)
                {
                    if (!isRebuilder)
                    {
                        Organization tempOrg = Organizations.GetOrganization(_loginUser, organization.OrganizationID);
                        if (!tempOrg.IsRebuildingIndex)
                        {
                            UpdateItems(indexDataSource, tableName, primaryKeyName);
                        }
                    }
                    else
                    {
                        MoveRebuiltIndex(organization.OrganizationID, mainIndexPath, path);
                    }
                }
            }
        }