Search in sources :

Example 1 with QueryCachingPolicy

use of org.apache.lucene.search.QueryCachingPolicy in project elasticsearch by elastic.

the class ElasticsearchQueryCachingPolicyTests method testDoesNotCacheTermQueries.

public void testDoesNotCacheTermQueries() throws IOException {
    QueryCachingPolicy policy = QueryCachingPolicy.ALWAYS_CACHE;
    assertTrue(policy.shouldCache(new TermQuery(new Term("foo", "bar"))));
    assertTrue(policy.shouldCache(new PhraseQuery("foo", "bar", "baz")));
    policy = new ElasticsearchQueryCachingPolicy(policy);
    assertFalse(policy.shouldCache(new TermQuery(new Term("foo", "bar"))));
    assertTrue(policy.shouldCache(new PhraseQuery("foo", "bar", "baz")));
}
Also used : QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) TermQuery(org.apache.lucene.search.TermQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) Term(org.apache.lucene.index.Term)

Example 2 with QueryCachingPolicy

use of org.apache.lucene.search.QueryCachingPolicy in project elasticsearch by elastic.

the class ElasticsearchQueryCachingPolicyTests method testDoesNotPutTermQueriesIntoTheHistory.

public void testDoesNotPutTermQueriesIntoTheHistory() {
    boolean[] used = new boolean[1];
    QueryCachingPolicy policy = new QueryCachingPolicy() {

        @Override
        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]);
}
Also used : QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) TermQuery(org.apache.lucene.search.TermQuery) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) PhraseQuery(org.apache.lucene.search.PhraseQuery) Term(org.apache.lucene.index.Term)

Example 3 with QueryCachingPolicy

use of org.apache.lucene.search.QueryCachingPolicy in project elasticsearch by elastic.

the class AggregatorTestCase method createSearchContext.

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
        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 -> {
        releasables.add((Releasable) invocation.getArguments()[0]);
        return null;
    }).when(searchContext).addReleasable(anyObject(), anyObject());
    return searchContext;
}
Also used : QueryCachingPolicy(org.apache.lucene.search.QueryCachingPolicy) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) QueryCache(org.apache.lucene.search.QueryCache) Query(org.apache.lucene.search.Query) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) FetchPhase(org.elasticsearch.search.fetch.FetchPhase) ContextIndexSearcher(org.elasticsearch.search.internal.ContextIndexSearcher) SearchContext(org.elasticsearch.search.internal.SearchContext) Engine(org.elasticsearch.index.engine.Engine) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) FetchSourceSubPhase(org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase) DocValueFieldsFetchSubPhase(org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase)

Aggregations

QueryCachingPolicy (org.apache.lucene.search.QueryCachingPolicy)3 Term (org.apache.lucene.index.Term)2 PhraseQuery (org.apache.lucene.search.PhraseQuery)2 Query (org.apache.lucene.search.Query)2 TermQuery (org.apache.lucene.search.TermQuery)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 QueryCache (org.apache.lucene.search.QueryCache)1 DisabledQueryCache (org.elasticsearch.index.cache.query.DisabledQueryCache)1 Engine (org.elasticsearch.index.engine.Engine)1 FetchPhase (org.elasticsearch.search.fetch.FetchPhase)1 DocValueFieldsFetchSubPhase (org.elasticsearch.search.fetch.subphase.DocValueFieldsFetchSubPhase)1 FetchSourceSubPhase (org.elasticsearch.search.fetch.subphase.FetchSourceSubPhase)1 ContextIndexSearcher (org.elasticsearch.search.internal.ContextIndexSearcher)1 SearchContext (org.elasticsearch.search.internal.SearchContext)1