Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
global search
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Oct 8, 2024
1 parent 71a0f50 commit 3ab6611
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 0 deletions.
20 changes: 20 additions & 0 deletions R/global-search.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#' Search among all universes
#'
#' @inheritParams universe_search
#'
#' @return A list with query results. The `total` field indicates the
#' total number of results and can be used as `limit` value in a second call.
#' @export
#'
#' @examplesIf interactive()
#' global_search(query = '"weather data"', limit = 1)
#' global_search(query = 'needs:httr2', limit = 1)
global_search <- function(query, limit = 100) {
httr2::request("https://r-universe.dev") |>
httr2::req_url_path("api") |>
httr2::req_url_path_append("search") |>
httr2::req_user_agent("starchart R package") |>
httr2::req_url_query(limit = limit, q = query) |>
httr2::req_perform() |>
httr2::resp_body_json()
}
26 changes: 26 additions & 0 deletions man/global_search.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 131 additions & 0 deletions tests/testthat/global-search/r-universe.dev/api/search-420206.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"results": [
{
"_id": "66efb9c1363ce6fc66389768",
"Package": "devtools",
"Title": "Tools to Make Developing R Packages Easier",
"Description": "Collection of package development tools.",
"_user": "r-lib",
"_owner": "r-lib",
"_usedby": 141,
"_score": 19.742559633132295,
"_uuid": 22618716,
"maintainer": {
"name": "Jennifer Bryan",
"email": "[email protected]",
"login": "jennybc",
"mastodon": "https://fosstodon.org/@jennybryan",
"uuid": 599454,
"orcid": "0000-0002-6983-2759"
},
"updated": 1726848647,
"stars": 2392,
"topics": [
"package-creation"
],
"rundeps": [
"askpass",
"base64enc",
"brew",
"brio",
"bslib",
"cachem",
"callr",
"cli",
"clipr",
"commonmark",
"cpp11",
"crayon",
"credentials",
"curl",
"desc",
"diffobj",
"digest",
"downlit",
"ellipsis",
"evaluate",
"fansi",
"fastmap",
"fontawesome",
"fs",
"gert",
"gh",
"gitcreds",
"glue",
"highr",
"htmltools",
"htmlwidgets",
"httpuv",
"httr2",
"ini",
"jquerylib",
"jsonlite",
"knitr",
"later",
"lifecycle",
"magrittr",
"memoise",
"mime",
"miniUI",
"openssl",
"pillar",
"pkgbuild",
"pkgconfig",
"pkgdown",
"pkgload",
"praise",
"prettyunits",
"processx",
"profvis",
"promises",
"ps",
"purrr",
"R6",
"ragg",
"rappdirs",
"rcmdcheck",
"Rcpp",
"rematch2",
"remotes",
"rlang",
"rmarkdown",
"roxygen2",
"rprojroot",
"rstudioapi",
"rversions",
"sass",
"sessioninfo",
"shiny",
"sourcetools",
"stringi",
"stringr",
"sys",
"systemfonts",
"testthat",
"textshaping",
"tibble",
"tinytex",
"urlchecker",
"usethis",
"utf8",
"vctrs",
"waldo",
"whisker",
"withr",
"xfun",
"xml2",
"xopen",
"xtable",
"yaml",
"zip"
],
"rank": 19.742559633132295
}
],
"query": {
"_rundeps": "gert"
},
"skip": 0,
"limit": 1,
"total": 359
}
7 changes: 7 additions & 0 deletions tests/testthat/test-global-search.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("universe_search() works", {
httptest2::with_mock_dir("global-search", {
packages <- global_search(query = 'needs:gert', limit = 1)
})
expect_type(packages, "list")
expect_gt(length(packages), 0)
})

0 comments on commit 3ab6611

Please sign in to comment.