Skip to content

Commit

Permalink
Use HTTPS for on the search server
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Apr 20, 2024
1 parent 1944f50 commit e3cc156
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ Suggests:
testthat (>= 2.1.0),
whoami
Encoding: UTF-8
RoxygenNote: 7.2.0.9000
RoxygenNote: 7.3.1.9000
Roxygen: list(markdown = TRUE)
12 changes: 5 additions & 7 deletions R/advanced_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#' # Packages with both Hester and Wickham as authors
#' advanced_search(Author = "Hester", Author = "Wickham")
#' advanced_search("Author: Hester AND Author: Wickham")
#'
#'
#' # Packages with Hester but not Wickham as author
#' advanced_search(Author = "Hester AND NOT Wickham")
#'
#'
#' # Packages with Hester as an Author, and Wickham in any field
#' advanced_search(Author = "Hester", "Wickham")
#'
#'
#' # Packages with Hester as an Author and Wickham nowhere in the metadata
#' advanced_search(Author = "Hester", "NOT Wickham")
#'
Expand Down Expand Up @@ -93,10 +93,9 @@ advanced_search <- function(..., json = NULL, format = c("short", "long"),
qstr <- json
}

server <- Sys.getenv("R_PKG_SEARCH_SERVER", "search.r-pkg.org")
port <- as.integer(Sys.getenv("R_PKG_SEARCH_PORT", "80"))
server <- Sys.getenv("R_PKG_SEARCH_SERVER", "https://search.r-pkg.org")

resp <- do_query(qstr, server, port, from, size)
resp <- do_query(qstr, server, from, size)

result <- format_result(
resp,
Expand All @@ -105,7 +104,6 @@ advanced_search <- function(..., json = NULL, format = c("short", "long"),
from = from,
size = size,
server = server,
port = port,
qstr = qstr
)

Expand Down
26 changes: 10 additions & 16 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,22 @@ pkg_search <- function(query = NULL, format = c("short", "long"),

if (is.null(query)) return(pkg_search_again())
format <- match.arg(format)
server <- Sys.getenv("R_PKG_SEARCH_SERVER", "search.r-pkg.org")
port <- as.integer(Sys.getenv("R_PKG_SEARCH_PORT", "80"))
server <- Sys.getenv("R_PKG_SEARCH_SERVER", "https://search.r-pkg.org")

make_pkg_search(query, format, from, size, server, port)
make_pkg_search(query, format, from, size, server)
}

#' @rdname pkg_search
#' @export

ps <- pkg_search

make_pkg_search <- function(query, format, from, size, server, port) {
make_pkg_search <- function(query, format, from, size, server) {

qry <- make_query(query = query)
rsp <- do_query(qry, server = server, port = port, from = from,
size = size)
rsp <- do_query(qry, server = server, from = from, size = size)
rst <- format_result(rsp, query = query, format = format, from = from,
size = size, server = server, port = port)
size = size, server = server)

s_data$prev_q <- list(type = "simple", result = rst)

Expand All @@ -108,8 +106,7 @@ more <- function(format = NULL, size = NULL) {
format = format %||% meta(rst)$format,
from = meta(rst)$from + meta(rst)$size,
size = size %||% meta(rst)$size,
server = meta(rst)$server,
port = meta(rst)$port
server = meta(rst)$server
)

} else if (s_data$prev_q$type == "advanced") {
Expand Down Expand Up @@ -184,14 +181,13 @@ make_query <- function(query) {

#' @importFrom jsonlite fromJSON

do_query <- function(query, server, port, from, size) {
do_query <- function(query, server, from, size) {

check_count(from)
check_count(size)

url <- "http://" %+% server %+% ":" %+% as.character(port) %+%
"/package/_search?from=" %+% as.character(from - 1) %+%
"&size=" %+% as.character(size)
url <- server %+% "/package/_search?from=" %+%
as.character(from - 1) %+% "&size=" %+% as.character(size)
result <- http_post(
url, body = query,
headers = c("Content-Type" = "application/json"))
Expand Down Expand Up @@ -239,8 +235,7 @@ print.pkgsearch_query_error <- function(x, ...) {

#' @importFrom parsedate parse_iso_8601

format_result <- function(result, query, format, from, size, server,
port, ...) {
format_result <- function(result, query, format, from, size, server, ...) {
result <- fromJSON(result, simplifyVector = FALSE)

meta <- list(
Expand All @@ -249,7 +244,6 @@ format_result <- function(result, query, format, from, size, server,
from = from,
size = size,
server = server,
port = port,
total = result$hits$total,
max_score = result$hits$max_score,
took = result$took,
Expand Down

0 comments on commit e3cc156

Please sign in to comment.