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

1,182 views
1,087 views

Published on

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

No Downloads
Views
Total views
1,182
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

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

  1. 1. Sphinx <ul><li>как база данных </li></ul>
  2. 2. Почему Sphinx? <ul><li>Очень быстрый </li></ul><ul><li>Интегрированный поиск </li></ul><ul><li>Простые запросы (без JOIN, UNION, TEMPORARY TABLE) </li></ul>
  3. 3. Типы атрибутов <ul><li>String (по умолчанию) </li></ul><ul><li>Integer </li></ul><ul><li>Float </li></ul><ul><li>Multi Value (array of integer) </li></ul>
  4. 4. Использование атрибутов <ul><li>A = B </li></ul><ul><li>A <> B </li></ul><ul><li>A IN (B) </li></ul><ul><li>A NOT IN (B) </li></ul><ul><li>A BETWEEN B AND C </li></ul>
  5. 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. 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. 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. 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. 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. 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

×