Search in sources :

Example 1 with AggregationBuilder

use of com.b2international.index.aggregations.AggregationBuilder in project snow-owl by b2ihealthcare.

the class RevisionIndexReadRequest method execute.

@Override
public B execute(final BranchContext context) {
    final String branchPath = context.path();
    RevisionIndex index = context.service(RevisionIndex.class);
    if (snapshot) {
        return index.read(branchPath, searcher -> {
            try {
                return next(context.inject().bind(RevisionSearcher.class, searcher).build());
            } catch (QueryParseException e) {
                throw new IllegalQueryParameterException(e.getMessage());
            }
        });
    } else {
        return next(context.inject().bind(RevisionSearcher.class, new RevisionSearcher() {

            @Override
            public <T> Aggregation<T> aggregate(AggregationBuilder<T> aggregation) throws IOException {
                return index.read(branchPath, searcher -> searcher.aggregate(aggregation));
            }

            @Override
            public Searcher searcher() {
                return index.read(branchPath, searcher -> searcher.searcher());
            }

            @Override
            public <T> Hits<T> search(Query<T> query) throws IOException {
                return index.read(branchPath, searcher -> searcher.search(query));
            }

            @Override
            public <T> Iterable<T> get(Class<T> type, Iterable<String> keys) throws IOException {
                return index.read(branchPath, searcher -> searcher.get(type, keys));
            }

            @Override
            public <T> T get(Class<T> type, String key) throws IOException {
                return index.read(branchPath, searcher -> searcher.get(type, key));
            }

            @Override
            public String branch() {
                return branchPath;
            }
        }).build());
    }
}
Also used : Searcher(com.b2international.index.Searcher) Query(com.b2international.index.query.Query) Hits(com.b2international.index.Hits) QueryParseException(com.b2international.index.query.QueryParseException) Request(com.b2international.snowowl.core.events.Request) IOException(java.io.IOException) Aggregation(com.b2international.index.aggregations.Aggregation) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) AggregationBuilder(com.b2international.index.aggregations.AggregationBuilder) RevisionIndex(com.b2international.index.revision.RevisionIndex) DelegatingRequest(com.b2international.snowowl.core.events.DelegatingRequest) IllegalQueryParameterException(com.b2international.commons.exceptions.IllegalQueryParameterException) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Hits(com.b2international.index.Hits) RevisionIndex(com.b2international.index.revision.RevisionIndex) Searcher(com.b2international.index.Searcher) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) IOException(java.io.IOException) QueryParseException(com.b2international.index.query.QueryParseException) Aggregation(com.b2international.index.aggregations.Aggregation) IllegalQueryParameterException(com.b2international.commons.exceptions.IllegalQueryParameterException) RevisionSearcher(com.b2international.index.revision.RevisionSearcher)

Aggregations

IllegalQueryParameterException (com.b2international.commons.exceptions.IllegalQueryParameterException)1 Hits (com.b2international.index.Hits)1 Searcher (com.b2international.index.Searcher)1 Aggregation (com.b2international.index.aggregations.Aggregation)1 AggregationBuilder (com.b2international.index.aggregations.AggregationBuilder)1 Query (com.b2international.index.query.Query)1 QueryParseException (com.b2international.index.query.QueryParseException)1 RevisionIndex (com.b2international.index.revision.RevisionIndex)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 DelegatingRequest (com.b2international.snowowl.core.events.DelegatingRequest)1 Request (com.b2international.snowowl.core.events.Request)1 IOException (java.io.IOException)1