Commit 66ef63f4 authored by Matija Obreza's avatar Matija Obreza

TaxonomyFilter: use Taxonomy2.id instead of joined tables

parent 04926eae
......@@ -83,4 +83,16 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long>, Que
@Query("select distinct t.genus from Taxonomy2 t")
List<String> getAllGenera();
@Query("select distinct t.id from Taxonomy2 t where t.grinTaxonomySpecies.taxonomyGenus.name in (?1)")
List<Long> findByGrinGenus(List<String> genus);
@Query("select distinct t.id from Taxonomy2 t where t.currentTaxonomySpecies.taxonomyGenus.name in (?1)")
List<Long> findByCurrentGrinGenus(List<String> genus);
@Query("select distinct t.id from Taxonomy2 t where t.grinTaxonomySpecies.genusSpecies in (?1)")
List<Long> findByGrinGenusAndSpecies(List<String> genusSpecies);
@Query("select distinct t.id from Taxonomy2 t where t.currentTaxonomySpecies.genusSpecies in (?1)")
List<Long> findByCurrentGrinGenusAndSpecies(List<String> genusSpecies);
}
......@@ -19,7 +19,6 @@ package org.genesys2.server.service;
import java.io.Serializable;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.grin.TaxonomySpecies;
import org.genesys2.server.service.filter.TaxonomyExtraFilter;
......@@ -29,6 +28,8 @@ import org.genesys2.server.service.impl.SearchException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
public interface TaxonomyService {
List<String> autocompleteGenus(String term);
......@@ -90,4 +91,11 @@ public interface TaxonomyService {
return taxonomy2Info;
}
}
List<Long> findTaxonomy2ByGrinGenus(List<String> genus);
List<Long> findTaxonomy2ByCurrentGrinGenus(List<String> genus);
List<Long> findTaxonomy2ByGrinSpecies(List<String> genusSpecies);
List<Long> findTaxonomy2ByCurrentGrinSpecies(List<String> genusSpecies);
}
......@@ -76,13 +76,16 @@ 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));
List<Long> taxByGrinGenus = taxonomyService.findTaxonomy2ByGrinGenus(new ArrayList<>(genus));
BooleanBuilder builder = new BooleanBuilder(taxonomy.taxGenus.in(taxGenus));
if (!grinGenus.isEmpty()) {
builder.or(taxonomy.grinTaxonomySpecies.taxonomyGenus.id.in(grinGenus));
if (!taxByGrinGenus.isEmpty()) {
builder.or(taxonomy.id.in(taxByGrinGenus));
if (synonyms == null || synonyms) {
builder.or(taxonomy.currentTaxonomySpecies.taxonomyGenus.id.in(grinGenus));
List<Long> taxByCurrentGrinGenus = taxonomyService.findTaxonomy2ByCurrentGrinGenus(new ArrayList<>(genus));
if (! taxByCurrentGrinGenus.isEmpty()) {
builder.or(taxonomy.id.in(taxByCurrentGrinGenus));
}
}
}
predicates.add(builder);
......@@ -115,13 +118,16 @@ 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> taxSpecies = taxonomyService.findTaxonomy2SpeciesId(new ArrayList<>(genusSpecies));
List<Long> grinSpecies = taxonomyService.findGrinSpeciesId(new ArrayList<>(genusSpecies));
List<Long> taxByGrinSpecies = taxonomyService.findTaxonomy2ByGrinSpecies(new ArrayList<>(genusSpecies));
BooleanBuilder builder = new BooleanBuilder(taxonomy.taxSpecies.in(taxSpecies));
if (!grinSpecies.isEmpty()) {
builder.or(taxonomy.grinTaxonomySpecies.id.in(grinSpecies));
if (!taxByGrinSpecies.isEmpty()) {
builder.or(taxonomy.id.in(taxByGrinSpecies));
if (synonyms == null || synonyms) {
builder.or(taxonomy.currentTaxonomySpecies.id.in(grinSpecies));
List<Long> taxByCurrentGrinSpecies = taxonomyService.findTaxonomy2ByCurrentGrinSpecies(new ArrayList<>(genusSpecies));
if (! taxByCurrentGrinSpecies.isEmpty()) {
builder.or(taxonomy.id.in(taxByCurrentGrinSpecies));
}
}
}
predicates.add(builder);
......
......@@ -376,4 +376,24 @@ public class TaxonomyServiceImpl implements TaxonomyService {
public List<Long> findGrinSpeciesId(List<String> speciesNames) {
return grinSpeciesRepository.findTaxonomySpeciesId(speciesNames);
}
@Override
public List<Long> findTaxonomy2ByGrinGenus(List<String> genus) {
return taxonomy2Repository.findByGrinGenus(genus);
}
@Override
public List<Long> findTaxonomy2ByCurrentGrinGenus(List<String> genus) {
return taxonomy2Repository.findByCurrentGrinGenus(genus);
}
@Override
public List<Long> findTaxonomy2ByGrinSpecies(List<String> genusSpecies) {
return taxonomy2Repository.findByGrinGenusAndSpecies(genusSpecies);
}
@Override
public List<Long> findTaxonomy2ByCurrentGrinSpecies(List<String> genusSpecies) {
return taxonomy2Repository.findByCurrentGrinGenusAndSpecies(genusSpecies);
}
}
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