Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Better search for minne with Ruby and Solr

Better search for minne with Ruby and Solr

Pepabo tech conference #2 in Fukuoka. #pbtech

768d8af8a98bef1658b60f01b08db77e?s=128

Ryutaro Mizokami

July 04, 2015
Tweet

Other Decks in Technology

Transcript

  1. minneͷݕࡧΛ Ruby ͱ Solr Ͱ ͪΐͬͱศརʹͨ͠࿩‗ GMOϖύϘ ߔ্ ཽଠ࿠ ϖύϘςοΫΧϯϑΝϨϯεʲ෱Ԭʳ

  2. ࣗݾ঺հ • ߔ্ ཽଠ࿠ (github.com/mizoR) • minneࣄۀ෦ ΤϯδχΞ • Ruby

    / Rails
  3. minne ʹ͍ͭͯ • ೔ຊ࠷େڃͷϋϯυϝΠυϚʔέοτ • ొ࿥࡞඼਺ɿ131ສ఺ • ࡞Ո਺ɿ12.4ສਓ • TV

    CM શࠃ์ө
  4. ΞδΣϯμ • ੒௕ʹͱ΋ͳ͏՝୊ • ͳͥݕࡧ݁Ռͱ࣮σʔλͱͷؒʹζϨ͕͋Δ? • Ͳ͏΍ͬͯૣ͘͢Δ͔? • ·ͱΊ

  5. ੒௕ʹͱ΋ͳ͏՝୊

  6. ࡞඼ͷݕࡧ݁Ռʹ ചΓ੾Ε͕໨ཱͭ

  7. ϑʔϓ ΞΫηαϦʔɾϐΞε ൢചத ݕࡧ݁Ռ

  8. ϑʔϓ ΞΫηαϦʔɾϐΞε ൢചத ݕࡧ݁Ռ ചΓ੾Ε

  9. ͳͥݕࡧ݁Ռͱ࣮σʔλͱͷ ؒʹζϨ͕͋Δʁ

  10. minneͷݕࡧΛࢧ͑Δٕज़ • ϑϨʔϜϫʔΫɿRuby on Rails • શจݕࡧΤϯδϯɿSolr 4 (master-slave ߏ੒)

    • ΫϥΠΞϯτɿsunspot
  11. ݕࡧΠϯσοΫεߋ৽ઓུ • શ݅࠶ΠϯσΩγϯά 1.ݹ͍ΠϯσοΫεΛશͯফͯ͠ɺ 2.৽͘͠ΠϯσοΫεΛ࡞੒͢Δ

  12. શ݅࠶ΠϯσΩγϯάͰ ݕࡧͰ͖ΔΑ͏ʹͳΔ·Ͱ • ΠϯσοΫεΛશ෦ফͯ͠࡞Γ௚͢ NBTUFS TMBWF #BUDI BQQ BQQ BQQ

    TMBWF TMBWF %BUBCBTF ɿ ɿ
  13. • ϨϓϦέʔγϣϯΛ࣮ߦ NBTUFS TMBWF TVOTQPUJOEFY BQQ BQQ BQQ TMBWF TMBWF

    %BUBCBTF ɿ ɿ શ݅࠶ΠϯσΩγϯάͰ ݕࡧͰ͖ΔΑ͏ʹͳΔ·Ͱ
  14. શ݅࠶ΠϯσΩγϯά ☀όονΛ࣮ߦ͢Δ͚ͩ ☀ਖ਼֬ͳΠϯσοΫε͕ੜ੒͞ΕΔ ☔ΠϯσΩγϯά్தͰϨϓϦέʔγϣϯͰ͖ͳ͍ 㱺 ݕࡧ݁Ռͷ൓өϥά͕େ͖͘ͳΔ (3~4࣌ؒ͘Β͍͔͔Δ)

  15. Ͳ͏΍ͬͯૣ͘͢Δ͔?

  16. શ݅࠶ΠϯσΩγϯά ‑ ࠩ෼ΠϯσΩγϯά

  17. • ࠩ෼ΠϯσΩγϯά • ඞཁͳ෼͚ͩΠϯσΩγϯάΛߦ͏ ݕࡧΠϯσοΫεߋ৽ઓུᶄ

  18. ࠩ෼ΠϯσΩγϯάͰ ݕࡧͰ͖ΔΑ͏ʹͳΔ·Ͱ • ݕࡧʹؔ࿈ͨ͠৘ใͷมߋ͕ཁٻɾ࣮ߦ͞ΕΔ NBTUFS TMBWF BQQ BQQ BQQ TMBWF

    TMBWF %BUBCBTF ɿ ɿ +PC ࡞඼ͷߋ৽ ࡞Ոͷߋ৽
  19. • ΠϯσΩγϯάλεΫΛΩϡʔΠϯά͢Δ NBTUFS TMBWF BQQ BQQ BQQ TMBWF TMBWF %BUBCBTF

    ɿ ɿ +PC ࡞඼ͷߋ৽ ࡞Ոͷߋ৽ ࠩ෼ΠϯσΩγϯάͰ ݕࡧͰ͖ΔΑ͏ʹͳΔ·Ͱ
  20. • ϨϓϦέʔγϣϯΛ࣮ߦ NBTUFS TMBWF BQQ BQQ BQQ TMBWF TMBWF %BUBCBTF

    ɿ ɿ +PC ࡞඼ͷߋ৽ ࡞Ոͷߋ৽ ࠩ෼ΠϯσΩγϯάͰ ݕࡧͰ͖ΔΑ͏ʹͳΔ·Ͱ
  21. ࡞඼σʔλͷมߋ࣌ʹ ࠩ෼ΠϯσΩγϯάΛߦ͏ # /app/models/item.rb class Item < ActiveRecord::Base after_commit(if: :persisted?)

    {self.delay.perform_index} def perform_index indexable? ? index : remove_from_index end end shops items 0..*
  22. ࡞඼ʹؔ࿈ͨ͠σʔλͷมߋ࣌ʹ ࠩ෼ΠϯσΩγϯάΛߦ͏ # /app/models/shop.rb class Shop < ActiveRecord::Base has_many :items

    after_commit(if: :persisted?) { ItemsIndexing.perform_later(items) } end # /app/jobs/items_indexing.rb class ItemsIndexing < ActiveJob::Base def perform(items) items.find_in_batches(batch_size: 50) do |group| Sunspot.batch { group.each(&:perform_index) } end end end
  23. ☀͍ͭϨϓϦέʔγϣϯͯ͠΋OK 㱺 ݕࡧ݁Ռͷߋ৽ϥάΛখ͘͞Ͱ͖Δ (3~4࣌ؒˠ10෼લޙ) ☀࣮૷΋೉͘͠ͳ͍ ࠩ෼ΠϯσΩγϯά

  24. ·ͱΊ

  25. ·ͱΊ • ൓өϥάΛখ͘͞ͳͬͯ޾ͤʢϏδωεతଆ ໘ʣ • ࢓૊Έ΋ίʔυ΋γϯϓϧʢٕज़తଆ໘ʣ Ϗδωε × ٕज़ =

  26. ͋Γ͕ͱ͏͍͟͝·ͨ͠