Module: Blacklight

Defined in:
app/services/blacklight/search_service.rb,
lib/blacklight.rb,
lib/blacklight/solr.rb,
lib/blacklight/engine.rb,
lib/blacklight/routes.rb,
lib/blacklight/version.rb,
lib/blacklight/component.rb,
lib/blacklight/exceptions.rb,
lib/blacklight/parameters.rb,
app/models/blacklight/icon.rb,
app/values/blacklight/types.rb,
lib/blacklight/search_state.rb,
lib/blacklight/configuration.rb,
lib/blacklight/search_builder.rb,
lib/blacklight/runtime_registry.rb,
lib/blacklight/routes/exportable.rb,
lib/blacklight/routes/searchable.rb,
lib/blacklight/abstract_repository.rb,
lib/blacklight/configuration/field.rb,
lib/blacklight/configuration/fields.rb,
app/models/blacklight/suggest_search.rb,
lib/blacklight/configuration/context.rb,
app/models/blacklight/facet_paginator.rb,
app/builders/blacklight/action_builder.rb,
app/services/blacklight/field_retriever.rb,
lib/blacklight/configuration/null_field.rb,
lib/blacklight/configuration/show_field.rb,
lib/blacklight/configuration/sort_field.rb,
app/presenters/blacklight/json_presenter.rb,
app/presenters/blacklight/rendering/join.rb,
app/presenters/blacklight/show_presenter.rb,
app/services/blacklight/document_factory.rb,
lib/blacklight/configuration/facet_field.rb,
lib/blacklight/configuration/index_field.rb,
lib/blacklight/configuration/tool_config.rb,
lib/blacklight/search_state/filter_field.rb,
lib/generators/blacklight/solr_generator.rb,
lib/generators/blacklight/user_generator.rb,
app/components/blacklight/facet_component.rb,
app/presenters/blacklight/field_presenter.rb,
app/presenters/blacklight/index_presenter.rb,
lib/blacklight/configuration/search_field.rb,
app/components/blacklight/header_component.rb,
app/presenters/blacklight/clause_presenter.rb,
lib/blacklight/configuration/display_field.rb,
lib/generators/blacklight/assets_generator.rb,
lib/generators/blacklight/models_generator.rb,
lib/blacklight/open_struct_with_hash_access.rb,
lib/generators/blacklight/install_generator.rb,
app/components/blacklight/document_component.rb,
app/presenters/blacklight/document_presenter.rb,
app/presenters/blacklight/rendering/pipeline.rb,
lib/generators/blacklight/document_generator.rb,
app/components/blacklight/skip_link_component.rb,
app/helpers/blacklight/layout_helper_behavior.rb,
app/presenters/blacklight/rendering/microdata.rb,
app/presenters/blacklight/thumbnail_presenter.rb,
app/components/blacklight/constraint_component.rb,
app/components/blacklight/facet_item_component.rb,
app/components/blacklight/icons/icon_component.rb,
app/components/blacklight/icons/list_component.rb,
app/components/blacklight/search_bar_component.rb,
app/components/blacklight/top_navbar_component.rb,
app/presenters/blacklight/facet_item_presenter.rb,
app/presenters/blacklight/rendering/terminator.rb,
lib/blacklight/search_state/pivot_filter_field.rb,
lib/generators/blacklight/controller_generator.rb,
app/components/blacklight/constraints_component.rb,
app/components/blacklight/facet_field_component.rb,
app/models/concerns/blacklight/suggest/response.rb,
app/presenters/blacklight/facet_field_presenter.rb,
lib/blacklight/configuration/null_display_field.rb,
app/components/blacklight/icons/remove_component.rb,
app/components/blacklight/icons/search_component.rb,
app/components/blacklight/system/modal_component.rb,
app/helpers/blacklight/component_helper_behavior.rb,
app/services/blacklight/bookmarks_search_builder.rb,
app/services/blacklight/search_params_yaml_coder.rb,
lib/generators/blacklight/test_support_generator.rb,
app/components/blacklight/response/sort_component.rb,
app/components/blacklight/search_button_component.rb,
app/components/blacklight/search_header_component.rb,
app/components/blacklight/search_navbar_component.rb,
app/presenters/blacklight/rendering/abstract_step.rb,
app/presenters/blacklight/rendering/helper_method.rb,
app/presenters/blacklight/rendering/link_to_facet.rb,
app/components/blacklight/document/group_component.rb,
app/components/blacklight/document_title_component.rb,
app/components/blacklight/metadata_field_component.rb,
app/components/blacklight/search/sidebar_component.rb,
app/controllers/concerns/blacklight/search_history.rb,
app/presenters/blacklight/link_alternate_presenter.rb,
lib/blacklight/nested_open_struct_with_hash_access.rb,
lib/generators/blacklight/search_builder_generator.rb,
app/components/blacklight/document/action_component.rb,
app/components/blacklight/search/per_page_component.rb,
app/components/blacklight/system/dropdown_component.rb,
app/components/blacklight/document/actions_component.rb,
app/components/blacklight/document/sidebar_component.rb,
app/components/blacklight/facet_field_list_component.rb,
app/components/blacklight/facet_item_pivot_component.rb,
app/presenters/blacklight/facet_item_pivot_presenter.rb,
lib/generators/blacklight/assets/importmap_generator.rb,
lib/generators/blacklight/assets/propshaft_generator.rb,
lib/generators/blacklight/assets/sprockets_generator.rb,
app/components/blacklight/constraint_layout_component.rb,
app/components/blacklight/document/bookmark_component.rb,
app/components/blacklight/document/citation_component.rb,
app/components/blacklight/document_metadata_component.rb,
app/components/blacklight/icons/legacy_icon_component.rb,
app/components/blacklight/start_over_button_component.rb,
app/components/blacklight/document/thumbnail_component.rb,
app/components/blacklight/facet_field_filter_component.rb,
app/components/blacklight/response/view_type_component.rb,
app/presenters/blacklight/facet_grouped_item_presenter.rb,
app/components/blacklight/document/show_tools_component.rb,
app/components/blacklight/hidden_search_state_component.rb,
app/components/blacklight/icons/bookmark_icon_component.rb,
app/components/blacklight/response/pagination_component.rb,
app/components/blacklight/response/spellcheck_component.rb,
app/presenters/blacklight/facet_checkbox_item_presenter.rb,
app/components/blacklight/advanced_search_form_component.rb,
app/components/blacklight/document/page_header_component.rb,
app/components/blacklight/response/facet_group_component.rb,
app/components/blacklight/system/flash_message_component.rb,
app/presenters/blacklight/inclusive_facet_item_presenter.rb,
app/components/blacklight/facet_field_no_layout_component.rb,
app/components/blacklight/metadata_field_layout_component.rb,
app/components/blacklight/facet_field_checkboxes_component.rb,
app/components/blacklight/facet_field_pagination_component.rb,
app/components/blacklight/system/dropdown_button_component.rb,
app/components/blacklight/document/more_like_this_component.rb,
app/components/blacklight/response/view_type_button_component.rb,
app/components/blacklight/facet_field_inclusive_constraint_component.rb,
app/components/blacklight/metadata_field_plain_text_layout_component.rb,
app/components/blacklight/search_history_constraint_layout_component.rb,
app/components/blacklight/search_context/server_applied_params_component.rb,
app/components/blacklight/search_context/server_item_pagination_component.rb

Overview

Methods added to this helper will be available to all templates in the hosting application

Defined Under Namespace

Modules: Assets, BlacklightHelperBehavior, Bookmarks, Catalog, CatalogHelperBehavior, ComponentHelperBehavior, Configurable, ConfigurationHelperBehavior, Controller, Document, DocumentHelperBehavior, Exceptions, FacetsHelperBehavior, IconHelperBehavior, Icons, LayoutHelperBehavior, RenderPartialsHelperBehavior, Rendering, Response, Routes, Search, SearchContext, SearchHistory, Searchable, Solr, Suggest, System, TokenBasedUser, Types, UrlHelperBehavior, User Classes: AbstractRepository, ActionBuilder, AdvancedSearchFormComponent, AssetsGenerator, BookmarksSearchBuilder, ClausePresenter, Component, Configuration, ConstraintComponent, ConstraintLayoutComponent, ConstraintsComponent, ControllerGenerator, DocumentComponent, DocumentFactory, DocumentGenerator, DocumentMetadataComponent, DocumentPresenter, DocumentTitleComponent, Engine, FacetCheckboxItemPresenter, FacetComponent, FacetFieldCheckboxesComponent, FacetFieldComponent, FacetFieldFilterComponent, FacetFieldInclusiveConstraintComponent, FacetFieldListComponent, FacetFieldNoLayoutComponent, FacetFieldPaginationComponent, FacetFieldPresenter, FacetGroupedItemPresenter, FacetItemComponent, FacetItemPivotComponent, FacetItemPivotPresenter, FacetItemPresenter, FacetPaginator, FieldPresenter, FieldRetriever, HeaderComponent, HiddenSearchStateComponent, Icon, InclusiveFacetItemPresenter, IndexPresenter, Install, JsonPresenter, LinkAlternatePresenter, MetadataFieldComponent, MetadataFieldLayoutComponent, MetadataFieldPlainTextLayoutComponent, ModelsGenerator, NestedOpenStructWithHashAccess, OpenStructWithHashAccess, Parameters, RuntimeRegistry, SearchBarComponent, SearchBuilder, SearchBuilderGenerator, SearchButtonComponent, SearchHeaderComponent, SearchHistoryConstraintLayoutComponent, SearchNavbarComponent, SearchParamsYamlCoder, SearchService, SearchState, ShowPresenter, SkipLinkComponent, SolrGenerator, StartOverButtonComponent, SuggestSearch, TestSupport, ThumbnailPresenter, TopNavbarComponent, UserGenerator

Constant Summary collapse

VERSION =
version

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.blacklight_config_fileObject



13
14
15
# File 'lib/blacklight.rb', line 13

def self.blacklight_config_file
  Rails.root.join("config/blacklight.yml")
end

.blacklight_ymlObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/blacklight.rb', line 65

def self.blacklight_yml
  require 'erb'
  require 'yaml'

  return @blacklight_yml if @blacklight_yml
  unless blacklight_yml?
    raise "You are missing a configuration file: #{blacklight_config_file}. Have you run \"rails generate blacklight:install\"?"
  end

  begin
    blacklight_erb = ERB.new(File.read(blacklight_config_file)).result(binding)
  rescue StandardError, SyntaxError => e
    raise("#{blacklight_config_file} was found, but could not be parsed with ERB. \n#{e.inspect}")
  end

  begin
    @blacklight_yml = if RUBY_VERSION > '2.6'
                        YAML.safe_load(blacklight_erb, aliases: true)
                      else
                        YAML.safe_load(blacklight_erb, [], [], true)
                      end
  rescue => e
    raise("#{blacklight_config_file} was found, but could not be parsed.\n#{e.inspect}")
  end

  if @blacklight_yml.nil? || !@blacklight_yml.is_a?(Hash)
    raise("#{blacklight_config_file} was found, but was blank or malformed.\n")
  end

  @blacklight_yml
end

.blacklight_yml?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/blacklight.rb', line 97

def self.blacklight_yml?
  File.exist?(blacklight_config_file)
end

.connection_configObject



50
51
52
# File 'lib/blacklight.rb', line 50

def self.connection_config
  Blacklight::RuntimeRegistry.connection_config ||= blacklight_yml[::Rails.env]&.symbolize_keys if blacklight_yml?
end

.connection_config=(value) ⇒ Object



54
55
56
# File 'lib/blacklight.rb', line 54

def self.connection_config=(value)
  Blacklight::RuntimeRegistry.connection_config = value
end

.default_configurationObject

The default Blacklight configuration.



46
47
48
# File 'lib/blacklight.rb', line 46

def self.default_configuration
  Blacklight::Configuration.new
end

.default_indexObject

The default index connection for the search index



19
20
21
# File 'lib/blacklight.rb', line 19

def self.default_index
  Blacklight::RuntimeRegistry.connection ||= repository_class.new(default_configuration)
end

.default_index=(repository) ⇒ Object



23
24
25
# File 'lib/blacklight.rb', line 23

def self.default_index=(repository)
  Blacklight::RuntimeRegistry.connection = repository
end

.deprecationObject



122
123
124
# File 'lib/blacklight.rb', line 122

def self.deprecation
  @deprecation ||= ActiveSupport::Deprecation.new('9.0', 'Blacklight')
end

.loggerObject



101
102
103
# File 'lib/blacklight.rb', line 101

def self.logger
  @logger ||= (::Rails.logger if defined? Rails && Rails.respond_to?(:logger))
end

.logger=(logger) ⇒ Object



105
106
107
# File 'lib/blacklight.rb', line 105

def self.logger= logger
  @logger = logger
end

.repository_classObject

The configured repository class. By convention, this is the class Blacklight::(name of the adapter)::Repository, e.g.

elastic_search => Blacklight::ElasticSearch::Repository


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/blacklight.rb', line 31

def self.repository_class
  case connection_config[:adapter]
  when 'solr'
    Blacklight::Solr::Repository
  when /::/
    connection_config[:adapter].constantize
  else
    raise "The value for :adapter was not found in the blacklight.yml config" unless connection_config.key? :adapter

    Blacklight.const_get("#{connection_config.fetch(:adapter)}/Repository".classify)
  end
end

.rootObject

returns the full path the the blacklight plugin installation



118
119
120
# File 'lib/blacklight.rb', line 118

def self.root
  @root ||= File.expand_path(File.dirname(File.dirname(__FILE__)))
end

.versionObject



5
6
7
# File 'lib/blacklight/version.rb', line 5

def self.version
  @version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
end

Instance Method Details

#defaults_versionObject



58
59
60
61
62
63
# File 'lib/blacklight.rb', line 58

def defaults_version
  @defaults_version ||= blacklight_yml['load_defaults'] ||
                        Blacklight::VERSION

  @defaults_version == 'latest' ? Blacklight::VERSION : @defaults_version
end