Esempio n. 1
0
        private int Index(IndexWriter writer, int start, int end, String lng)
        {
            #if DEBUG
            T.TraceMessage("Begin indexing from {0} to {1}, language {2}, time: {3}", start, end, lng, DateTime.Now.ToLongTimeString());
            #endif
            Document doc = null;
            Field field = null;
            Dictionary<string, IssueDocumentDto> list = new Dictionary<string, IssueDocumentDto>();

            try
            {

                list = new IssuesDao().GetIssuesIndexList(start, end, lng);

                foreach (KeyValuePair<string, IssueDocumentDto> pair in list)
                {
                    IssueDocumentDto bean = pair.Value;
                    doc = new Document();

                    doc.Add(new Field("issue_id", bean.IssueId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if(bean.CompanyId !=-1) doc.Add(new Field("company_id", bean.CompanyId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (bean.IssueIdPerCompany != -1) doc.Add(new Field("issue_per_company", bean.IssueIdPerCompany.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (bean.PriorityId != -1) doc.Add(new Field("priority_id", bean.PriorityId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (bean.StatusId != -1) doc.Add(new Field("status_id", bean.StatusId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (!string.IsNullOrEmpty(bean.CurrentOwner))  doc.Add(new Field("curr_owner", bean.CurrentOwner, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (!string.IsNullOrEmpty(bean.LastOwner)) doc.Add(new Field("last_owner", bean.LastOwner, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (!string.IsNullOrEmpty(bean.ProjectName)) doc.Add(new Field("project_name", bean.ProjectName, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));

                    if (bean.AssignedCUDate != DateTime.MinValue) doc.Add(new Field("assigned_cu_date", DateTools.DateToString(bean.AssignedCUDate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    if (bean.DestinationDate != DateTime.MinValue) doc.Add(new Field("destination_date", DateTools.DateToString(bean.DestinationDate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    if (!string.IsNullOrEmpty(bean.DescLast)) doc.Add(new Field("desc_last", bean.DescLast, Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    if (bean.ReadUsersBitIds1 != -1) doc.Add(new Field("read_usr_bit1", bean.ReadUsersBitIds1.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (bean.ReadUsersBitIds2 != -1) doc.Add(new Field("read_usr_bit1", bean.ReadUsersBitIds2.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (bean.LastUpdate != DateTime.MinValue) doc.Add(new Field("last_update", DateTools.DateToString(bean.LastUpdate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    if (bean.StartDate != DateTime.MinValue) doc.Add(new Field("start_date", DateTools.DateToString(bean.StartDate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    if(bean.IsAllDay) doc.Add(new Field("is_all_day", "1", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    else doc.Add(new Field("is_all_day", "0", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (bean.DestReminderDate != DateTime.MinValue) doc.Add(new Field("dest_rem_date", DateTools.DateToString(bean.DestReminderDate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    if (bean.ReccurenceId != -1) doc.Add(new Field("reccurence_id", bean.ReccurenceId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));

                    writer.AddDocument(doc);
                }

                writer.Optimize();
            }
            catch (Exception ex)
            {
                T.TraceError("Error Index (start: {1}, end: {2}, language {3}), class {0} ", CLASS_NAME, start, end, lng);
                T.TraceError(ex);
                throw ex;
            }
            return list.Count;
        }
Esempio n. 2
0
        /// <summary>
        /// Update Index by Language
        /// </summary>
        /// <param name="indexDir"></param>
        /// <param name="lng"></param>
        /// <returns></returns>
        public void UpdateIndex(Lucene.Net.Store.Directory indexDir, String lng)
        {
#if DEBUG
            T.TraceMessage("Begin full indexing , language {0}, time: {1}", lng, DateTime.Now.ToLongTimeString());
#endif
            IndexWriter writer   = null;
            int         step     = 1000;
            int         totalDoc = 0;

            try
            {
                DateTime beginTime = DateTime.Now;
                int      num = 0, numPar = 0;

                num = new IssuesDao().GetTotalPublicationByLanguage(lng);


                if (IndexWriter.IsLocked(indexDir))
                {
                    IndexWriter.Unlock(indexDir);
                }
                writer = new IndexWriter(indexDir, this.Analizer, true, new IndexWriter.MaxFieldLength(2500000));

                // change number of documents to store in memory before writing them to the disk
                //writer.SetMergeFactor();
                if (num != 0)
                {
                    if (step >= num)
                    {
                        long ini = DateTime.Now.Millisecond;
                        totalDoc = Index(writer, 1, num, lng);
                        long fin = DateTime.Now.Millisecond;
                    }
                    else
                    {
                        int numStep = (num / step);
                        int cont    = 1;
                        int start   = 0;
                        int end     = 0;

                        for (int i = 0; i < numStep; i++)
                        {
                            start = (cont + (i * step));
                            end   = start + step;
                            DateTime ini = DateTime.Now;

                            numPar = Index(writer, start, end, lng);

                            DateTime fin = DateTime.Now;
                            TimeSpan ts  = fin.Subtract(ini);

#if DEBUG
                            T.TraceMessage("Indexing from {0} to {1} took {2} seconds", start, end, (ts.Minutes * 60 + ts.Seconds));
#endif
                        }

                        if (num != end)
                        {
                            start = end;
                            end   = num;

                            numPar = Index(writer, start, end + 1, lng);
                        }
                    }
                }
                DateTime endTime = DateTime.Now;
                TimeSpan tsFull  = endTime.Subtract(beginTime);

                //Commit writer
                writer.Commit();
                writer.Dispose();

#if DEBUG
                T.TraceMessage("Full indexing took {0} seconds, indexed {1} documents", ((tsFull.Hours * 3600) + (tsFull.Minutes * 60) + tsFull.Seconds), writer.MaxDoc());
#endif
            }
            catch (Exception ex)
            {
                if (writer != null)
                {
                    writer.Optimize();
                    writer.Commit();
                    writer.Dispose();
                }
                T.TraceError("Error Full Index , class {0}, language {1} ", CLASS_NAME, lng);
                T.TraceError(ex);
                throw ex;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Update Index by Language
        /// </summary>
        /// <param name="indexDir"></param>
        /// <param name="lng"></param>
        /// <returns></returns>
        public void UpdateIndex(Lucene.Net.Store.Directory indexDir, String lng)
        {
            #if DEBUG
            T.TraceMessage("Begin full indexing , language {0}, time: {1}", lng, DateTime.Now.ToLongTimeString());
            #endif
            IndexWriter writer = null;
            int step = 1000;
            int totalDoc = 0;

            try
            {
                DateTime beginTime = DateTime.Now;
                int num = 0, numPar = 0;

                num = new IssuesDao().GetTotalPublicationByLanguage(lng);

                if (IndexWriter.IsLocked(indexDir))
                    IndexWriter.Unlock(indexDir);
                writer = new IndexWriter(indexDir, this.Analizer, true, new IndexWriter.MaxFieldLength(2500000));

                // change number of documents to store in memory before writing them to the disk
                //writer.SetMergeFactor();
                if (num != 0)
                {
                    if (step >= num)
                    {
                        long ini = DateTime.Now.Millisecond;
                        totalDoc = Index(writer, 1, num, lng);
                        long fin = DateTime.Now.Millisecond;
                    }
                    else
                    {
                        int numStep = (num / step);
                        int cont = 1;
                        int start = 0;
                        int end = 0;

                        for (int i = 0; i < numStep; i++)
                        {
                            start = (cont + (i * step));
                            end = start + step;
                            DateTime ini = DateTime.Now;

                            numPar = Index(writer, start, end, lng);

                            DateTime fin = DateTime.Now;
                            TimeSpan ts = fin.Subtract(ini);

            #if DEBUG
                            T.TraceMessage("Indexing from {0} to {1} took {2} seconds", start, end, (ts.Minutes * 60 + ts.Seconds));
            #endif
                        }

                        if (num != end)
                        {
                            start = end;
                            end = num;

                            numPar = Index(writer, start, end + 1, lng);
                        }
                    }
                }
                DateTime endTime = DateTime.Now;
                TimeSpan tsFull = endTime.Subtract(beginTime);

                //Commit writer
                writer.Commit();
                writer.Dispose();

            #if DEBUG
                T.TraceMessage("Full indexing took {0} seconds, indexed {1} documents", ((tsFull.Hours * 3600) + (tsFull.Minutes * 60) + tsFull.Seconds), writer.MaxDoc());
            #endif
            }
            catch (Exception ex)
            {
                if (writer != null)
                {
                    writer.Optimize();
                    writer.Commit();
                    writer.Dispose();
                }
                T.TraceError("Error Full Index , class {0}, language {1} ", CLASS_NAME, lng);
                T.TraceError(ex);
                throw ex;
            }
        }
Esempio n. 4
0
        private int Index(IndexWriter writer, int start, int end, String lng)
        {
#if DEBUG
            T.TraceMessage("Begin indexing from {0} to {1}, language {2}, time: {3}", start, end, lng, DateTime.Now.ToLongTimeString());
#endif
            Document doc   = null;
            Field    field = null;
            Dictionary <string, IssueDocumentDto> list = new Dictionary <string, IssueDocumentDto>();

            try
            {
                list = new IssuesDao().GetIssuesIndexList(start, end, lng);


                foreach (KeyValuePair <string, IssueDocumentDto> pair in list)
                {
                    IssueDocumentDto bean = pair.Value;
                    doc = new Document();

                    doc.Add(new Field("issue_id", bean.IssueId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    if (bean.CompanyId != -1)
                    {
                        doc.Add(new Field("company_id", bean.CompanyId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    if (bean.IssueIdPerCompany != -1)
                    {
                        doc.Add(new Field("issue_per_company", bean.IssueIdPerCompany.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    if (bean.PriorityId != -1)
                    {
                        doc.Add(new Field("priority_id", bean.PriorityId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    if (bean.StatusId != -1)
                    {
                        doc.Add(new Field("status_id", bean.StatusId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    if (!string.IsNullOrEmpty(bean.CurrentOwner))
                    {
                        doc.Add(new Field("curr_owner", bean.CurrentOwner, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    if (!string.IsNullOrEmpty(bean.LastOwner))
                    {
                        doc.Add(new Field("last_owner", bean.LastOwner, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    if (!string.IsNullOrEmpty(bean.ProjectName))
                    {
                        doc.Add(new Field("project_name", bean.ProjectName, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }

                    if (bean.AssignedCUDate != DateTime.MinValue)
                    {
                        doc.Add(new Field("assigned_cu_date", DateTools.DateToString(bean.AssignedCUDate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    }
                    if (bean.DestinationDate != DateTime.MinValue)
                    {
                        doc.Add(new Field("destination_date", DateTools.DateToString(bean.DestinationDate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    }
                    if (!string.IsNullOrEmpty(bean.DescLast))
                    {
                        doc.Add(new Field("desc_last", bean.DescLast, Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    }
                    if (bean.ReadUsersBitIds1 != -1)
                    {
                        doc.Add(new Field("read_usr_bit1", bean.ReadUsersBitIds1.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    if (bean.ReadUsersBitIds2 != -1)
                    {
                        doc.Add(new Field("read_usr_bit1", bean.ReadUsersBitIds2.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    if (bean.LastUpdate != DateTime.MinValue)
                    {
                        doc.Add(new Field("last_update", DateTools.DateToString(bean.LastUpdate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    }
                    if (bean.StartDate != DateTime.MinValue)
                    {
                        doc.Add(new Field("start_date", DateTools.DateToString(bean.StartDate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    }
                    if (bean.IsAllDay)
                    {
                        doc.Add(new Field("is_all_day", "1", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    else
                    {
                        doc.Add(new Field("is_all_day", "0", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }
                    if (bean.DestReminderDate != DateTime.MinValue)
                    {
                        doc.Add(new Field("dest_rem_date", DateTools.DateToString(bean.DestReminderDate, DateTools.Resolution.DAY), Lucene.Net.Documents.Field.Store.NO, Lucene.Net.Documents.Field.Index.ANALYZED));
                    }
                    if (bean.ReccurenceId != -1)
                    {
                        doc.Add(new Field("reccurence_id", bean.ReccurenceId.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NO));
                    }


                    writer.AddDocument(doc);
                }

                writer.Optimize();
            }
            catch (Exception ex)
            {
                T.TraceError("Error Index (start: {1}, end: {2}, language {3}), class {0} ", CLASS_NAME, start, end, lng);
                T.TraceError(ex);
                throw ex;
            }
            return(list.Count);
        }