Lucene 03 索引庫的維護 索引庫的查詢

2021-08-21 15:23:47 字數 1714 閱讀 7652

1.1.1抽取通用的方法

//	抽取公共的方法

private indexwriter getindexwriter() throws exception

1.1.2 刪除所有 或者針對性的刪除

@test

public void testindexdel() throws exception

/**

* 更新就是按照傳入的term進行搜尋,如果找到結果那麼刪除,將更新的內容重新生成乙個document物件

* 如果沒有搜尋到結果,那麼將更新的內容直接新增乙個新的document物件

* @throws exception

*/@test

public void testindexupdate() throws exception

//	使用termquery()方法進行查詢termquery,通過項查詢,termquery不使用分析器所以建議匹配不分詞的field域查詢,比如訂單號、分類id號等。

@test

public void testindextermquery() throws exception

}

@test

public void testnumericrangequery() throws exception

}

@test

public void testbooleanquery() throws exception

}

@test

public void testmultifieldqueryparser() throws exception;

//從檔名稱和檔案內容中查詢,只有含有apache的就查出來

multifieldqueryparser multiquery = new multifieldqueryparser(fields, analyzer);

//輸入需要搜尋的關鍵字

query query = multiquery.parse("apache");

//指定索引和文件的目錄

directory dir = fsdirectory.open(new file("g://lucene"));

//索引和文件的讀取物件

indexreader indexreader = indexreader.open(dir);

//建立索引的搜尋物件

indexsearcher indexsearcher = new indexsearcher(indexreader);

//搜尋:第乙個引數為查詢語句物件, 第二個引數:指定顯示多少條

topdocs topdocs = indexsearcher.search(query, 5);

//一共搜尋到多少條記錄

system.out.println("*****count*****" + topdocs.totalhits);

//從搜尋結果物件中獲取結果集

scoredoc scoredocs = topdocs.scoredocs;

for(scoredoc scoredoc : scoredocs)

}

Lucene索引庫的維護

公共 提取,下面的例子會用到的方法 提取公共 獲得indexwrite物件 public indexwriter getindexwriter throws ioexception和建立索引庫一樣 test public void addindex throws ioexception test p...

Lucene專題 索引庫維護

是否分析 是否對域的內容進行分詞處理。前提是我們要對域的內容進行查詢。是否索引 將field分析後的詞或整個field值進行索引,只有索引方可搜尋到。比如 商品名稱 商品簡介分析後進行索引,訂單號 身份證號不用分析但也要索引,這些將來都要作為查詢條件。是否儲存 將field值儲存在文件中,儲存在文件...

Lucene索引庫的維護功能實現

向索引庫中新增document物件。第一步 先建立乙個indexwriter物件 第二步 建立乙個document物件 第三步 把document物件寫入索引庫 第四步 關閉indexwriter。新增索引 test public void adddocument throws exception ...