More Related Content
Similar to Дмитрий Галинский "Sphinx - как база данных"
Similar to Дмитрий Галинский "Sphinx - как база данных" (20)
Дмитрий Галинский "Sphinx - как база данных"
- 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