Skip to content

Commit

Permalink
Merge pull request #34 from uktrade/HOTFIX/date-formatting-default-sort
Browse files Browse the repository at this point in the history
Sorts by most recent on page load, fixes date formats
  • Loading branch information
gdbarnes authored Oct 18, 2024
2 parents 7dc8d1b + 31475b5 commit 567ec5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions orp/orp_search/public_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ def search(self, config: SearchDocumentConfig):
)
]

# Format dates in the DataFrame
filtered_df["date_modified"] = pd.to_datetime(
filtered_df["date_modified"], format="%d/%m/%Y"
)

# If config.publisher_terms is not None, then add filter
# for publisher in filtered_df
if config.publisher_terms is not None:
Expand All @@ -154,27 +159,21 @@ def search(self, config: SearchDocumentConfig):
)
]

if config.sort_by is None:
results = filtered_df.to_dict(orient="records")
# logger.info("filtered data: %s", results)
return results
# if config.sort_by is None:
# results = filtered_df.to_dict(orient="records")
# # logger.info("filtered data: %s", results)
# return results

sorted_df = None

if config.sort_by == "recent":
# Sort the DataFrame by 'date_modified' in descending order
# Ensure 'date_modified' is in datetime format
filtered_df["date_modified"] = pd.to_datetime(
filtered_df["date_modified"], format="%d/%m/%Y"
)
# sorted_df = None

if config.sort_by == "recent" or config.sort_by is None:
# Sort the DataFrame by 'date_modified' in descending order
sorted_df = filtered_df.sort_values(
by="date_modified", ascending=False
)
elif config.sort_by == "relevance":
# Calculate relevance score
# (based on the number of keywords found)

def calculate_relevance(row, search_terms):
def score_text(text, terms):
text_processed = text.replace(" ", "").lower()
Expand Down
2 changes: 1 addition & 1 deletion orp/orp_search/templates/orp.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ <h2 class="govuk-heading-m">
Published by: {{ result.publisher}}
</p>
<p class="govuk-body-s orp-secondary-text-colour">
Last updated: {{ result.date_modified }}
Last updated: {{ result.date_modified | date:"j F Y" }}
</p>
<ul class="govuk-list orp-topics-list">
{% for topic in result.regulatory_topics %}
Expand Down

0 comments on commit 567ec5b

Please sign in to comment.