Search in sources :

Example 1 with Query

use of org.obiba.mica.spi.search.support.Query in project mica2 by obiba.

the class DatasetQuery method updateDatasetQuery.

private void updateDatasetQuery() {
    if (datasetIdProvider == null)
        return;
    List<String> datasetIds = datasetIdProvider.getIds();
    if (datasetIds.size() > 0) {
        Query datasetQuery = searcher.makeQuery(String.format("in(%s,(%s))", "id", Joiner.on(",").join(datasetIds)));
        setQuery(isQueryNotEmpty() ? searcher.andQuery(getQuery(), datasetQuery) : datasetQuery);
    }
}
Also used : Query(org.obiba.mica.spi.search.support.Query)

Example 2 with Query

use of org.obiba.mica.spi.search.support.Query in project mica2 by obiba.

the class VariableQuery method updateDatasetQuery.

private void updateDatasetQuery() {
    if (datasetIdProvider == null)
        return;
    List<String> datasetIds = datasetIdProvider.getIds();
    if (datasetIds.size() > 0) {
        Query datasetQuery = searcher.makeQuery(String.format("in(%s,(%s))", DATASET_ID, Joiner.on(",").join(datasetIds)));
        setQuery(isQueryNotEmpty() ? searcher.andQuery(getQuery(), datasetQuery) : datasetQuery);
    }
}
Also used : Query(org.obiba.mica.spi.search.support.Query)

Example 3 with Query

use of org.obiba.mica.spi.search.support.Query in project mica2 by obiba.

the class AbstractDocumentQuery method createStudyIdQuery.

private Query createStudyIdQuery(List<String> studyIds) {
    if (studyIds == null || studyIds.isEmpty()) {
        return query.isEmpty() ? new EmptyQuery() : query;
    }
    List<String> joinFields = getJoinFields();
    String joinedStudyIds = Joiner.on(",").join(studyIds);
    String rql;
    if (joinFields.size() == 1) {
        rql = String.format("in(%s,(%s))", joinFields.get(0), joinedStudyIds);
    } else {
        rql = String.format("or(%s)", joinFields.stream().map(field -> String.format("in(%s,(%s))", field, joinedStudyIds)).collect(Collectors.joining(",")));
    }
    // return searcher.makeQuery(String.format("%s,limit(%s,%s)", rql, query.getFrom(), query.getSize()));
    return searcher.makeQuery(rql);
}
Also used : EmptyQuery(org.obiba.mica.spi.search.support.EmptyQuery) java.util(java.util) AggregationHelper(org.obiba.mica.spi.search.support.AggregationHelper) Query(org.obiba.mica.spi.search.support.Query) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) LoggerFactory(org.slf4j.LoggerFactory) QueryResultDto(org.obiba.mica.web.model.MicaSearch.QueryResultDto) AggregationMetaDataProvider(org.obiba.mica.micaConfig.service.helper.AggregationMetaDataProvider) QueryMode(org.obiba.mica.spi.search.QueryMode) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) MicaSearch(org.obiba.mica.web.model.MicaSearch) Lists(com.google.common.collect.Lists) DocumentQueryHelper(org.obiba.mica.search.DocumentQueryHelper) CountStatsData(org.obiba.mica.spi.search.CountStatsData) TaxonomyEntity(org.obiba.opal.core.domain.taxonomy.TaxonomyEntity) Nullable(javax.annotation.Nullable) QueryScope(org.obiba.mica.spi.search.QueryScope) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) Searcher(org.obiba.mica.spi.search.Searcher) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) COVERAGE(org.obiba.mica.spi.search.QueryMode.COVERAGE) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) EmptyQuery(org.obiba.mica.spi.search.support.EmptyQuery) DETAIL(org.obiba.mica.spi.search.QueryScope.DETAIL) AggregationMetaDataResolver(org.obiba.mica.search.aggregations.AggregationMetaDataResolver) StringReader(java.io.StringReader) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) TaxonomyService(org.obiba.mica.micaConfig.service.TaxonomyService) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner)

Example 4 with Query

use of org.obiba.mica.spi.search.support.Query in project mica2 by obiba.

the class AbstractDocumentQuery method queryStudyIds.

private List<String> queryStudyIds(Query localQuery) {
    if (localQuery == null)
        return null;
    if ("Network".equals(getSearchType()) && !micaConfigService.getConfig().isNetworkEnabled())
        return null;
    Query updatedQuery = updateWithJoinKeyQuery(localQuery);
    Searcher.IdFilter idFilter = getAccessibleIdFilter();
    try {
        Searcher.DocumentResults results = searcher.aggregate(getSearchIndex(), getSearchType(), updatedQuery, getJoinFieldsAsProperties(), idFilter);
        DocumentQueryJoinKeys joinKeys = processJoinKeys(results);
        return joinKeys.studyIds.stream().distinct().collect(Collectors.toList());
    } catch (Exception e) {
        log.error("Query study IDs execution error [{}]: {}", getSearchType(), e.getMessage());
        if (log.isDebugEnabled())
            log.error("Query study IDs execution error", e);
    }
    return Lists.newArrayList();
}
Also used : Query(org.obiba.mica.spi.search.support.Query) EmptyQuery(org.obiba.mica.spi.search.support.EmptyQuery) Searcher(org.obiba.mica.spi.search.Searcher) IOException(java.io.IOException)

Example 5 with Query

use of org.obiba.mica.spi.search.support.Query in project mica2 by obiba.

the class CoverageQueryExecutor method coverageQuery.

public MicaSearch.TaxonomiesCoverageDto coverageQuery(String rqlJoinQuery, boolean strict) throws IOException {
    joinQuery = searcher.makeJoinQuery(rqlJoinQuery);
    // If no variable query is specified, nothing is returned if strictness is applied, otherwise coverage of all terms is returned.
    if (strict) {
        restrictedTermsMap = joinQuery.getVariableQuery().getTaxonomyTermsMap();
        // If do not need all the facets then we can restrict the variable aggregations to the ones matching these names.
        if (!joinQuery.isWithFacets()) {
            restrictedTermsMap.forEach((taxo, vocMap) -> vocMap.keySet().forEach(voc -> joinQuery.getVariableQuery().getAggregations().add("attributes." + AttributeKey.getMapKey(voc, taxo) + "." + LanguageTag.UNDETERMINED)));
        }
    }
    // We need the aggregations internally for building the coverage result,
    // but we may not need them in the final result
    JoinQuery joinQueryWithFacets = new JoinQueryWrapperWithFacets(joinQuery);
    MicaSearch.JoinQueryResultDto result = joinQueryExecutor.queryCoverage(joinQueryWithFacets);
    List<MicaSearch.AggregationResultDto> aggregations = ungroupAggregations(result.getVariableResultDto().getAggsList());
    MicaSearch.TaxonomiesCoverageDto.Builder builder = // 
    MicaSearch.TaxonomiesCoverageDto.newBuilder().setTotalCount(// 
    result.getVariableResultDto().getTotalCount()).setTotalHits(// 
    result.getVariableResultDto().getTotalHits()).addAllTaxonomies(getCoverages(aggregations)).setQueryResult(result);
    // Do not append the aggregations if no facets is requested
    if (joinQuery.isWithFacets())
        builder.setQueryResult(result);
    return builder.build();
}
Also used : Searcher(org.obiba.mica.spi.search.Searcher) Query(org.obiba.mica.spi.search.support.Query) Collection(java.util.Collection) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) IOException(java.io.IOException) AttributeKey(org.obiba.mica.spi.search.support.AttributeKey) OpalService(org.obiba.mica.micaConfig.service.OpalService) NotNull(javax.validation.constraints.NotNull) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Scope(org.springframework.context.annotation.Scope) Term(org.obiba.opal.core.domain.taxonomy.Term) Inject(javax.inject.Inject) MicaSearch(org.obiba.mica.web.model.MicaSearch) Component(org.springframework.stereotype.Component) List(java.util.List) Lists(com.google.common.collect.Lists) LanguageTag(sun.util.locale.LanguageTag) JoinQuery(org.obiba.mica.spi.search.support.JoinQuery) Map(java.util.Map) Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Dtos(org.obiba.mica.web.model.Dtos) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) JoinQuery(org.obiba.mica.spi.search.support.JoinQuery) MicaSearch(org.obiba.mica.web.model.MicaSearch)

Aggregations

Query (org.obiba.mica.spi.search.support.Query)5 IOException (java.io.IOException)3 Searcher (org.obiba.mica.spi.search.Searcher)3 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 Inject (javax.inject.Inject)2 EmptyQuery (org.obiba.mica.spi.search.support.EmptyQuery)2 MicaSearch (org.obiba.mica.web.model.MicaSearch)2 Taxonomy (org.obiba.opal.core.domain.taxonomy.Taxonomy)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Joiner (com.google.common.base.Joiner)1 Strings (com.google.common.base.Strings)1 StringReader (java.io.StringReader)1 java.util (java.util)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1