检索源代码(成功运行!)
时间:2007-07-31 来源:sdwsyjp
package test;
import java.io.IOException;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.queryParser.ParseException;
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 Searcher3 { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
IndexSearcher searcher = new IndexSearcher(Constants.INDEX_STORE_PATH);
Query query = null;
Hits hits = null;
QueryParser qp = new QueryParser("contents",new StandardAnalyzer());
try {
query = qp.parse("金鹏");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
hits = searcher.search(query);
System.out.println(hits.length());
} catch (CorruptIndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
运行结果为:7,^_^
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.queryParser.ParseException;
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 Searcher3 { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
IndexSearcher searcher = new IndexSearcher(Constants.INDEX_STORE_PATH);
Query query = null;
Hits hits = null;
QueryParser qp = new QueryParser("contents",new StandardAnalyzer());
try {
query = qp.parse("金鹏");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
hits = searcher.search(query);
System.out.println(hits.length());
} catch (CorruptIndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
运行结果为:7,^_^
相关阅读 更多 +