⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexmodifier.cs

📁 Lucene.Net 版本源码 测试通过
💻 CS
📖 第 1 页 / 共 2 页
字号:
				CreateIndexReader();
				return indexReader.DeleteDocuments(term);
			}
		}
		
		/// <summary> Deletes the document numbered <code>docNum</code>.</summary>
		/// <seealso cref="IndexReader#DeleteDocument(int)">
		/// </seealso>
		/// <throws>  IllegalStateException if the index is closed </throws>
		public virtual void  DeleteDocument(int docNum)
		{
			lock (directory)
			{
				AssureOpen();
				CreateIndexReader();
				indexReader.DeleteDocument(docNum);
			}
		}
		
		
		/// <summary> Returns the number of documents currently in this index.</summary>
		/// <seealso cref="IndexWriter#DocCount()">
		/// </seealso>
		/// <seealso cref="IndexReader#NumDocs()">
		/// </seealso>
		/// <throws>  IllegalStateException if the index is closed </throws>
		public virtual int DocCount()
		{
			lock (directory)
			{
				AssureOpen();
				if (indexWriter != null)
				{
					return indexWriter.DocCount();
				}
				else
				{
					return indexReader.NumDocs();
				}
			}
		}
		
		/// <summary> Merges all segments together into a single segment, optimizing an index
		/// for search.
		/// </summary>
		/// <seealso cref="IndexWriter#Optimize()">
		/// </seealso>
		/// <throws>  IllegalStateException if the index is closed </throws>
		public virtual void  Optimize()
		{
			lock (directory)
			{
				AssureOpen();
				CreateIndexWriter();
				indexWriter.Optimize();
			}
		}
		
		/// <summary> If non-null, information about merges and a message when
		/// {@link #GetMaxFieldLength()} is reached will be printed to this.
		/// <p>Example: <tt>index.setInfoStream(System.err);</tt>
		/// </summary>
		/// <seealso cref="IndexWriter#SetInfoStream(PrintStream)">
		/// </seealso>
		/// <throws>  IllegalStateException if the index is closed </throws>
		public virtual void  SetInfoStream(System.IO.StreamWriter infoStream)
		{
			lock (directory)
			{
				AssureOpen();
				if (indexWriter != null)
				{
					indexWriter.SetInfoStream(infoStream);
				}
				this.infoStream = infoStream;
			}
		}
		
		/// <throws>  IOException </throws>
		/// <seealso cref="IndexModifier#SetInfoStream(PrintStream)">
		/// </seealso>
		public virtual System.IO.TextWriter GetInfoStream()
		{
			lock (directory)
			{
				AssureOpen();
				CreateIndexWriter();
				return indexWriter.GetInfoStream();
			}
		}
		
		/// <summary> Setting to turn on usage of a compound file. When on, multiple files
		/// for each segment are merged into a single file once the segment creation
		/// is finished. This is done regardless of what directory is in use.
		/// </summary>
		/// <seealso cref="IndexWriter#SetUseCompoundFile(boolean)">
		/// </seealso>
		/// <throws>  IllegalStateException if the index is closed </throws>
		public virtual void  SetUseCompoundFile(bool useCompoundFile)
		{
			lock (directory)
			{
				AssureOpen();
				if (indexWriter != null)
				{
					indexWriter.SetUseCompoundFile(useCompoundFile);
				}
				this.useCompoundFile = useCompoundFile;
			}
		}
		
		/// <throws>  IOException </throws>
		/// <seealso cref="IndexModifier#SetUseCompoundFile(boolean)">
		/// </seealso>
		public virtual bool GetUseCompoundFile()
		{
			lock (directory)
			{
				AssureOpen();
				CreateIndexWriter();
				return indexWriter.GetUseCompoundFile();
			}
		}
		
		/// <summary> The maximum number of terms that will be indexed for a single field in a
		/// document.  This limits the amount of memory required for indexing, so that
		/// collections with very large files will not crash the indexing process by
		/// running out of memory.<p/>
		/// Note that this effectively truncates large documents, excluding from the
		/// index terms that occur further in the document.  If you know your source
		/// documents are large, be sure to set this value high enough to accomodate
		/// the expected size.  If you set it to Integer.MAX_VALUE, then the only limit
		/// is your memory, but you should anticipate an OutOfMemoryError.<p/>
		/// By default, no more than 10,000 terms will be indexed for a field.
		/// </summary>
		/// <seealso cref="IndexWriter#SetMaxFieldLength(int)">
		/// </seealso>
		/// <throws>  IllegalStateException if the index is closed </throws>
		public virtual void  SetMaxFieldLength(int maxFieldLength)
		{
			lock (directory)
			{
				AssureOpen();
				if (indexWriter != null)
				{
					indexWriter.SetMaxFieldLength(maxFieldLength);
				}
				this.maxFieldLength = maxFieldLength;
			}
		}
		
		/// <throws>  IOException </throws>
		/// <seealso cref="IndexModifier#SetMaxFieldLength(int)">
		/// </seealso>
		public virtual int GetMaxFieldLength()
		{
			lock (directory)
			{
				AssureOpen();
				CreateIndexWriter();
				return indexWriter.GetMaxFieldLength();
			}
		}
		
		/// <summary> Determines the minimal number of documents required before the buffered
		/// in-memory documents are merging and a new Segment is created.
		/// Since Documents are merged in a {@link Lucene.Net.Store.RAMDirectory},
		/// large value gives faster indexing.  At the same time, mergeFactor limits
		/// the number of files open in a FSDirectory.
		/// 
		/// <p>The default value is 10.
		/// 
		/// </summary>
		/// <seealso cref="IndexWriter#SetMaxBufferedDocs(int)">
		/// </seealso>
		/// <throws>  IllegalStateException if the index is closed </throws>
		/// <throws>  IllegalArgumentException if maxBufferedDocs is smaller than 2 </throws>
		public virtual void  SetMaxBufferedDocs(int maxBufferedDocs)
		{
			lock (directory)
			{
				AssureOpen();
				if (indexWriter != null)
				{
					indexWriter.SetMaxBufferedDocs(maxBufferedDocs);
				}
				this.maxBufferedDocs = maxBufferedDocs;
			}
		}
		
		/// <throws>  IOException </throws>
		/// <seealso cref="IndexModifier#SetMaxBufferedDocs(int)">
		/// </seealso>
		public virtual int GetMaxBufferedDocs()
		{
			lock (directory)
			{
				AssureOpen();
				CreateIndexWriter();
				return indexWriter.GetMaxBufferedDocs();
			}
		}
		
		/// <summary> Determines how often segment indices are merged by addDocument().  With
		/// smaller values, less RAM is used while indexing, and searches on
		/// unoptimized indices are faster, but indexing speed is slower.  With larger
		/// values, more RAM is used during indexing, and while searches on unoptimized
		/// indices are slower, indexing is faster.  Thus larger values (&gt; 10) are best
		/// for batch index creation, and smaller values (&lt; 10) for indices that are
		/// interactively maintained.
		/// <p>This must never be less than 2.  The default value is 10.
		/// 
		/// </summary>
		/// <seealso cref="IndexWriter#SetMergeFactor(int)">
		/// </seealso>
		/// <throws>  IllegalStateException if the index is closed </throws>
		public virtual void  SetMergeFactor(int mergeFactor)
		{
			lock (directory)
			{
				AssureOpen();
				if (indexWriter != null)
				{
					indexWriter.SetMergeFactor(mergeFactor);
				}
				this.mergeFactor = mergeFactor;
			}
		}
		
		/// <throws>  IOException </throws>
		/// <seealso cref="IndexModifier#SetMergeFactor(int)">
		/// </seealso>
		public virtual int GetMergeFactor()
		{
			lock (directory)
			{
				AssureOpen();
				CreateIndexWriter();
				return indexWriter.GetMergeFactor();
			}
		}
		
		/// <summary> Close this index, writing all pending changes to disk.
		/// 
		/// </summary>
		/// <throws>  IllegalStateException if the index has been closed before already </throws>
		public virtual void  Close()
		{
			lock (directory)
			{
				if (!open)
					throw new System.SystemException("Index is closed already");
				if (indexWriter != null)
				{
					indexWriter.Close();
					indexWriter = null;
				}
				else
				{
					indexReader.Close();
					indexReader = null;
				}
				open = false;
			}
		}
		
		public override System.String ToString()
		{
			return "Index@" + directory;
		}
		
		/*
		// used as an example in the javadoc:
		public static void main(String[] args) throws IOException {
		Analyzer analyzer = new StandardAnalyzer();
		// create an index in /tmp/index, overwriting an existing one:
		IndexModifier indexModifier = new IndexModifier("/tmp/index", analyzer, true);
		Document doc = new Document();
		doc.add(new Fieldable("id", "1", Fieldable.Store.YES, Fieldable.Index.UN_TOKENIZED));
		doc.add(new Fieldable("body", "a simple test", Fieldable.Store.YES, Fieldable.Index.TOKENIZED));
		indexModifier.addDocument(doc);
		int deleted = indexModifier.delete(new Term("id", "1"));
		System.out.println("Deleted " + deleted + " document");
		indexModifier.flush();
		System.out.println(indexModifier.docCount() + " docs in index");
		indexModifier.close();
		}*/
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -