From f444a916c33573a939585fbac22ba8598acd2536 Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Mon, 1 Apr 2024 16:52:14 +0300 Subject: [PATCH 1/2] 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 From 4f599cddab9d7330fcd61a6c944f9f1c6333c0be Mon Sep 17 00:00:00 2001 From: amercader Date: Wed, 3 Apr 2024 12:22:39 +0200 Subject: [PATCH 2/2] Add changelog --- changes/8138.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/8138.bugfix diff --git a/changes/8138.bugfix b/changes/8138.bugfix new file mode 100644 index 00000000000..a26641213cc --- /dev/null +++ b/changes/8138.bugfix @@ -0,0 +1 @@ +Allow using ``.`` in Solr local parser parameters