debian-mirror-gitlab/elasticsearch-model/spec/support/app/article.rb
2020-03-13 15:44:24 +05:30

22 lines
578 B
Ruby

class ::Article < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
document_type 'article'
settings index: {number_of_shards: 1, number_of_replicas: 0} do
mapping do
indexes :title, type: 'text', analyzer: 'snowball'
indexes :body, type: 'text'
indexes :clicks, type: 'integer'
indexes :created_at, type: 'date'
end
end
def as_indexed_json(options = {})
attributes
.symbolize_keys
.slice(:title, :body, :clicks, :created_at)
.merge(suggest_title: title)
end
end