view · edit · sidebar · attach · print · history

20110826-search_by_companyname-migel-drb-client-oddb_org

<< Masa.20110829-import-fr_data-migel-drb-client-oddb_org | 2011 | Masa.20110825-limitation-feedback-email-links-migel-drb-client-oddb_org >>


  1. gdm failed (libpng problem)
  2. Fix DRbUndump module problem
  3. Search by product (ODDB::Migel::Item) name
  4. Grouping the search result with migel code
  5. Import migel data in both 'de' and 'fr'

Goal/Estimate/Evaluation:

  • Migel drb client in oddb.org / 100% /
Milestones
  1. fix gdm libpng
  2. FB, Email links (-> Segmentation fault, gd lib error) suspend
  3. Search by product name, company name and show the list
  4. Grouping result with migel code
  5. import fr data
Summary
Commits
Keep in Mind
  • How to import data from csv with DRbUndumped module
  • lib/migel/importer.rb#update_product check for de and fr
  • How to check the class of DRbObject in drb server side
ToDo
  • Refactor Group, Subgroup, Migelid because some code in the classes are totally same
  • Testcases oddb.org, migel

gdm failed (libpng problem)

Note

  • oddbd also does not start
masa@masa ~/ywesee/oddb.org $ bin/oddbd 
/usr/lib64/ruby/gems/1.8/gems/gd2-1.1.1/lib/gd2.rb:58:in `initialize': libpng12.so.0: cannot open shared object file: No such file or directory (RuntimeError)
        from /usr/lib64/ruby/gems/1.8/gems/gd2-1.1.1/lib/gd2.rb:58:in `dlopen'
        from /usr/lib64/ruby/gems/1.8/gems/gd2-1.1.1/lib/gd2.rb:58
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/lib64/ruby/gems/1.8/gems/turing-0.0.11/lib/turing/image.rb:13
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /usr/lib64/ruby/gems/1.8/gems/turing-0.0.11/lib/turing.rb:34
         ... 8 levels...
        from /home/masa/ywesee/oddb.org/src/util/oddbapp.rb:9
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bin/oddbd:9

Reinstall libpng old version

$ ls /usr/portage/media-libs/libpng/
ChangeLog             libpng-1.4.5.ebuild  libpng-1.5.2.ebuild  metadata.xml
libpng-1.2.44.ebuild  libpng-1.4.7.ebuild  Manifest

$ sudo emerge =media-libs/libpng-1.2.44

Result

  • It works

Fix DRbUndump module problem

Problem

  • If DRbUndump module is included in Multilingual class, the updater stops
migel> Migel::Importer.new.update('data/csv/migel_de_test.csv', 'de')
-> /usr/lib64/ruby/1.8/drb/drb.rb:395:in `_dump': can't dump

Solution

  • lib/migel/util/multilingual.rb
    class Multilingual
      #include DRb::DRbUndumped
  • lib/migel/util/server.rb
      def search_limitation(migel_code)
        case migel_code.length
        when 2 # Group
          if group = Migel::Model::Group.find_by_migel_code(migel_code)
            ODBA::DRbWrapper.new(group.limitation_text)
          end
        when 5 # Subgroup
          if subgroup = Migel::Model::Subgroup.find_by_migel_code(migel_code)
             ODBA::DRbWrapper.new(subgroup.limitation_text)
          end
        else # Migelid
          if migelid = Migel::Model::Migelid.find_by_migel_code(migel_code)
             ODBA::DRbWrapper.new(migelid.limitation_text)
          end
        end
      end
  • src/util/oddbapp.rb
    def search_migel_limitation(migel_code)
      code = migel_code.split(/(\d\d)/).select{|x| !x.empty?}.join('.')
      MIGEL_SERVER.search_limitation(code)
    end

Access

Result

undefined method `de' for #<DRb::DRbUnknown:0x7ffb597630c0>
/home/masa/ywesee/oddb.org/src/view/migel/product.rb:82:in `send'
/home/masa/ywesee/oddb.org/src/view/migel/product.rb:82:in `description'
/home/masa/ywesee/oddb.org/src/view/migel/product.rb:103:in `limitation_text'
/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:66:in `send'
/usr/lib64/ruby/site_ruby/1.8/htmlgrid/composite.rb:66:in `create'
  • Also every Product (Migelid) has 'L' (limitation) mark

Experiment

  • lib/migel/model/group.rb, subgroup.rb
      def limitation_text(update = false)
        if update
          @limitation_text ||= Migel::Util::Multilingual.new
        else
          if @limitation_text
            ODBA::DRbWrapper.new(@limitation_text)
          end
        end
      end
  • lib/migel/model/migelid.rb
      def limitation_text(update = false)
        if update
          @limitation_text ||= Migel::Util::Multilingual.new
        else
          if @limitation_text
            ODBA::DRbWrapper.new(@limitation_text)
          end
        end
      end

Result

  • Everything looks fine

Search by product (ODDB::Migel::Item) name

Experiment

  • lib/migel/persistence/odba/product.rb
module Migel
  module Model
    class Product < ModelSuper
      odba_index :pharmacode
      odba_index :ean_code
      odba_index :article_name
      odba_index :companyname
    end
  end
end

Restore database

$ sudo -u postgres dropdb migel
$ sudo -u postgres createdb -E UTF8 -T template0 migel
$ bin/migeld
migel> Migel::Importer.new.update('data/csv/migel_de_test.csv', 'de')
migel> Migel::Importer.new.update_products_by_migel_code('15.30.50.00.1')

Run

  • bin/migeld
  • bin/admin
migel> Migel::Model::Product.search_by_article_name('CONTAM Vaginaltampon 26mm regular')[0].pharmacode
-> 2126923
migel> Migel::Model::Product.search_by_article_name('CONTAM Vaginaltampon 26mm regular').length
-> 1
migel> Migel::Model::Product.search_by_article_name('CONTAM Vaginaltampon 26mm regular')[0].class
-> Migel::Model::Product
migel> Migel::Model::Product.search_by_article_name('CONTAM Vaginaltampon 26mm regular')[0].pharmacode
-> 2126923
migel> Migel::Model::Product.find_by_pharmacode('2126923').article_name
-> CONTAM Vaginaltampon 26mm regular

migel> Migel::Model::Product.search_by_article_name('CONTAM Vaginaltampon').length
-> 4

Note

  • Basic search functions work on migel server side

Next

  • Search function and view in the client side (oddb.org)

Problem

  • Basically, search button (function) of migel is linked to the @session.search_migel_products method in ODDB::State::Global class
  • But now I have to prepare a method fo the array of Migel::Model::Product (ODDB::Migel::Item) instances

Idea

  • First, search product (Migel::Model::Migelid) and if there is nothing found then second search item (Migel::Model::Product)

Experiment

  • src/state/global.rb
      def search
...
         when :migel
            if result = @session.search_migel_products(query) and !result.empty?
              State::Migel::Result.new(@session, result)
            elsif result = @session.app.search_migel_items(query) and !result.empty?
              State::Migel::Items.new(@session, result)
            else
              State::Migel::Result.new(@session, [])
            end

  • src/util/oddbapp.rb
    def search_migel_items(query)
      MIGEL_SERVER.product.search_by_article_name(query) + MIGEL_SERVER.product.search_by_companyname(query)
    end

Search (z.B. 'CONTAM')

Result

Note

  • company name is also available for the search
  • But We want to know the migel_code of result list too
  • But sometimes some migel_codes are mixed together in the result
  • It would be better if the products are grouped with migel_code or company name like drug search result with company name

Grouping the search result with migel code

Refer to

  • src/state/drugs/result.rb
  • src/model/search_result.rb
  • src/view/drugs/result.rb
  • src/view/migel/result.rb

Create test data (Similar company name but different migel code)

migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').products.push Migel::Model::Product.new('1234567')
->
migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').save
-> Stück
migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').products[0].migelid = Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1')
-> Stück
migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').products[0].save
->
migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').products[0].class
-> Migel::Model::Product
migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').products[0].migelid.migel_code
-> 15.11.01.00.1
migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').products[0].pharmacode
-> 1234567
migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').products[0].article_name = 'CONTAM Vaginaltampon 22mm mini 10 Stk'
-> CONTAM Vaginaltampon 22mm mini 10 Stk
migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').products[0].save
-> CONTAM Vaginaltampon 22mm mini 10 Stk
migel> Migel::Model::Migelid.find_by_migel_code('15.11.01.00.1').products[0].article_name
-> CONTAM Vaginaltampon 22mm mini 10 Stk

Experiment

  • src/view/migel/result.rb
class SearchedList < HtmlGrid::List
....
  def compose_list(model = @model, offset=[0,0])
    # Grouping products with migel_code
    migel_code_group = {}
    model.each do |product|
      (migel_code_group[product.migel_code] ||= []) <<  product
    end

    # list up items
    migel_code_group.keys.each do |migel_code|
      offset_length = migel_code_group[migel_code].length
      compose_subheader(migel_code_group[migel_code][0], offset)
      super(migel_code_group[migel_code], offset)
      offset[1] += offset_length
    end
  end

  def compose_subheader(item, offset, css='list atc')
    subheader = SubHeader.new(item, @session, self)
    @grid.add(subheader, *offset)
    @grid.set_colspan(offset.at(0), offset.at(1), full_colspan)
    offset[1] += 1
  end

Search migel by company name

Result

Import migel data in both 'de' and 'fr'

Restore and import

masa@masa ~/ywesee/migel $ sudo -u postgres dropdb migel
masa@masa ~/ywesee/migel $ sudo -u postgres createdb -E UTF8 -T template0 migel
masa@masa ~/ywesee/migel $ bin/migeld
migel> Migel::Importer.new.update('data/csv/migel_de.csv', 'de')
migel> Migel::Importer.new.update('data/csv/migel_fr.csv', 'fr')
migel> Migel::Importer.new.update_all_products true

Let's see the result on Monday...

view · edit · sidebar · attach · print · history
Page last modified on February 02, 2015, at 01:59 PM