Skip to content

Commit

Permalink
Adjust suggest configuration and behavior
Browse files Browse the repository at this point in the history
- return more 25 suggestions instead of 5 to possibly get a better mix
  of datasets and maps when using the titleSuggest dictionary.
- remove the commented out search based suggest
- move the splitting of datasets and maps out of the template and into the response class
- switch the spatialSuggester from FuzzyLookupFactory to
  BlendedInfixLookupFactory to get the match highlighting
- link results to search URLs (is there a better way to do this?)
  • Loading branch information
edsu committed Aug 12, 2024
1 parent e074eb0 commit a4c5037
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 128 deletions.
25 changes: 1 addition & 24 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
class CatalogController < ApplicationController
include BlacklightRangeLimit::ControllerOverride
include Blacklight::Catalog
include Blacklight::Searchable

configure_blacklight do |config|
# Ensures that JSON representations of Solr Documents can be retrieved using
Expand Down Expand Up @@ -301,7 +300,7 @@ class CatalogController < ApplicationController

# If there are more than this many search results, no spelling ("did you
# mean") suggestion is offered.
config.spell_max = 5
config.spell_max = 25

# Nav actions from Blacklight
config.add_nav_action(:bookmark, partial: 'blacklight/nav/bookmark', if: :render_bookmarks_control?)
Expand Down Expand Up @@ -331,9 +330,6 @@ class CatalogController < ApplicationController
# Configuration for autocomplete suggestor
config.autocomplete_enabled = true
config.autocomplete_path = 'suggest'
# This path is translating to the SOLR endpoint
# not the URL in the dropdown
# config.autocomplete_path = 'select'
end

def web_services
Expand All @@ -346,23 +342,4 @@ def web_services
end
end
end

# def autosearch
# @suggestions = [
# {
# 'term' => 'serious'
# }
# ]
# render 'autosearch', layout: false
# # end
# We do not need to override this if still using the suggestion service
# and the suggest.html.erb template. Leaving this here in case something
# needs to be changed with processing the results
# def suggest
# # @autoresults = search_service.repository.search(q: params[:q], fq: ['-gbl_suppressed_b: true'], rows: 20,
# # 'facet.field': %w[gbl_resourceClass_sm dct_spatial_sm])

# @suggestions = suggestions_service.suggestions
# render 'suggest', layout: false
# end
end
16 changes: 8 additions & 8 deletions app/models/concerns/blacklight/suggest/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def initialize(response, request_params, suggest_path, suggester_name)
# present
# @return [Array]
def suggestions
# (response.dig(suggest_path, suggester_name, request_params[:q], 'suggestions') || []).uniq
suggester_names = %w[spatialSuggester titleSuggester]
suggestion_results = {}
suggester_names.each do |suggester_name|
suggestion_results[suggester_name] =
(response.dig(suggest_path, suggester_name, request_params[:q], 'suggestions') || []).uniq
end
suggestion_results
locations = response.dig(suggest_path, 'spatialSuggester', request_params[:q], 'suggestions')

# unpack the titles into datasets and maps using their payload value
titles = response.dig(suggest_path, 'titleSuggester', request_params[:q], 'suggestions')
datasets = titles.select { |s| s['payload'] == 'Datasets' }
maps = titles.select { |s| s['payload'] == 'Maps' }

{ locations: locations, datasets: datasets, maps: maps }
end
end
end
Expand Down
37 changes: 0 additions & 37 deletions app/views/catalog/autosearch.html.erb

This file was deleted.

60 changes: 25 additions & 35 deletions app/views/catalog/suggest.html.erb
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
<%
spatial_results = @suggestions["spatialSuggester"]
title_results = @suggestions["titleSuggester"]
<% if @suggestions[:locations].length > 0 %>
<li class="fw-bold" aria-disabled="true">Locations</li>
<% @suggestions[:locations].first(3).each do |result| %>
<li role="option" class="dropdown-item" data-autocomplete-value="<%= strip_tags result['term'] %>">
<span><%= link_to sanitize(result['term']), controller: 'catalog', params: {"f[dct_spatial_sm][]": strip_tags(result['term'])} %></span>
</li>
<% end %>
<% end %>
# Map documents by resource class which is saved in payload
data_results = title_results.select { |s| s['payload'] == 'Datasets' }
map_results = title_results.select { |s| s['payload'] == 'Maps' }

%>
<%= 'Locations' if spatial_results.length > 0 %>
<%
l_num = spatial_results.length > 3 ? 3: spatial_results.length
spatial_results.first(l_num).each do |loc|
%>
<li role="option" class="dropdown-item"><span><%=loc['term']%></span></li>
<%
end
%>
<%= 'Datasets' if data_results.length > 0 %>
<%
d_num = data_results.length > 3 ? 3: data_results.length
data_results.first(d_num).each do |data_result|
%>
<li role="option" class="dropdown-item"><span><%=sanitize data_result['term']%></span></li>
<%
end
%>
<%= 'Maps' if map_results.length > 0 %>
<%
m_num = map_results.length > 3 ? 3: map_results.length
map_results.first(m_num).each do |map_result|
%>
<li role="option" class="dropdown-item"><span><%=sanitize map_result['term']%></span></li>
<%
end
%>
<% if @suggestions[:datasets].length > 0 %>
<li class="fw-bold" aria-disabled="true">Datasets</li>
<% @suggestions[:datasets].first(3).each do |result| %>
<li role="option" class="dropdown-item">
<span><%= link_to sanitize(result['term']), controller: 'catalog', params: {"q": strip_tags(result['term'])} %></span>
</li>
<% end %>
<% end %>
<% if @suggestions[:maps].length > 0 %>
<li class="fw-bold" aria-disabled="true">Maps</li>
<% @suggestions[:maps].first(3).each do |result| %>
<li role="option" class="dropdown-item">
<span><%= link_to sanitize(result['term']), controller: 'catalog', params: {"q": strip_tags(result['term'])} %></span>
</li>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/layouts/catalog_result.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
</section>
<% end %>
<%= render template: "layouts/blacklight/base" %>
<%= render template: "layouts/blacklight/base" %>
9 changes: 0 additions & 9 deletions config/solr_configs/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,6 @@
<copyField source="dct_subject_sm" dest="spell"/>
<copyField source="dct_spatial_sm" dest="spell"/>

<!-- for suggestions -->
<!-- Commenting out original suggest field, remove after testing-->
<!--copyField source="dct_title_s" dest="suggest"/>
<copyField source="dct_creator_sm" dest="suggest"/>
<copyField source="dct_publisher_sm" dest="suggest"/>
<copyField source="schema_provider_s" dest="suggest"/>
<copyField source="dct_subject_sm" dest="suggest"/>
<copyField source="dct_spatial_sm" dest="suggest"/-->

<!-- for specific field suggestions-->
<copyField source="dct_title_s" dest="title_suggest"/>
<copyField source="dct_spatial_sm" dest="spatial_suggest"/>
Expand Down
17 changes: 3 additions & 14 deletions config/solr_configs/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,6 @@
</searchComponent>

<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="suggestAnalyzerFieldType">textSuggest</str>
<str name="buildOnCommit">true</str>
<str name="field">suggest</str>
</lst>
<!-- Suggester for the title field -->
<!-- Uses BlendedInfixLookupFactor to favor strings matching at the beginning-->
<!-- Can also use FuzzyLookupFactor or other lookup implementations-->
<lst name="suggester">
<str name="name">titleSuggester</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
Expand All @@ -224,11 +214,10 @@
<str name="field">title_suggest</str>
<str name="payloadField">gbl_resourceClass_sm</str>
</lst>
<!-- Suggester for location based on dct_spatial_sm-->
<!-- When no dictionary is specified, HighFrequencyDictionaryFactory is used-->
<lst name="suggester">
<str name="name">spatialSuggester</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="lookupImpl">BlendedInfixLookupFactory</str>
<str name="suggestAnalyzerFieldType">textSuggest</str>
<str name="buildOnCommit">true</str>
<str name="field">spatial_suggest</str>
Expand All @@ -238,7 +227,7 @@
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="suggest">true</str>
<str name="suggest.count">5</str>
<str name="suggest.count">25</str>
<str name="suggest.dictionary">titleSuggester</str>
<str name="suggest.dictionary">spatialSuggester</str>
</lst>
Expand Down

0 comments on commit a4c5037

Please sign in to comment.