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

New search #558

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

New search #558

wants to merge 10 commits into from

Conversation

RJ722
Copy link
Contributor

@RJ722 RJ722 commented Feb 8, 2021

Summary of the changes in this pull request

Previously, a search would only return results with exact matches, that is if the search string is a substring of the text in the window buffer. With this new edition, we support searching for multiple words. A result would only be shown if all of those words appear at least once in the text.

There is a bug in there due to which highlights in the main windows aren't working properly. I have figured that one needs to have the day opened on the side, go to the search bar, and hit enter again for the highlights to work correctly. I have a hunch that this is because I've skipped the "scroll to query" part -- which I'm guessing refreshes the view? Just a hunch, I can be totally off on this.

EDIT: Whenever a search result is clicked, Day.show_day method is called to update the view. It used the self.search_text to take care of highlighting and scrolling to search results. I updated it to use the new self.search_queries instead, and everything appears to be working! \o/

Pull request checklist

  • I have added an entry in CHANGELOG.md including my name and issue and/or pull request number.
  • If applicable: I have removed the corresponding entry in TODO.md.

Copy link
Owner

@jendrikseipp jendrikseipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :-) I only have a few comments. Maybe the bug you're seeing will be gone after taking care of these.

rednotebook/data.py Outdated Show resolved Hide resolved
rednotebook/gui/editor.py Outdated Show resolved Hide resolved
rednotebook/gui/search.py Outdated Show resolved Hide resolved
@RJ722 RJ722 marked this pull request as ready for review February 28, 2021 12:28
@RJ722 RJ722 force-pushed the new-search branch 2 times, most recently from 38263d8 to d79034e Compare February 28, 2021 12:42
@RJ722
Copy link
Contributor Author

RJ722 commented Mar 5, 2021

@jendrikseipp After the latest changes, indeed the bug went away. (I was actually still checking the old search_text, whereas I had renamed it to search_queries.)

I've found another bug now which causes an exception if only a date string is passed to search (easily fixable). I'll do that. Plus, I was thinking that I should change all occurrences of queries to words. What do you think?

@jendrikseipp
Copy link
Owner

Plus, I was thinking that I should change all occurrences of queries to words. What do you think?

Sounds good!

@RJ722
Copy link
Contributor Author

RJ722 commented Mar 9, 2021

Took me a lot longer, but pheww. finally done. :D

@jendrikseipp
Copy link
Owner

Awesome! I hope to be able to review this soon.

Copy link
Owner

@jendrikseipp jendrikseipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally found the time to have a look :-) This is shaping up nicely!

rednotebook/gui/browser.py Outdated Show resolved Hide resolved
for query in search_words:
self.get_find_controller().search(
query, WebKit2.FindOptions.CASE_INSENSITIVE, MAX_HITS
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we stop after the first word is found?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little confused here since the docs say that the search method performs the search asynchronously. If so, would this be possible?

rednotebook/gui/main_window.py Show resolved Hide resolved
rednotebook/gui/search.py Outdated Show resolved Hide resolved
rednotebook/data.py Outdated Show resolved Hide resolved
rednotebook/data.py Outdated Show resolved Hide resolved
rednotebook/data.py Outdated Show resolved Hide resolved
rednotebook/data.py Outdated Show resolved Hide resolved
rednotebook/data.py Outdated Show resolved Hide resolved
rednotebook/data.py Outdated Show resolved Hide resolved
RJ722 and others added 8 commits May 15, 2021 10:50
Previously, a search would only return results with exact matches, that is if
the search string is a substring of the text in the window buffer.  With this
new edition, we support searching for multiple words. A result would only be
shown if *all* of those words appear at least once in the text.
@RJ722
Copy link
Contributor Author

RJ722 commented May 15, 2021

Hey, thanks for the review Jendrik! \o/

I believe I've addressed all of the comments. I also took the liberty and renamed the DayEditor.scroll_to_text to DayEditor.scroll_to_non_date_text which will help prevent the confusion because of the method in the parent class by the same name. Let me know if you don't like that and would like to revert.

@RJ722
Copy link
Contributor Author

RJ722 commented May 15, 2021

Closing and re-opening to trigger CI again.

@RJ722 RJ722 closed this May 15, 2021
@RJ722 RJ722 reopened this May 15, 2021
If one of the searched words is present in the current day's text, highlight it.
Previously, the higlighting would only account for the last searched word.
Copy link
Owner

@jendrikseipp jendrikseipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of my comments! I looked into the webkit highlighting. Now everything should work. I only have minor comments remaining.

words_contain_date = len(non_date_words) != len(words)
if words_contain_date:
results.append(get_text_with_dots(self.text, 0, TEXT_RESULT_LENGTH))
# If all the words matched agains the date, return.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"matched agains" -> "match"

@@ -814,17 +814,29 @@ def _get_buffer(self, key, text):
def _get_buffer_for_day(self, day):
return self._get_buffer(day.date, day.text)

def scroll_to_non_date_text(self, words):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new method name.

"""
for word in words:
# If word matches date, it probably is not present in the text.
if word in str(self.day):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the pass by inverting the if statement: if word not in str(self.day)

if word in str(self.day):
pass
else:
super().scroll_to_text(word)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need the super() now that the child method is renamed?

@jendrikseipp
Copy link
Owner

@RJ722 Do you still want to pursue this? If so, it seems you'll have to merge with master first and then take care of my latest few comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants