<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    huangfox

    韜光隱晦
    隨筆 - 1, 文章 - 8, 評論 - 1, 引用 - 0
    數(shù)據(jù)加載中……

    有關(guān)Lucene的問題(6):Lucene的事務(wù)性【轉(zhuǎn)】

      所謂事務(wù)性,本多指數(shù)據(jù)庫的屬性,包括ACID四個(gè)基本要素:原子性(Atomicity)、一致性(Consistency)、隔離性(Isolation)、持久性(Durability)。

      我們這里主要討論隔離性,Lucene的IndexReader和IndexWriter具有隔離性。

      當(dāng)IndexReader.open打開一個(gè)索引的時(shí)候,相對于給當(dāng)前索引進(jìn)行了一次snapshot,此后的任何修改都不會被看到。

      僅當(dāng)IndexReader.open打開一個(gè)索引后,才有可能看到從上次打開后對索引的修改。

      當(dāng)IndexWriter沒有調(diào)用Commit的時(shí)候,其修改的內(nèi)容是不能夠被看到的,哪怕IndexReader被重新打開。

      欲使最新的修改被看到,一方面IndexWriter需要commit,一方面IndexReader重新打開。

      下面我們舉幾個(gè)例子來說明上述隔離性:

      (1) 首先做準(zhǔn)備,索引十篇文檔

      File indexDir = new File("TestIsolation/index");
      IndexWriter writer = new IndexWriter(FSDirectory.open(indexDir), new StandardAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.LIMITED);
      for(int i =0; i < 10; i++){
      indexDocs(writer);
      }
      writer.close();

      (2) 然后再索引十篇文檔,并不commit

      writer = new IndexWriter(FSDirectory.open(indexDir), new StandardAnalyzer(Version.LUCENE_CURRENT), IndexWriter.MaxFieldLength.LIMITED);
      for(int i =0; i < 10; i++){
      indexDocs(writer);
      }

      (3) 打開一個(gè)IndexReader,但是由于IndexWriter沒有commit,所以仍然僅看到十篇文檔。

      IndexReader reader = IndexReader.open(FSDirectory.open(indexDir));
      IndexSearcher searcher = new IndexSearcher(reader);
      TopDocs docs = searcher.search(new TermQuery(new Term("contents","hello")), 50);
      System.out.println(docs.totalHits);

      (4) IndexWriter進(jìn)行提交commit

      writer.commit();

      (5) 不重新打開IndexReader,進(jìn)行搜索,仍然僅看到十篇文檔。

      docs = searcher.search(new TermQuery(new Term("contents","hello")), 50);
      System.out.println(docs.totalHits);

      (6) IndexReader重新打開,則可以看到二十篇文檔。

      reader = IndexReader.open(FSDirectory.open(indexDir));
      searcher = new IndexSearcher(reader);
      docs = searcher.search(new TermQuery(new Term("contents","hello")), 50);
      System.out.println(docs.totalHits);

    posted on 2010-09-25 16:02 fox009 閱讀(159) 評論(0)  編輯  收藏 所屬分類: 搜索引擎技術(shù)

    主站蜘蛛池模板: 99精品视频在线观看免费播放| 国产AV无码专区亚洲AV蜜芽| av网站免费线看| 亚洲国产成人久久综合野外| 亚洲欧美日韩中文无线码| 24小时日本在线www免费的| 亚洲一级毛片免费观看| 8x8×在线永久免费视频| 亚洲国产高清人在线| 一级特黄aa毛片免费观看| 67pao强力打造67194在线午夜亚洲| a毛片免费观看完整| 亚洲人成在线观看| 最好看的中文字幕2019免费| 亚洲色偷偷av男人的天堂| 99re免费视频| 亚洲国产品综合人成综合网站| 999国内精品永久免费视频| 亚洲人xxx日本人18| 日韩免费视频在线观看| 国产成人高清亚洲一区久久| 亚洲AV蜜桃永久无码精品| 国产精品青草视频免费播放| 国产成人A人亚洲精品无码| 嫩草成人永久免费观看| 亚洲色偷偷av男人的天堂| 性色av无码免费一区二区三区| 亚洲日本VA午夜在线影院| 亚洲精品tv久久久久| 日韩精品在线免费观看| 亚洲国产精品综合久久20| 亚洲AⅤ视频一区二区三区| 国产一区二区免费| 亚洲一区二区三区播放在线| 国产精品国产午夜免费福利看| 一区二区三区免费视频网站| 亚洲色四在线视频观看| 成年女人午夜毛片免费视频| 美女被免费网站视频在线| 久久精品九九亚洲精品天堂| 成人无码区免费A片视频WWW |