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

📄 baseindexingtestcase.cs

📁 DotLucentet,用来做撬
💻 CS
字号:
using System;

using Lucene.Net.Analysis;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Store;
using NUnit.Framework;
namespace dotLucene.inAction.Index
{

	[TestFixture]
	public abstract class BaseIndexingTestCase 
	{
		protected String[] keywords = {"1", "2"};

		protected String[] unindexed = {"Netherlands", "Italy"};

		protected String[] unstored = {
										  "Amsterdam has lots of bridges",
										  "Venice has lots of canals"
									  };

		protected String[] text = {"Amsterdam", "Venice"};

		protected Directory dir;

		[SetUp]
		protected void Init()
		{
			string indexDir="index";
			dir = FSDirectory.GetDirectory(indexDir, true);
			AddDocuments(dir);
		}

	
		protected void AddDocuments(Directory dir)
		{
			IndexWriter writer = new IndexWriter(dir,GetAnalyzer(),true);
			writer.SetUseCompoundFile(IsCompound());
			for (int i = 0; i < keywords.Length; i++)
			{
				Document doc = new Document();
				doc.Add(Field.Keyword("id", keywords[i]));
				doc.Add(Field.UnIndexed("country", unindexed[i]));
				doc.Add(Field.UnStored("contents", unstored[i]));
				doc.Add(Field.Text("city", text[i]));
				writer.AddDocument(doc);
			}
			writer.Optimize();
			writer.Close();

		}

		protected virtual Analyzer GetAnalyzer()
		{
			return new SimpleAnalyzer();
		}

		protected virtual bool IsCompound()
		{
			return true;
		}
	}
}

⌨️ 快捷键说明

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