Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
fix #184 fix to europe pmc - changed /search route interface, bump de…
Browse files Browse the repository at this point in the history
…v ver
  • Loading branch information
sckott committed Dec 31, 2018
1 parent 15d6285 commit 98b0e71
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 49 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Description: Provides a single interface to many sources of full text
included for searching for articles, downloading full or partial
text, downloading supplementary materials, converting to various
data formats.
Version: 1.1.0.9211
Version: 1.1.0.9231
License: MIT + file LICENSE
Authors@R: c(
person("Scott", "Chamberlain",
Expand Down
71 changes: 44 additions & 27 deletions R/europe_pmc_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,46 @@
#' @export
#' @keywords internal
#' @name eupmc
#' @param query (character) Search terms. Required.
#' @param resulttype (character) The result type can either be idlist, core or lite.
#' This parameter determines the fields returned by XML and JSON formats, but it has
#' no effect on the DC format. See Details.
#' @param synonym (boolean) Synonym searches are not made by default (Default: \code{FALSE}),
#' however queries can be expanded using MeSH terminology and the UniProt synonyms list.
#' For example aspirin, a synonym would be acetylsalicylic acid;this could be included in
#' @param query (character) Search terms. Required. See Details
#' @param resulttype (character) The result type can either be idlist,
#' core or lite. This parameter determines the fields returned by XML and
#' JSON formats, but it has no effect on the DC format. See Details.
#' @param synonym (boolean) Synonym searches are not made by default
#' (Default: \code{FALSE}), however queries can be expanded using MeSH
#' terminology and the UniProt synonyms list. For example aspirin, a synonym
#' would be acetylsalicylic acid;this could be included in
#' the search by setting the parameter value to \code{TRUE}
#' @param per_page (integer) Number of records to return. Max: 1000. Default: 25
#' @param page Page (integer) Page numbers start at 1. Default: 1
#' @param per_page (integer) Number of records to return. Max: 1000.
#' Default: 25
#' @param cursorMark (character) cursor string, default: `*`
#' @param sort (character) The default sort order is relevance. Specify the
#' sort field and sort order. This parameter provides "asc" or "desc" order
#' for every single-valued field: P_PDATE_D, AUTH_FIRST, CITED etc. For
#' example sorting by CITED in ascending order: CITED asc
#' @param ... curl options passed on to [crul::HttpClient]
#' @param id A single Europe PMC article identifier, begins with "PMC", followed by
#' numbers, e.g., "PMC3257301"
#' @param id A single Europe PMC article identifier, begins with "PMC",
#' followed by numbers, e.g., "PMC3257301"
#'
#' @return `eupmc_search` returns a list with results. `eupmc_fields` returns
#' @return `eupmc_search` returns a list with results. `eupmc_fields` returns
#' a data.frame. `eupmc_xml` returns an object of class `xml_document`
#' @details resulttype parameter options:
#' @section `query` parameter options:
#'
#' - a keyword or combination of keywords (e.g. HPV virus).
#' - a phrase with enclosing speech marks (e.g. "human malaria").
#' - a fielded search (e.g. auth:stoehr). Available search fields are listed
#' in the Appendix 1 of the Reference Guide or can be retrieved using the
#' fields module of the API.
#' - a specific publication (e.g. ext_id:781840 src:med) Specify ext_id as the
#' article identifier, and src as the source database. List of the data sources
#' can be found on the help pages or in section 3 of the Reference Guide.
#'
#' @section `resulttype` parameter options:
#'
#' - idlist - returns a list of IDs and sources for the given search terms
#' - lite - returns key metadata for the given search terms; this is the default
#' value if the parameter is unspecified.
#' - core - returns full metadata for a given publication ID; including abstract,
#' full text links, and MeSH terms.
#' - lite - returns key metadata for the given search terms; this is the
#' default value if the parameter is unspecified.
#' - core - returns full metadata for a given publication ID; including
#' abstract, full text links, and MeSH terms.
#'
#' @references https://europepmc.org/RestfulWebService
#'
Expand All @@ -41,19 +58,21 @@
#' eupmc_search(query = 'ext_id:IND43783977 src:agr')
#'
#' # list indexed search fields
#' head(eupmc_fields())
#' x <- eupmc_fields()
#' NROW(x)
#' head(x)
#'
#' # get full text XML
#' eupmc_xml('PMC3257301')
#' }
eupmc_search <- function(query, resulttype = NULL, synonym = FALSE, per_page = 25,
page = 1, ...) {
eupmc_search <- function(query, resulttype = 'lite', synonym = FALSE,
per_page = 25, cursorMark = '*', ...) {

is_it(per_page, "numeric")
is_it(page, "numeric")
is_it(cursorMark, "character")
is_it(synonym, "logical")
args <- ft_compact(list(query = query, resulttype = resulttype,
synonym = ft_as_log(synonym), pageSize = per_page, page = page,
args <- ft_compact(list(query = query, resultType = resulttype,
synonym = ft_as_log(synonym), pageSize = per_page, cursorMark = cursorMark,
format = "json"))
newargs <- paste(names(args), args, sep = "=", collapse = "&")
cli <- crul::HttpClient$new(
Expand All @@ -73,12 +92,10 @@ eupmc_fields <- function(...) {
cli <- crul::HttpClient$new(
url = utils::URLencode(paste0(eupmc_base(), "fields")),
opts = list(...))
out <- cli$get()
out <- cli$get(query = list(format = "json"))
eupmc_errors(out)
tt <- out$parse("UTF-8")
tmp <- xml2::as_list(xml2::read_xml(tt))
data.frame(terms = unname(unlist(lapply(tmp$searchTermList, "[[", "term"))),
stringsAsFactors=FALSE)
jsonlite::fromJSON(tt)$searchTermList$searchTerms
}

#' @export
Expand Down
3 changes: 3 additions & 0 deletions R/ft_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
#' # Europe PMC
#' (res <- ft_search(query='ecology', from='europmc'))
#' res$europmc
#' ## get the next batch of results, using the cursorMark result
#' ft_search(query='ecology', from='europmc',
#' euroopts = list(cursorMark = res$europmc$cursorMark))
#'
#' # Scopus
#' (res <- ft_search(query = 'ecology', from = 'scopus', limit = 100,
Expand Down
3 changes: 2 additions & 1 deletion R/plugins_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ plugin_search_europe_pmc <- function(sources, query, limit, start, opts){
opts$query <- query
out <- do.call(eupmc_search, opts)
zz <- list(source = "europmc", found = out$hitCount,
data = out$resultList$result, opts = opts)
data = out$resultList$result, opts = opts,
cursorMark = out$nextCursorMark)
structure(zz, class = "ft_ind", query = query)
} else {
zz <- list(source = "europmc", found = NULL, data = NULL, opts = opts)
Expand Down
64 changes: 44 additions & 20 deletions man/eupmc.Rd

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

3 changes: 3 additions & 0 deletions man/ft_search.Rd

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

0 comments on commit 98b0e71

Please sign in to comment.