同じデータにインデックスを付けると、なぜルセンインデックスのサイズが大きくなったのですか?

StackOverflow https://stackoverflow.com/questions/1021554

質問

Hibernate Searchをアプリケーションに実装しました。つまり、Luceneに基づいています。データベースにインデックスを作成するたびに、luceneインデックスのサイズが増加します。ただし、クエリの結果は毎回同じ結果を返します。

毎回同じデータにインデックスを付けると、毎回ルセンのサイズが大きくなるのはなぜですか?

FullTextSession fullTextSession = Search.getFullTextSession(getSession());
    org.hibernate.Transaction tx = fullTextSession.beginTransaction();

    Criteria criteria = fullTextSession.createCriteria(getPersistentClass())
    .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
    .setCacheMode(CacheMode.IGNORE)
    .setFetchSize(pageSize)
    .setFlushMode(FlushMode.MANUAL);


    int i = 0;
    List<ProdAttrAssociationVO> results = null;
    do {
      criteria = criteria.setFirstResult(i)
        .setMaxResults(pageSize);
      results = criteria.list();

      for (ProdAttrAssociationVO entity : results) {
        fullTextSession.delete(entity);
        fullTextSession.index(entity);
      }

      // flush the index changes to disk so we don't hold until a commit
      if (i % batchSize == 0) {
        fullTextSession.flushToIndexes();
        fullTextSession.clear();
      }

      i += pageSize;
    } while (results.size() > 0);


    System.out.println("ProdAttrAssociation Indexing Completed");
    tx.commit();
役に立ちましたか?

解決

Hibernateについては何も知りませんが、一般的にLuceneでは、削除されたドキュメントは最適化されるまでインデックスに残ります。インデックスが成長しているのはなぜかを説明できます。

インデックスでoptimize()を実行してみてください。 Hibernateからどのように実行するのかわかりません( SearchFactory )。

これがお役に立てば幸いです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top