From fc7756d37b4a3e4e5733c0bbd7a44b506d8d7bb3 Mon Sep 17 00:00:00 2001 From: Gede Primahadi Wijaya Rajeg Date: Tue, 13 Aug 2024 18:09:23 +0800 Subject: [PATCH] Fix the Global Search mechanism and add colour-highlighter for the match. --- enolex/app.R | 53 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/enolex/app.R b/enolex/app.R index 8e2a9ae..26f0ffa 100644 --- a/enolex/app.R +++ b/enolex/app.R @@ -459,7 +459,7 @@ ui <- page_navbar( secondary = "#E4F0EF", "link-hover-color" = "#be0f34", "link-color" = "#3277ae" - # source from Oxford colour parameters: https://www.ox.ac.uk/public-affairs/style-guide/digital-style-guide + # source from Oxford colour parameters: https://communications.web.ox.ac.uk/communications-resources/visual-identity/identity-guidelines/colours ), # collapsible = TRUE, underline = TRUE, @@ -696,24 +696,57 @@ server <- function(input, output, session) { if (input$pattern_matching_options == "regex") { glb <- elx |> - select(-CITATION, -URL, -YEAR, -BIBTEXKEY, -Concepticon, -AUTHOR, -TITLE, -YEAR_URL, -Number_of_Cognates, -matches("Segments")) |> + rename(Original_gloss = English_Original, + # Concepticon = Concepticon_Gloss, + Dialect = Dialect_Info) |> + select(-CITATION, -URL, -YEAR, -BIBTEXKEY, -Concepticon, -AUTHOR, -TITLE, -YEAR_URL, -Number_of_Cognates, -matches("Segments"), -Collected) |> filter(if_any(where(is.character), ~str_detect(., regex(input$global_search, ignore_case = FALSE)))) |> - select(where(function(x) any(!is.na(x)))) + select(where(function(x) any(!is.na(x)))) |> + mutate(across(where(is.character), ~gsub( + paste(c("\\b(", input$global_search, ")\\b"), collapse = ""), + "\\1", + ., + TRUE, + TRUE + ))) |> + rename(Concepticon = Concepticon_Gloss) } else if (input$pattern_matching_options == "exact_match") { glb <- elx |> - select(-CITATION, -URL, -YEAR, -BIBTEXKEY, -Concepticon, -AUTHOR, -TITLE, -YEAR_URL, -Number_of_Cognates, -matches("Segments")) |> - filter(if_any(where(is.character), ~str_detect(., fixed(input$global_search, ignore_case = FALSE)))) |> - select(where(function(x) any(!is.na(x)))) + rename(Original_gloss = English_Original, + # Concepticon = Concepticon_Gloss, + Dialect = Dialect_Info) |> + select(-CITATION, -URL, -YEAR, -BIBTEXKEY, -Concepticon, -AUTHOR, -TITLE, -YEAR_URL, -Number_of_Cognates, -matches("Segments"), -Collected) |> + filter(if_any(where(is.character), ~str_detect(., regex(str_c("\\b", input$global_search, "\\b", sep = ""), ignore_case = FALSE)))) |> + select(where(function(x) any(!is.na(x)))) |> + mutate(across(where(is.character), ~gsub( + paste(c("\\b(", input$global_search, ")\\b"), collapse = ""), + "\\1", + ., + TRUE, + TRUE + ))) |> + rename(Concepticon = Concepticon_Gloss) } else if (input$pattern_matching_options == "partial_match") { glb <- elx |> - select(-CITATION, -URL, -YEAR, -BIBTEXKEY, -Concepticon, -AUTHOR, -TITLE, -YEAR_URL, -Number_of_Cognates, -matches("Segments")) |> - filter(if_any(where(is.character), ~str_detect(., regex(input$global_search, ignore_case = FALSE)))) |> - select(where(function(x) any(!is.na(x)))) + rename(Original_gloss = English_Original, + # Concepticon = Concepticon_Gloss, + Dialect = Dialect_Info) |> + select(-CITATION, -URL, -YEAR, -BIBTEXKEY, -Concepticon, -AUTHOR, -TITLE, -YEAR_URL, -Number_of_Cognates, -matches("Segments"), -Collected) |> + filter(if_any(where(is.character), ~str_detect(string = ., pattern = input$global_search))) |> + select(where(function(x) any(!is.na(x)))) |> + mutate(across(where(is.character), ~gsub( + paste(c("(", input$global_search, ")"), collapse = ""), + "\\1", + ., + TRUE, + TRUE + ))) |> + rename(Concepticon = Concepticon_Gloss) } @@ -746,7 +779,7 @@ server <- function(input, output, session) { }) output$global_search_output <- DT::renderDT({ - req(nchar(input$global_search) > 0) + req(input$global_search) global_search() })