Esempio n. 1
0
        /// <summary> Adds a document to this index, using the provided culture.
        /// If the document contains more than
        /// {@link #SetMaxFieldLength(int)} terms for a given field, the remainder are
        /// discarded.
        /// </summary>
        /// <exception cref="InvalidOperationException">If the index is closed </exception>
        private void AddMultipleDocuments(Document[] docs, string culture)
        {
            if (docs == null || docs.Length == 0)
            {
                return;
            }

            Analyzer analyzer = null;

            if (!string.IsNullOrEmpty(culture))
            {
                analyzer = LuceneSearch.GetAnalyzer(culture);
            }
#if TRACE_INDEX_OPS
            _log.Info("Add multiple IndexDoc(s)...");
#endif
            lock (SyncRoot)
            {
                AssureOpen();
                CreateIndexWriter();

                for (int i = 0; i < docs.Length; i++)
                {
                    if (analyzer != null)
                    {
                        indexWriter.AddDocument(docs[i], analyzer);
                    }
                    else
                    {
                        indexWriter.AddDocument(docs[i]);
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary> Initialize an IndexWriter.</summary>
 /// <exception cref="IOException"></exception>
 protected internal void Init()
 {
     lock (this.SyncRoot) {
         this.indexWriter = new IndexWriter(this.settings.GetIndexDirectory(),
                                            LuceneSearch.GetAnalyzer(LuceneSearch.DefaultLanguage), !this.IndexExists);
         open = true;
     }
 }
Esempio n. 3
0
        /// <summary> Adds a document to this index, using the provided culture.
        /// If the document contains more than
        /// {@link #SetMaxFieldLength(int)} terms for a given field, the remainder are
        /// discarded.
        /// </summary>
        /// <exception cref="InvalidOperationException">If the index is closed </exception>
        private void AddSingleDocument(Document doc, string culture)
        {
            if (doc == null)
            {
                return;
            }
//#if TRACE_INDEX_OPS
            _log.DebugFormat("Adding document {0} to the index", doc.GetField(LuceneSearch.Keyword.ItemLink));
//#endif
            lock (SyncRoot)
            {
                AssureOpen();
                CreateIndexWriter();
                try
                {
                    if (!string.IsNullOrEmpty(culture))
                    {
                        indexWriter.AddDocument(doc, LuceneSearch.GetAnalyzer(culture));
                    }
                    else
                    {
                        indexWriter.AddDocument(doc);
                    }
                }
                catch (IOException ioe)
                {
                    _log.Error("IOException adding document to the index", ioe);

                    /* see  http://issues.apache.org/jira/browse/LUCENE-665 */
                    if (ioe.Message.IndexOf("segments.new") != -1)
                    {
                        FileHelper.MoveFile(Path.Combine(this.settings.IndexPath, "segments.new"), Path.Combine(this.settings.IndexPath, "segments"), MoveFileFlag.ReplaceExisting);
                    }
                    else if (ioe.Message.IndexOf("deleteable.new") != -1)
                    {
                        FileHelper.MoveFile(Path.Combine(this.settings.IndexPath, "deleteable.new"), Path.Combine(this.settings.IndexPath, "deleteable"), MoveFileFlag.ReplaceExisting);
                    }
                }
                catch (UnauthorizedAccessException uae)
                {
                    _log.Error("Access denied error while adding document to the index", uae);

                    /* see  http://issues.apache.org/jira/browse/LUCENE-665 */
                    if (uae.Message.IndexOf("segments.new") != -1)
                    {
                        FileHelper.MoveFile(Path.Combine(this.settings.IndexPath, "segments.new"), Path.Combine(this.settings.IndexPath, "segments"), MoveFileFlag.ReplaceExisting);
                    }
                    else if (uae.Message.IndexOf("deleteable.new") != -1)
                    {
                        FileHelper.MoveFile(Path.Combine(this.settings.IndexPath, "deleteable.new"), Path.Combine(this.settings.IndexPath, "deleteable"), MoveFileFlag.ReplaceExisting);
                    }
                }
                catch (SystemException se) //indicates "docs out of order" when trying to merge docs in index
                {
                    _log.Error("Non-fatal error occured while adding document to index", se);
                }
            }
        }
Esempio n. 4
0
        /// <summary> Close the IndexReader and open an IndexWriter.</summary>
        /// <exception cref="IOException"></exception>
        protected internal virtual void  CreateIndexWriter()
        {
            if (this.indexWriter == null)
            {
#if TRACE_INDEX_OPS
                _log.Info("Creating IndexWriter...");
#endif
                this.indexWriter = new IndexWriter(this.BaseDirectory,
                                                   LuceneSearch.GetAnalyzer(LuceneSearch.DefaultLanguage), false);
                this.indexWriter.SetInfoStream(_logHelper);
                this.indexWriter.SetMergeFactor(MaxSegments);
                this.indexWriter.SetMaxBufferedDocs(DocsPerSegment);
                this.indexWriter.SetMergeScheduler(new NoExceptionsConcurrentMergeScheduler());
            }
        }