From 39ed051cb4926f62829deb0fb08a3684782e3780 Mon Sep 17 00:00:00 2001 From: Jay Guo Date: Tue, 9 Dec 2025 13:48:00 -0500 Subject: [PATCH] fix: handle date strings in column search --- ckanext/og_datatablesview/blueprint.py | 4 +++ ckanext/og_datatablesview/tests/test_logic.py | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/ckanext/og_datatablesview/blueprint.py b/ckanext/og_datatablesview/blueprint.py index 43561a9..9be5f83 100644 --- a/ckanext/og_datatablesview/blueprint.py +++ b/ckanext/og_datatablesview/blueprint.py @@ -24,6 +24,10 @@ def format_fts_query(search_value): processed_terms = [] for word in space_separated: if word: + is_date = re.match(r'^\d{1,2}[/-]\d{1,2}[/-]\d{2,4}$', word) + if is_date: + processed_terms.append(word + u':*') + continue # replace non-alphanumeric characters with FTS wildcard (_) processed = re.sub(r'[^0-9a-zA-Z\-]+', '_', word) if processed: diff --git a/ckanext/og_datatablesview/tests/test_logic.py b/ckanext/og_datatablesview/tests/test_logic.py index 57acc27..ac1d8e8 100644 --- a/ckanext/og_datatablesview/tests/test_logic.py +++ b/ckanext/og_datatablesview/tests/test_logic.py @@ -285,3 +285,38 @@ def test_format_fts_query_multiple_apostrophes(self): # Multiple apostrophes result = format_fts_query("O'Brien's") assert result == "(O:* | Brien:* | s:*)" + + def test_format_fts_query_date_single_digit_month_day(self): + # Date with single digit month and day + result = format_fts_query('1/3/2025') + assert result == '1/3/2025:*' + + def test_format_fts_query_date_two_digit_month_day(self): + # Date with two digit month and day + result = format_fts_query('1/13/2025') + assert result == '1/13/2025:*' + + def test_format_fts_query_date_two_digit_year(self): + # Date with two digit year + result = format_fts_query('1/13/25') + assert result == '1/13/25:*' + + def test_format_fts_query_date_with_dash(self): + # Date with dashes instead of slashes + result = format_fts_query('1-13-2025') + assert result == '1-13-2025:*' + + def test_format_fts_query_date_in_phrase(self): + # Date within a phrase + result = format_fts_query('Contract Begin Date 1/13/2025') + assert result == 'Contract:* & Begin:* & Date:* & 1/13/2025:*' + + def test_format_fts_query_multiple_dates(self): + # Multiple dates in search + result = format_fts_query('1/13/2025 6/30/2025') + assert result == '1/13/2025:* & 6/30/2025:*' + + def test_format_fts_query_date_with_compound_word(self): + # Date with compound word in same search + result = format_fts_query('Board/Village 1/13/2025') + assert result == '(Board:* | Village:*) & 1/13/2025:*'