Package org.elasticsearch.search.internal

Examples of org.elasticsearch.search.internal.SearchContext


        String parentType = childDocMapper.parentFieldMapper().type();

        // wrap the query with type query
        query = new FilteredQuery(query, parseContext.cacheFilter(childDocMapper.typeFilter(), null));

        SearchContext searchContext = SearchContext.current();

        HasChildFilter childFilter = new HasChildFilter(query, scope, childType, parentType, searchContext);
        searchContext.addScopePhase(childFilter);

        if (filterName != null) {
            parseContext.addNamedFilter(filterName, childFilter);
        }
        return childFilter;
View Full Code Here


        new MatchQueryBuilder(null, cache, null, options);
    }

    @Test
    public void testSimpleSingleMatchSingleTerm() throws Exception {
        SearchContext searchContext = mockSearchContext();
        Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).map();
        MatchQueryBuilder builder = new MatchQueryBuilder(searchContext, cache, null, Collections.emptyMap());
        Query query = builder.query(fields, new BytesRef("foo"));
        assertThat(query, instanceOf(TermQuery.class));
    }
View Full Code Here

        assertThat(query, instanceOf(TermQuery.class));
    }

    @Test
    public void testSimpleSingleMatchTwoTerms() throws Exception {
        SearchContext searchContext = mockSearchContext();
        Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).map();
        MatchQueryBuilder builder = new MatchQueryBuilder(searchContext, cache, null, Collections.emptyMap());
        Query query = builder.query(fields, new BytesRef("foo bar"));
        assertThat(query, instanceOf(BooleanQuery.class));
    }
View Full Code Here

        assertThat(query, instanceOf(BooleanQuery.class));
    }

    @Test
    public void testSingleFieldWithCutFrequency() throws Exception {
        SearchContext searchContext = mockSearchContext();
        MatchQueryBuilder builder = new MatchQueryBuilder(
                searchContext, cache, null, newMapBuilder().put("cutoff_frequency", 3).map());

        Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder().put("col1", null).map();
        Query query = builder.query(fields, new BytesRef("foo bar"));
View Full Code Here

    }

    @Test
    public void testCrossFieldMatchType() throws Exception {
        Analyzer analyzer = new GermanAnalyzer(Version.LUCENE_4_9);
        SearchContext searchContext = mock(SearchContext.class);
        MapperService.SmartNameFieldMappers smartNameFieldMappers = mock(MapperService.SmartNameFieldMappers.class);
        when(searchContext.smartFieldMappers(anyString())).thenReturn(smartNameFieldMappers);
        when(smartNameFieldMappers.hasMapper()).thenReturn(true);
        FieldMapper fieldMapper = mock(FieldMapper.class, Answers.RETURNS_MOCKS.get());
        when(smartNameFieldMappers.mapper()).thenReturn(fieldMapper);
        when(fieldMapper.searchAnalyzer()).thenReturn(analyzer);

        MapperService mapperService = mock(MapperService.class);
        when(searchContext.mapperService()).thenReturn(mapperService);
        when(mapperService.searchAnalyzer()).thenReturn(analyzer);

        MatchQueryBuilder builder = new io.crate.lucene.match.MultiMatchQueryBuilder(
                searchContext, cache, new BytesRef("cross_fields"), Collections.emptyMap());
        Map<String, Object> fields = MapBuilder.<String, Object>newMapBuilder()
View Full Code Here

        assertThat(query, instanceOf(MultiPhrasePrefixQuery.class));
    }

    private SearchContext mockSearchContext() {
        Analyzer analyzer = new GermanAnalyzer(Version.LUCENE_4_9);
        SearchContext searchContext = mock(SearchContext.class);
        MapperService mapperService = mock(MapperService.class);
        when(searchContext.mapperService()).thenReturn(mapperService);
        when(mapperService.searchAnalyzer()).thenReturn(analyzer);
        return searchContext;
    }
View Full Code Here

        fieldData.load(readerContext);

        ShardSearchRequest request = new ShardSearchRequest();
        request.types(new String[]{Constants.DEFAULT_MAPPING_TYPE});

        SearchContext searchContext = mock(SearchContext.class);
        when(searchContext.mapperService()).thenReturn(mapperService);
        when(searchContext.fieldData()).thenReturn(ifd);
        ctx = new CollectorContext().searchContext(searchContext);
    }
View Full Code Here

                new CollectInputSymbolVisitor<>(functions, LuceneDocLevelReferenceResolver.INSTANCE);
        sortSymbolVisitor = new SortSymbolVisitor(inputSymbolVisitor);
    }

    public QuerySearchResult executeQueryPhase(QueryShardRequest request) {
        SearchContext context = createAndPutContext(request);
        try {
            context.indexShard().searchService().onPreQueryPhase(context);
            long time = System.nanoTime();
            contextProcessing(context);
            queryPhase.execute(context);

            assert context.searchType() != SearchType.COUNT : "searchType COUNT is not supported using QueryShardRequests";
            contextProcessedSuccessfully(context);

            context.indexShard().searchService().onQueryPhase(context, System.nanoTime() - time);
            return context.queryResult();
        } catch (Throwable e) {
            context.indexShard().searchService().onFailedQueryPhase(context);
            logger.trace("Query phase failed", e);
            freeContext(context.id());
            throw ExceptionsHelper.convertToRuntime(e);
        } finally {
            cleanContext(context);
        }
    }
View Full Code Here

            cleanContext(context);
        }
    }

    private SearchContext createAndPutContext(QueryShardRequest request) {
        SearchContext context = createContext(request, null);
        boolean success = false;
        try {
            activeContexts.put(context.id(), context);
            context.indexShard().searchService().onNewContext(context);
            success = true;
            return context;
        } finally {
            if (!success) {
                freeContext(context.id());
            }
        }
    }
View Full Code Here

        ShardSearchRequest shardSearchRequest = new ShardSearchRequest();
        shardSearchRequest.types(new String[] {Constants.DEFAULT_MAPPING_TYPE });

        // TODO: use own CrateSearchContext that doesn't require ShardSearchRequest
        SearchContext context = new DefaultSearchContext(
                idGenerator.incrementAndGet(),
                shardSearchRequest,
                searchShardTarget,
                engineSearcher,
                indexService,
                indexShard,
                scriptService,
                cacheRecycler,
                pageCacheRecycler,
                bigArrays
        );
        SearchContext.setCurrent(context);

        try {
            LuceneQueryBuilder builder = new LuceneQueryBuilder(functions, context, indexService.cache());
            LuceneQueryBuilder.Context ctx = builder.convert(request.whereClause());
            context.parsedQuery(new ParsedQuery(ctx.query(), ImmutableMap.<String, Filter>of()));
            Float minScore = ctx.minScore();
            if (minScore != null) {
                context.minimumScore(minScore);
            }

            // the OUTPUTS_VISITOR sets the sourceFetchContext / version / minScore onto the SearchContext
            OutputContext outputContext = new OutputContext(context, request.partitionBy());
            OUTPUTS_VISITOR.process(request.outputs(), outputContext);

            context.sort(generateLuceneSort(
                    context, request.orderBy(), request.reverseFlags(), request.nullsFirst()));

            context.from(request.offset());
            context.size(request.limit());

            // pre process
            dfsPhase.preProcess(context);
            queryPhase.preProcess(context);
            fetchPhase.preProcess(context);

            // compute the context keep alive
            long keepAlive = defaultKeepAlive;
            context.keepAlive(keepAlive);
        } catch (Throwable e) {
            context.close();
            throw ExceptionsHelper.convertToRuntime(e);
        }
        return context;
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.internal.SearchContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.