Sort dynamic choice list search results by relevance #35494
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please note, this PR needs tests. I've only tested the code in this PR manually.
Product Description
This PR is a fix for the
dynamic_choice_list
filter; some values that should have popped up in the filter as the user types did not pop up, not even if the user entered the fully qualified filter value. This made it impossible to select this particular filter.Technical Summary
Ticket
An issue was raised where a dynamic choice filter option did not appear in the list of options, even when the user typed in the full expected value.
The offending line of code was identified as this one. Adding the code (with some added context) also below:
What happens here is, after the user query is applied to the DB query (with
.ilike
), the results are being ordered by thesql_column
, effectively ordering whatever results is returned alphabetically. In this particular case the qualified user query was in fact also a subset of a bunch of other results. This resulted in a post-sorted query having pushed down the expected result to the bottom of the list and further being cut off after the limit was applied, effectively prohibiting the user to see the desired filter value.Example of what happened (with fake values):
Assume a column have the following values:
User input query
"ab"
(this is the fully qualified value, but also a substring of other results)Assume the query limit is
3
Query results:
After limit is applied:
*insert user sad face here
Solution
A more intuitive (I think) way of ordering the results would be to show the results in the following priority manner:
Taking the above example, the query results would become:
This solution is open for debate.
Note: this PR does not cover the
get_values_for_query
method ofMultiFieldDataSourceColumnChoiceProvider
(only forDataSourceColumnChoiceProvider
), so a similar issue might still exist with filters having this type of choice provider.Feature Flag
UCR
Safety Assurance
Safety story
Automated tests to be written + QA to commence on staging.
Automated test coverage
Automated test to be written
QA Plan
QA will be done
Rollback instructions
Labels & Review