/** * 多条件查询 * * @param termQueryList * @return */ public List<Document> complexSearch(List<Query> termQueryList) { List<Document> docList = new ArrayList<Document>(); try { directory = FSDirectory.open(new File(LuceneConstant.INDEX_PATH));//打开索引文件夹 IndexReader reader = DirectoryReader.open(directory);//读取目录 IndexSearcher search = new IndexSearcher(reader);//初始化查询组件 BooleanQuery query = new BooleanQuery(); for (Query termQuery : termQueryList) { query.add(termQuery, BooleanClause.Occur.MUST); } TopDocs td = search.search(query, 10000);//获取匹配上元素的一个docid for (ScoreDoc doc : td.scoreDocs) { docList.add(search.doc(doc.doc)); } reader.close();//关闭资源 directory.close();//关闭连接 } catch (Exception e) { e.printStackTrace(); } return docList; }