-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: remove Relevance
when query
parameter is empty for /codebases/
search
#769
Conversation
this branch is a little borked because of the last pr getting squashed and then reverting the requirements.txt change. Can you just cherry-pick fdfacaa? |
2400cd9
to
ac9f964
Compare
Thanks, Scott! |
sure, I believe Allen had a comment about the spread thing on the old commit. I don't think its super unreadable personally but I guess let opts = [2,3,4];
if (hasQuery()) opts = [1, ...opts] ; is slightly more readable |
Relevance
when query
parameter is empty for /codebases/
searchRelevance
when query
parameter is empty for /codebases/
search
oh, did I kill it?? You mean here?
|
yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, it's fine to leave the spread operator if you all prefer, it is a bit more concise
@@ -399,12 +399,13 @@ def filter_queryset(self, request, queryset, view): | |||
criteria.update(id__in=codebases.values_list("id", flat=True)) | |||
# or we could include the PL in the query | |||
# qs += " ".join(programming_languages) | |||
|
|||
default_ordering = "-first_published_at" | |||
if ordering: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this conditional could probably be simplified also, is this equivalent?
default_ordering = "relevance" if qs else "-first_published_at"
criteria.update(ordering=ordering if ordering else default_ordering)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I asked Perplexity if the approaches are equivalent. Crazy, it does execution! I have also checked the answer. It is correct.
Perplexity Response
The two approaches are not equivalent, as demonstrated by the execution results of the provided code snippets.
Approach 1:
default_ordering = "-first_published_at"
if ordering:
criteria.update(ordering=ordering if qs else default_ordering)
else:
# set default ordering for search when ordering is not specified
criteria.update(ordering="relevance" if qs else default_ordering)
Execution Results:
(True, None, 'relevance')
(True, 'some_order', 'some_order')
(False, None, '-first_published_at')
(False, 'some_order', '-first_published_at')
Approach 2:
default_ordering = "relevance" if qs else "-first_published_at"
criteria.update(ordering=ordering if ordering else default_ordering)
Execution Results:
(True, None, 'relevance')
(True, 'some_order', 'some_order')
(False, None, '-first_published_at')
(False, 'some_order', 'some_order')
Key Differences:
When qs is False and ordering is 'some_order':
Approach 1 results in -first_published_at
.
Approach 2 results in some_order
.
This difference arises because Approach 1 checks whether ordering should be used based on the value of qs, while Approach 2 uses ordering directly if it is provided. Therefore, the logic for determining the final ordering differs between the two approaches when qs is False and an ordering is specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR if no query
is given, the ordering should be -first_published_at
and not some_order
which might be present in request params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's cute that the AI can generate truth tables! I ran this a few times on perplexity and it sometimes got the wrong answer though. Also it doesn't actually answer the question of "is it the behavior we want"...
Four cases:
ordering
is set,qs
is not - should be set toordering
, right? not the default ordering. This is when user changes the sort by ordering without specifying a queryordering
is not set, butqs
is - set to "relevance" by defaultordering
is set,qs
is set - respect ordering requested by the user againordering
not set,qs
is not set - use "-first_published_at"
Here's the current truth table for approach 1:
ordering | qs | criteria['ordering'] |
---|---|---|
True | True | ordering |
True | False | default_ordering |
False | True | "relevance" |
False | False | default_ordering |
The issue is the second line here, which should respect the user-specified ordering
even when qs
is empty.
The code I suggested would generate something like this instead:
ordering | qs | default_ordering | criteria['ordering'] |
---|---|---|---|
True | True | "relevance" | ordering |
True | False | "-first_published_at" | ordering |
False | True | "relevance" | "relevance" |
False | False | "-first_published_at" | "-first_published_at" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree!
…t be visible for /codebases/
ac9f964
to
376bc27
Compare
closing in favor of up-to-date branch #770 |
No description provided.