Commit 4fd19bc1 authored by Matija Obreza's avatar Matija Obreza Committed by Maxym Borodenko
Browse files

Taxonomy filters: synonymous search is optional

parent 7d873476
......@@ -27,13 +27,17 @@ import org.genesys2.server.model.genesys.QTaxonomy2;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.service.TaxonomyService;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
/**
* The Class TaxonomyFilter.
*/
public class TaxonomyFilter extends AuditedVersionedModelFilter<TaxonomyFilter, Taxonomy2> {
// Handle synonymous names, null is treated as true
public Boolean synonyms;
/** The genus. */
public Set<String> genus;
......@@ -72,23 +76,49 @@ public class TaxonomyFilter extends AuditedVersionedModelFilter<TaxonomyFilter,
// We need to look up the taxonomy2.id for provided names so that ES queries also work out of the box
List<Long> taxGenus = taxonomyService.findTaxonomy2GenusId(new ArrayList<>(genus));
List<Long> grinGenus = taxonomyService.findGrinGenusId(new ArrayList<>(genus));
predicates.add(taxonomy.taxGenus.in(taxGenus).or(taxonomy.grinTaxonomySpecies.taxonomyGenus.id.in(grinGenus)).or(taxonomy.currentTaxonomySpecies.taxonomyGenus.id.in(grinGenus)));
BooleanBuilder builder = new BooleanBuilder(taxonomy.taxGenus.in(taxGenus));
builder.or(taxonomy.grinTaxonomySpecies.taxonomyGenus.id.in(grinGenus));
if (synonyms == null || synonyms) {
builder.or(taxonomy.currentTaxonomySpecies.taxonomyGenus.id.in(grinGenus));
}
predicates.add(builder);
}
if (species != null && !species.isEmpty()) {
predicates.add(taxonomy.species.in(species).or(taxonomy.grinTaxonomySpecies.speciesName.in(species).or(taxonomy.currentTaxonomySpecies.speciesName.in(species))));
BooleanBuilder builder = new BooleanBuilder(taxonomy.species.in(species));
builder.or(taxonomy.grinTaxonomySpecies.speciesName.in(species));
if (synonyms == null || synonyms) {
builder.or(taxonomy.currentTaxonomySpecies.speciesName.in(species));
}
predicates.add(builder);
}
if (subtaxa != null) {
predicates.add(subtaxa.buildQuery(taxonomy.subtaxa).or(subtaxa.buildQuery(taxonomy.grinTaxonomySpecies.subtaxa)).or(subtaxa.buildQuery(taxonomy.currentTaxonomySpecies.subtaxa)));
BooleanBuilder builder = new BooleanBuilder(subtaxa.buildQuery(taxonomy.subtaxa));
builder.or(subtaxa.buildQuery(taxonomy.grinTaxonomySpecies.subtaxa));
if (synonyms == null || synonyms) {
builder.or(subtaxa.buildQuery(taxonomy.currentTaxonomySpecies.subtaxa));
}
predicates.add(builder);
}
if (taxonName != null) {
predicates.add(taxonName.buildQuery(taxonomy.taxonName).or(taxonName.buildQuery(taxonomy.grinTaxonomySpecies.name)).or(taxonName.buildQuery(taxonomy.currentTaxonomySpecies.name)));
BooleanBuilder builder = new BooleanBuilder(taxonName.buildQuery(taxonomy.taxonName));
builder.or(taxonName.buildQuery(taxonomy.grinTaxonomySpecies.name));
if (synonyms == null || synonyms) {
builder.or(taxonName.buildQuery(taxonomy.currentTaxonomySpecies.name));
}
predicates.add(builder);
}
if (CollectionUtils.isNotEmpty(genusSpecies) && taxonomyService != null) {
// We need to look up the taxonomy2.id for provided names so that ES queries also work out of the box
List<Long> taxSpecies = taxonomyService.findTaxonomy2SpeciesId(new ArrayList<>(genusSpecies));
List<Long> grinSpecies = taxonomyService.findGrinSpeciesId(new ArrayList<>(genusSpecies));
predicates.add(taxonomy.taxSpecies.in(taxSpecies).or(taxonomy.grinTaxonomySpecies.id.in(grinSpecies)).or(taxonomy.currentTaxonomySpecies.id.in(grinSpecies)));
BooleanBuilder builder = new BooleanBuilder(taxonomy.taxSpecies.in(taxSpecies));
builder.or(taxonomy.grinTaxonomySpecies.id.in(grinSpecies));
if (synonyms == null || synonyms) {
builder.or(taxonomy.currentTaxonomySpecies.id.in(grinSpecies));
}
predicates.add(builder);
}
return predicates;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment