Your SlideShare is downloading. ×
Дмитрий Галинский "Sphinx - как база данных"
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Дмитрий Галинский "Sphinx - как база данных"

978
views

Published on


0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
978
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Sphinx
    • как база данных
  • 2. Почему Sphinx?
    • Очень быстрый
    • Интегрированный поиск
    • Простые запросы (без JOIN, UNION, TEMPORARY TABLE)
  • 3. Типы атрибутов
    • String (по умолчанию)
    • Integer
    • Float
    • Multi Value (array of integer)
  • 4. Использование атрибутов
    • A = B
    • A <> B
    • A IN (B)
    • A NOT IN (B)
    • A BETWEEN B AND C
  • 5. Создание индекса define_index do indexes name, :sortable => true indexes tags(:name), :as => :tags_name has id, :as => :post_id, :type => :integer has created_at, :as => :created_at, :type => :datetime, :sortable => true has author(:id), :as => :author_id, :type => :integer has author(:name), :as => :author_name, :sortable => true has tags(:id), :as => :tag_ids end
  • 6. Поиск Post.search(query, :with => {:author_id => 1}) Post.search(query, :with => {:author_id => [1,2,3]}) Post.search(query, :with => {:tag_ids => 1}) Post.search(query, :with => {:created_at => 1.day.ago..Time.now}) Post.search(query, :without => {:post_id => [1,2,3]}) Post.search(query, :without => {:comments_count => 0})
  • 7. Сортировка Post.search(query, :order => :created_at, :sort_mode => :asc) Post.search(query, :order => :author_name, :sort_mode => :desc) Post.search(query, :order => “created_at DESC, @relevance DESC”, :sort_mode => :extended)
  • 8. Групировка результата Post.search(query, :group_by => :author_id, :group_function => :attr) Post.search(query, :group_by => :author_id, :group_function => :attr, :group_clause => “@count DESC”) Post.search(query, :group_by => :created_at, :group_function => :day, # :week, :month, :year :group_clause => “created_at DESC”) @posts.each_with_count do |post, count| ... end
  • 9. Delta index define_index do ... set_property :delta => true # или set_property :delta => :datetime, :delta_column => :created_at, :threshold => DateTime.now.zone.to_i.hours + 1.hour ... end add_column :posts, :delta, :boolean add_index :posts, :delta
  • 10. Обновление дельты rake ts:in RAILS_ENV=env или indexer --config <FILE> post_delta --rotate indexer --config <FILE> --merge post_core post_delta --rotate --merge-dst-range sphinx_deleted 0 0

×