青菜猫(孙宇博客),青菜猫(孙宇博客),青菜猫(孙宇博客)http://www.javasdc.cn/
posts - 29,  comments - 63,  trackbacks - 0

上次提到如何建立索引.查询索引,下面主要是说下lucene2.2.0更新索引.
   我个人查了下资源,lucene是没有更新索引这个的功能的,但是可以增加,删除.所以我们可以这样去做,先把它删除,然后增加,这样也可以达到我们要的效果.
 Directory directory = FSDirectory.getDirectory("d:\\index/sellindex", false); 
    for(int i=0;i<li.length;i++){
     IndexReader reader = IndexReader.open(directory);
     IndexReader.unlock(directory);
     Term term = new Term("vcsid",li[i]);
     reader.deleteDocuments(term);
     reader.close();
     directory.close();

这是的vcsid必须被索引进去,否则不能删除,建索引的时候设成Field.Index.TOKENIZED,就可以了.

String indexDir = "d:\\index/sellindex";
   boolean indexExist = indexExist(indexDir);
   if (indexExist) {
    writer = new IndexWriter(indexDir, new StandardAnalyzer(),
      false);
   } else {

    writer = new IndexWriter(indexDir, new StandardAnalyzer(), true);
   }


public static boolean indexExist(String indexDir) {
  return IndexReader.indexExists(indexDir);
 }
这上面表示如果false的就重新建,而true就是追加,我在项目是这样做的,索引建完后,把一个字段的属性改成1,这样表示已经建,如果对这条记录操作的话,把这条记录索引删除,然后,把一个字段的属性改成2,这样,第二建的时候,我查询数据的时候只要查字段的属性==2的,这样就被索引进来了.,不知道大家明白没有....
                           
                                                                                                                                                                               青菜猫(孙宇)
posted on 2007-10-24 21:38 青菜猫(孙宇) 阅读(2407) 评论(7)  编辑  收藏 所属分类: 搜索


FeedBack:
# re: 青菜猫lucene2.2.0全文检索更新
2007-10-25 13:13 | 小鱼
这么简单的东西也写出来?  回复  更多评论
  
# re: 青菜猫lucene2.2.0全文检索更新
2007-10-25 13:21 | 青菜猫(孙宇)
@小鱼
也许对于你简单,都是慢慢来的嘛...  回复  更多评论
  
# re: 青菜猫lucene2.2.0全文检索更新
2007-10-25 16:18 | zht
越简单的越应该写出来
越简单越基础,刚开始学习的人犯的错误越多  回复  更多评论
  
# re: 青菜猫lucene2.2.0全文检索更新
2007-10-25 17:26 | BeanSoft
呵呵 基础代码永不过时 例如 Hello World  回复  更多评论
  
# re: 青菜猫lucene2.2.0全文检索更新
2007-10-25 19:42 | sundc
@BeanSoft
慢慢来好了,框架也是用最基础的技术..  回复  更多评论
  
# Seo Prodvijeni
2009-05-18 05:30 | Seo Prodvijeni
Hello. We are made to persist. That's how we find out who we are.
I am from Tome and learning to write in English, give true I wrote the following sentence: "Common seo mistakes wordtracker, the leading keyword research tool most seo advice is given for a single page, word or technique.Advertising affiliate marketing autos babies beauty blogging boxing busby seo test business christmas credit card."

With love :p, Albert.  回复  更多评论
  
# re: 青菜猫lucene2.2.0全文检索更新
2010-02-02 15:23 | jay88489
楼主说的很有道理。。  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 
<2007年10月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

青菜猫(孙宇)结交天下朋友,在网上吸取知识..

常用链接

留言簿(16)

随笔分类

随笔档案

文章分类

搜索

  •  

最新评论

阅读排行榜

评论排行榜

青菜猫(孙宇博客),青菜猫(孙宇博客),青菜猫(孙宇博客)http://www.javasdc.cn/