예제 #1
0
        private void Delete(IndexRecord indexRecord)
        {
            IndexReader reader = Reader;

            if (reader == null)
            {
                return;
            }

            try
            {
                if (indexRecord.Uri != null)
                {
                    reader.DeleteDocuments(new Term(IndexRecord.URIFIELD, indexRecord.Uri));
                }
                else
                {
                    reader.DeleteDocuments(new Term(IndexRecord.ENTITYFIELD, indexRecord.Entity));
                }
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "Delete error", e);
            }
            finally
            {
                reader.Dispose();

                Searcher.Instance.Close();
            }
        }
예제 #2
0
        public bool InsertContent(Object obj, GxContentInfo contentInfo)
        {
            IndexRecord ir = GetIndexRecord(obj, contentInfo);

            if (ir != null)
            {
                Enqueue(new IndexAction(Action.Insert, ir));
            }
            return(true);
        }
예제 #3
0
        private void Insert(IndexRecord indexRecord)
        {
            IndexWriter writer = Writer;

            if (writer == null)
            {
                return;
            }

            try
            {
                Document doc = new Document();
                doc.Add(new Field(IndexRecord.URIFIELD, indexRecord.Uri, Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field(IndexRecord.ENTITYFIELD, indexRecord.Entity, Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field(IndexRecord.CONTENTFIELD, new StringReader(IndexRecord.ProcessContent(indexRecord.Content))));
#pragma warning disable CS0618 // Type or member is obsolete
                doc.Add(new Field(IndexRecord.TIMESTAMPFIELD, DateField.DateToString(DateTime.Now), Field.Store.YES, Field.Index.NO));
#pragma warning restore CS0618 // Type or member is obsolete

                doc.Add(new Field(IndexRecord.VIEWERFIELD, indexRecord.Viewer, Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field(IndexRecord.TITLEFIELD, indexRecord.Title, Field.Store.YES, Field.Index.NOT_ANALYZED));

                int i = 1;
                foreach (string key in indexRecord.Keys)
                {
                    doc.Add(new Field(string.Format("{0}{1}", IndexRecord.KEYFIELDPREFIX, (i++).ToString()), key, Field.Store.YES, Field.Index.NO));
                }

                GXLogging.Debug(log, "AddDocument:" + indexRecord.Uri + " content:" + indexRecord.Content);
                writer.AddDocument(doc, m_analyzer);
                if (m_counter++ > Settings.Instance.OptimizeThreshold)
                {
                    m_counter = 0;
                    GXLogging.Warn(log, "Optimizing index");
                    writer.Optimize();
                }
            }
            catch (Exception e)
            {
                GXLogging.Error(log, "Insert error", e);
            }
            finally
            {
                try {
                    writer.Dispose();

                    Searcher.Instance.Close();
                }
                catch (Exception ex)
                {
                    GXLogging.Error(log, "Close writer error", ex);
                }
            }
        }
예제 #4
0
        private IndexRecord GetIndexRecord(object obj, GxContentInfo contentInfo)
        {
            IndexRecord    ir     = null;
            GxFile         file   = obj as GxFile;
            GxSilentTrnSdt silent = obj as GxSilentTrnSdt;
            string         str    = obj as string;

            if (file != null && contentInfo != null)
            {
                ir         = new IndexRecord();
                ir.Uri     = file.GetAbsoluteName();
                ir.Content = DocumentHandler.GetText(file.GetAbsoluteName(), Path.GetExtension(file.GetAbsoluteName()));
                ir.Entity  = contentInfo.Entity == null?file.GetType().ToString() : contentInfo.Entity;

                ir.Title = contentInfo.Title == null?file.GetName() : contentInfo.Title;

                ir.Viewer = contentInfo.Viewer == null?file.GetName() : contentInfo.Viewer;

                ir.Keys = contentInfo.Keys == null || contentInfo.Keys.Count == 0 ? new List <string>() : contentInfo.Keys;
            }
            else if (silent != null)
            {
                IGxSilentTrn  bc   = (silent).getTransaction();
                GxContentInfo info = bc.GetContentInfo();
                if (info != null)
                {
                    ir         = new IndexRecord();
                    ir.Uri     = info.Id;
                    ir.Content = bc.ToString();
                    ir.Entity  = contentInfo.Entity == null ? info.Entity : contentInfo.Entity;
                    ir.Title   = contentInfo.Title == null ? info.Title : contentInfo.Title;
                    ir.Viewer  = contentInfo.Viewer == null ? info.Viewer : contentInfo.Viewer;
                    ir.Keys    = contentInfo.Keys == null || contentInfo.Keys.Count == 0 ? info.Keys : contentInfo.Keys;
                }
            }
            else if (str != null && contentInfo != null)
            {
                ir         = new IndexRecord();
                ir.Uri     = contentInfo.Id == null ? string.Empty : contentInfo.Id;
                ir.Content = str;
                ir.Entity  = contentInfo.Entity == null ? String.Empty : contentInfo.Entity;
                ir.Title   = contentInfo.Title == null ? String.Empty : contentInfo.Title;
                ir.Viewer  = contentInfo.Viewer == null ? String.Empty : contentInfo.Viewer;
                ir.Keys    = contentInfo.Keys == null || contentInfo.Keys.Count == 0 ? new List <string>() : contentInfo.Keys;
            }
            return(ir);
        }
예제 #5
0
        public SearchResult Search(string query, int itemsPerPage, int pageNumber, IGxContext context)
        {
            if (string.IsNullOrEmpty(query))
            {
                return(SearchResult.Empty);
            }
            if (context != null)
            {
                query = TranslateQuery(query, context);
            }

            IndexSearcher searcher = GetSearcher();

            if (searcher == null)
            {
                return(new EmptySearchResult());
            }

            try
            {
                QueryParser qp = new QueryParser(Indexer.LUCENE_VERSION, IndexRecord.CONTENTFIELD, m_analyzer);

                qp.AllowLeadingWildcard = true;
                qp.DefaultOperator      = QueryParser.Operator.AND;
                Query    q  = qp.Parse(IndexRecord.ProcessContent(query));
                DateTime t1 = DateTime.Now;

                TopDocs  results = searcher.Search(q, int.MaxValue);
                DateTime t2      = DateTime.Now;

                return(new LuceneSearchResult(results, itemsPerPage, pageNumber, TimeSpan.FromTicks(t2.Ticks - t1.Ticks).TotalMilliseconds));
            }
            catch (ParseException)
            {
                GXLogging.Error(log, "Search error", new SearchException(SearchException.PARSEERROR));
                return(SearchResult.Empty);
            }
            catch (Exception ex)
            {
                GXLogging.Debug(log, "Search error", ex);
                throw new SearchException(SearchException.IOEXCEPTION);
            }
        }
예제 #6
0
 internal IndexAction(Action action, IndexRecord record)
 {
     m_action = action;
     m_record = record;
 }