このコンテンツは選択した言語では利用できません。

5.4. Optimizing the Query Process


Query performance depends on several criteria:
  • The Lucene query.
  • The number of objects loaded: use pagination or index projection where required.
  • The way the Query Module interacts with the Lucene readers defines the appropriate reader strategy.
  • Caching frequently extracted values from the index.

5.4.1. Caching Index Values: FieldCache

The Lucene index identifies matches to queries. Once the query is performed the results must be analyzed to extract useful information. The Lucene-based Query API is used to extract the Class type and the primary key.
Extracting the required values from the index reduces performance. In some cases this may be minor, other cases may require caching.
Requirements depend on the kind of projections being used and in some cases the Class type is not required.
The @CacheFromIndex annotation is used to perform caching on the main metadata fields required by the Lucene-based Query API.

Example 5.28. The @CacheFromIndex Annotation

import static org.hibernate.search.annotations.FieldCacheType.CLASS;
import static org.hibernate.search.annotations.FieldCacheType.ID;

@Indexed
@CacheFromIndex( { CLASS, ID } )
public class Essay {
Copy to Clipboard Toggle word wrap
It is possible to cache Class types and IDs using this annotation:
  • CLASS: The Query Module uses a Lucene FieldCache to improve performance of the Class type extraction from the index.
    This value is enabled by default. The Lucene-based Query API applies this value when the @CacheFromIndex annotation is not specified.
  • ID: Extracting the primary identifier uses a cache. This method produces the best querying results, however it may reduce performance.

Note

Measure the performance and memory consumption impact after warmup (executing some queries). Performance may improve by enabling Field Caches but this is not always the case.
Using a FieldCache has following two disadvantages:
  • Memory usage: Typically the CLASS cache has lower requirements than the ID cache.
  • Index warmup: When using field caches, the first query on a new index or segment is slower than when caching is disabled.
Some queries may not require a classtype, and ignore the CLASS field cache even when enabled. For example, when targeting a single class, all returned values are of that type.
The ID FieldCache requires the ids of targeted entities to be using a TwoWayFieldBridge. All types being loaded in a specific query must use the fieldname for the id and have ids of the same type. This is evaluated at query execution.
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat