Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gem 'rails', '~> 5.0.2'

# Cortex-specific
gem 'cortex-exceptions', '= 0.0.4'
gem 'cortex-plugins-core', '= 0.12.3'
gem 'cortex-plugins-core', '= 0.12.4'

# API
gem 'grape', '~> 0.17'
Expand Down
9 changes: 5 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ GEM
concurrent-ruby (1.0.5)
connection_pool (2.2.1)
cortex-exceptions (0.0.4)
cortex-plugins-core (0.12.3)
cortex-plugins-core (0.12.4)
cells (~> 4.1)
cells-haml (~> 0.0)
cells-rails (~> 0.0)
Expand Down Expand Up @@ -172,7 +172,7 @@ GEM
dotenv-rails (2.2.1)
dotenv (= 2.2.1)
railties (>= 3.2, < 5.2)
down (2.4.3)
down (2.5.1)
elasticsearch (5.0.4)
elasticsearch-api (= 5.0.4)
elasticsearch-transport (= 5.0.4)
Expand Down Expand Up @@ -327,8 +327,9 @@ GEM
json_spec (1.1.4)
multi_json (~> 1.0)
rspec (>= 2.0, < 4.0)
jsonb_accessor (1.0.0.beta.4)
jsonb_accessor (1.0.0.beta.6)
activerecord (>= 5.0)
activesupport (>= 5.0)
pg (>= 0.18.1)
kaminari (0.17.0)
actionpack (>= 3.0.0)
Expand Down Expand Up @@ -618,7 +619,7 @@ DEPENDENCIES
cells-rails (~> 0.0.7)
codeclimate-test-reporter (~> 0.6)
cortex-exceptions (= 0.0.4)
cortex-plugins-core (= 0.12.3)
cortex-plugins-core (= 0.12.4)
database_cleaner (~> 1.5)
deep_cloneable (~> 2.2.2)
devise (~> 4.2.1)
Expand Down
6 changes: 3 additions & 3 deletions app/models/concerns/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def range_search(field, type, q)
def published_filter
# Bring in documents based on Draft status, Published date met, or either: Expired date not yet met, or Expired date null
[
{bool: {should: [term_search(:draft, false)]}},
{bool: {should: [range_search(:published_at, :lte, DateTime.now.to_s)]}},
{bool: {should: [range_search(:expired_at, :gte, DateTime.now.to_s), {missing: { field: :expired_at }}]}}
{bool: {must: [term_search(:draft, false)]}},
{bool: {must: [range_search(:published_at, :lte, DateTime.now.to_s)]}},
{bool: {should: [range_search(:expired_at, :gte, DateTime.now.to_s), {bool: {must_not: {exists: { field: :expired_at }}}}]}}
]
end
end
Expand Down
10 changes: 7 additions & 3 deletions app/models/concerns/searchable_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,25 @@ def search_with_params(params, tenant, published = nil)
if author
bool[:bool][:filter] << term_search(:author, author)
end

if published
bool[:bool][:filter] << published_filter
search query: bool, sort: [{is_sticky: {order: 'desc'}, published_at: {order: 'desc'}}]
else
search query: bool
end

search query: bool
end

def show_all(tenant, published = nil)
bool = {bool: {filter: [{term: {tenant_id: tenant.id}}]}}

if published
bool[:bool][:filter] << published_filter
search query: bool, sort: [{is_sticky: {order: 'desc'}, published_at: {order: 'desc'}}]
else
search query: bool, sort: [{is_sticky: {order: 'desc'}, created_at: {order: 'desc'}}]
end

search query: bool, sort: [{is_sticky: {order: 'desc'}, created_at: {order: 'desc'}}]
end
end
end
2 changes: 1 addition & 1 deletion app/models/content_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def method_missing(*args)
"#{publish_state.downcase}?" == args[0].to_s
else
# Used to query for any field on the relevant ContentType and return data from the content_item
field_items.select { |field_item| field_item.field.name.parameterize({ separator: '_' }) == args[0].to_s }.first.data.values[0]
field_items.select { |field_item| field_item.field.name.parameterize(separator: '_') == args[0].to_s }.first.data.values[0]
end
end
end
2 changes: 1 addition & 1 deletion app/models/content_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.permissions
end

def content_items_index_name
content_type_name_sanitized = name.parameterize('_')
content_type_name_sanitized = name.parameterize(separator: '_')
"#{Rails.env}_content_type_#{content_type_name_sanitized}_content_items"
end

Expand Down