From f444a916c33573a939585fbac22ba8598acd2536 Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Mon, 1 Apr 2024 16:52:14 +0300 Subject: [PATCH] fix: Allow using `.` in solr local params --- ckan/lib/search/query.py | 2 +- ckan/tests/lib/search/test_search.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ckan/lib/search/query.py b/ckan/lib/search/query.py index a93bd10d12f..d213d8756d2 100644 --- a/ckan/lib/search/query.py +++ b/ckan/lib/search/query.py @@ -103,7 +103,7 @@ def _parse_local_params(local_params: str) -> list[Union[str, list[str]]]: {!type=dismax qf=myfield v='some value'} -> [['type', 'dismax'], ['qf', 'myfield'], ['v', 'some value']] """ - key = Word(alphanums + "_") + key = Word(alphanums + "_.") value = QuotedString('"') | QuotedString("'") | Word(alphanums + "_$") pair = Group(key + Suppress("=") + value) expression = Suppress("{!") + OneOrMore(pair | key) + Suppress("}") diff --git a/ckan/tests/lib/search/test_search.py b/ckan/tests/lib/search/test_search.py index 910ec879068..cf3365afd16 100644 --- a/ckan/tests/lib/search/test_search.py +++ b/ckan/tests/lib/search/test_search.py @@ -196,10 +196,9 @@ def test_allowed_local_params_via_config_not_defined(): assert str(e.value) == "Local parameters are not supported in param 'q'." -@pytest.mark.ckan_config("ckan.search.solr_allowed_query_parsers", "bool knn") +@pytest.mark.ckan_config("ckan.search.solr_allowed_query_parsers", "bool knn lucene") @pytest.mark.usefixtures("clean_index") def test_allowed_local_params_via_config(): - factories.Dataset(title="A dataset about bees") factories.Dataset(title="A dataset about butterflies") query = search.query_for(model.Package) @@ -212,3 +211,7 @@ def test_allowed_local_params_via_config(): assert query.run({"q": "{!type=bool must=beetles}", "defType": "lucene"})["count"] == 0 assert query.run({"q": "{!must=bees type=bool}", "defType": "lucene"})["count"] == 1 + + # Support dot symbol in keys + assert query.run({"fq": "{!lucene q.op=AND}bees butterflies"})["count"] == 0 + assert query.run({"fq": "{!lucene q.op=OR}bees butterflies"})["count"] == 2