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
model: Alter message search for searching in current narrow. #430
Conversation
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.
@sumanthvrao I just tested this manually.
I started by searching in all-messages, and searching for 'RDS'. That gave various results across multiple streams/topics. I then went to a production-help topic (AWS Deployment) and used 'z' to jump to that topic. I then used '/' again, left the text as 'RDS' and hit enter, and I get a traceback. If I jumped out to the stream before searching again, then it gives zero results, which seems incorrect ;) The latter also seems to hide the cursor or stop it moving somehow? (I've not figured out quite what is happening there).
A few things to think about and try out :)
Ah! Thanks for the report. I'll check why this is happening. |
3ffd545
to
81687d0
Compare
@neiljp updated this. This turned out more intensive than the straightforward fix I initially assumed it would be. Hope this simplifies the searching process ;) I have also added tests, which have some 'expected' behaviours of the 'search_message' logic. |
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.
@sumanthvrao From manual testing again, this is definitely an improvement in the sense of searching over only narrows:
- All messages -> / RDS -> multiple streams/topics with RDS in :)
- Production help -> / RDS -> multiple topics with RDS in, in stream :)
- Production help -> / AWS -> various topics with AWS in :)
- Production help / topic -> / AWS -> shows same topic, but indicates it's in a stream? (doesn't show 'topic narrow', or anything indicating something similar)
However that last point, with the confusing stream/topic UI has me concerned right now, and also that it's not clear when the search text (which is not cleared unless explicitly using '/'+backspace?) is applied to the existing - or next/new - narrow.
I think we should clear the search when we change to some 'different enough' narrows. What conditions are 'enough' might be up for discussion, since perhaps the user wishes to keep searching until they clear the search box, even between narrows, or the exact opposite! We are also running into the issue that #278 tries to work around, but here with empty search narrows.
81687d0
to
51d79a5
Compare
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.
@sumanthvrao I just had a quick manual test of this again.
- Did we come to a decision on how to clarify the UI? (narrow + search-text when not in search narrow?) This seems to still rather unclear.
- Searching in 'starred' does seem to show the expected results, but doesn't show the right narrow title (ie. starred)
- Similarly, searching in 'all PMs' results in the narrow being shown as 'private conversation' narrow, even though it is clearly showing a search in all PMs
The last few issues appear to also cause the narrow to update whenever switching between messages, which is unexpected!
e756573
to
a649818
Compare
@neiljp @amanagr Have pushed an update for this. The behaviour is more what one expects when searching. The main changes include:
I leave you to explore more of how this feels. Any suggestions or improvements are welcome. A few improvements which I can think of right now would be:
|
a649818
to
f5b2ef8
Compare
@sumanthvrao This looks a lot cleaner than before in manual testing. The remaining issues I see are:
Other than the first point, practically speaking this looks like a good 'v2' of our search, ie. including the narrow. |
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.
@sumanthvrao The code looks pretty good, though perhaps a few extra methods might make things clearer? I mentioned moving the first added test to near the start, since it might make the early changes more obvious in terms of the behavior changing as defined by the tests.
({100}) | ||
]) | ||
def test_search_message(self, initial_narrow, final_narrow, | ||
controller, mocker, msg_ids): |
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 know that it might be less simple to write, but it would be informative of the changes you have made to search if this test existed at the start, and then was amended as you worked through the previous commits? Then you wouldn't need to say 'from the previous commits', either.
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.
@neiljp I have managed to include the tests in this commit itself. It would benefit the flow of commits.
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 test is fine as a separate commit. The intent of my original suggestion was that you move (and adjust) the test commit to be first/early in the list of commits. Then when you change/add the search-in-narrow behavior you can change/add the expected behaviors to the test.
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.
Yes. The behaviour has been adjusted.
if 'search' in [ele[0] for ele in curr_narrow]: | ||
is_search_narrow = True | ||
curr_narrow = [sub_narrow for sub_narrow in curr_narrow | ||
if sub_narrow[0] != 'search'] |
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.
This code seems similar to that which you added to the model (and what I hinted at for the is_search_narrow
case). I think this comes down to the idea of some kind of 'base' narrow, combined with a filter on top (ie. the search). If thinking of it that way, maybe the model could provide some kind of base_narrow
narrow, separate to a search
filter (if necessary)?
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.
Thanks for pointing this out @neiljp. I do like the idea of making it like a base narrow and the search being an add on top of the base narrow. I have used the is_search_narrow
helper now and it has helped reduce complexity a little bit. I am planning on taking this up as a follow-up if its okay.
0b50b64
to
00924c9
Compare
@neiljp Thanks for the review. I have included the tests in the starting commit which introduces the |
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.
@sumanthvrao I've left some comments which are mostly minor or regarding commit structuring thoughts. However, it does still seem to not 'reset' when returning back to an 'empty' search?
As I clarified in a comment, I think it's fine to keep the introduction of the search test in a separate commit and early to define the current state, before updating it as the behavior changes through this PR.
({100}) | ||
]) | ||
def test_search_message(self, initial_narrow, final_narrow, | ||
controller, mocker, msg_ids): |
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 test is fine as a separate commit. The intent of my original suggestion was that you move (and adjust) the test commit to be first/early in the list of commits. Then when you change/add the search-in-narrow behavior you can change/add the expected behaviors to the test.
@@ -117,6 +117,7 @@ def show_msg_info(self, msg: Any) -> None: | |||
|
|||
def search_messages(self, text: str) -> None: | |||
# Search for a text in messages | |||
self.model.index['search'].clear() |
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.
Does the test need to be amended here? Shouldn't it need to be?
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.
Rather 'added'. We didn't test for self.model.index
contents after call to search_messages, but we can do that now.
Tests added involve a previous narrow being unset and a new search narrow being set based on search query. This reflects the old earch behaviour which will be changed in the subsequent commits.
Helper aded to check if a narrow is a result of searching. This can be determined by checking if the narrow containts ['search', text] at any position. We make use of the helper to now as the conditional to add and fetch searches messages in the index. Tests added for model.is_search_narrow().
We make use of two helper functions, one to set the search narrow based on searched text and another to unset search narrow after a search has completed. model.set_narrow(search=text) has been removed due to the current version of using set_search_narrow specifically for setting such type of narrows. Tests amended to remove setting search narrow for set_narrow. Tests amended for setting narrow with `set_search_narrow` method based on new behaviour.
To avoid displaying search results indexed away from a previous search result, we flush the search index at the start of each search. Tests added.
To easily distinguish between a search result and other narrows, we mark the top_search_bar with 'Search Result'. Navigating out of this view remove the indicator from the header impying that the search query does not hold to the current narrow. Tests added.
Before we use 'z' keypress in order for the conditionals to work, we unset the ['search', text] part of the narrow.
00924c9
to
630510f
Compare
@neiljp Updated based on your feedback. |
@sumanthvrao Thanks for this - as discussed, merged with slight adjustments with some extra tests, but this is a really useful search improvement 🎉 |
The earlier logic of message search [/], searched for messages
in the default view by setting the narrow to [['search', text]].
We now alter this, to search for messages in current narrow
by extending the narrow before fetching messages from
the server. This is the syntax required by get_messages
for searching within narrow.