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);
}
}
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);
}
}
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);
}
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();
}
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();
}
Aggregations