add search to archive
This commit is contained in:
parent
704db56925
commit
30824d1620
|
@ -1,9 +1,4 @@
|
||||||
<% if @data.blank? and @search %>
|
<%= render :partial => 'shared/search_header',:locals=>{:items=>@data} %>
|
||||||
<%=render :partial => 'shared/search_not_found' %>
|
|
||||||
<% elsif @search %>
|
|
||||||
<%= t("search.result_get",:search_word => params[:search_query],:item_num=>@data.count) unless (@data.count == 30) %>
|
|
||||||
<%= t("search.too_many",:search_word => params[:search_query],:exceed_num=>@data.count) if (@data.count ==30) %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render @partial %>
|
<%= render @partial %>
|
||||||
<% if @paginate and !@data.blank? %>
|
<% if @paginate and !@data.blank? %>
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<% if items.blank? and !params[:search_query].blank? %>
|
||||||
|
<%=render :partial => 'shared/search_not_found' %>
|
||||||
|
<% elsif !params[:search_query].blank? %>
|
||||||
|
<%= t("search.result_get",:search_word => params[:search_query],:item_num=>items.count) unless (items.count == 30) %>
|
||||||
|
<%= t("search.too_many",:search_word => params[:search_query],:exceed_num=>items.count) if (items.count ==30) %>
|
||||||
|
<% end %>
|
|
@ -17,12 +17,7 @@
|
||||||
<%= t("search.unit_get",:unit_name => params[:name],:item_num=>@bulletins.count) %>
|
<%= t("search.unit_get",:unit_name => params[:name],:item_num=>@bulletins.count) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @bulletins.blank? and !params[:search_query].blank? %>
|
<%= render :partial => 'shared/search_header',:locals=>{:items=>@bulletins} %>
|
||||||
<%=render :partial => 'shared/search_not_found' %>
|
|
||||||
<% elsif !params[:search_query].blank? %>
|
|
||||||
<%= t("search.result_get",:search_word => params[:search_query],:item_num=>@bulletins.count) unless (@bulletins.count == 30) %>
|
|
||||||
<%= t("search.too_many",:search_word => params[:search_query],:exceed_num=>@bulletins.count) if (@bulletins.count ==30) %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% @bulletins.each do |post| %>
|
<% @bulletins.each do |post| %>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -17,12 +17,8 @@
|
||||||
<%= t("search.unit_get",:unit_name => params[:name],:item_num=>@bulletins.count) %>
|
<%= t("search.unit_get",:unit_name => params[:name],:item_num=>@bulletins.count) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @bulletins.blank? and !params[:search_query].blank? %>
|
|
||||||
<%=render :partial => 'shared/search_not_found' %>
|
<%= render :partial => 'shared/search_header',:locals=>{:items=>@bulletins} %>
|
||||||
<% elsif !params[:search_query].blank? %>
|
|
||||||
<%= t("search.result_get",:search_word => params[:search_query],:item_num=>@bulletins.count) unless (@bulletins.count == 30) %>
|
|
||||||
<%= t("search.too_many",:search_word => params[:search_query],:exceed_num=>@bulletins.count) if (@bulletins.count ==30) %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% @bulletins.each do |post| %>
|
<% @bulletins.each do |post| %>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -5,6 +5,18 @@ class Panel::Archive::FrontEnd::ArchiveFilesController < OrbitWidgetController
|
||||||
@app_title = 'archive_files'
|
@app_title = 'archive_files'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_search_result
|
||||||
|
@search = ArchiveFileCategory.solr_search do
|
||||||
|
fulltext params[:search_query]
|
||||||
|
with(:frontend_search,true)
|
||||||
|
end
|
||||||
|
|
||||||
|
search_result = @search.results.collect{|result| result.id}
|
||||||
|
params[:category_id] = @search.results.collect{|result| result.id}
|
||||||
|
|
||||||
|
@archive_file_categorys = ArchiveFileCategory.any_in(_id:search_result).page( params[:page_main]).per(@page_num)
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@item = Page.find(params[:page_id])
|
@item = Page.find(params[:page_id])
|
||||||
@title = @item.title
|
@title = @item.title
|
||||||
|
@ -16,9 +28,12 @@ class Panel::Archive::FrontEnd::ArchiveFilesController < OrbitWidgetController
|
||||||
|
|
||||||
date_now = Time.now
|
date_now = Time.now
|
||||||
@archive_file_categorys = ArchiveFileCategory.all
|
@archive_file_categorys = ArchiveFileCategory.all
|
||||||
|
|
||||||
# @archive_files = ArchiveFile.where( :is_hidden => false ).desc(:is_top).page(params[:page]).per(@page_num)
|
# @archive_files = ArchiveFile.where( :is_hidden => false ).desc(:is_top).page(params[:page]).per(@page_num)
|
||||||
|
|
||||||
|
if params[:search_query]
|
||||||
|
get_search_result
|
||||||
|
@archive_files = ArchiveFile.can_display.where(:archive_file_category_id.in => @archive_file_categorys.collect{|t| t.id}).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
|
||||||
|
else
|
||||||
if !params[:category_id].blank? && !params[:tag_id].blank?
|
if !params[:category_id].blank? && !params[:tag_id].blank?
|
||||||
@archive_files = @archive_files.can_display.where(:archive_file_category_id.in => params[:category_id], :tagged_ids.in => params[:tag_id]).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
|
@archive_files = @archive_files.can_display.where(:archive_file_category_id.in => params[:category_id], :tagged_ids.in => params[:tag_id]).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
|
||||||
|
|
||||||
|
@ -32,6 +47,8 @@ class Panel::Archive::FrontEnd::ArchiveFilesController < OrbitWidgetController
|
||||||
else
|
else
|
||||||
@archive_files = ArchiveFile.can_display.desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
|
@archive_files = ArchiveFile.can_display.desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
get_categorys
|
get_categorys
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,16 @@ class ArchiveFile
|
||||||
|
|
||||||
after_save :save_archive_file_multiples
|
after_save :save_archive_file_multiples
|
||||||
|
|
||||||
|
# searchable do
|
||||||
|
# text :titles do
|
||||||
|
# title_translations.to_a.collect{|t| t[1]}
|
||||||
|
# end
|
||||||
|
# boolean :frontend_search do
|
||||||
|
# !is_hidden
|
||||||
|
# end
|
||||||
|
|
||||||
|
# end
|
||||||
|
|
||||||
def self.search( category_id = nil )
|
def self.search( category_id = nil )
|
||||||
|
|
||||||
if category_id.to_s.size > 0
|
if category_id.to_s.size > 0
|
||||||
|
|
|
@ -5,6 +5,7 @@ class ArchiveFileCategory
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
include OrbitCoreLib::ObjectAuthable
|
include OrbitCoreLib::ObjectAuthable
|
||||||
include OrbitCoreLib::ObjectDisable
|
include OrbitCoreLib::ObjectDisable
|
||||||
|
include Sunspot::Mongo
|
||||||
# include Mongoid::MultiParameterAttributes
|
# include Mongoid::MultiParameterAttributes
|
||||||
APP_NAME = 'Archive'
|
APP_NAME = 'Archive'
|
||||||
ObjectAuthTitlesOptions = %W{submit_new fact_check}
|
ObjectAuthTitlesOptions = %W{submit_new fact_check}
|
||||||
|
@ -19,6 +20,22 @@ class ArchiveFileCategory
|
||||||
|
|
||||||
validates :title, :at_least_one => true
|
validates :title, :at_least_one => true
|
||||||
|
|
||||||
|
searchable do
|
||||||
|
text :titles do
|
||||||
|
title_translations.to_a.collect{|t| t[1]}
|
||||||
|
end
|
||||||
|
|
||||||
|
boolean :frontend_search do
|
||||||
|
!disable
|
||||||
|
end
|
||||||
|
|
||||||
|
text :files do
|
||||||
|
archive_files.can_display.collect{|t| t.title_translations.to_a.collect{|t| t[1]}}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def pp_object
|
def pp_object
|
||||||
title
|
title
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<% # encoding: utf-8 %>
|
<% # encoding: utf-8 %>
|
||||||
|
|
||||||
|
<%= render :partial => 'shared/search_header',:locals=>{:items=>@archive_files} %>
|
||||||
|
|
||||||
<div class="o-archives layout-table">
|
<div class="o-archives layout-table">
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
<% @archive_files.each_with_index do |post,i| %>
|
<% @archive_files.each_with_index do |post,i| %>
|
||||||
<tr <% if ( (i + 1) % 2 ) == 0 %> class="even" <% end %>>
|
<tr <% if i.even?%> class="even" <% end %>>
|
||||||
<td><div class="o-archives-title"><%= post.title %></div></td>
|
<td><div class="o-archives-title"><%= post.title %></div></td>
|
||||||
<td>
|
<td>
|
||||||
<div class="o-archives-list-item">
|
<div class="o-archives-list-item">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<%= form_tag panel_announcement_front_end_bulletins_path, method: :get do %>
|
<%= form_tag panel_archive_front_end_archive_files_path, method: :get do %>
|
||||||
<%= hidden_field_tag :category_id, params[:category_id] %>
|
<%= hidden_field_tag :category_id, params[:category_id] %>
|
||||||
<%= hidden_field_tag :tag_id, params[:tag_id] %>
|
<%= hidden_field_tag :tag_id, params[:tag_id] %>
|
||||||
<p>
|
<p>
|
|
@ -16,6 +16,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
namespace :widget do
|
namespace :widget do
|
||||||
match "index" => "archive_files#index"
|
match "index" => "archive_files#index"
|
||||||
|
match "archive_search_block" => "archive_files#archive_search_block"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,6 +34,11 @@ module Archive
|
||||||
widget_i18n "archive.widget.index"
|
widget_i18n "archive.widget.index"
|
||||||
style ["1"]
|
style ["1"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
customize_widget "archive_search_block" do
|
||||||
|
widget_i18n "announcement.widget.search"
|
||||||
|
end
|
||||||
|
|
||||||
# item "index","announcement.widget.index",:default_template=>true,:fields=>["title","category","postdate"]
|
# item "index","announcement.widget.index",:default_template=>true,:fields=>["title","category","postdate"]
|
||||||
# item "bulletins_and_web_links","announcement.widget.bulletins_and_web_links"
|
# item "bulletins_and_web_links","announcement.widget.bulletins_and_web_links"
|
||||||
end
|
end
|
||||||
|
|
Reference in New Issue