-
Notifications
You must be signed in to change notification settings - Fork 993
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
Fixes #36711 - Fix searching in settings #9818
Conversation
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
Issues: #36711 |
Can one of the admins verify this patch? |
02d2040
to
3632477
Compare
ok to test |
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.
I have a few observations to share regarding this PR:
As I discussed previously with @girijaasoni in a private conversation, there are a couple of issues that require attention:
- The 'and'/'or' operations don't seem to be functioning correctly.
- When searching for descriptions containing special characters, it triggers a 500 error code or generates an error message.
One more note, I'm not sure why we didn't opt for the ext_method option, which appears to address our concerns, as detailed in this link: GitHub PR #178. Given that the description search is already operational through the code found here: Setting Presenter, I'm uncertain about the need for additional code. Wouldn't it be more efficient to resolve the error by incorporating the ext_method into the settings model?
Thanks @nofaralfasi Searching in the search bar is implemented by the search_for function which gives us the results, it has always been operational. However, in this PR, The concern addressed is implementing the autocomplete functionality which needs some existing scoped search functions to be overridden. IMHO, The ext method is usually used in case of searching from a different table column or searching based on creating SQL relations as per this Reference and not when we are searching from a memory object. |
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.
I have a different idea:
How about turning off suggestions completely, and do not show name
and description
in the form at all?
The only thing users could do would be to enter value into the search form, and that's it.
The search would then be equal to the name ~ $VALUE OR description ~ $VALUE
It's simple and it's going to cover 99% cases IMHO. It looks to me like it's unnecessarily complex for a simple search in a very simple table.
I agree, and we can always add this functionality if users request it. |
Turning off auto complete would break the search pattern from the other components. In my opinion, suggestions help the user the determine what exactly they want to look for. In this PR, autocomplete works and is only an issue when there's the use of special characters which is fixable(I will update it soon). I think removing the name and description search would be a great hack if and when it's not implementable (which is not the case here) and might require additional suggestions and votes. |
Is it an issue? This fix looks like overkill to me. |
@@ -22,7 +22,6 @@ class SettingsController < V2::BaseController | |||
|
|||
api :GET, "/settings/", N_("List all settings") | |||
param_group :search_and_pagination, ::Api::V2::BaseController | |||
add_scoped_search_description_for(Setting) |
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.
Please, don't remove it completely, it's for documenting what can be used for searching via API/hammer.
A few notes from the testing:
|
To illustrate I recorded few videos. description.webmdescription shows auto completion, that feels overwhelming and does not add quotes around the multiword term name_exact.webmname with typing equal sign provides full name sugestions that don't work at all, even with manually added quotes, as it turns out, it searches by name, e.g. name_fuzzy.webmfuzzy searching on name seems to work (not sure why Hope this helps. Again to be clear, searching in full name is preferred over the name. I would love to search for |
9b3a76b
to
7309fad
Compare
Thanks a lot @ares In this push I have addressed these few things:
|
app/services/setting_registry.rb
Outdated
scoped_search :on => :id, :complete_enabled => false, :only_explicit => true, :validator => ScopedSearch::Validators::INTEGER | ||
scoped_search on: :name, complete_value: :true, operators: ['~', "="] | ||
scoped_search on: :description, complete_value: :true, operators: ['~'] |
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.
Those definitions should be moved to setting model, since the scoped search does not use the SettingRegistry
class for search definition.
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.
we have the definitions in the setting model as well for hammer purpose, but we need it in the registry as well because we need to pass the scoped search definition in the auto_complete method (which we are overriding)
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.
That's not a problem, just pass the definition from the Setting
model:
SettingCompleter.auto_complete(self, Setting.scoped_search_definition, query, opts)
Otherwise we are creating duplication of search definitions, and it will be hard to track down which definition is used.
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.
That was a great catch @ShimShtein
updated it :)
app/services/setting_registry.rb
Outdated
elsif field.field == :description | ||
results = [] | ||
else | ||
raise ::Foreman::Exception.new N_('Unsupported completion, only name and description are supported') |
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.
We have to send here a ScopedSearch::QueryNotSupported
error instead of a general Exception
, so the error would be handled correctly by the controller.
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.
THanks @ShimShtein
that's doable
Thanks @ares |
app/services/setting_registry.rb
Outdated
def complete_value_from_db(field, val) | ||
count = 20 | ||
if field.field == :name | ||
results = @registry.map { |set| ((set.full_name =~ /\s/) ? "\"#{set.full_name.gsub('"', '\"')}\"" : set.full_name) if set.name.include?(val) || set.full_name&.include?(val) } |
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.
This will return empty values when the condition is not met. e.g:
For settings => ['aaa', 'abc', 'bbb']
and val => 'b'
you will get:
[nil, 'abc', 'bbb']
.
We should use filter_map
instead:
results = @registry.map { |set| ((set.full_name =~ /\s/) ? "\"#{set.full_name.gsub('"', '\"')}\"" : set.full_name) if set.name.include?(val) || set.full_name&.include?(val) } | |
results = @registry.filter_map { |set| ((set.full_name =~ /\s/) ? "\"#{set.full_name.gsub('"', '\"')}\"" : set.full_name) if set.name.include?(val) || set.full_name&.include?(val) } |
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.
That makes much more sense, thanks!
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.
LGTM, but I don't have the latest Foreman to test. Can someone take this one to a quick run?
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.
Tested:
- Default search
name ~
&name =
description
Looks like it's working, let's get this in!
Thanks @girijaasoni, @ezr-ondrej, @ShimShtein |
This PR addresses: