Skip to content

Commit

Permalink
Merge pull request #60 from TheJacksonLaboratory/enhancement/monitor-…
Browse files Browse the repository at this point in the history
…and-sorting

Enhancement/monitor and sorting
  • Loading branch information
iimpulse committed Jun 11, 2024
2 parents 6935b61 + e00b287 commit d496d5d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 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.11"
version = "0.5.12"
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.11",
version = "0.5.12",
contact = @Contact(name = "Michael Gargano", email = "[email protected]")
)
)
Expand Down
56 changes: 43 additions & 13 deletions src/main/java/org/jacksonlaboratory/service/TermService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,49 @@ public List<OntologyTerm> searchOntologyTerm(String q){
}).collect(Collectors.toList());
}
return this.termRepository.search(q, false).stream().sorted((a, b) -> {
boolean aStarts = a.getName().toLowerCase().startsWith(q);
boolean bStarts = b.getName().toLowerCase().startsWith(q);
// Bring synonym matches to the top
boolean aStarts = a.getSynonyms().stream().anyMatch(s -> s.toLowerCase().startsWith(q.toLowerCase()));
boolean bStarts = b.getSynonyms().stream().anyMatch(s -> s.toLowerCase().startsWith(q.toLowerCase()));

// Sort objects based on whether the name starts with the prefix
if (aStarts && !bStarts) {
return -1; // o1 comes before o2
} else if (!aStarts && bStarts) {
return 1; // o2 comes before o1
} else {
boolean aContains = a.getName().toLowerCase().contains(q);
boolean bContains = b.getName().toLowerCase().contains(q);
return aContains && !bContains ? -1 : !aContains && bContains ? 1 : 0;
}
}).collect(Collectors.toList());
if (aStarts && !bStarts) {
return -1;
} else if (!aStarts && bStarts) {
return 1;
}
return 0;
}).sorted((a, b) -> {
// Bring synonym matches to the top
boolean aStarts = a.getName().toLowerCase().contains(q.toLowerCase());
boolean bStarts = b.getName().toLowerCase().contains(q.toLowerCase());

if (aStarts && !bStarts) {
return -1;
} else if (!aStarts && bStarts) {
return 1;
}
return 0;
}).sorted((a, b) -> {
// Then bring synonym matches to the top
boolean aStarts = a.getName().toLowerCase().startsWith(q.toLowerCase());
boolean bStarts = b.getName().toLowerCase().startsWith(q.toLowerCase());

if (aStarts && !bStarts) {
return -1;
} else if (!aStarts && bStarts) {
return 1;
}
return 0;
}).sorted((a, b) -> {
// Then bring exact matches to the top
boolean aStarts = a.getName().toLowerCase().equalsIgnoreCase(q);
boolean bStarts = b.getName().toLowerCase().equalsIgnoreCase(q);

if (aStarts && !bStarts) {
return -1;
} else if (!aStarts && bStarts) {
return 1;
}
return 0;
}).collect(Collectors.toList());
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ micronaut:
inclusion: ALWAYS
endpoints:
all:
path: /${api-url.prefix}/${ontology}/
path: /${api-url.prefix}/${ontology}/monitor/
datasources:
default:
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ micronaut:
server:
cors:
enabled: true
port: 8081
application:
name: ontology-service-${ONTOLOGY_SERVICE_ONTOLOGY:unknown}
router:
Expand All @@ -17,7 +18,7 @@ micronaut:
inclusion: ALWAYS
endpoints:
all:
path: /${api-url.prefix}/${ontology}/
path: /${api-url.prefix}/${ontology}/monitor/
datasources:
default:
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
Expand Down

0 comments on commit d496d5d

Please sign in to comment.