---
title: "删除索引的问题"
author: "linsl"
date: "2010-10-26T11:22:43Z"
tags: []
categories: ["企业架构"]
slug: "untitled"
draft: false
lastmod: "2010-10-26T11:22:43Z"
id: 794154
url: "https://linsl.iteye.com/blog/794154"
---

```
				Field articleID = new Field(FieldConstant.ArticleID,""+article.getArticleID(), Field.Store.YES,Field.Index.NOT_ANALYZED);
				doc.add(articleID);
```

 

 对文章ID建立所引，

```
Term t=new Term(FieldConstant.ArticleID,article.getArticleID()+"");
IndexReader ir=IndexReader.open(fsd,false);		
ir.deleteDocuments(t);
ir.close();
IndexWriter iw = new IndexWriter(fsd, analyzer, false,new IndexWriter.MaxFieldLength(1000));
iw.optimize();
iw.close();
```

 

 根据文章ID来删除索引，如果IndexWriter第三个参数是true，不管ID 是否为唯一，都把所有的索引给删除了，如果为false则会根据条件来删除对应索引