@@ -89,6 +89,19 @@ public boolean isCacheable(LeafReaderContext ctx) {
89
89
90
90
}
91
91
92
+ private static QueryCachingPolicy alwaysCachePolicy () {
93
+ return new QueryCachingPolicy () {
94
+ @ Override
95
+ public void onUse (Query query ) {
96
+
97
+ }
98
+ @ Override
99
+ public boolean shouldCache (Query query ) {
100
+ return true ;
101
+ }
102
+ };
103
+ }
104
+
92
105
public void testBasics () throws IOException {
93
106
Directory dir = newDirectory ();
94
107
IndexWriter w = new IndexWriter (dir , newIndexWriterConfig ());
@@ -98,7 +111,7 @@ public void testBasics() throws IOException {
98
111
ShardId shard = new ShardId ("index" , "_na_" , 0 );
99
112
r = ElasticsearchDirectoryReader .wrap (r , shard );
100
113
IndexSearcher s = new IndexSearcher (r );
101
- s .setQueryCachingPolicy (QueryCachingPolicy . ALWAYS_CACHE );
114
+ s .setQueryCachingPolicy (alwaysCachePolicy () );
102
115
103
116
Settings settings = Settings .builder ()
104
117
.put (IndicesQueryCache .INDICES_CACHE_QUERY_COUNT_SETTING .getKey (), 10 )
@@ -169,7 +182,7 @@ public void testTwoShards() throws IOException {
169
182
ShardId shard1 = new ShardId ("index" , "_na_" , 0 );
170
183
r1 = ElasticsearchDirectoryReader .wrap (r1 , shard1 );
171
184
IndexSearcher s1 = new IndexSearcher (r1 );
172
- s1 .setQueryCachingPolicy (QueryCachingPolicy . ALWAYS_CACHE );
185
+ s1 .setQueryCachingPolicy (alwaysCachePolicy () );
173
186
174
187
Directory dir2 = newDirectory ();
175
188
IndexWriter w2 = new IndexWriter (dir2 , newIndexWriterConfig ());
@@ -179,7 +192,7 @@ public void testTwoShards() throws IOException {
179
192
ShardId shard2 = new ShardId ("index" , "_na_" , 1 );
180
193
r2 = ElasticsearchDirectoryReader .wrap (r2 , shard2 );
181
194
IndexSearcher s2 = new IndexSearcher (r2 );
182
- s2 .setQueryCachingPolicy (QueryCachingPolicy . ALWAYS_CACHE );
195
+ s2 .setQueryCachingPolicy (alwaysCachePolicy () );
183
196
184
197
Settings settings = Settings .builder ()
185
198
.put (IndicesQueryCache .INDICES_CACHE_QUERY_COUNT_SETTING .getKey (), 10 )
@@ -295,7 +308,7 @@ public void testStatsOnEviction() throws IOException {
295
308
ShardId shard1 = new ShardId ("index" , "_na_" , 0 );
296
309
r1 = ElasticsearchDirectoryReader .wrap (r1 , shard1 );
297
310
IndexSearcher s1 = new IndexSearcher (r1 );
298
- s1 .setQueryCachingPolicy (QueryCachingPolicy . ALWAYS_CACHE );
311
+ s1 .setQueryCachingPolicy (alwaysCachePolicy () );
299
312
300
313
Directory dir2 = newDirectory ();
301
314
IndexWriter w2 = new IndexWriter (dir2 , newIndexWriterConfig ());
@@ -305,7 +318,7 @@ public void testStatsOnEviction() throws IOException {
305
318
ShardId shard2 = new ShardId ("index" , "_na_" , 1 );
306
319
r2 = ElasticsearchDirectoryReader .wrap (r2 , shard2 );
307
320
IndexSearcher s2 = new IndexSearcher (r2 );
308
- s2 .setQueryCachingPolicy (QueryCachingPolicy . ALWAYS_CACHE );
321
+ s2 .setQueryCachingPolicy (alwaysCachePolicy () );
309
322
310
323
Settings settings = Settings .builder ()
311
324
.put (IndicesQueryCache .INDICES_CACHE_QUERY_COUNT_SETTING .getKey (), 10 )
0 commit comments