Lucene在多個索引上進行搜尋

2021-04-18 04:49:16 字數 1556 閱讀 6571

資訊源自:http://blog.csdn.net/caoxu1987728/archive/2008/04/27/2335730.aspx

**如下:

package com.lucene.search;

import org.apache.lucene.analysis.standard.standardanalyzer;

import org.apache.lucene.document.document;

import org.apache.lucene.document.field;

import org.apache.lucene.index.indexwriter;

import org.apache.lucene.queryparser.multifieldqueryparser;

import org.apache.lucene.search.booleanclause;

import org.apache.lucene.search.hits;

import org.apache.lucene.search.indexsearcher;

import org.apache.lucene.search.multisearcher;

import org.apache.lucene.search.query;

public class multisearcher

public static void multisearcher() throws exception ;

//指定兩個域field

string field1 = "bookname";

string field2 = "price";

string fields = ;

//指定查詢字句之間的關係

booleanclause.occur clauses = ;

//轉成多域查詢multifieldquery

query q = multifieldqueryparser.parse(queries, fields, clauses, new standardanalyzer());

//列印query的內容

system.out.println(q.tostring());

//建立兩個indexsearcher,以實現在多個索引目錄進行查詢

indexsearcher searcher1 = new indexsearcher(index_store_path1);

indexsearcher searcher2 = new indexsearcher(index_store_path2);

indexsearcher searchers = ;

//使用multisearcher進行多域搜尋

multisearcher searcher = new multisearcher(searchers);

hits hits = searcher.search(q);

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

}}

lucene索引合併

lucene 索引合併 關鍵步驟如下 indexwriter fswriter null fs indexwriter ramwriter null ram directory fsdir directory ramdir ramdir new ramdirectory 判斷原索引檔案是否存在 開啟...

Lucene 建立索引

public class indexer public static string indexdir d luceneindex public static void main string args system.out.println 被索引的文件個數 writer.numdocs catch ...

lucene 索引技術

一 lucene索引建立和優化 版本2.9.0以上 lucene索引的建立首先需要取得幾個必須的物件 1 分詞器 可以採用其他的中文分詞器 standardanalyzer analyzer new standardanalyzer version.lucene current 分詞器 2 luce...