📄 baseindexingtestcase.cs
字号:
using System;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Store;
using NUnit.Framework;
namespace dotLucene.inAction.BasicSearch
{
[TestFixture]
public class BaseIndexingTestCase
{
protected String[] isbn = {"1930110994", "1930110995"};
protected String[] title = {"Java Development with Ant", "JUnit in Action"};
protected String[] contents = {
"we have ant and junit",
"junit use a mock,ant is also",
};
protected String[] subject = {
"ant junit",
"junit mock"
};
protected String[] pubmonth = {
"200206",
"200309"
};
protected String[] category = {
"/Computers/Ant", "/Computers/JUnit"
};
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);;
for (int i = 0; i < isbn.Length; i++)
{
Document doc = new Document();
doc.Add(Field.Keyword("isbn", isbn[i]));
doc.Add(Field.UnIndexed("title", title[i]));
doc.Add(Field.UnStored("contents", contents[i]));
doc.Add(Field.Text("subject", subject[i]));
doc.Add(Field.Text("pubmonth", pubmonth[i]));
doc.Add(Field.Text("category", category[i]));
writer.AddDocument(doc);
}
writer.Optimize();
writer.Close();
}
protected virtual Analyzer GetAnalyzer()
{
PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(
new SimpleAnalyzer());
analyzer.AddAnalyzer("pubmonth", new WhitespaceAnalyzer());
analyzer.AddAnalyzer("category", new WhitespaceAnalyzer());
return analyzer;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -