代碼如下
view plaincopy to clipboardprint?
package com
import org
import org
import org
import org
import org
import org
import org
import org
import org
import org
public class Multisearcher {
private static String INDEX_STORE_PATH
private static String INDEX_STORE_PATH
public static void main(String[] args) throws Exception {
Multisearcher
}
public static void multisearcher() throws Exception {
IndexWriter writer = new IndexWriter(INDEX_STORE_PATH
writer
Document doc
Field f
Field f
doc
doc
Document doc
Field f
Field f
doc
doc
Document doc
Field f
Field f
doc
doc
writer
writer
writer
writer
//創建第二個索引器
IndexWriter writer
writer
Document doc
Field f
Field f
doc
doc
Document doc
Field f
Field f
doc
doc
Document doc
Field f
Field f
doc
doc
writer
writer
writer
writer
String query
String query
String[] queries = { query
//指定兩個域Field
String field
String field
String[] fields = { field
//指定查詢字句之間的關系
BooleanClause
//轉成多域查詢MultiFieldQuery
Query q = MultiFieldQueryParser
//打印Query的內容
System
//創建兩個IndexSearcher
IndexSearcher searcher
IndexSearcher searcher
IndexSearcher[] searchers = { searcher
//使用MultiSearcher進行多域搜索
MultiSearcher searcher = new MultiSearcher(searchers);
Hits hits = searcher
for (int i =
System
}
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26839.html