import java.io.IOException;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
/**
* 与或非布尔查询——Lucene中的BooleanQuery
* @author USER
*
*/
public class TestBooleanQuery {
/**
* 主函数,运行测试程序
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
//建索引
createIndex();
//多个TermQuery构建BooleanQuery检索
searchIndex4TermQuery();
//一个MultiFieldQueryParser构建BooleanQuery多个域的检索
searchIndex4MultiFieldQueryParser();
}
/**
* 建索引
* @throws Exception
*/
public static void createIndex() throws Exception {
Document doc1 = new Document();
Field field = null;
field = new Field("name", "word1 word2 word3", Field.Store.YES,
Field.Index.TOKENIZED);
doc1.add(field);
field = new Field("title", "doc1", Field.Store.YES, Field.Index.TOKENIZED)