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

          上次提到如何建立索引.查詢索引,下面主要是說下lucene2.2.0更新索引.
             我個人查了下資源,lucene是沒有更新索引這個的功能的,但是可以增加,刪除.所以我們可以這樣去做,先把它刪除,然后增加,這樣也可以達(dá)到我們要的效果.
           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必須被索引進(jìn)去,否則不能刪除,建索引的時候設(shè)成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,這樣表示已經(jīng)建,如果對這條記錄操作的話,把這條記錄索引刪除,然后,把一個字段的屬性改成2,這樣,第二建的時候,我查詢數(shù)據(jù)的時候只要查字段的屬性==2的,這樣就被索引進(jìn)來了.,不知道大家明白沒有....
                                     
                                                                                                                                                                                         青菜貓(孫宇)
          posted on 2007-10-24 21:38 青菜貓(孫宇) 閱讀(2431) 評論(7)  編輯  收藏 所屬分類: 搜索


          FeedBack:
          # re: 青菜貓lucene2.2.0全文檢索更新
          2007-10-25 13:13 | 小魚
          這么簡單的東西也寫出來?  回復(fù)  更多評論
            
          # re: 青菜貓lucene2.2.0全文檢索更新
          2007-10-25 13:21 | 青菜貓(孫宇)
          @小魚
          也許對于你簡單,都是慢慢來的嘛...  回復(fù)  更多評論
            
          # re: 青菜貓lucene2.2.0全文檢索更新
          2007-10-25 16:18 | zht
          越簡單的越應(yīng)該寫出來
          越簡單越基礎(chǔ),剛開始學(xué)習(xí)的人犯的錯誤越多  回復(fù)  更多評論
            
          # re: 青菜貓lucene2.2.0全文檢索更新
          2007-10-25 17:26 | BeanSoft
          呵呵 基礎(chǔ)代碼永不過時 例如 Hello World  回復(fù)  更多評論
            
          # re: 青菜貓lucene2.2.0全文檢索更新
          2007-10-25 19:42 | sundc
          @BeanSoft
          慢慢來好了,框架也是用最基礎(chǔ)的技術(shù)..  回復(fù)  更多評論
            
          # 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.  回復(fù)  更多評論
            
          # re: 青菜貓lucene2.2.0全文檢索更新
          2010-02-02 15:23 | jay88489
          樓主說的很有道理。。  回復(fù)  更多評論
            

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2007年10月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          青菜貓(孫宇)結(jié)交天下朋友,在網(wǎng)上吸取知識..

          常用鏈接

          留言簿(16)

          隨筆分類

          隨筆檔案

          文章分類

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          青菜貓(孫宇博客),青菜貓(孫宇博客),青菜貓(孫宇博客)http://www.javasdc.cn/
          主站蜘蛛池模板: 轮台县| 乌恰县| 安顺市| 福安市| 盐源县| 万源市| 阿尔山市| 溧水县| 临夏市| 隆尧县| 鲁山县| 加查县| 九龙县| 来凤县| 孝昌县| 彝良县| 万荣县| 东海县| 泸州市| 齐齐哈尔市| 吴堡县| 彝良县| 翼城县| 玉门市| 奉新县| 澄迈县| 岳普湖县| 合肥市| 醴陵市| 蒙自县| 武功县| 兰坪| 永新县| 边坝县| 云龙县| 攀枝花市| 景洪市| 枣庄市| 永济市| 岢岚县| 洱源县|