Skip to content

Commit

Permalink
Replace our custom code with new traject delete_if.
Browse files Browse the repository at this point in the history
* Not having to maintain custom code is a good thing.
  • Loading branch information
dkinzer committed Feb 9, 2022
1 parent 4627685 commit 02d1cea
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 101 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashie (4.1.0)
hashie (5.0.0)
http (5.0.4)
addressable (~> 2.8)
http-cookie (~> 1.0)
Expand Down Expand Up @@ -331,10 +331,10 @@ GEM
activesupport (>= 5.2)
sprockets (>= 3.0.0)
thor (1.1.0)
traject (3.6.0)
traject (3.7.0)
concurrent-ruby (>= 0.8.0)
dot-properties (>= 0.1.1)
hashie (>= 3.1, < 5)
hashie (>= 3.1, < 6)
http (>= 3.0, < 6)
httpclient (~> 2.5)
marc (~> 1.0)
Expand Down
6 changes: 2 additions & 4 deletions lib/cob_index/indexer_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Include custom traject macros
extend CobIndex::Macros::Custom

# include unicode normalize for thread safety
extend CobIndex::Macros::Transformations

CORPORATE_NAMES = CobIndex::Util.load_list_file("corporate_names")

settings(&CobIndex::DefaultConfig.indexer_settings)
Expand Down Expand Up @@ -80,7 +77,7 @@

# Creator/contributor fields
to_field "creator_t", extract_marc_with_flank("245c:100abcdejlmnopqrtu:110abcdelmnopt:111acdejlnopt:700abcdejqu:710abcde:711acdej", trim_punctuation: true)
to_field "creator_facet", extract_marc("100abcdq:110abcd:111ancdj:700abcdq:710abcd:711ancdj", trim_punctuation: true), filter_values(CORPORATE_NAMES)
to_field "creator_facet", extract_marc("100abcdq:110abcd:111ancdj:700abcdq:710abcd:711ancdj", trim_punctuation: true), delete_if(CORPORATE_NAMES)
to_field "creator_display", extract_creator
to_field "contributor_display", extract_contributor
to_field "creator_vern_display", extract_creator_vern
Expand Down Expand Up @@ -201,6 +198,7 @@
to_field "items_json_display", extract_item_info

# Identifier fields
# include unicode normalize for thread safety
to_field("isbn_display", extract_marc("020a", separator: nil), &normalize_isbn)
to_field("alt_isbn_display", extract_marc("020z:776z", separator: nil), &normalize_isbn)
to_field("issn_display", extract_marc("022a", separator: nil), &normalize_issn)
Expand Down
1 change: 0 additions & 1 deletion lib/cob_index/macros.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module CobIndex::Macros
autoload :Transformations, "cob_index/macros/transformations"
autoload :Custom, "cob_index/macros/custom"
autoload :Marc21, "cob_index/macros/marc21"
autoload :MarcFormats, "cob_index/macros/marc_format_classifier"
Expand Down
11 changes: 0 additions & 11 deletions lib/cob_index/macros/transformations.rb

This file was deleted.

26 changes: 26 additions & 0 deletions spec/cob_index/indexer_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,30 @@
end
end
end

describe "creator_facet field" do
before do
stub_const("ENV", ENV.to_hash.merge("SOLR_URL" => "foo"))
indexer.load_config_file("lib/cob_index/indexer_config.rb")
end

context "Unwanted corp present" do
# Note: that "Books24x7, Inc" is excluded via ./lib/list/corporate_names.txt
let(:record_text) { "
<record>
<datafield ind1=' ' ind2=' ' tag='100'>
<subfield code='b'>FOO</subfield>
</datafield>
<datafield ind1=' ' ind2=' ' tag='100'>
<subfield code='a'>Books24x7, Inc</subfield>
</datafield>
</record>
" }

it "it removes the unwanted corp" do
expect(indexer.map_record(record)["creator_facet"]).to eq(["FOO"])
end
end

end
end
82 changes: 0 additions & 82 deletions spec/cob_index/macros/transformations_spec.rb

This file was deleted.

0 comments on commit 02d1cea

Please sign in to comment.