Fix matchStart and matchEnd for queries with focus
Change-Id: I5de1e983ab78fdeffdf77685d1360a86f063b65a
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 8e72b60..60f0729 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -338,7 +338,7 @@
currentMatches <- currentMatches %>%
select(kqo@fields) %>%
mutate(
- tmp_positions = gsub(".*-p(\\d+)-(\\d+)", "\\1 \\2", res$matches$matchID),
+ 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
) %>%
diff --git a/tests/testthat/test-corpusQuery.R b/tests/testthat/test-corpusQuery.R
index 13e2d51..34aba74 100644
--- a/tests/testthat/test-corpusQuery.R
+++ b/tests/testthat/test-corpusQuery.R
@@ -135,3 +135,14 @@
right_contexts <- matches$tokens$right
expect_true(TRUE %in% grepl("Begriff", right_contexts))
})
+
+test_that("matchStart and matchEnd are present and correct", {
+ skip_if_offline()
+ kco <- new("KorAPConnection", accessToken = NULL, verbose = TRUE)
+ q <- corpusQuery(kco, "focus([tt/p=ADJA] {Newstickeritis})", vc = "corpusSigle=/W.D17/", metadataOnly = FALSE)
+ q <- fetchNext(q)
+ matches <-q@collectedMatches
+ expect_gt(max(matches$matchEnd), 1000)
+ expect_true(all(matches$matchEnd == matches$matchStart))
+})
+