---
title: "new IndexSearcher(path)报错"
author: "lijun87"
date: "2010-05-11T18:32:41Z"
tags: ["Apache", "Lucene"]
categories: ["编程语言"]
slug: "new-indexsearcher-path"
draft: false
lastmod: "2010-05-11T18:32:41Z"
id: 664176
url: "https://bocolijun.iteye.com/blog/664176"
---

lucene创建索引中的构造函数IndexWriter(String path, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl) ，这里的boolean create参数的意思并非是否创建索引，而是覆盖还是追加的意思。原文见官方文档：create - true to create the index or overwrite the existing one; false to append to the existing index

引用

create - true to create the index or overwrite the existing one; false to append to the existing index  
true：创建新的索引或者覆盖现有索引  
false：追加索引到现有索引。

所以。当该参数为false，而所以目录下由不存在索引的时候，便会产生该异常。

引用

java.io.FileNotFoundException: no segments* file found in org.apache.lucene.store.FSDirectory@.....

解决方法:

 

在new IndexSearcher(path); 前面加一句

IndexWriter writer = new IndexWriter(path, new StandardAnalyzer(), true);