-
Notifications
You must be signed in to change notification settings - Fork 0
/
plumber.R
33 lines (28 loc) · 916 Bytes
/
plumber.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#* @param query The query to search for
#* @get /search
#* @serializer json
function(query) {
# Sidestep pkgmatch feature of automatically assuming that single-words are
# a package name by adding a trailing space
if (!grepl(" ", query, fixed = TRUE)) {
query <- paste0(query, " ")
}
matches <- pkgmatch::pkgmatch_similar_pkgs(
input = query,
embeddings = pkgmatch.epi::epi_embeddings
)
matches$relevance <- 1 - matches$rank / nrow(matches) # FIXME: use better function
matches <- matches[, colnames(matches) != "rank"]
matches <- merge(matches, pkgmatch.epi::pkgs_metadata)
matches <- matches[order(matches$relevance, decreasing = TRUE), ]
list(
query = query,
filter = "epiverse-connect",
response = list(results = purrr::transpose(matches))
)
}
#* @filter cors
cors <- function(res) {
res$setHeader("Access-Control-Allow-Origin", "*")
plumber::forward()
}