lucene2 0學習文件四

2021-08-30 07:13:56 字數 1443 閱讀 2027

public void searchermaxfield() throws parseexception, ioexception

query = queryparser.parse("程式設計師之家");

indexsearcher= new indexsearcher("c:\\index");

hits = indexsearcher.search(query);

system.out.println("您搜的是:程式設計師之家");

system.out.println("找到了"+hits.length()+"個結果");

system.out.println("它們分別是:");

for (int i = 0; i < hits.length(); i++)

queryparser = new queryparser("name2",new standardanalyzer());

query = queryparser.parse("welcome");

indexsearcher= new indexsearcher("c:\\index");

hits = indexsearcher.search(query);

system.out.println("您搜的是:welcome");

system.out.println("找到了"+hits.length()+"個結果");

system.out.println("它們分別是:");

for (int i = 0; i < hits.length(); i++)

query = queryparser.parse("the");

indexsearcher= new indexsearcher("c:\\index");

hits = indexsearcher.search(query);

system.out.println("您搜的是:the");

system.out.println("找到了"+hits.length()+"個結果");

system.out.println("它們分別是:");

for (int i = 0; i < hits.length(); i++)

query = queryparser.parse("home");

indexsearcher= new indexsearcher("c:\\index");

hits = indexsearcher.search(query);

system.out.println("您搜的是:home");

system.out.println("找到了"+hits.length()+"個結果");

system.out.println("它們分別是:");

for (int i = 0; i < hits.length(); i++)

}

Lucene 2 0學習文件( )

接 indexwriter file path,analyzer a,boolean create indexwriter string path,analyzer a,boolean create 可見構造它需要乙個索引檔案目錄,乙個分析器 一般用標準的這個 最後乙個引數是標識是否清空索引目錄 它...

lucene2 0學習文件二

下面講一下索引的建立 其實從上面的例子就可以看出建立索引就用到document,indexwriter,field。最簡單的步驟就是 首先分別new 乙個document,indexwriter,field,然後用doument.add 方法加入field.其次用indexwrtier.adddoc...

lucene2 0學習文件三

先看一下它的建構函式 indexwriter directory d,analyzer a,boolean create indexwriter file path,analyzer a,boolean create indexwriter string path,analyzer a,boolea...