use of org.obiba.mica.spi.search.TaxonomyTarget in project mica2 by obiba.
the class AbstractTaxonomySearchResource method filterTerms.
protected List<String> filterTerms(TaxonomyTarget target, String query, String locale, List<String> vocabularies) {
try {
if (vocabularies != null && vocabularies.size() > 0) {
// filter on vocabulary names; remove taxonomy prefixes ('Mica_study:')
String vocabulariesQuery = vocabularies.stream().map(v -> String.format("vocabularyName:%s", v.replaceAll("^([^\\:]+):", ""))).collect(Collectors.joining(" AND "));
query = Strings.isNullOrEmpty(query) ? vocabulariesQuery : query + " " + vocabulariesQuery;
}
return esTaxonomyTermService.find(0, MAX_SIZE, DEFAULT_SORT, "asc", null, getTargettedQuery(target, query), getFields(locale, TERM_FIELDS)).getList();
} catch (Exception e) {
initTaxonomies();
// for a 404 response
throw new NoSuchElementException();
}
}
use of org.obiba.mica.spi.search.TaxonomyTarget in project mica2 by obiba.
the class TaxonomiesSearchResource method filter.
@GET
@Path("/_filter")
@Timed
public List<Opal.TaxonomyDto> filter(@QueryParam("target") @DefaultValue("variable") String target, @QueryParam("query") String query, @QueryParam("locale") String locale) {
TaxonomyTarget taxonomyTarget = getTaxonomyTarget(target);
List<String> filteredVocabularies = filterVocabularies(taxonomyTarget, query, locale);
Map<String, Map<String, List<String>>> taxoNamesMap = TaxonomyResolver.asMap(filteredVocabularies, filterTerms(taxonomyTarget, query, locale, filteredVocabularies));
List<Opal.TaxonomyDto> results = Lists.newArrayList();
getTaxonomies(taxonomyTarget).stream().filter(t -> taxoNamesMap.containsKey(t.getName())).forEach(taxo -> {
Opal.TaxonomyDto.Builder tBuilder = Dtos.asDto(taxo, false).toBuilder();
populate(tBuilder, taxo, taxoNamesMap);
results.add(tBuilder.build());
});
return results;
}
use of org.obiba.mica.spi.search.TaxonomyTarget in project mica2 by obiba.
the class TaxonomySearchResource method filterVocabulary.
@GET
@Path("/vocabulary/{vocabulary}/_filter")
@Timed
public Opal.VocabularyDto filterVocabulary(@PathParam("name") String name, @PathParam("vocabulary") String vocabularyName, @QueryParam("target") @DefaultValue("variable") String target, @QueryParam("query") String query, @QueryParam("locale") String locale) {
TaxonomyTarget taxonomyTarget = getTaxonomyTarget(target);
if (taxonomyTarget.equals(TaxonomyTarget.TAXONOMY))
return Dtos.asDto(getTaxonomy(taxonomyTarget, name).getVocabulary(vocabularyName));
List<String> foundVocabularies = filterVocabularies(taxonomyTarget, String.format("name:%s", vocabularyName), locale);
if (foundVocabularies.isEmpty()) {
throw new NoSuchVocabularyException(name, vocabularyName);
}
Taxonomy taxonomy = getTaxonomy(taxonomyTarget, name);
Vocabulary vocabulary = taxonomy.getVocabulary(vocabularyName);
Opal.VocabularyDto.Builder tBuilder = Dtos.asDto(vocabulary, false).toBuilder();
String filteredQuery = String.format(Strings.isNullOrEmpty(query) ? "taxonomyName:%s AND vocabularyName:%s" : "taxonomyName:%s AND vocabularyName:%s AND (%s)", name, vocabularyName, query);
Map<String, Map<String, List<String>>> taxoNamesMap = asMap(filterTerms(taxonomyTarget, filteredQuery, locale, null));
if (taxoNamesMap.isEmpty() || !taxoNamesMap.containsKey(name) || taxoNamesMap.get(name).isEmpty() || taxoNamesMap.get(name).get(vocabularyName).isEmpty())
return tBuilder.build();
taxoNamesMap.get(name).get(vocabularyName).forEach(term -> tBuilder.addTerms(Dtos.asDto(vocabulary.getTerm(term))));
return tBuilder.build();
}
use of org.obiba.mica.spi.search.TaxonomyTarget in project mica2 by obiba.
the class TaxonomySearchResource method filterTaxonomy.
@GET
@Path("/_filter")
@Timed
public Opal.TaxonomyDto filterTaxonomy(@PathParam("name") String name, @QueryParam("target") @DefaultValue("variable") String target, @QueryParam("query") String query, @QueryParam("locale") String locale) {
TaxonomyTarget taxonomyTarget = getTaxonomyTarget(target);
if (taxonomyTarget.equals(TaxonomyTarget.TAXONOMY))
return Dtos.asDto(getTaxonomy(taxonomyTarget, name));
List<String> filteredVocabularies = filterVocabularies(taxonomyTarget, query, locale);
Map<String, Map<String, List<String>>> taxoNamesMap = asMap(filteredVocabularies, filterTerms(taxonomyTarget, query, locale, filteredVocabularies));
Taxonomy taxonomy = getTaxonomy(taxonomyTarget, name);
Opal.TaxonomyDto.Builder tBuilder = Dtos.asDto(taxonomy, false).toBuilder();
if (taxoNamesMap.isEmpty() || !taxoNamesMap.containsKey(name) || taxoNamesMap.get(name).isEmpty())
return tBuilder.build();
populate(tBuilder, taxonomy, taxoNamesMap);
return tBuilder.build();
}
Aggregations