?? querynews.java~2~
字號(hào):
package news;
/**
* <p>Title: 新聞搜索引擎</p>
* <p>Description: 畢業(yè)設(shè)計(jì)</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author 計(jì)算機(jī)99630 沈晨
* @version 1.0
*/
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.cn.ChineseAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
public class QueryNews {
public static void main(String[] args) throws Exception{
// 從索引目錄創(chuàng)建索引
IndexSearcher _searcher = new IndexSearcher("c:\\news\\index");
// 創(chuàng)建標(biāo)準(zhǔn)分析器
Analyzer analyzer = new ChineseAnalyzer();
// 查詢條件
String line = "程序員";
// Query是一個(gè)抽象類
Query query = QueryParser.parse(line, "title", analyzer);
System.out.println("Searching for: " + query.toString("title"));
Hits hits = _searcher.search(query);
System.out.println(hits.length() + " total matching News");
final int HITS_PER_PAGE = 10;
for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) {
int end = Math.min(hits.length(), start + HITS_PER_PAGE);
for (int i = start; i < end; i++) {
Document doc = hits.doc(i);
String path = doc.get("path");
if (path != null) {
System.out.println(i + ". " + path);
}
else {
String url = doc.get("url");
if (url != null) {
System.out.println(i + ". " + url);
System.out.println(" - " + doc.get("title"));
}
else {
System.out.println(i + ". " + "No path nor URL for this document");
}
}
}
}
_searcher.close();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -