Skip to content

Commit

Permalink
Merge pull request #761 from alee/search_tags_only
Browse files Browse the repository at this point in the history
fix: switch back to multiple queries on tags directly
  • Loading branch information
alee authored Sep 13, 2024
2 parents 1725fc0 + 7e75a0e commit ab52a15
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
5 changes: 1 addition & 4 deletions django/core/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


SORT_BY_FILTERS = defaultdict(
lambda: "Sort by: Relevance",
lambda: "Sort by: Relevance", # default sort by relevance
{
"-first_published_at": "Sort by: Publish date: newest",
"first_published_at": "Sort by: Publish date: oldest",
Expand Down Expand Up @@ -62,9 +62,6 @@ def limit_page_range(cls, page=1, count=max_result_window, size=page_size):
max_result_window = es_settings["default"]["INDEX_SETTINGS"]["settings"][
"index"
]["max_result_window"]
logger.debug(
"max_result_window from elasticsearch settings: %s", max_result_window
)
except KeyError as e:
logger.warning(
"max_result_window not set for Elasticsearch, setting to default %s",
Expand Down
16 changes: 7 additions & 9 deletions django/core/view_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,18 @@ def get_search_queryset(
query = query & Phrase(tag)

"""
Order by relevance
Set up order by relevance override for search
other sort orders are handled by SmallResultSetPagination filtering and SORT_BY_FILTERS
"""
order_by_relevance = False
ordering = criteria.get("ordering")
if ordering:
if ordering == "relevance":
if "ordering" in criteria:
sort_order = criteria.pop("ordering")
if sort_order == "relevance":
order_by_relevance = True
criteria.pop("ordering")

"""
Filter queryset
"""
Filter queryset
"""
if criteria:
logger.debug("filter criteria=%s", criteria)
try:
queryset = queryset.filter(**criteria)
except FieldError as e:
Expand Down
7 changes: 6 additions & 1 deletion django/library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,12 @@ def filter_queryset(self, request, queryset, view):
# FIXME: this does not work for the same reason tags__name__in does not work, e.g.,
# https://docs.wagtail.org/en/stable/topics/search/indexing.html#filtering-on-index-relatedfields
# criteria.update(releases__programming_languages__name__in=programming_languages)
qs += " ".join(programming_languages)
codebases = Codebase.objects.public(
releases__programming_languages__name__in=programming_languages
)
criteria.update(id__in=codebases.values_list("id", flat=True))
# or we could include the PL in the query
# qs += " ".join(programming_languages)
if ordering:
criteria.update(ordering=ordering)
else:
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/components/ListSortBy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ onMounted(() => {
let initialOrdering = "";
if (url.pathname.includes("codebases")) {
initialOrdering = "-first_published_at";
// special case for model library: initial load should sort by latest published
// if given a bare query with no ordering, sort by relevance
if (url.searchParams.get("query")) {
initialOrdering = "relevance";
} else {
// FIXME: should probably remove "Relevance" if there's no query as it doesn't really make sense to sort by
// "relevance" when there's no criteria in play
initialOrdering = "-first_published_at";
}
}
selectedOrdering.value = url.searchParams.get("ordering") || initialOrdering;
});
Expand Down

0 comments on commit ab52a15

Please sign in to comment.