First check-in of modified demo function from CMLC-publication
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
new file mode 100644
index 0000000..82bcc80
--- /dev/null
+++ b/R/KorAPQuery.R
@@ -0,0 +1,64 @@
+#' @import jsonlite
+#' @import curl
+
+library(jsonlite)
+
+defaultFields <- c("corpusSigle", "textSigle", "pubDate",  "pubPlace",
+            "availability", "textClass")
+
+derekoStats <- function(vc='') {
+  return(fromJSON(paste0(apiurl, 'statistics?cq=',
+                         URLencode(vc, reserved=TRUE))))
+}
+
+KorAPQuery <- function(con, query, vc="", ql="poliqarp", fields=defaultFields) {
+  request <- paste0('?q=', URLencode(query, reserved=TRUE),
+                    ifelse(vc != '', paste0('&cq=', URLencode(vc, reserved=TRUE)), ''),
+                    '&ql=', ql);
+  webUIRequestUrl <- paste0(con$KorAPUrl, request)
+  requestUrl <- paste0(con$apiUrl, 'search', request,
+                       '&fields=', paste(defaultFields, collapse = ","),
+                       '&access-rewrite-disabled=true')
+  result <- fromJSON(paste0(requestUrl, '&count=1'))
+
+  result$fields <- fields
+  result$requestUrl <- requestUrl
+  result$request <- request
+  result$webUIRequestUrl <- webUIRequestUrl
+  return(result)
+}
+
+KorAPFectAll <- function(query) {
+  if (query$meta$totalResults == 0) { return(data.frame()) }
+
+  page <- 1
+  results <- 0
+
+  repeat {
+    res <- fromJSON(paste0(query$requestUrl, '&count=50&page=', page))
+    if (res$meta$totalResults == 0) { return(data.frame()) }
+    for (field in query$fields) {
+      if (!field %in% colnames(res$matches)) {
+        res$matches[, field] <- NA
+      }
+    }
+    currentMatches <- res$matches[query$fields]
+    factorCols <- colnames(subset(currentMatches, select=-c(pubDate)))
+    currentMatches[factorCols] <- lapply(currentMatches[factorCols], factor)
+    currentMatches$pubDate = as.Date(currentMatches$pubDate, format = "%Y-%m-%d")
+    if (page == 1) {
+      allMatches <- currentMatches
+      expectedResults <- res$meta$totalResults
+    } else {
+      allMatches <- rbind(allMatches, currentMatches)
+    }
+    print(paste0("Retrieved page: ", page, "/",
+                 ceiling(expectedResults / res$meta$itemsPerPage)))
+    page <- page + 1
+    results <- results + res$meta$itemsPerPage
+    if (results >= expectedResults) {
+      break
+    }
+  }
+  return(allMatches)
+}