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

Fixes #36711 - Fix searching in settings #9818

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

girijaasoni
Copy link
Contributor

@girijaasoni girijaasoni commented Aug 31, 2023

This PR addresses:

  • Allowing description search with fuzzy operator
  • Displaying all the relevant suggestions for autocomplete while searching with name including the suggestions for settings with Non Nil values.

@theforeman-bot
Copy link
Member

Can one of the admins verify this patch?

1 similar comment
@theforeman-bot
Copy link
Member

Can one of the admins verify this patch?

@theforeman-bot
Copy link
Member

Issues: #36711

@theforeman-bot
Copy link
Member

Can one of the admins verify this patch?

@girijaasoni girijaasoni force-pushed the 36711 branch 2 times, most recently from 02d2040 to 3632477 Compare August 31, 2023 14:01
@girijaasoni girijaasoni changed the title Fixes #36711 - Add search by name and description in settings Fixes #36711 - Add search by description in settings Aug 31, 2023
@stejskalleos
Copy link
Contributor

ok to test

@stejskalleos stejskalleos self-assigned this Sep 1, 2023
@stejskalleos stejskalleos self-requested a review September 1, 2023 07:25
Copy link
Contributor

@nofaralfasi nofaralfasi left a 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?

@girijaasoni
Copy link
Contributor Author

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.

Copy link
Contributor

@stejskalleos stejskalleos left a 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.

@nofaralfasi
Copy link
Contributor

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.

@girijaasoni
Copy link
Contributor Author

girijaasoni commented Sep 26, 2023

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.

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.

@stejskalleos
Copy link
Contributor

Turning off auto complete would break the search pattern from the other components.

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)
Copy link
Member

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.

@ares
Copy link
Member

ares commented Oct 10, 2023

A few notes from the testing:

  • this makes searching by description possible again, with the ~ operator. It gives auto completion list though, which I would not expect as it shows complete descriptions.
  • for the name it does not work at all, the auto completion suggest the names that user sees in the table (good), these can have spacebars but the value is not wrapped in quotes (bad), even if I add quotes it does not work (bad), because the search actually responds on the setting identifier. So e.g. name = "Foreman URL" does not work while name = foreman_url works fine.
  • searching on name also auto suggests only ~, while other operators like = works fine

@ares
Copy link
Member

ares commented Oct 16, 2023

To illustrate I recorded few videos.

description.webm

description shows auto completion, that feels overwhelming and does not add quotes around the multiword term

name_exact.webm

name 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. Foreman URL vs foreman_url

name_fuzzy.webm

fuzzy searching on name seems to work (not sure why = is not autosuggested), but again, does not add quotes, so "Foreman URL" will give you all settings with either Foreman or URL in their name. With added quotes, it searches correctly.

Hope this helps. Again to be clear, searching in full name is preferred over the name. I would love to search for Foreman URL instead of foreman_url, provided it works.

@girijaasoni
Copy link
Contributor Author

girijaasoni commented Oct 17, 2023

To illustrate I recorded few videos.

description.webm
description shows auto completion, that feels overwhelming and does not add quotes around the multiword term

name_exact.webm
name 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. Foreman URL vs foreman_url

name_fuzzy.webm
fuzzy searching on name seems to work (not sure why = is not autosuggested), but again, does not add quotes, so "Foreman URL" will give you all settings with either Foreman or URL in their name. With added quotes, it searches correctly.

Hope this helps. Again to be clear, searching in full name is preferred over the name. I would love to search for Foreman URL instead of foreman_url, provided it works.

To illustrate I recorded few videos.

description.webm
description shows auto completion, that feels overwhelming and does not add quotes around the multiword term

name_exact.webm
name 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. Foreman URL vs foreman_url

name_fuzzy.webm
fuzzy searching on name seems to work (not sure why = is not autosuggested), but again, does not add quotes, so "Foreman URL" will give you all settings with either Foreman or URL in their name. With added quotes, it searches correctly.

Hope this helps. Again to be clear, searching in full name is preferred over the name. I would love to search for Foreman URL instead of foreman_url, provided it works.

Thanks a lot @ares
These videos were really helpful

In this push I have addressed these few things:

  • Ditched autocomplete for description fuzzy operator as they were very long
  • name = "Foreman URL" or name = Foreman URL wasn't working as we didn't define searching with full name in our matches_search_query method which was unrelated to scoped search but since it was a minor fix so I added it in this PR, Now we can search for name = "Foreman URL"
  • Wrapped the name suggestions with quotes for multiple words

@ares
Copy link
Member

ares commented Nov 8, 2023

From user perspective, this works now as expected. There's one issue, if user enters something that's not supported, e.g. id =`, then they see Error: Request failed with status code 500.

settings

Previously it was showing better error message.

set2

This should be fixed I guess

Comment on lines 53 to 55
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: ['~']
Copy link
Member

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.

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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 :)

elsif field.field == :description
results = []
else
raise ::Foreman::Exception.new N_('Unsupported completion, only name and description are supported')
Copy link
Member

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.

Copy link
Contributor Author

@girijaasoni girijaasoni Nov 22, 2023

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

@girijaasoni girijaasoni changed the title Fixes #36711 - Add search by description in settings Fixes #36711 - Fix searching in settings Nov 22, 2023
@girijaasoni
Copy link
Contributor Author

girijaasoni commented Nov 22, 2023

From user perspective, this works now as expected. There's one issue, if user enters something that's not supported, e.g. id =`, then they see Error: Request failed with status code 500.

settings

Previously it was showing better error message.

set2

This should be fixed I guess

Thanks @ares
Fixed it in this commit
@stejskalleos , I also cutshort the complete_value method (the method which was causing the overkill) as much as possible

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) }
Copy link
Member

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:

Suggested change
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) }

Copy link
Contributor Author

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!

Copy link
Member

@ShimShtein ShimShtein left a 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?

Copy link
Contributor

@stejskalleos stejskalleos left a 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!

@stejskalleos stejskalleos merged commit 2c4139e into theforeman:develop Nov 27, 2023
11 checks passed
@stejskalleos
Copy link
Contributor

Thanks @girijaasoni, @ezr-ondrej, @ShimShtein

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.

7 participants