Skip to content

Conversation

@shreddd
Copy link
Contributor

@shreddd shreddd commented Oct 3, 2025

Add filters to the geospatial searches to allow for searching based on properties

@shreddd shreddd requested review from Copilot and eecavanna October 3, 2025 21:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables additional filtering capabilities for geospatial search endpoints by adding an optional filter_json parameter that accepts MongoDB-style queries to refine search results beyond geographic constraints.

  • Added filter_json parameter to both /bertron/geo/nearby and /bertron/geo/bbox endpoints
  • Implemented JSON parsing and filter combination logic using MongoDB's $and operator
  • Added comprehensive test coverage for various filter scenarios including validation, complex queries, and property-based filtering

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/server.py Added filter_json parameter support and JSON parsing logic to geospatial endpoints
tests/test_api.py Added comprehensive test cases for filtered geospatial searches and edge cases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

# Should find at least the NMDC entity with depth property
found_nmdc = False
for entity in entities_data["documents"]:
properties = [ prop["attribute"]["label"] for prop in entity.get("properties", []) ]
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing space after opening bracket in list comprehension. Should be [prop["attribute"]["label"] for prop in entity.get("properties", [])] for consistency with Python style guidelines.

Suggested change
properties = [ prop["attribute"]["label"] for prop in entity.get("properties", []) ]
properties = [prop["attribute"]["label"] for prop in entity.get("properties", [])]

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@eecavanna eecavanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for implementing this and including that variety of tests. I left a few comments. No deal-breakers, in my opinion.

Comment on lines +315 to +321
# All returned entities should be from EMSL
for entity in entities_data["documents"]:
assert entity["ber_data_source"] == "EMSL"
self._verify_entity_structure(entity)

# Should find at least one entity
assert entities_data["count"] > 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick (optional): Swap the order of these blocks (assert there are items, then check the items).

Comment on lines +385 to +387
# Should find entities regardless of data source (empty filter = no additional restrictions)
for entity in entities_data["documents"]:
self._verify_entity_structure(entity)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the comment mentions the data source, I suggest adding an assertion that multiple data sources are represented in the response. The test can get a list of data sources directly from the database beforehand, for comparison.

for entity in entities_data["documents"]:
self._verify_entity_structure(entity)

def test_geo_search_filter_with_complex_query(self, test_client: TestClient, seeded_db: Database):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this illustrative test.

if "depth" in properties and entity["id"] == "nmdc:bsm-11-bsf8yq62":
found_nmdc = True
self._verify_entity_structure(entity)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an assertion that the value of the retrieved property is 24 (like in the specified filter).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants