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

Implement Endless Zim Search Suggestions #1224

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

ShaopengLin
Copy link
Collaborator

Fixes (pat of) #413

Changes:

  • Added a custom model to enable endless suggestions
  • Added basic UI elements such as the search header and icon of the zim for convenience.
  • Endless can be triggered by up/down/pagedown keypresses and mouse scrolls.

src/suggestionlistmodel.h Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
@veloman-yunkan
Copy link
Collaborator

Also there is the following bug:

  1. Open the Ray Charles ZIM file
  2. Start typing beatles in the search box

As soon as you have typed the first three letters (bea) the text in the search box automatically changes to bea (Fulltext search).

@ShaopengLin ShaopengLin force-pushed the Issue#413-endless-search-suggestuon branch 3 times, most recently from cc90069 to 1804f56 Compare October 9, 2024 06:40
@ShaopengLin
Copy link
Collaborator Author

@veloman-yunkan The bug is caused by the absence of the commits that prevent suggestion completer flickering. I added those and the bug should be solved.

src/searchbar.h Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.h Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/suggestionlistmodel.cpp Outdated Show resolved Hide resolved
@ShaopengLin ShaopengLin force-pushed the Issue#413-endless-search-suggestuon branch 5 times, most recently from 02b297f to b4e5695 Compare October 11, 2024 01:10
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

You can guess from the changed nature of most comments that we are now very close to merging this PR. The next iteration can be the final one.

src/suggestionlistworker.h Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.h Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.h Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
@ShaopengLin ShaopengLin force-pushed the Issue#413-endless-search-suggestuon branch from b4e5695 to fc5de3f Compare October 14, 2024 22:53
Allow future customizing of suggestions.
More cohesive design to utilize new model's index data.
@ShaopengLin ShaopengLin force-pushed the Issue#413-endless-search-suggestuon branch 2 times, most recently from aebe4db to 4fa9ab4 Compare October 15, 2024 02:05
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

There are still a couple of bugs (one old and one new) so let's brush up the PR a bit more.

src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
Data required can be retrieved from model.
Remove unecessary checks and prevent misuse if openCompletion.
Refactor to simplify book icon retrieval
Add offset and fetch size, prepare for endless.
Automatically determine start and allow custom callback. Prepare for endless
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

An issue was still left because of hasty conflict resolution. Since you have to fix it, please address a few other comments as well.

src/searchbar.cpp Outdated Show resolved Hide resolved
if (!m_aboutToScrollPastEnd)
return false;

if (auto e = dynamic_cast<QKeyEvent *>(event))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This time I checked the documentation of QObject::eventFilter() as I was curious about the need for its first parameter). I saw in the example that a dynamic_cast is not used because there is a cheaper way - QEvent::type().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This won't work, as many key press events are not based on exactly keypress, such as QEvent::ShortcutOverride. This also explains some the same issue: https://forum.qt.io/topic/101176/casts-for-events


if (auto e = dynamic_cast<QKeyEvent *>(event))
{
if (e->key() == Qt::Key_PageDown && e->modifiers().testFlag(Qt::NoModifier))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now I wonder if it's better to handle key down here too (instead of your previous fix for it). Won't it eliminate the need to undo the handling of wrapping from bottom to top? If yes then the final code will be simpler, and so let's do it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So it seems the scrolling event from Key_down either reaches the popup first or isn't blocked from reaching the popup. I simply removed onScrollPastEnd and put the scrolling only inside the onScroll !m_completer.popup()->currentIndex().isValid() case.

src/searchbar.cpp Outdated Show resolved Hide resolved
src/searchbar.cpp Outdated Show resolved Hide resolved
Comment on lines +173 to +217
void SearchBarLineEdit::fetchMoreSuggestions()
{
fetchSuggestions(&SearchBarLineEdit::onAdditionalSuggestions);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This encapsulates a performance bug. fetchSuggestions() creates a temporary SuggestionListWorker which creates zim::SuggestionSearcher that is discarded after a single use. In a more optimal implementation the zim::SuggestionSearcher should be reused for loading additional suggestions (since those incremental calls to zim::SuggestionSearcher::getResults() should be much cheaper compared to the first call). I am not implying that that optimization be implemented in this PR. I propose to do it myself after this PR is merged, but if you feel like becoming married to this suggestions feature and would like to take care of it to the end I will humbly stay away :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's do this separately.

Trigger on scroll.
Down/Page_Down Key press correctly fetches.
Fetch offset and model removal requires this.
Before, view scroll to row based on prefix match
Focus event can happen more than once.
setCompleter call setCompletionPrefix on typing which flicker
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.

3 participants