Add matchStart and matchEnd columns to collectedMatches in corpusQuery result

Resolves #22

Change-Id: I6af9de503e5911cbe5c566b0fae529cfba7b764c
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 7abed6a..432dea4 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -276,7 +276,8 @@
 #' @aliases fetchNext
 #' @rdname KorAPQuery-class
 #' @importFrom dplyr rowwise mutate bind_rows select summarise n select
-#' @importFrom tibble enframe
+#' @importFrom tibble enframe add_column
+#' @importFrom stringr word
 #' @importFrom tidyr unnest unchop pivot_wider
 #' @importFrom purrr map
 #' @export
@@ -330,7 +331,15 @@
         currentMatches[, field] <- NA
       }
     }
-    currentMatches <- currentMatches %>% select(kqo@fields)
+    currentMatches <- currentMatches %>%
+      select(kqo@fields) %>%
+      mutate(
+        tmp_positions = gsub(".*-p(\\d+)-(\\d+)", "\\1 \\2", res$matches$matchID),
+        matchStart = as.integer(stringr::word(tmp_positions, 1)),
+        matchEnd = as.integer(stringr::word(tmp_positions, 2)) - 1
+      ) %>%
+      select(-tmp_positions)
+
     if (!is.list(collectedMatches)) {
       collectedMatches <- currentMatches
     } else {