public List<Document> rangeSearch(){ List<Document> docList = new ArrayList<Document>(); Double start = 20.0; Double end = 40.0; NumericRangeQuery rangeQuery = NumericRangeQuery.newDoubleRange("carPrice",start,end,true, true); try { directory = FSDirectory.open(new File(LuceneConstant.INDEX_PATH));//打开索引文件夹 IndexReader reader = DirectoryReader.open(directory);//读取目录 IndexSearcher search = new IndexSearcher(reader);//初始化查询组件 TopDocs td = search.search(rangeQuery, 10000);//获取匹配上元素的一个docid for (ScoreDoc doc : td.scoreDocs) { docList.add(search.doc(doc.doc)); } reader.close();//关闭资源 directory.close();//关闭连接 } catch (IOException ex) { Logger.getLogger(LuceneDao.class.getName()).log(Level.SEVERE, null, ex); } return docList; }