?? mydocument.java
字號:
package performance.document;
import java.io.*;
import java.util.StringTokenizer;
import org.apache.lucene.document.*;
public class MyDocument {
/**
* 將文本文檔轉成Lucene的Document格式
* @param file
* @return document that represents a file
* @throws Exception
*/
public static Document getDocument(File file) throws IOException {
Document doc = new Document();
/**
* 為文件路徑構建一個字段
*/
doc.add(Field.Text("path", file.getPath()));
/**
* 為文件名構建一個字段
*/
doc.add(Field.Keyword("title", getFileName(file)));
/**
* 為文件內容構建一個字段
*/
FileInputStream is = new FileInputStream(file);
Reader reader = new BufferedReader(new InputStreamReader(is));
doc.add(Field.Text("contents", reader));
/**
* 為文件的最后修改時間構建一個字段
*/
doc.add(Field.Keyword("modified", DateField.timeToString(file
.lastModified())));
return doc;
}
/**
*
* @param file
* @return
*/
private static String getFileName(File file) {
String path = file.getPath();
StringTokenizer st = new StringTokenizer(path, File.separator);
String token = "";
while (st.hasMoreTokens()) {
token = st.nextToken();
}
if (token != null) {
token = token.substring(0, token.indexOf(".txt"));
}
return token;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -