Skip to content
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

Closed

Conversation

sumanthvrao
Copy link
Member

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.

Copy link
Collaborator

@neiljp neiljp left a 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 :)

@sumanthvrao
Copy link
Member Author

Ah! Thanks for the report. I'll check why this is happening.

@sumanthvrao
Copy link
Member Author

sumanthvrao commented Jul 13, 2019

@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.

Copy link
Collaborator

@neiljp neiljp left a 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.

Copy link
Collaborator

@neiljp neiljp left a 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!

@sumanthvrao sumanthvrao force-pushed the zt-improve-search-in-stream branch 4 times, most recently from e756573 to a649818 Compare August 2, 2019 14:37
@sumanthvrao
Copy link
Member Author

@neiljp @amanagr Have pushed an update for this. The behaviour is more what one expects when searching. The main changes include:

  • Clearly marking 'Search Results' from the current narrow. This handles the last few points mentioned in Neils comment above.
  • Clearing the search result when switching narrow to something else from the search result.

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:

  • Not clearing search text for 'close enough' narrows. (In which case the search carries over)
  • Display a dummy message when no search hits are found after search.
  • Allowing the search to carry on across narrows and defining some key to exit search (To be discussed)

@neiljp
Copy link
Collaborator

neiljp commented Aug 4, 2019

@sumanthvrao This looks a lot cleaner than before in manual testing. The remaining issues I see are:

  • searching for an empty string seems to give no results? (regression? do we have tests for that?)
  • having 'Search Results' and 'Search [/]:' in the same bar is not a great use of space, or textually very good; adjusting that could be a follow-up PR as it's just UI (?) but perhaps either have "Search [/]:" in white, or "Search Results [/]: " all in red?

Other than the first point, practically speaking this looks like a good 'v2' of our search, ie. including the narrow.

Copy link
Collaborator

@neiljp neiljp left a 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.

zulipterminal/core.py Show resolved Hide resolved
zulipterminal/helper.py Outdated Show resolved Hide resolved
({100})
])
def test_search_message(self, initial_narrow, final_narrow,
controller, mocker, msg_ids):
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

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.

Copy link
Member Author

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']
Copy link
Collaborator

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)?

Copy link
Member Author

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.

zulipterminal/ui_tools/boxes.py Show resolved Hide resolved
@sumanthvrao sumanthvrao force-pushed the zt-improve-search-in-stream branch 3 times, most recently from 0b50b64 to 00924c9 Compare August 5, 2019 10:25
@sumanthvrao
Copy link
Member Author

@neiljp Thanks for the review. I have included the tests in the starting commit which introduces the set_search_narrow function. This helped reduce some code duplication to a good degree. Further, the base_narrow implementation is a good idea. I am okay to do this as a follow-up.

Copy link
Collaborator

@neiljp neiljp left a 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.

zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Show resolved Hide resolved
zulipterminal/model.py Show resolved Hide resolved
({100})
])
def test_search_message(self, initial_narrow, final_narrow,
controller, mocker, msg_ids):
Copy link
Collaborator

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()
Copy link
Collaborator

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?

Copy link
Member Author

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.
@sumanthvrao
Copy link
Member Author

@neiljp Updated based on your feedback.

@neiljp
Copy link
Collaborator

neiljp commented Aug 13, 2019

@sumanthvrao Thanks for this - as discussed, merged with slight adjustments with some extra tests, but this is a really useful search improvement 🎉

@neiljp neiljp closed this Aug 13, 2019
@sumanthvrao sumanthvrao deleted the zt-improve-search-in-stream branch August 13, 2019 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants