-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Fast search #2179
Open
leolost2605
wants to merge
20
commits into
main
Choose a base branch
from
leolost/fast-search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fast search #2179
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2a8107c
Prototype fast search
leolost2605 e3337aa
Some improvements
leolost2605 526a379
Only show unique packages
leolost2605 619cf8f
Add category filtering
leolost2605 3f9f18e
Search for multiple queries
leolost2605 0f556c5
Cleanup
leolost2605 dfd0e73
Rename to search engine
leolost2605 031edd2
Proper recycling
leolost2605 15e2df3
Fix alert view not showing
leolost2605 541edca
Merge branch 'main' into leolost/fast-search
leolost2605 9509b50
Add license header
leolost2605 a498747
Merge branch 'main' into leolost/fast-search
danirabbit 9289e0d
Merge branch 'main' into leolost/fast-search
danirabbit bd1900b
Some null checking
leolost2605 3e62db0
Fix warnings
leolost2605 566d26c
Merge branch 'main' into leolost/fast-search
leolost2605 6fee2e1
Less lambdas
leolost2605 26bdef7
Merge branch 'main' into leolost/fast-search
danirabbit 667045f
Fix memory leak
leolost2605 11adc7d
Better comment
leolost2605 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io) | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* | ||
* Authored by: Leonhard Kargl <[email protected]> | ||
*/ | ||
|
||
public class AppCenterCore.SearchEngine : Object { | ||
public ListModel results { get; construct; } | ||
|
||
private ListStore packages; | ||
private AppStream.Pool pool; | ||
|
||
private string[] query; | ||
private AppStream.Category? category; | ||
|
||
public SearchEngine (Package[] packages, AppStream.Pool pool) { | ||
var unique_packages = new Gee.HashMap<string, Package> (); | ||
foreach (var package in packages) { | ||
var package_component_id = package.normalized_component_id; | ||
if (unique_packages.has_key (package_component_id)) { | ||
if (package.origin_score > unique_packages[package_component_id].origin_score) { | ||
unique_packages[package_component_id] = package; | ||
} | ||
} else { | ||
unique_packages[package_component_id] = package; | ||
} | ||
} | ||
|
||
this.packages.splice (0, 0, unique_packages.values.to_array ()); | ||
this.pool = pool; | ||
} | ||
|
||
construct { | ||
packages = new ListStore (typeof (Package)); | ||
|
||
var filter_model = new Gtk.FilterListModel (packages, new Gtk.CustomFilter ((obj) => { | ||
var package = (Package) obj; | ||
|
||
if (category != null && !package.component.is_member_of_category (category)) { | ||
return false; | ||
} | ||
|
||
return ((Package) obj).matches_search (query) > 0; | ||
})) { | ||
incremental = true | ||
}; | ||
|
||
var sort_model = new Gtk.SortListModel (filter_model, new Gtk.CustomSorter ((obj1, obj2) => { | ||
var package1 = (Package) obj1; | ||
var package2 = (Package) obj2; | ||
return (int) (package2.cached_search_score - package1.cached_search_score); | ||
})); | ||
|
||
results = sort_model; | ||
} | ||
|
||
public void search (string query, AppStream.Category? category) { | ||
this.query = pool.build_search_tokens (query); | ||
this.category = category; | ||
packages.items_changed (0, packages.n_items, packages.n_items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -210,7 +210,8 @@ public class AppCenter.Views.AppInfoView : Adw.NavigationPage { | |||||||||||
overflow = VISIBLE | ||||||||||||
}; | ||||||||||||
|
||||||||||||
action_stack = new ActionStack (package); | ||||||||||||
action_stack = new ActionStack (); | ||||||||||||
action_stack.package = package; | ||||||||||||
Comment on lines
+213
to
+214
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do:
Suggested change
|
||||||||||||
|
||||||||||||
var button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { | ||||||||||||
halign = Gtk.Align.END, | ||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we make sure we're using GObject-style construction here? https://docs.vala.dev/tutorials/programming-language/main/03-00-object-oriented-programming/03-14-gobject-style-construction.html
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.
Yeah I didn't use it here because we don't need the packages array but only the liststore with the unique packages so it seemed kinda pointless to first put the array into a property and then in construct extracting this stuff and then setting the property to null to free the memory. Alternatively we could ofc do all of this in the flatpackbackend and hand over the liststore right away 🤷
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.
Yeah that might be the way to go here so we can stick to coding conventions