-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a new plugin for indexing repeating subfields
The `scheming_subfields_index` plugin will group the values of the same subfields in a text field that will make the values findable. They are indexed as `extras_{field_name}__{key}`. `extras_*` is a dynamic `text` Solr field that will allow free-text search on these values. Added tests and updated the docs.
- Loading branch information
Showing
5 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
import ckantoolkit | ||
|
||
from ckantoolkit.tests.factories import Dataset | ||
from ckantoolkit.tests.helpers import call_action | ||
|
||
|
||
dataset_dict = { | ||
"name": "test-dataset", | ||
"type": "test-subfields", | ||
# Repeating subfields | ||
"contact_address": [ | ||
{"address": "Maple Street 123", "city": "New Paris", "country": "Maplonia"}, | ||
{"address": "Rose Avenue 452", "city": "Old York", "country": "Rosestan"}, | ||
], | ||
} | ||
|
||
|
||
@pytest.mark.usefixtures("with_plugins", "clean_db") | ||
def test_repeating_subfields_index(): | ||
|
||
with mock.patch("ckan.lib.search.index.make_connection") as m: | ||
call_action("package_create", **dataset_dict) | ||
|
||
# Dict sent to Solr | ||
search_dict = m.mock_calls[1].kwargs["docs"][0] | ||
assert search_dict["extras_contact_address__city"] == "New Paris Old York" | ||
assert search_dict["extras_contact_address__country"] == "Maplonia Rosestan" | ||
|
||
|
||
@pytest.mark.usefixtures("with_plugins", "clean_db") | ||
def test_repeating_subfields_search(): | ||
|
||
dataset = call_action("package_create", **dataset_dict) | ||
|
||
result = call_action("package_search", q="Old York") | ||
|
||
assert result["results"][0]["id"] == dataset["id"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters