青菜貓(孫宇博客),青菜貓(孫宇博客),青菜貓(孫宇博客)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 青菜貓(孫宇) 閱讀(2436) 評論(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/
          主站蜘蛛池模板: 昌黎县| 灵丘县| 南陵县| 东源县| 招远市| 贵阳市| 浦江县| 随州市| 霞浦县| 吴忠市| 柳州市| 克拉玛依市| 佛教| 永州市| 达日县| 石景山区| 三门县| 垣曲县| 潮州市| 马尔康县| 乐亭县| 肃南| 和静县| 全州县| 泽州县| 墨脱县| 德州市| 陇南市| 兴业县| 寿阳县| 永兴县| 祁连县| 宜都市| 桑日县| 西乌珠穆沁旗| 南平市| 太白县| 墨竹工卡县| 土默特左旗| 廉江市| 科尔|