Skip to content

Commit

Permalink
Merge branch 'allow-dot-in-solr-local-params'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Apr 3, 2024
2 parents 7926c62 + 4f599cd commit d124e33
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/8138.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow using ``.`` in Solr local parser parameters
2 changes: 1 addition & 1 deletion ckan/lib/search/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("}")
Expand Down
7 changes: 5 additions & 2 deletions ckan/tests/lib/search/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit d124e33

Please sign in to comment.