mirror of
https://github.com/Neetpone/foalfetch.git
synced 2025-02-08 18:06:43 +01:00
61 lines
No EOL
2 KiB
Ruby
61 lines
No EOL
2 KiB
Ruby
module StoryIndex
|
|
def self.included(base)
|
|
base.settings index: { number_of_shards: 5, max_result_window: 10_000_000 } do
|
|
mappings dynamic: false do
|
|
indexes :id, type: 'integer'
|
|
indexes :author_id, type: 'keyword'
|
|
indexes :completion_status, type: 'keyword'
|
|
indexes :content_rating, type: 'keyword'
|
|
indexes :date_published, type: 'date'
|
|
indexes :date_updated, type: 'date'
|
|
indexes :date_modified, type: 'date'
|
|
indexes :num_comments, type: 'integer'
|
|
indexes :num_views, type: 'integer'
|
|
indexes :num_words, type: 'integer'
|
|
indexes :rating, type: 'integer'
|
|
indexes :short_description, type: 'text', analyzer: 'snowball'
|
|
indexes :description_html, type: 'text', analyzer: 'snowball'
|
|
indexes :title, type: 'text', analyzer: 'snowball'
|
|
indexes :author, type: 'text', analyzer: 'snowball'
|
|
indexes :tags, type: 'keyword'
|
|
end
|
|
end
|
|
|
|
base.extend ClassMethods
|
|
end
|
|
|
|
module ClassMethods
|
|
def default_sort(_options = {})
|
|
[date_published: :desc]
|
|
end
|
|
|
|
def allowed_search_fields(access_options = {})
|
|
[:title, :completion_status, :content_rating, :date_published, :date_updated, :date_modified, :num_comments, :num_views, :num_words, :rating, :short_description, :description_html, :title, :tags, :author]
|
|
end
|
|
end
|
|
|
|
def as_json(*)
|
|
{
|
|
id: id,
|
|
author_id: author.id,
|
|
completion_status: completion_status,
|
|
content_rating: content_rating,
|
|
date_published: date_published,
|
|
date_updated: date_updated,
|
|
date_modified: date_modified,
|
|
num_comments: num_comments,
|
|
num_views: num_views,
|
|
num_words: num_words,
|
|
rating: rating,
|
|
short_description: short_description,
|
|
description_html: description_html,
|
|
title: title,
|
|
tags: tags.map(&:name),
|
|
author: author.name
|
|
}
|
|
end
|
|
|
|
def as_indexed_json(*)
|
|
as_json
|
|
end
|
|
end |