lucene ---- DemoSearch
/*
* Created on 2004-4-26
*
*/
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.search.*;
import org.apache.lucene.queryParser.*;
import org.apache.lucene.document.*;
//import com.augmentum.hrms.*;
/**
* @author bell.wang
*
*/
public class DemoSearch {
public static void main(String[] args) {
//XMap a = new XMap("");
Analyzer anlzr = new StandardAnalyzer();
try{
Query q = QueryParser.parse("file", "contents", anlzr);
System.out.println("Searching for : " + q.toString("contents"));
Searcher serch = new IndexSearcher("myindex");
Hits hts = serch.search(q);
for(int i=0; i<hts.length(); i++){
Document doc = hts.doc(i);
String path = doc.get("path");
System.out.println("Find: " +i+": "+ path);
//System.out.println("Find: " + doc.get("modified"));
//System.out.println("Find: " + doc.get("path"));
}
System.out.println("Find Total: " + hts.length());
}catch(Exception e){
System.out.println(e);
}
}
}
posted on 2004-04-30 18:26 whbell-blog 阅读(886) 评论(0) 收藏 举报
浙公网安备 33010602011771号