Skip to content

Commit

Permalink
Search for projects by exact mapping type:
Browse files Browse the repository at this point in the history
- Add mappingTypesExact search param
- Add new query to return only projects matching the requested types if mappingTypesExact is true
- Add query to return all projects with any of the mapping types for mappingTypesExact is false
- Add mappingTypesExact param to docstrings
  • Loading branch information
d-rita committed Nov 24, 2020
1 parent 3b908e4 commit 2141fae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions backend/api/projects/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@ def setup_search_dto(self):
search_dto.mapping_types = map(
str, mapping_types_str.split(",")
) # Extract list from string
search_dto.mapping_types_exact = strtobool(
request.args.get("mappingTypesExact", "false")
)
project_statuses_str = request.args.get("projectStatuses")
if project_statuses_str:
search_dto.project_statuses = map(str, project_statuses_str.split(","))
Expand Down Expand Up @@ -569,6 +572,11 @@ def get(self):
- in: query
name: mappingTypes
type: string
- in: query
name: mappingTypesExact
type: boolean
default: false
description: if true, limits projects to match the exact mapping types requested
- in: query
name: organisationName
description: Organisation name to search for
Expand Down
1 change: 1 addition & 0 deletions backend/models/dtos/project_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class ProjectSearchDTO(Model):
preferred_locale = StringType(default="en")
mapper_level = StringType(validators=[is_known_mapping_level])
mapping_types = ListType(StringType, validators=[is_known_mapping_type])
mapping_types_exact = BooleanType(required=False)
project_statuses = ListType(StringType, validators=[is_known_project_status])
organisation_name = StringType()
organisation_id = IntType()
Expand Down
19 changes: 14 additions & 5 deletions backend/services/project_search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,21 @@ def _filter_projects(search_dto: ProjectSearchDTO, user):
if search_dto.mapping_types:
# Construct array of mapping types for query
mapping_type_array = []
mapping_type_array = [
MappingTypes[mapping_type].value
for mapping_type in search_dto.mapping_types
]

query = query.filter(Project.mapping_types.contains(mapping_type_array))
if search_dto.mapping_types_exact:
mapping_type_array = [
{
MappingTypes[mapping_type].value
for mapping_type in search_dto.mapping_types
}
]
query = query.filter(Project.mapping_types.in_(mapping_type_array))
else:
mapping_type_array = [
MappingTypes[mapping_type].value
for mapping_type in search_dto.mapping_types
]
query = query.filter(Project.mapping_types.overlap(mapping_type_array))

if search_dto.text_search:
# We construct an OR search, so any projects that contain or more of the search terms should be returned
Expand Down

0 comments on commit 2141fae

Please sign in to comment.