-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving cog/over search results (#4528)
* Improving cog/over search results * Restoring deleting log line * Accepting empty string or either
- Loading branch information
1 parent
20fd465
commit 73dd827
Showing
4 changed files
with
97 additions
and
67 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
47 changes: 47 additions & 0 deletions
47
backend/dissemination/searchlib/search_cog_or_oversight.py
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,47 @@ | ||
from .search_general import report_timing | ||
|
||
from django.db.models import Q | ||
|
||
import logging | ||
import time | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def search_cog_or_oversight(general_results, params): | ||
t0 = time.time() | ||
|
||
q_cogover = _get_cog_or_oversight_match_query( | ||
params.get("agency_name", None), params.get("cog_or_oversight", "either") | ||
) | ||
filtered_general_results = general_results.filter(q_cogover) | ||
|
||
t1 = time.time() | ||
report_timing("search_cog_or_oversight", params, t0, t1) | ||
|
||
return filtered_general_results | ||
|
||
|
||
def _get_cog_or_oversight_match_query(agency_name, cog_or_oversight): | ||
if cog_or_oversight.lower() in ["", "either"]: | ||
if agency_name: | ||
return Q( | ||
Q(cognizant_agency__in=[agency_name]) | ||
| Q(oversight_agency__in=[agency_name]) | ||
) | ||
else: | ||
# Every submission should have a value for either cog or over, so | ||
# nothing to do here | ||
return Q() | ||
elif cog_or_oversight.lower() == "cog": | ||
if agency_name: | ||
return Q(cognizant_agency__in=[agency_name]) | ||
else: | ||
# Submissions that have any cog | ||
return Q(cognizant_agency__isnull=False) | ||
elif cog_or_oversight.lower() == "oversight": | ||
if agency_name: | ||
return Q(oversight_agency__in=[agency_name]) | ||
else: | ||
# Submissions that have any over | ||
return Q(oversight_agency__isnull=False) |
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