Add tests for ordering and other queries
This commit is contained in:
parent
2945795b5f
commit
b89da29192
|
@ -313,6 +313,87 @@ class TestBBoxSearch(SpatialTestBase):
|
|||
assert result["count"] == 1
|
||||
assert result["results"][0]["id"] == dataset["id"]
|
||||
|
||||
def test_sorting_of_bbox_results(self):
|
||||
"""
|
||||
Bounding box based searches support ordering the results spatially. The default
|
||||
method used is overlap ratio, ie datasets with geometries that overlap more with
|
||||
the input bounding box are returned first. In this case for instance, we would
|
||||
expect the results to be ordered as B, D, A, C
|
||||
|
||||
2 ┌────────────┬────────────┐
|
||||
│ │ │
|
||||
│ xxxxxxxxxxxxx │
|
||||
│ A x │ x B │
|
||||
│ x │ x │
|
||||
│ x │ x │
|
||||
1 ├─────────x──┼────────x───┤
|
||||
│ x │ x │
|
||||
│ xxxxxxxxxxxxx │
|
||||
│ │ │
|
||||
│ C │ D │
|
||||
│ │ │
|
||||
└────────────┴────────────┘
|
||||
0,0 1 2
|
||||
"""
|
||||
|
||||
dataset_extents = [
|
||||
("Dataset A", (0, 1, 1, 2)),
|
||||
("Dataset B", (1, 1, 2, 2)),
|
||||
("Dataset C", (0, 0, 1, 1)),
|
||||
("Dataset D", (1, 0, 2, 1)),
|
||||
]
|
||||
|
||||
for item in dataset_extents:
|
||||
geom = """
|
||||
{{"type":"Polygon",
|
||||
"coordinates":[[[{xmin},{ymax}],[{xmin},{ymin}],[{xmax},{ymin}],[{xmax},{ymax}],[{xmin},{ymax}]]]}}
|
||||
""".format(
|
||||
xmin=item[1][0], ymin=item[1][1], xmax=item[1][2], ymax=item[1][3])
|
||||
factories.Dataset(
|
||||
title=item[0],
|
||||
extras=[{"key": "spatial", "value": geom}]
|
||||
)
|
||||
|
||||
result = helpers.call_action(
|
||||
"package_search", extras={"ext_bbox": "0.75,0.75,1.75,1.75"}
|
||||
)
|
||||
|
||||
assert result["count"] == 4
|
||||
|
||||
assert (
|
||||
[d["title"] for d in result["results"]] == [
|
||||
"Dataset B", "Dataset D", "Dataset A", "Dataset C"]
|
||||
)
|
||||
|
||||
def test_spatial_search_combined_with_other_q(self):
|
||||
dataset_extents = [
|
||||
("Dataset A", (0, 1, 1, 2), "rabbit"),
|
||||
("Dataset B", (1, 1, 2, 2), "rabbit"),
|
||||
("Dataset C", (0, 0, 1, 1), "mole"),
|
||||
("Dataset D", (1, 0, 2, 1), "badger"),
|
||||
]
|
||||
|
||||
for item in dataset_extents:
|
||||
geom = """
|
||||
{{"type":"Polygon",
|
||||
"coordinates":[[[{xmin},{ymax}],[{xmin},{ymin}],[{xmax},{ymin}],[{xmax},{ymax}],[{xmin},{ymax}]]]}}
|
||||
""".format(
|
||||
xmin=item[1][0], ymin=item[1][1], xmax=item[1][2], ymax=item[1][3])
|
||||
factories.Dataset(
|
||||
title=item[0],
|
||||
notes=item[2],
|
||||
extras=[{"key": "spatial", "value": geom}]
|
||||
|
||||
)
|
||||
|
||||
result = helpers.call_action(
|
||||
"package_search", q="rabbit", extras={"ext_bbox": "0.75,0.75,1.75,1.75"}
|
||||
)
|
||||
|
||||
assert result["count"] == 2
|
||||
|
||||
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("clean_db", "clean_index", "harvest_setup", "with_plugins")
|
||||
@pytest.mark.ckan_config("ckanext.spatial.search_backend", "solr-spatial-field")
|
||||
|
|
Loading…
Reference in New Issue