Also retrieve tokenized snippets
Change-Id: I83aa207161bc322d1a50107d52fb2a3b5fe707dd
diff --git a/NEWS.md b/NEWS.md
index cc4f985..83b6cef 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,7 @@
# RKorAPClient 0.7.7.9000 (unpublished)
+- if not `metadataOnly`, also retrieve tokenized snippets (in `collectedMatches$tokens`)
+
# RKorAPClient 0.7.7
- fixed R 4.3 compatibility (see <https://github.com/KorAP/RKorAPClient/issues/12>)
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index c2d971f..c8da98e 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -44,7 +44,7 @@
#' @export
setMethod("initialize", "KorAPQuery",
function(.Object, korapConnection = NULL, request = NULL, vc="", totalResults=0, nextStartIndex=0, fields=c("corpusSigle", "textSigle", "pubDate", "pubPlace",
- "availability", "textClass", "snippet"),
+ "availability", "textClass", "snippet", "tokens"),
requestUrl="", webUIRequestUrl = "", apiResponse = NULL, hasMoreMatches= FALSE, collectedMatches = NULL) {
.Object <- callNextMethod()
.Object@korapConnection = korapConnection
@@ -167,7 +167,8 @@
"pubPlace",
"availability",
"textClass",
- "snippet"
+ "snippet",
+ "tokens"
),
accessRewriteFatal = TRUE,
verbose = kco@verbose,
@@ -180,7 +181,7 @@
corpusQuery(kco, query=query, vc=vc, ql=ql, verbose=verbose, as.df = TRUE)) %>%
bind_rows()
} else {
- contentFields <- c("snippet")
+ contentFields <- c("snippet", "tokens")
if (metadataOnly) {
fields <- fields[!fields %in% contentFields]
}
@@ -188,7 +189,9 @@
paste0('?q=',
url_encode(enc2utf8(query)),
ifelse (!metadataOnly && ! is.null(context) && context != '', paste0('&context=', url_encode(enc2utf8(context))), ''),
- ifelse (vc != '', paste0('&cq=', url_encode(enc2utf8(vc))), ''), '&ql=', ql)
+ ifelse (vc != '', paste0('&cq=', url_encode(enc2utf8(vc))), ''),
+ ifelse (!metadataOnly, '&show-tokens=true', ''),
+ '&ql=', ql)
webUIRequestUrl <- paste0(kco@KorAPUrl, request)
requestUrl <- paste0(
kco@apiUrl,
@@ -300,7 +303,7 @@
if (!is.list(collectedMatches)) {
collectedMatches <- currentMatches
} else {
- collectedMatches <- rbind(collectedMatches, currentMatches)
+ collectedMatches <- bind_rows(collectedMatches, currentMatches)
}
if (verbose) {
cat(paste0(
@@ -426,7 +429,8 @@
"pubPlace",
"availability",
"textClass",
- "snippet"
+ "snippet",
+ "tokens"
),
accessRewriteFatal = TRUE) {
request <-
diff --git a/man/KorAPQuery-class.Rd b/man/KorAPQuery-class.Rd
index ebeb5c7..1f131a5 100644
--- a/man/KorAPQuery-class.Rd
+++ b/man/KorAPQuery-class.Rd
@@ -28,7 +28,7 @@
totalResults = 0,
nextStartIndex = 0,
fields = c("corpusSigle", "textSigle", "pubDate", "pubPlace", "availability",
- "textClass", "snippet"),
+ "textClass", "snippet", "tokens"),
requestUrl = "",
webUIRequestUrl = "",
apiResponse = NULL,
@@ -46,7 +46,7 @@
metadataOnly = TRUE,
ql = if (missing(KorAPUrl)) "poliqarp" else httr::parse_url(KorAPUrl)$query$ql,
fields = c("corpusSigle", "textSigle", "pubDate", "pubPlace", "availability",
- "textClass", "snippet"),
+ "textClass", "snippet", "tokens"),
accessRewriteFatal = TRUE,
verbose = kco@verbose,
expand = length(vc) != length(query),
@@ -85,7 +85,7 @@
metadataOnly = TRUE,
ql = if (missing(KorAPUrl)) "poliqarp" else httr::parse_url(KorAPUrl)$query$ql,
fields = c("corpusSigle", "textSigle", "pubDate", "pubPlace", "availability",
- "textClass", "snippet"),
+ "textClass", "snippet", "tokens"),
accessRewriteFatal = TRUE
)