<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                轉載請注明出處:[http://blog.csdn.net/xiaojimanman/article/details/44280311](http://blog.csdn.net/xiaojimanman/article/details/44280311) [http://www.llwjy.com/blogdetail/e42fa5c3097f4964fca0fdfe7cd7a9a2.html](http://www.llwjy.com/blogdetail/e42fa5c3097f4964fca0fdfe7cd7a9a2.html) 個人的博客小站已經上線了,網址 [www.llwjy.com](#),歡迎大家來吐槽~ 上一篇博客已經介紹了實時索引的檢索功能,這個就相當于數據的的查詢功能,我們都知道數據庫的增刪改查是最常用的四個功能,實時索引也是一樣,他也有增刪改查操作,這里就介紹一下實時索引的增刪改操作,在實時索引管理類的那篇博客中,我們已經提到實時索引中的IndexWriter的操作都是委托給TrackingIndexWriter來操作的,TrackingIndexWriter中的方法和IndexWriter中的方法類似,都實現了索引的基本操作,下面就一一介紹下。 **索引名就可以將我實例化** 這里的NRTIndex和之前的NRTSearch類一樣,都是根據索引名來實例化,在NRTIndex類中,我們定義兩個屬性,一個是TrackingIndexWriter對象,一個是索引名。因此NRTIndex的構造方法如下: ~~~ public NRTIndex(String indexName){ this.indexName = indexName; indexWriter = IndexManager.getIndexManager(indexName).getTrackingIndexWriter(); } ~~~ **操作一條語句足夠** TrackingIndexWriter中的操作和IndexWriter一樣簡單,幾乎都是一條語句足夠了,下面我們分別看下增刪改的操作語句: ~~~ //新增一條記錄 indexWriter.addDocument(doc); //刪除符合條件的記錄 indexWriter.deleteDocuments(query); //所有的記錄都不要了 indexWriter.deleteAll(); //按照條件更新記錄 indexWriter.updateDocument(term, doc); ~~~ 代碼的實現就是如此簡單,簡簡單單的一條語句就實現了索引的操作,當然這一切都要感謝Lucene的強大功能。 **我很懶的** 為了方便后面的操作,我們將這四個方法進行進一步的封裝,使后續操作更加簡單,NRTIndex類的源碼如下: ~~~ /** *@Description: 索引管理操作類,增刪改三種操作 */ package com.lulei.lucene.index.operation; import java.io.IOException; import org.apache.lucene.document.Document; import org.apache.lucene.index.Term; import org.apache.lucene.search.NRTManager.TrackingIndexWriter; import org.apache.lucene.search.Query; import com.lulei.lucene.index.manager.IndexManager; public class NRTIndex { private TrackingIndexWriter indexWriter; private String indexName; //直接使用IndexManager中的indexWriter,將索引的修改操作委托給TrackingIndexWriter實現 public NRTIndex(String indexName){ this.indexName = indexName; indexWriter = IndexManager.getIndexManager(indexName).getTrackingIndexWriter(); } /** * @param doc * @return boolean * @Author: lulei * @Description: 增加Document至索引 */ public boolean addDocument(Document doc){ try { indexWriter.addDocument(doc); return true; } catch (IOException e){ e.printStackTrace(); return false; } } /** * @param query * @return boolean * @Author: lulei * @Description: 按照Query條件從索引中刪除Document */ public boolean deleteDocument(Query query){ try { indexWriter.deleteDocuments(query); return true; } catch (IOException e) { e.printStackTrace(); return false; } } /** * @return * @Author: lulei * @Description: 清空索引 */ public boolean deleteAll(){ try { indexWriter.deleteAll(); return true; } catch (IOException e) { e.printStackTrace(); return false; } } /** * @param term * @param doc * @return * @Author: lulei * @Description: 按照Term條件修改索引中Document */ public boolean updateDocument(Term term, Document doc){ try { indexWriter.updateDocument(term, doc); return true; } catch (IOException e) { e.printStackTrace(); return false; } } /** * @throws IOException * @Author:lulei * @Description: 合并索引 */ public void commit() throws IOException { IndexManager.getIndexManager(indexName).getIndexWriter().commit(); } } ~~~ 這里的對NRTIndex類的介紹就結束了,后面博客會對NRTSearch和NRTIndex類創建應用子類,是索引的操作更加簡單。 ps:最近發現其他網站可能會對博客轉載,上面并沒有源鏈接,如想查看更多關于 [基于lucene的案例開發](http://www.llwjy.com/blogtype/lucene.html) ?請[點擊這里](http://blog.csdn.net/xiaojimanman/article/category/2841877)。或訪問網址http://blog.csdn.net/xiaojimanman/article/category/2841877 或 http://www.llwjy.com/
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看