R/solr.R

Defines functions solr_index_variables solr_index_entries

Documented in solr_index_entries solr_index_variables

#' SOLR
#'
#' Solr index catalog entries
#'
#' @return NULL
#' @param start_row (required) row ID to start indexing from
#' @param limit Number of records to process
#'
#'
#'
#'
#' @export
solr_index_entries <- function(
                      start_row=0,
                      limit=10,
                      loop=FALSE,
                      api_key=NULL,
                      api_base_url=NULL
){

  if(is.null(api_key)){
    api_key=get_api_key();
  }

  endpoint=paste0('solr/full_import_surveys/',start_row,'/',limit)
  url=get_api_url(endpoint)

  httpResponse <- GET(url, add_headers("X-API-KEY" = api_key), accept_json(), verbose(get_verbose()))
  output=NULL

  if(httpResponse$status_code!=200){
    warning(content(httpResponse, "text"))
  }

  output=list(
    "status_code"=httpResponse$status_code,
    "response"= nada_http_response_json(httpResponse)
  )

  message(output$response)

  if (loop==TRUE && output$response$result$rows_processed>0){
    Sys.sleep(1)
    solr_index_entries(start_row=output$response$result$last_row_id,limit=limit,loop=loop)
  }

  return (output)
}


#' SOLR
#'
#' Solr index variables
#'
#' @return NULL
#' @param start_row (required) row ID to start indexing from
#' @param limit Number of records to process
#'
#'
#'
#'
#' @export
solr_index_variables <- function(
  start_row=0,
  limit=10,
  loop=FALSE,
  api_key=NULL,
  api_base_url=NULL
){

  if(is.null(api_key)){
    api_key=get_api_key();
  }

  endpoint=paste0('solr/full_import_variables/',start_row,'/',limit)
  url=get_api_url(endpoint)

  httpResponse <- GET(url, add_headers("X-API-KEY" = api_key), accept_json(), verbose(get_verbose()))
  output=NULL

  if(httpResponse$status_code!=200){
    warning(content(httpResponse, "text"))
  }

  output=list(
    "status_code"=httpResponse$status_code,
    "response"= nada_http_response_json(httpResponse)
  )


  message(paste0("\r\n========= ",output$response))

  if (loop==TRUE && output$response$result$rows_processed>0){
    Sys.sleep(1)
    solr_index_variables(start_row=output$response$result$last_row_id,limit=limit,loop=loop)
  }

  return (output)
}
mah0001/nadar documentation built on March 30, 2024, 2:44 a.m.