List of usage examples for org.apache.lucene.search QueryCachingPolicy QueryCachingPolicy
QueryCachingPolicy
From source file:org.elasticsearch.index.shard.ElasticsearchQueryCachingPolicyTests.java
License:Apache License
public void testDoesNotPutTermQueriesIntoTheHistory() { boolean[] used = new boolean[1]; QueryCachingPolicy policy = new QueryCachingPolicy() { @Override/* w w w . ja v a2 s . c o m*/ public boolean shouldCache(Query query) throws IOException { throw new UnsupportedOperationException(); } @Override public void onUse(Query query) { used[0] = true; } }; policy = new ElasticsearchQueryCachingPolicy(policy); policy.onUse(new TermQuery(new Term("foo", "bar"))); assertFalse(used[0]); policy.onUse(new PhraseQuery("foo", "bar", "baz")); assertTrue(used[0]); }
From source file:org.elasticsearch.search.aggregations.AggregatorTestCase.java
License:Apache License
protected SearchContext createSearchContext(IndexSearcher indexSearcher, IndexSettings indexSettings) { Engine.Searcher searcher = new Engine.Searcher("aggregator_test", indexSearcher); QueryCache queryCache = new DisabledQueryCache(indexSettings); QueryCachingPolicy queryCachingPolicy = new QueryCachingPolicy() { @Override//from w w w. java 2 s.c o m public void onUse(Query query) { } @Override public boolean shouldCache(Query query) throws IOException { // never cache a query return false; } }; ContextIndexSearcher contextIndexSearcher = new ContextIndexSearcher(searcher, queryCache, queryCachingPolicy); SearchContext searchContext = mock(SearchContext.class); when(searchContext.numberOfShards()).thenReturn(1); when(searchContext.searcher()).thenReturn(contextIndexSearcher); when(searchContext.fetchPhase()).thenReturn( new FetchPhase(Arrays.asList(new FetchSourceSubPhase(), new DocValueFieldsFetchSubPhase()))); doAnswer(invocation -> { /* Store the releasables so we can release them at the end of the test case. This is important because aggregations don't * close their sub-aggregations. This is fairly similar to what the production code does. */ releasables.add((Releasable) invocation.getArguments()[0]); return null; }).when(searchContext).addReleasable(anyObject(), anyObject()); return searchContext; }