<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/tasks/horizons.rake</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -7,10 +7,12 @@ require &quot;xml_helpers&quot;
 require &quot;zoom_helpers&quot;
 require &quot;zoom_controller_helpers&quot;
 require &quot;extended_content_helpers&quot;
+require &quot;kete_url_for&quot;
 # used by importer scripts  in lib/workers
 module Importer
   unless included_modules.include? Importer
     def self.included(klass)
+      klass.send :include, KeteUrlFor
       klass.send :include, OaiDcHelpers
       klass.send :include, ZoomHelpers
       klass.send :include, ZoomControllerHelpers
@@ -134,6 +136,7 @@ module Importer
         @import_records_xml.xpath(@xml_path_to_record).each do |record|
           importer_process(record, params) unless record.content.blank?
         end
+
         importer_update_processing_vars_at_end
       #rescue
       #  importer_update_processing_vars_if_rescue
@@ -146,7 +149,24 @@ module Importer
       related_topics += importer_locate_existing_items(options)
 
       if related_topics.blank? &amp;&amp; !@record_identifier_xml_field.blank?
-        @import_records_xml.xpath(&quot;#{@xml_path_to_record}[#{@record_identifier_xml_field}='#{related_topic_identifier.strip}']&quot;).each do |record|
+        # HACK, for horizons agency/series import, needs to be handled better
+        return [] if @import_dir = 'series'
+        matching_records = @import_records_xml.xpath(&quot;#{@xml_path_to_record}[#{@record_identifier_xml_field}='#{related_topic_identifier.strip}']&quot;)
+
+        # if no matches, try downcase and upcase searches
+        matching_records = @import_records_xml.xpath(&quot;#{@xml_path_to_record}[#{@record_identifier_xml_field}='#{related_topic_identifier.strip.downcase}']&quot;) unless matching_records.any?
+        matching_records = @import_records_xml.xpath(&quot;#{@xml_path_to_record}[#{@record_identifier_xml_field}='#{related_topic_identifier.strip.upcase}']&quot;) unless matching_records.any?
+
+        matching_records.each do |record|
+          # HACK, for horizons agency/series import, needs to be handled better
+          # remove agency.Successor and agency.Predecessor (causes infinite loop) for nodes for now
+          record.search(&quot;//agency.Successor&quot;).each do |node|
+            node.remove
+          end
+          record.search(&quot;//agency.Predecessor&quot;).each do |node|
+            node.remove
+          end
+
           related_topics &lt;&lt; importer_process(record, params) unless record.blank? || record.content.blank?
         end
       end
@@ -200,21 +220,24 @@ module Importer
 
           # Kieran Pilkington, 2009-10-28
           # The following code does not work yet
-          elsif %w{ topic_type }.include?(extended_field.ftype)
+          # TODO: it looks like this still needs multiple support?
+          elsif extended_field.ftype == 'topic_type'
             logger.info 'dealing with topic_type extended field'
             logger.info 'what is value? ' + value.inspect
             unless value =~ /http:\/\//
               logger.info 'value does not include http://'
               topic_type = TopicType.find_by_id(extended_field.topic_type)
               logger.info 'finding topic in topic type: ' + topic_type.inspect
+
               topics = importer_fetch_related_topics(value, params, {
-                :item_type =&gt; 'topics',
-                :extended_field_data =&gt; value,
-                :topic_type =&gt; topic_type
-              })
+                                                       :item_type =&gt; 'topics',
+                                                       :extended_field_data =&gt; value,
+                                                       :topic_type =&gt; topic_type
+                                                     })
               logger.info 'what is found topics? ' + topics.inspect
               return params if topics.blank?
-              value = { 'label' =&gt; value, 'value' =&gt; &quot;#{SITE_URL}/#{topics.first.basket.id}/topics/show/#{topics.first.id}&quot; }
+              topic_url = url_for_dc_identifier(topics.first)
+              value = { 'label' =&gt; value, 'value' =&gt; topic_url }
               logger.info 'what is resulting value? ' + value.inspect
             end
             params[zoom_class_for_params]['extended_content_values'][extended_field.label_for_params] = value
@@ -435,11 +458,18 @@ module Importer
         ext_field_xml_element_name = @record_identifier_extended_field.xml_element_name
         ext_field_xml_element_name = &quot; xml_element_name=\&quot;#{ext_field_xml_element_name}\&quot;&quot; unless ext_field_xml_element_name.blank?
 
-        ext_field_data = &quot;&lt;#{ext_field_id}#{ext_field_xml_element_name}&gt;#{options[:extended_field_data]}&lt;/#{ext_field_id}&gt;&quot;
-        conditions &lt;&lt; &quot;(extended_content like '%#{ext_field_data}%' OR private_version_serialized like '%#{ext_field_data}%')&quot;
+        # making match more greedy, exact or downcased version or upcased version
+        ef_data_varations = [options[:extended_field_data], options[:extended_field_data].downcase, options[:extended_field_data].upcase]
+        ef_conditions = Array.new
+        ef_data_varations.each do |variant|
+          ext_field_data = &quot;&lt;#{ext_field_id}#{ext_field_xml_element_name}&gt;#{variant}&lt;/#{ext_field_id}&gt;&quot;
+          ef_conditions &lt;&lt; &quot;(extended_content like '%#{ext_field_data}%' OR private_version_serialized like '%#{ext_field_data}%')&quot;
+        end
+        conditions &lt;&lt; ef_conditions.join(' OR ')
       end
 
       conditions = !params.blank? ? ([conditions.join(' AND ')] + params) : conditions.join(' AND ')
+      logger.debug(&quot;what are conditions: &quot; + conditions.inspect)
       @current_basket.send(options[:item_type]).find(:all, :conditions =&gt; conditions)
     end
 </diff>
      <filename>lib/importer.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e179f046696be3ee2f2ae5fcf2a6ccf96f04ac42</id>
    </parent>
  </parents>
  <author>
    <name>Walter McGinnis</name>
    <email>walter@katipo.co.nz</email>
  </author>
  <url>http://github.com/kete/kete/commit/01b9b5e6b8552119b4cf7f71ed7f286cd78693da</url>
  <id>01b9b5e6b8552119b4cf7f71ed7f286cd78693da</id>
  <committed-date>2009-10-28T13:26:50-07:00</committed-date>
  <authored-date>2009-10-28T13:26:50-07:00</authored-date>
  <message>some fixes and unfortunately some hardcoding for horizons, will have to refactor to generlize later.</message>
  <tree>fc3ae5fb2acea7e81199f3a9c722c665d6001bd1</tree>
  <committer>
    <name>Walter McGinnis</name>
    <email>walter@katipo.co.nz</email>
  </committer>
</commit>
