Search in sources :

Example 1 with Searcher

use of com.b2international.index.Searcher 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)

Example 2 with Searcher

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

the class SearchIndexResourceRequest method doExecute.

@Override
protected final B doExecute(C context) throws IOException {
    final Searcher searcher = searcher(context);
    final Expression where = prepareQuery(context);
    // configure additional fields to load when subsetting the response
    List<String> fields = fields();
    if (!fields().isEmpty()) {
        fields = configureFieldsToLoad(fields);
    }
    final Hits<D> hits = searcher.search(Query.select(getSelect()).from(getFrom()).fields(fields).where(where).searchAfter(searchAfter()).limit(limit()).sortBy(querySortBy(context)).withScores(trackScores()).cached(cacheHits(context)).build());
    return toCollectionResource(context, hits);
}
Also used : Expression(com.b2international.index.query.Expression) Searcher(com.b2international.index.Searcher) RevisionSearcher(com.b2international.index.revision.RevisionSearcher)

Aggregations

Searcher (com.b2international.index.Searcher)2 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)2 IllegalQueryParameterException (com.b2international.commons.exceptions.IllegalQueryParameterException)1 Hits (com.b2international.index.Hits)1 Aggregation (com.b2international.index.aggregations.Aggregation)1 AggregationBuilder (com.b2international.index.aggregations.AggregationBuilder)1 Expression (com.b2international.index.query.Expression)1 Query (com.b2international.index.query.Query)1 QueryParseException (com.b2international.index.query.QueryParseException)1 RevisionIndex (com.b2international.index.revision.RevisionIndex)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