You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$500] Don't change the order of user-entered search syntax #69394
Let's not change the order of a user-entered query, as it's confusing and unexpected. Here's a recording, notice how the group-by syntax jumps around? Let's make sure we're not doing that.
changed the title [-]Don't change the order of user-entered search syntax[/-][+][$250] Don't change the order of user-entered search syntax[/+]on Aug 27, 2025
🚨 Edited by proposal-police: This proposal was edited at 2025-08-28 09:45:31 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Don't change the order of user-entered search syntax
What is the root cause of that problem?
When users submit a search, the query gets processed through multiple functions that rebuild it in a fixed order rather than preserving the original input sequence.
In SearchPageHeaderInput.tsx, getQueryWithUpdatedValues() calls buildSearchQueryString(), which processes parts in a fixed order.
As a result, queries are reconstructed in a constant order instead of matching the user’s input.
What changes do you think we should make in order to solve the problem?
Add a helper function in SearchQueryUtils.ts to sort query parts based on original input order (the exact sorting logic can be refined in the PR if needed)
functionsortQueryPartsToMatchInputOrder(parts: string[],originalQuery: string){constsortedFriendlyKeys=originalQuery.split(' ').map((part)=>{constkey=part.split(':').at(0);returngetUserFriendlyKey(keyasSearchFilterKey);});constsortedParts=parts.sort((a,b)=>{constaKey=a.split(':').at(0)??'';constbKey=b.split(':').at(0)??'';constaFriendly=getUserFriendlyKey(aKeyasSearchFilterKey);constbFriendly=getUserFriendlyKey(bKeyasSearchFilterKey);constaIndex=sortedFriendlyKeys.indexOf(aFriendly);constbIndex=sortedFriendlyKeys.indexOf(bFriendly);// If both keys are found in the original query, sort by their positionif(aIndex!==-1&&bIndex!==-1){returnaIndex-bIndex;}// If only one is found, prioritize itif(aIndex!==-1){return-1;}if(bIndex!==-1){return1;}// If neither is found, maintain the current orderreturn0;});returnsortedParts;}
If we want routing to stay consistent with what the user sees in the search input, then both buildSearchQueryString() and buildUserReadableQueryString() should apply sorting.
Apply sorting
In buildSearchQueryString:
// Sort queryParts to match the original input orderif(queryJSON?.inputQuery){queryParts=sortQueryPartsToMatchInputOrder(queryParts,queryJSON.inputQuery);}
In buildUserReadableQueryString(): Replace the current let title += approach with an array-based approach:
consttitleParts: string[]=[];// ... collect parts into titleParts array instead of concatenating to title// Sort titleParts to match the original input order if(queryJSON.inputQuery){titleParts=sortQueryPartsToMatchInputOrder(titleParts,queryJSON.inputQuery);}returntitleParts.join(' ');
If only the display order matters (and routing can stay as-is), then we don’t need to update buildSearchQueryString().
Instead, we can save the raw queryString at submitSearch() and pass it to buildUserReadableQueryString() to control sorting:
The downside of this approach is that the routing won’t preserve the user’s preferred order.
This means if the user refreshes the page, the query order will reset to the default.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
Add tests to confirm that getQueryWithUpdatedValues() and buildUserReadableQueryString() always keep the same order as the input query.
What alternative solutions did you explore? (Optional)
Create a function sortQueryPartsByFilterOrder that sorts query parts based on the position of filters.
functionsortQueryPartsByFilterOrder(queryParts: string[],filtersOrder: string[]){return[...queryParts].sort((a,b)=>{constaKey=a.split(':').at(0)??'';constbKey=b.split(':').at(0)??'';constaIdx=filtersOrder.indexOf(aKey);constbIdx=filtersOrder.indexOf(bKey);// If both keys are found, sort by their order in inputQueryif(aIdx!==-1&&bIdx!==-1){returnaIdx-bIdx;}// If only one is found, that one comes firstif(aIdx!==-1){return-1;}if(bIdx!==-1){return1;}// Otherwise, keep original orderreturn0;});}
Update the buildSearchQueryString function to return a query string sorted by the positions of the search filters.
Reviewers - let me know if you disagree, though one of your reviewed the proposals and another reviewed the PR, so that seemed like the fair thing to do.
@JmillsExpensify Thanks for checking this. But I think I should be paid same as contributor. We almost ended up with a new solution of the original proposal, see #69394 (comment) as well. Just wanted to highlight the work we have done and I'm not going to deny the effort previous reviewer put in for the task.
The PR for this issue caused #79952. When searching in #chat, the user was unintentionally being directed to type:expense in:#chat instead of type:chat in:#chat.
Activity
melvin-bot commentedon Aug 27, 2025
Current assignee @JmillsExpensify is eligible for the Bug assigner, not assigning anyone new.
[-]Don't change the order of user-entered search syntax[/-][+][$250] Don't change the order of user-entered search syntax[/+]melvin-bot commentedon Aug 27, 2025
Job added to Upwork: https://www.upwork.com/jobs/~021960818749737255277
melvin-bot commentedon Aug 27, 2025
Triggered auto assignment to Contributor-plus team member for initial proposal review - @shubham1206agra (
External)mohammadjafarinejad commentedon Aug 28, 2025
🚨 Edited by proposal-police: This proposal was edited at 2025-08-28 09:45:31 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Don't change the order of user-entered search syntax
What is the root cause of that problem?
When users submit a search, the query gets processed through multiple functions that rebuild it in a fixed order rather than preserving the original input sequence.
SearchPageHeaderInput.tsx,getQueryWithUpdatedValues()callsbuildSearchQueryString(), which processes parts in a fixed order.App/src/libs/SearchQueryUtils.ts
Line 383 in 62add1a
buildUserReadableQueryString()also enforces a fixed order for the title.App/src/libs/SearchQueryUtils.ts
Lines 790 to 794 in 62add1a
As a result, queries are reconstructed in a constant order instead of matching the user’s input.
What changes do you think we should make in order to solve the problem?
Add a helper function in
SearchQueryUtils.tsto sort query parts based on original input order (the exact sorting logic can be refined in the PR if needed)If we want routing to stay consistent with what the user sees in the search input, then both
buildSearchQueryString()andbuildUserReadableQueryString()should apply sorting.Apply sorting
buildSearchQueryString:buildUserReadableQueryString(): Replace the currentlet title +=approach with an array-based approach:If only the display order matters (and routing can stay as-is), then we don’t need to update
buildSearchQueryString().Instead, we can save the raw
queryStringatsubmitSearch()and pass it tobuildUserReadableQueryString()to control sorting:The downside of this approach is that the routing won’t preserve the user’s preferred order.
This means if the user refreshes the page, the query order will reset to the default.
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
Add tests to confirm that
getQueryWithUpdatedValues()andbuildUserReadableQueryString()always keep the same order as the input query.What alternative solutions did you explore? (Optional)
N/A
sofi-a commentedon Aug 28, 2025
🚨 Edited by proposal-police: This proposal was edited at 2025-08-28 03:01:20 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Avoid re-ordering user-entered search syntax
What is the root cause of that problem?
The
buildSearchQueryStringandbuildUserReadableQueryStringfunctions use a hardcoded order when computing the query string and search text, respectively.App/src/libs/SearchQueryUtils.ts
Lines 406 to 417 in 454a312
App/src/libs/SearchQueryUtils.ts
Lines 790 to 800 in 227c0c2
What changes do you think we should make in order to solve the problem?
searchParserto include tracking metadata for the positions of search filters.location()special function to get the start and end positions of the current rule match for both the default and standard filter keys.SearchQueryJSON.getFiltersOrderthat returns an array of filter keys ordered according to their positions in the query.sortQueryPartsByFilterOrderthat sorts query parts based on the position of filters.buildSearchQueryStringfunction to return a query string sorted by the positions of the search filters.buildUserReadableQueryStringfunction to order the search text properly.What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
N/A
What alternative solutions did you explore? (Optional)
N/A
71 remaining items
ShridharGoel commentedon Dec 10, 2025
@JmillsExpensify This seems to be due for payment.
JmillsExpensify commentedon Dec 11, 2025
Ah interesting. Looks like the automation failed.
JmillsExpensify commentedon Dec 11, 2025
Payment summary:
JmillsExpensify commentedon Dec 11, 2025
Reviewers - let me know if you disagree, though one of your reviewed the proposals and another reviewed the PR, so that seemed like the fair thing to do.
JmillsExpensify commentedon Dec 11, 2025
Regression test added and all contributors paid via ND, so closing.
eh2077 commentedon Dec 11, 2025
@JmillsExpensify Thanks for checking this. But I think I should be paid same as contributor. We almost ended up with a new solution of the original proposal, see #69394 (comment) as well. Just wanted to highlight the work we have done and I'm not going to deny the effort previous reviewer put in for the task.
JmillsExpensify commentedon Dec 11, 2025
That sounds reasonable, I've updated my comment.
eh2077 commentedon Dec 11, 2025
Thank you so much 🙇
twisterdotcom commentedon Dec 11, 2025
@ShridharGoel has submitted payment for this report on ND here.
SO: https://stackoverflowteams.com/c/expensify/questions/7582
Zapier Logs
Run ID: 00040eee-8e29-a187-556b-c15c49e2f3e4garrettmknight commentedon Dec 18, 2025
$500 approved for @eh2077
garrettmknight commentedon Apr 2, 2026
$250 approved for @shubham1206agra
thesahindia commentedon May 11, 2026
The fix for this caused #87285. Explanation here.
sobitneupane commentedon May 25, 2026
The PR for this issue caused #79952. When searching in
#chat, the user was unintentionally being directed totype:expense in:#chatinstead oftype:chat in:#chat.