



















1、Keyword 见名知意就是关键字,该字段中的内容不经过分析但会被索引并直接保存到索引中,比如:good,filename,teacher等字符串常量,也可以是一个字符串数组,如string [] contex={“doc”,”xls”,”ppt”,”pdf”,html”,txt”}



{
doc.Add(Filed.Keyword(“text”,strcontex);
}























private String[] keywords = {"20001895", "20001896"};

private String[] unindexed = {"Red star", "good morning"};

private String[] unstored = { "I am a programer", "you are programmer ,too",};

private String[] text1 = { " programer ", "morning" };

private String[] text2 = { "200606", "200609" };

private String[] text3 = { "/Computers/red", "/Computers/star" };





{
string indexDir = "index";
dir = FSDirectory.GetDirectory(indexDir, true);
IndexWriter writer=new IndexWriter(dir, GetAnalyzer(), true);
for (int i = 0; i < keywords.Length; i++)
{
Document doc = new Document();
doc.Add(Field.Keyword("isbn", keywords[i]));
doc.Add(Field.UnIndexed("title", unindexed[i]));
doc.Add(Field.UnStored("contents", unstored[i]));
doc.Add(Field.Text("subject", text1[i]));
doc.Add(Field.Text("pubmonth", text2[i]));
doc.Add(Field.Text("category", text3[i]));
writer.AddDocument(doc);
}
writer.Optimize();
writer.Close();
}



























{
Document doc = hits.Doc(i);
string path = doc.Get("path");
string plainText =doc.Get(“text”);;
string str=doc.Get ("filename");
通过Get方法将搜索的内容提取出来
}






