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

Merged
merged 17 commits into from
Oct 21, 2024

Conversation

ShaopengLin
Copy link
Collaborator

@ShaopengLin ShaopengLin commented Oct 5, 2024

Fixes (part 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/page-down keypresses and mouse scrolls.

Known Issues to be fixed in #1189: The first suggestion is hidden by the header due to QCompleter's incorrect size management.

@kelson42 kelson42 added this to the 2.4.0 milestone Oct 5, 2024
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 3 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
@ShaopengLin ShaopengLin force-pushed the Issue#413-endless-search-suggestuon branch from 4fa9ab4 to b6a6c06 Compare October 15, 2024 22:13
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
@ShaopengLin ShaopengLin force-pushed the Issue#413-endless-search-suggestuon branch from b6a6c06 to 1bc6c82 Compare October 18, 2024 06:19
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 221
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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely. But please add a TODO comment in the body of SearchBarLineEdit::fetchMoreSuggestions() in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't start working on this until the rest of your kiwix-desktop PRs are merged.

@ShaopengLin ShaopengLin force-pushed the Issue#413-endless-search-suggestuon branch from 1bc6c82 to 07aa791 Compare October 18, 2024 19:14
Allow future customizing of suggestions.
More cohesive design to utilize new model's index data.
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
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
@ShaopengLin ShaopengLin force-pushed the Issue#413-endless-search-suggestuon branch from f62d9ac to 9982a22 Compare October 21, 2024 18:30
@kelson42 kelson42 merged commit c6ea91f into main Oct 21, 2024
6 checks passed
@kelson42 kelson42 deleted the Issue#413-endless-search-suggestuon branch October 21, 2024 18:41
@veloman-yunkan
Copy link
Collaborator

This PR broke the handling of pressing ENTER in the search bar - it always opens the first suggestion (even if it doesn't fully match the text in the searchbar).

@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Oct 24, 2024

@veloman-yunkan I believe its mainly from this #1224 (comment) where we discarded the checks for text comparison inside openCompletion.

I will think of a way to avoid the duplication of text check in both openCompletion and getDefaultSuggestionIndex in #1189

@veloman-yunkan
Copy link
Collaborator

@veloman-yunkan I believe its mainly from this #1224 (comment) where we discarded the checks for text comparison inside openCompletion.

I cannot agree. I don't see any flaw with the design of that approach. getDefaultSuggestionIndex() picks up the suggestion that needs to be opened and openCompletion() just opens it. It looks like there is a bug in getDefaultSuggestionIndex() but it's not immediately clear what's wrong with it.

@ShaopengLin
Copy link
Collaborator Author

@veloman-yunkan getDefaultSuggestionIndex is only called during typing. openCompletion is also signaled normalled when user activate(click/enter) on a cell when not typing. openCompletion itself does not use getDefaultSuggestionIndex.

@veloman-yunkan
Copy link
Collaborator

@veloman-yunkan getDefaultSuggestionIndex is only called during typing. openCompletion is also signaled normalled when user activate(click/enter) on a cell when not typing. openCompletion itself does not use getDefaultSuggestionIndex.

@ShaopengLin Yes. But when an item from the list is activated openCompletion() is called with its exact index. getDefaultSuggestionIndex() is (or, rather, should be) invoked only when the ENTER key is pressed with no item selected.

@veloman-yunkan
Copy link
Collaborator

The bug is that openCompletion(getDefaulSuggestionIndex()); is called only from onInitialSuggestions(). It works as intended only if ENTER is pressed before suggestions are generated.

@kelson42
Copy link
Collaborator

@veloman-yunkan Please open a dedicated issue, not very much cinfirtable with discussion on closed issues/PRa.

@veloman-yunkan
Copy link
Collaborator

@veloman-yunkan Please open a dedicated issue, not very much cinfirtable with discussion on closed issues/PRa.

Done (#1230)

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