Skip to content

Commit

Permalink
🐛 Fix bug OCR search bug with AllinsonFlex
Browse files Browse the repository at this point in the history
This commit fixes a bug where the OCR search was not working with
AllinsonFlex.  The problem was the `qf` parameter was getting extra
fields added but was missing a `' '` between the fields default fields
and the AllinsonFlex fields.  Also in this fix, I realize that I was
trying to decorate the `IiifSearchBuilder` when it is actually a file
that the generator installs.  Since the file is in Blacklight, I opted
to gsub the content instead.
  • Loading branch information
kirkkwang committed Jul 18, 2023
1 parent 0c3edc4 commit 19232b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
10 changes: 5 additions & 5 deletions app/search_builders/concerns/iiif_print/allinson_flex_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ module AllinsonFlexFields
def include_allinson_flex_fields(solr_parameters)
return unless defined?(AllinsonFlex)

solr_parameters[:qf] += IiifPrint.allinson_flex_fields
.each_with_object([]) do |field, arr|
arr << (field.name + '_tesim') if field.is_a?(AllinsonFlex::ProfileProperty)
end
.join(' ')
query_fields = solr_parameters[:qf].split(' ') + IiifPrint.allinson_flex_fields
.each_with_object([]) do |field, arr|
arr << (field.name + '_tesim') if field.is_a?(AllinsonFlex::ProfileProperty)
end
solr_parameters[:qf] = query_fields.uniq.join(' ')
end
end
end

This file was deleted.

8 changes: 8 additions & 0 deletions lib/generators/iiif_print/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,13 @@ def lint_iiif_search_builder
contents.insert(0, "# frozen_string_literal: true\n\n")
File.write(file, contents)
end

def add_allinson_flex_fields_method_to_iiif_search_builder
file_path = "app/models/iiif_search_builder.rb"
contents = File.read(file_path)
contents.gsub!('include Blacklight::Solr::SearchBuilderBehavior', "include Blacklight::Solr::SearchBuilderBehavior\n include IiifPrint::AllinsonFlexFields")
contents.gsub!('self.default_processor_chain += [:ocr_search_params]', 'self.default_processor_chain += %i[ocr_search_params include_allinson_flex_fields]')
File.write(file_path, contents)
end
end
end
2 changes: 0 additions & 2 deletions lib/iiif_print/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class Engine < ::Rails::Engine
::BlacklightIiifSearch::IiifSearchResponse.prepend(IiifPrint::IiifSearchResponseDecorator)
::BlacklightIiifSearch::IiifSearchAnnotation.prepend(IiifPrint::BlacklightIiifSearch::AnnotationDecorator)
::BlacklightIiifSearch::IiifSearch.prepend(IiifPrint::IiifSearchDecorator)
::IiifSearchBuilder.prepend(IiifPrint::IiifSearchBuilderDecorator)
::IiifSearchBuilder.default_processor_chain += [:include_allinson_flex_fields]
Hyrax::Actors::FileSetActor.prepend(IiifPrint::Actors::FileSetActorDecorator)

Hyrax.config do |config|
Expand Down

0 comments on commit 19232b7

Please sign in to comment.