/*这段代码写的是TermQuery,
* 词条搜索方法,是Query搜索的一个根据提供指定的词条进行搜索的
* */
package query;
import java.io.IOException;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
public class Query_Term {
public Query_Term(String INDEX_STORE_PATH){
try{
IndexSearcher searcher = new IndexSearcher(INDEX_STORE_PATH);
Term t = new Term("bookname", "女");
Query q = new TermQuery(t);
Hits hits = searcher.search(q);
for(int i = 0; i
System.out.println(hits.doc(i));
System.out.println(hits.score(i));
System.out.println(hits.id(i));
System.out.println("========================");
}
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Query_Term qt = new Query_Term("E:\\Lucene项目\\索引文件");
}
}