-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #690 from berkmancenter/media_mention
Media mention
- Loading branch information
Showing
40 changed files
with
486 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.media_mentions-search { | ||
.media-mention-result { | ||
.title { | ||
margin-bottom: 5px; | ||
} | ||
|
||
.media-mention-result-meta { | ||
label { | ||
margin-top: 5px; | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.media-mention-show { | ||
.main { | ||
padding: 35px; | ||
} | ||
|
||
&-metadata { | ||
@include clearfix; | ||
margin-bottom: 10px; | ||
|
||
&-item { | ||
margin-bottom: 5px; | ||
|
||
.label { | ||
@extend %notices-label; | ||
} | ||
|
||
.field { | ||
clear: both; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class MediaMentions::SearchController < SearchController | ||
URL_ROOT = 'media_mention'.freeze | ||
SEARCHED_MODEL = MediaMention | ||
|
||
private | ||
|
||
def set_model_specific_variables | ||
@model_class = MediaMention | ||
@search_index_path = media_mentions_search_index_path | ||
@searchable_fields = MediaMention::SEARCHABLE_FIELDS | ||
@filterable_fields = MediaMention::FILTERABLE_FIELDS | ||
@ordering_options = MediaMention::ORDERING_OPTIONS | ||
@url_root = URL_ROOT | ||
@search_all_placeholder = 'Search all research and media mentions...' | ||
end | ||
|
||
def item_searcher | ||
ElasticsearchQuery.new(params, MediaMention).tap do |searcher| | ||
@searchable_fields.each do |searched_field| | ||
searcher.register searched_field | ||
end | ||
|
||
@filterable_fields.each do |filtered_field| | ||
searcher.register filtered_field | ||
end | ||
|
||
searcher.sort_by = sort_by(params[:sort_by]) | ||
end | ||
end | ||
|
||
# We don't need to limit access to research papers | ||
def restrict_deep_pagination; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class MediaMentionsController < ApplicationController | ||
def show | ||
return resource_not_found("Can't fing research paper with id=#{params[:id]}") unless (@media_mention = MediaMention.find_by(id: params[:id])) | ||
|
||
render :show | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
class ResultOrdering | ||
attr_reader :param, :sort_by, :label | ||
attr_reader :param, :sort_by, :label, :default | ||
|
||
# The param is passed in from the UI; the sort_by is the same information, | ||
# but in the format used by Elasticsearch; the label is a human-readable | ||
# representation. It's up to the caller of #new to get the mappings among | ||
# these right. | ||
def initialize(param, sort_by, label) | ||
def initialize(param, sort_by, label, default = false) | ||
@param = param | ||
@sort_by = sort_by | ||
@label = label | ||
@default = default | ||
end | ||
|
||
def self.define(sort_by_param, model_class = Notice) | ||
model_class::ORDERING_OPTIONS.find { |ordering| ordering.param == sort_by_param } || | ||
self.default_ordering | ||
end | ||
|
||
private | ||
|
||
def self.default_ordering | ||
ResultOrdering.new('relevancy desc', [:_score, :desc], 'Most Relevant') | ||
model_class::ORDERING_OPTIONS.find { |ordering| ordering.default == true } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'validates_automatically' | ||
|
||
class MediaMention < ApplicationRecord | ||
include ValidatesAutomatically | ||
include Elasticsearch::Model | ||
include Elasticsearch::Model::Callbacks | ||
|
||
PER_PAGE = 10 | ||
|
||
MULTI_MATCH_FIELDS = %w(base_search) | ||
|
||
SEARCHABLE_FIELDS = [ | ||
TermSearch.new(:term, MULTI_MATCH_FIELDS, 'All Fields') | ||
].freeze | ||
|
||
now = Time.now.beginning_of_day | ||
DATE_FACET_RANGES = [ | ||
{ from: now - 1.year, to: now }, | ||
{ from: now - 5.years, to: now }, | ||
{ from: now - 10.years, to: now }, | ||
{ from: now - 20.years, to: now } | ||
] | ||
|
||
FILTERABLE_FIELDS = [ | ||
TermFilter.new(:source_facet, 'Source'), | ||
TermFilter.new(:document_type_facet, 'Document Type'), | ||
TermFilter.new(:scale_of_mention_facet, 'Scale of Mention'), | ||
DateRangeFilter.new(:date_facet, :date, 'Date Published', DATE_FACET_RANGES) | ||
].freeze | ||
|
||
ORDERING_OPTIONS = [ | ||
ResultOrdering.new('relevancy desc', [:_score, :desc], 'Most Relevant'), | ||
ResultOrdering.new('relevancy asc', [:_score, :asc], 'Least Relevant'), | ||
ResultOrdering.new('date desc', [:date, :desc], 'Date Published - newest', true), | ||
ResultOrdering.new('date asc', [:date, :asc], 'Date Published - oldest') | ||
].freeze | ||
|
||
HIGHLIGHTS = [].freeze | ||
|
||
validates :scale_of_mention, presence: true, inclusion: { in: LumenSetting.get('media_mentions_scale_of_mentions').split(',') } | ||
|
||
settings do | ||
mappings dynamic: false do | ||
# fields | ||
indexes :base_search, type: 'text' | ||
indexes :title, copy_to: 'base_search' | ||
indexes :description, copy_to: 'base_search' | ||
indexes :source, copy_to: %w[base_search source_facet] | ||
indexes :document_type, copy_to: %w[base_search document_type_facet] | ||
indexes :date, type: 'date', copy_to: %w[base_search date_facet] | ||
indexes :published, type: 'boolean' | ||
indexes :author, copy_to: 'base_search' | ||
indexes :scale_of_mention, copy_to: %w[base_search scale_of_mention_facet] | ||
|
||
# facets | ||
indexes :source_facet, type: 'keyword' | ||
indexes :document_type_facet, type: 'keyword' | ||
indexes :scale_of_mention_facet, type: 'keyword' | ||
indexes :date_facet, type: 'date' | ||
end | ||
end | ||
|
||
def self.visible_qualifiers | ||
{ published: true } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render partial: 'search/date_range_filter', locals: { results: results, date_range_filter: date_range_filter } %> |
Oops, something went wrong.