Skip to content

Commit

Permalink
change cancer type query to prioritize starts with (oncokb#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
bprize15 authored Jun 10, 2024
1 parent 4adbb8a commit 415a68d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public interface CancerTypeRepository extends JpaRepository<CancerType, Long>, J
@Query("select cancerType from CancerType cancerType left join fetch cancerType.synonyms where cancerType.id =:id")
Optional<CancerType> findOneWithEagerRelationships(@Param("id") Long id);

@Query(
"SELECT cancerType from CancerType cancerType WHERE cancerType.mainType LIKE %:containing% OR cancerType.subtype LIKE %:containing% OR cancerType.code LIKE %:containing% ORDER BY CASE WHEN cancerType.subtype LIKE :startsWith% THEN 0 WHEN cancerType.subtype IS NULL AND cancerType.mainType LIKE :startsWith% THEN 0 ELSE 1 END"
)
Page<CancerType> findAllByQueryPrioritizeStartsWith(
@Param("containing") String containing,
@Param("startsWith") String startsWith,
Pageable pageable
);

List<CancerType> findAllByMainTypeIs(@Param("maintype") String mainType);

List<CancerType> findByTumorFormIn(List<TumorForm> tumorForms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tech.jhipster.service.QueryService;
import tech.jhipster.service.filter.StringFilter;

/**
* Service for executing complex queries for {@link CancerType} entities in the database.
Expand All @@ -36,13 +35,7 @@ public CancerTypeQueryService(CancerTypeRepository cancerTypeRepository) {

@Transactional(readOnly = true)
public Page<CancerType> findBySearchQuery(String query, Pageable page) {
CancerTypeCriteria cancerTypeCriteria = new CancerTypeCriteria();
StringFilter stringFilter = new StringFilter();
stringFilter.setContains(query);
cancerTypeCriteria.setMainType(stringFilter);
cancerTypeCriteria.setSubtype(stringFilter);
cancerTypeCriteria.setCode(stringFilter);
return findByCriteria(cancerTypeCriteria, page);
return cancerTypeRepository.findAllByQueryPrioritizeStartsWith(query, query, page);
}

/**
Expand Down Expand Up @@ -119,34 +112,27 @@ protected Specification<CancerType> createSpecification(CancerTypeCriteria crite
specification = specification.or(buildSpecification(criteria.getTumorForm(), CancerType_.tumorForm));
}
if (criteria.getChildrenId() != null) {
specification =
specification.or(
buildSpecification(
criteria.getChildrenId(),
root -> root.join(CancerType_.children, JoinType.LEFT).get(CancerType_.id)
)
);
specification = specification.or(
buildSpecification(criteria.getChildrenId(), root -> root.join(CancerType_.children, JoinType.LEFT).get(CancerType_.id))
);
}
if (criteria.getSynonymId() != null) {
specification =
specification.or(
buildSpecification(criteria.getSynonymId(), root -> root.join(CancerType_.synonyms, JoinType.LEFT).get(Synonym_.id))
);
specification = specification.or(
buildSpecification(criteria.getSynonymId(), root -> root.join(CancerType_.synonyms, JoinType.LEFT).get(Synonym_.id))
);
}
if (criteria.getParentId() != null) {
specification =
specification.or(
buildSpecification(criteria.getParentId(), root -> root.join(CancerType_.parent, JoinType.LEFT).get(CancerType_.id))
);
specification = specification.or(
buildSpecification(criteria.getParentId(), root -> root.join(CancerType_.parent, JoinType.LEFT).get(CancerType_.id))
);
}
if (criteria.getAssociationId() != null) {
specification =
specification.or(
buildSpecification(
criteria.getAssociationId(),
root -> root.join(CancerType_.associations, JoinType.LEFT).get(Association_.id)
)
);
specification = specification.or(
buildSpecification(
criteria.getAssociationId(),
root -> root.join(CancerType_.associations, JoinType.LEFT).get(Association_.id)
)
);
}
}
return specification;
Expand Down

0 comments on commit 415a68d

Please sign in to comment.