Skip to content

Commit

Permalink
Show expanded advanced search form on empty search query (#879)
Browse files Browse the repository at this point in the history
* Show expanded advanced search form on empty search query

* Add Advanced Search helper screen

* Updated styling on Search help

* Documentation Tweak

* Add Advanced Search to help dropdown menu

* Make AND/OR work properly and update user documentation

* Figured out the search tooltip part

* Cleanup

---------

Co-authored-by: manfromjupyter <51969207+manfromjupyter@users.noreply.github.com>
  • Loading branch information
mcrutch and manfromjupyter committed Jul 10, 2023
1 parent a5a53a8 commit cd6116d
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 35 deletions.
10 changes: 3 additions & 7 deletions app/assets/javascripts/gallery.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,10 @@ $(document).ready(function(){
}
});
});
$('#searchTooltipButton').on('click', function(e){
$('body.page-home #searchTooltipButton').on('click', function(e){
e.preventDefault();
let carot_direction = 'left';
let element = 'form.search-form'
if ($('body').hasClass('page-home')){
element = 'form.search-form .form-group'
carot_direction = 'top';
}
let carot_direction = 'top';
let element = 'form.search-form .form-group:first-child'
if (reveal_search_info_message){
$(element).prepend('<div class="search-tooltip popover ' + carot_direction + ' fade in" role="alert"><div class="arrow"></div><h1 class="popover-title center">Adding Search Filter</h1><div class="popover-content"><p>Filter your search results by adding filters such as:</p><ul><li>user:username</li><li>title:mapping</li><li>description:"interactive maps"</li></ul></div></div>');
$('form.search-form .searchFieldBox').focus();
Expand Down
23 changes: 22 additions & 1 deletion app/assets/stylesheets/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,19 @@ body.page-notebooks .carousel-caption h1.long-title {
#carousel .carousel-caption .btn {
color: #fff;
}
#homeAdvancedSearchLink {
border-bottom: 1px solid transparent;
color: $text-color-on-dark-background;
float: left;
font-size: 14px;
margin-top: .35em;
opacity: .9;
&:hover,
&:focus {
border-bottom: 1px solid;
text-decoration: none;
}
}
h1 .icon-container {
display: inline-block;
margin: 0 0 0 8px;
Expand Down Expand Up @@ -2165,7 +2178,9 @@ body.page-notebook-search #main .search-alerts-container .alert:last-child {
}
#bigSearchBar .form-group,
.search-filters-super-container,
#addFilterFormContainer, #addDateFilterFormContainer {
#addFilterFormContainer,
#addDateFilterFormContainer,
#searchHelpContainer {
display: block;
margin: 0 auto;
@media all and (min-width: 1025px) {
Expand Down Expand Up @@ -2317,6 +2332,11 @@ body.page-home #bigSearchBar {
}
}

/* ===== Empty Search Page ===== */
#searchHelpContainer strong.search-term {
font-family: monospace;
}

/* === Other === */
body.page-home #notebookDisplay {
clear: both;
Expand Down Expand Up @@ -3648,6 +3668,7 @@ body.dark-theme {
#headerIcons > a > .fa,
#headerIcons > a > .caret,
&.page-summary #main p,
&.page-notebook-search #main ul.search-help li,
&.page-user_preferences #main p,
&.page-notebooks-learning #main p,
&.page-subscriptions #main p,
Expand Down
42 changes: 23 additions & 19 deletions app/controllers/notebooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -816,32 +816,36 @@ def reviews

# GET /notebooks
def index
@notebooks = query_notebooks
if !@notebooks
@tag_text_with_counts = []
@groups = []
flash[:error] = "Unable to perform a search at this time"
if params.has_key?(:q) && params[:q].blank?
render 'advanced_search'
else
if params[:q].blank?
if !params.has_key?(:q)
@notebooks = @notebooks.where("notebooks.deprecated=False") unless (params[:show_deprecated] && params[:show_deprecated] == "true")
end
@notebooks = query_notebooks
if !@notebooks
@tag_text_with_counts = []
@groups = []
flash[:error] = "Unable to perform a search at this time"
else
words = params[:q].split.reject {|w| w.start_with? '-'}
@tag_text_with_counts = Tag.readable_by(@user, words)
begin
ids = Group.search_ids do
fulltext(params[:q])
if params[:q].blank?
if !params.has_key?(:q)
@notebooks = @notebooks.where("notebooks.deprecated=False") unless (params[:show_deprecated] && params[:show_deprecated] == "true")
end
@tag_text_with_counts = []
@groups = []
else
words = params[:q].split.reject {|w| w.start_with? '-'}
@tag_text_with_counts = Tag.readable_by(@user, words)
begin
ids = Group.search_ids do
fulltext(params[:q])
end
@groups = Group.readable_by(@user, ids).select {|group, _count| ids.include?(group.id)}
rescue Exception => e
end
@groups = Group.readable_by(@user, ids).select {|group, _count| ids.include?(group.id)}
rescue Exception => e
end
end
end
if params[:ajax].present? && params[:ajax] == 'true'
render partial: 'notebooks'
if params[:ajax].present? && params[:ajax] == 'true'
render partial: 'notebooks'
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/notebook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def self.fulltext_search(text, user, opts={})
sort_dir = opts[:sort_dir] || :desc
use_admin = opts[:use_admin].nil? ? false : opts[:use_admin]
# Remove keywords out of the text search (such as Lang:Python)
filtered_text = text.split(/\s(?=(?:[^"]|"[^"]*"|[^:]+:"[^"]*")*$)/).reject{ |w| w =~ /[^:]+:.*+/}.join(" ")
filtered_text = text.split(/\s(?=(?:[^"]|"[^"]*"|[^:]+:"[^"]*")*$)/).reject{ |w| w =~ /[^:]+:.*+/}.map!{ |w| w.gsub(/^and$/i,"&&").gsub(/^or$/i,"||")}.join(" ")
# Create array of all of the keywords for search
keywords = text.split(/\s(?=(?:[^"]|"[^"]*"|[^:]+:"[^"]*")*$)/).select{ |w| w =~ /[^:]+:[^:]+/}
search_fields = {}
Expand Down
8 changes: 4 additions & 4 deletions app/views/application/_search_banner.slim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
-filters.push(term)
-else
-search = search + " " + term
div class=(filters.length > 0 ? "super-container" : "super-container no-filter")
div class=(params[:q].blank? || filters.length > 0 ? "super-container" : "super-container no-filter")
div.content-container
div.sub-container
h1.search-title Search #{params[:q].blank? ? "" : "Results"}
Expand All @@ -39,15 +39,15 @@ div class=(filters.length > 0 ? "super-container" : "super-container no-filter")
input type="hidden" name==CGI.escape_html(key) value==CGI.escape_html(value)
-else
input type="hidden" name==CGI.escape_html(key)
a id="filterToggle" href="#" role="button" aria-expanded=(filters.length > 0 ? "true" : "false")
i class=(filters.length > 0 ? "fa fa-chevron-down spin": "fa fa-chevron-down") aria-hidden="true"
a id="filterToggle" href="#" role="button" aria-expanded=(params[:q].blank? || filters.length > 0 ? "true" : "false")
i class=(params[:q].blank? || filters.length > 0 ? "fa fa-chevron-down spin": "fa fa-chevron-down") aria-hidden="true"
span.add-filter-text aria-hidden="true" Advanced
i.fa.fa-filter aria-hidden="true"
span.sr-only Toggle Advanced Search Form
button.btn.search-submit type="submit"
i.fa.fa-search aria-hidden="true"
span.sr-only Search
div id="addFilterFormContainer" class=(filters.length > 0 ? "expand" : "") style=(filters.length > 0 ? "display: block" : "display: none")
div id="addFilterFormContainer" class=(params[:q].blank? || filters.length > 0 ? "expand" : "") style=(params[:q].blank? || filters.length > 0 ? "display: block" : "display: none")
form.flex id="addFilterForm"
div
strong
Expand Down
8 changes: 5 additions & 3 deletions app/views/layouts/layout.slim
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ html lang="en"
form.search-form role="search" action="#{notebooks_path}" id="navbarSearchBar"
input.searchFieldBox.form-control type="search" placeholder="Search" name="q" value="#{params[:q] || ''}" tabindex="0"
input type="hidden" name="sort" value="score"
a.tooltips href="#" id="searchTooltipButton" title="Toggle advanced search filtering help"
a href="#{notebooks_path}?q=" id="searchTooltipButton"
i.info-button.fa.fa-info-circle aria-hidden="true"
span.sr-only Toggle advanced search filtering information dialog
span.sr-only Learn more about advanced searching
button.btn.search-submit tabindex="0"
i.fa.fa-search aria-hidden="true"
span.sr-only Search
Expand Down Expand Up @@ -129,7 +129,9 @@ html lang="en"
i.fa.fa-question-circle aria-hidden="true"
b.caret
ul.dropdown-menu id="learnMoreDropdown" style="display: none"
li.dropdown-header.filter-item Recommended Resources
li.dropdown-header.filter-item Documentation
li
a href="#{notebooks_path}?q=" Advanced Search
li id="learnMoreLink"
a href="#" rel="external" What is Jupyter?
br.hidden
Expand Down
74 changes: 74 additions & 0 deletions app/views/notebooks/advanced_search.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
-if params[:q] != nil
==render partial: 'search_banner'
div.search-alerts-container
==render partial: 'alert_container'

div.content-container id="searchHelpContainer"
h2.center Advanced Search Help
ul.search-help
li To search for multi-word strings encapsulate them in quotes (ex: "sample search")
li To find results excluding a specific term or filter, pre-pend it with - (ex: -sample, -"sample search", -package:pandas)
li Deprecated notebooks are excluded by default but you can add them with the "Show Deprecated" checkbox.
li
| You can use AND, OR and parenthesis to group conditions
ul
li
' sample
strong.search-term and
| search
li
' (sample
strong.search-term or
' example)
strong.search-term and
| notebook
li
' sample
strong.search-term and
| -"search string"
li
| Use the advanced search filters to search for notebooks by specific attributes. Search Filters can be negatied (-) but can not be combined with boolean logic (AND/OR)
ul
li
strong.search-term user:username -
| The specified user name is the Owner, Creator an Updator of the notebook
li
strong.search-term owner:username
' or
strong.search-term owner:groupnmame -
| The specified user name or group name is the owner of the notebook
li
strong.search-term creator:username -
| The specified user name is the creator of the notebook
li
strong.search-term updater:username -
| The specified user name was the last updater of the notebook
li
strong.search-term description:string -
| The specified string is found in the notebook description
li
strong.search-term package:string -
| The notebook imports the specified package (works in Python and Ruby)
li
strong.search-term language:string -
| The notebook is written in the specified language
li
strong.search-term title:string -
| The specified string is found in the notebook title
li
strong.search-term tag:string -
| The specified string is found in the notebook tags
li
| Date Filters
ul
li
' Fields:
strong.search-term updated
' and
strong.search-term created
li Operations: &gt;=, &gt;, &lt;
li Date Format: YYYY-MM-dd
li
' Sample:
strong.search-term
| updated:&gt;=2021-01-01
2 changes: 2 additions & 0 deletions app/views/static_pages/home.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
button.btn.search-submit
i.fa.fa-search aria-hidden="true"
span.sr-only Search
div.form-group
a href="#{notebooks_path}?q=" id="homeAdvancedSearchLink" Advanced Search Guide
section.content-container id="main" role="main"
==render partial: 'alert_container'
-user_pref = UserPreference.find_by(user_id: @user.id)
Expand Down

0 comments on commit cd6116d

Please sign in to comment.