Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorts by most recent on page load, fixes date formats #34

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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