Skip to content

Commit

Permalink
Merge pull request #62 from TheJacksonLaboratory/enhancement/search
Browse files Browse the repository at this point in the history
Enhancement/search
  • Loading branch information
iimpulse authored Jun 12, 2024
2 parents d496d5d + 7aec717 commit 75fe6e1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("com.dorongold.task-tree") version "3.0.0"
}

version = "0.5.12"
version = "0.5.13"
group = "org.jacksonlaboratory"

repositories {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jacksonlaboratory/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
info = @Info(
title = "ontology-service-${ontology}",
description = "A restful service for the ${ontology} ontology.",
version = "0.5.12",
version = "0.5.13",
contact = @Contact(name = "Michael Gargano", email = "[email protected]")
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jacksonlaboratory.repository;

import io.micronaut.context.annotation.Property;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.transaction.annotation.ReadOnly;
import jakarta.inject.Singleton;
import jakarta.persistence.EntityManager;
Expand Down Expand Up @@ -53,12 +54,17 @@ public List<OntologyTerm> findByTermIdIn(List<TermId> ids) {
*/
@Override
@Transactional
public List<OntologyTerm> search(String searchTerm, boolean prefixSearch) {
public List<OntologyTerm> search(@NonNull String searchTerm, boolean prefixSearch) {

if (searchTerm.trim().isEmpty()){
return Collections.emptyList();
}

if (prefixSearch){
return searchPartialId(searchTerm).collect(Collectors.toList());
return searchPartialId(searchTerm.trim()).collect(Collectors.toList());
} else {
TypedQuery<OntologyTerm> sp = entityManager.createNamedQuery("searchQuery", OntologyTerm.class);
sp.setParameter("param1", String.format("%s*", searchTerm));
sp.setParameter("param1", String.format("%s*", searchTerm.trim()));
return sp.getResultStream().collect(Collectors.toList());

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ class TermRepositorySpec extends Specification {
t | prefixSearch | expectedSize
"HP:00000" | true | 5
"test" | false | 1
"" | false | 0
"test " | false | 1
"" | true | 0
}
}

0 comments on commit 75fe6e1

Please sign in to comment.