Merge branch 'fgu' of gitlab.tp.rulingcom.com:saurabh/orbit-4-2 into fgu
This commit is contained in:
commit
77663feb84
|
@ -169,11 +169,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
#search_footer{
|
#search_footer{
|
||||||
height: 10px;
|
min-height: 10px;
|
||||||
padding: 5px 25px 5px 10px;
|
padding: 5px 25px 5px 10px;
|
||||||
|
border-top: 1px solid #DDD;
|
||||||
border-bottom: 1px solid #CCC;
|
border-bottom: 1px solid #CCC;
|
||||||
color: #666;
|
color: #666;
|
||||||
/*background: #DDD;*/
|
background: #EEE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#search_footer .pagination{
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#search_footer .pagination ul li a{
|
||||||
|
padding: 4px 10px;
|
||||||
|
color: #0053CF;
|
||||||
}
|
}
|
||||||
|
|
||||||
#search_results{
|
#search_results{
|
||||||
|
@ -181,7 +191,10 @@
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
#search_results img{
|
||||||
|
margin: 20px auto;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
#search_results::-webkit-scrollbar {
|
#search_results::-webkit-scrollbar {
|
||||||
width: 8px;
|
width: 8px;
|
||||||
background: #CCC;
|
background: #CCC;
|
||||||
|
|
|
@ -8,6 +8,7 @@ class SiteSearchController < ApplicationController
|
||||||
]
|
]
|
||||||
|
|
||||||
key_string = params[:keywords]
|
key_string = params[:keywords]
|
||||||
|
key_string = key_string.strip.nil? ? key_string : key_string.strip
|
||||||
keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
|
keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
|
||||||
regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")})
|
regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")})
|
||||||
|
|
||||||
|
@ -45,7 +46,8 @@ class SiteSearchController < ApplicationController
|
||||||
tmp[:content] = ""
|
tmp[:content] = ""
|
||||||
tmp[:matches] = 0
|
tmp[:matches] = 0
|
||||||
mod[:fields].each do |f|
|
mod[:fields].each do |f|
|
||||||
value = eval("r.#{f}").gsub(/<\/?[^>]*>/, "").gsub(/ /i,"") rescue ""
|
value = ActionView::Base.full_sanitizer.sanitize(eval("r.#{f}")) rescue ""
|
||||||
|
value = value.nil? ? "" : value
|
||||||
|
|
||||||
if f=="title" or f=="name"
|
if f=="title" or f=="name"
|
||||||
tmp[:title] = value
|
tmp[:title] = value
|
||||||
|
@ -62,11 +64,11 @@ class SiteSearchController < ApplicationController
|
||||||
result.each do |res|
|
result.each do |res|
|
||||||
res[:matches] = 0
|
res[:matches] = 0
|
||||||
|
|
||||||
res[:matches] += res[:title].match(/(#{key_string})/i) ? 100 : 0 rescue 0
|
res[:matches] += res[:title].match(/(#{key_string})/i) ? 500 : 0 rescue 0
|
||||||
res[:matches] += res[:content].match(/(#{key_string})/i) ? 100 : 0 rescue 0
|
res[:matches] += res[:content].match(/(#{key_string})/i) ? 300 : 0 rescue 0
|
||||||
|
|
||||||
keywords.each do |k|
|
keywords.each do |k|
|
||||||
res[:matches] += res[:title].scan(/(#{k})/i).size + res[:content].scan(/(#{k})/i).size
|
res[:matches] += (res[:title].scan(/(#{k})/i).size)*100 + res[:content].scan(/(#{k})/i).size
|
||||||
res[:title].gsub!(/(#{k})/i, '<b>\1</b>') rescue ""
|
res[:title].gsub!(/(#{k})/i, '<b>\1</b>') rescue ""
|
||||||
res[:content].gsub!(/(#{k})/i, '<b>\1</b>') rescue ""
|
res[:content].gsub!(/(#{k})/i, '<b>\1</b>') rescue ""
|
||||||
end
|
end
|
||||||
|
@ -76,7 +78,7 @@ class SiteSearchController < ApplicationController
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
res[:content] = truncate(res[:content], length: 150)
|
res[:content] = truncate(res[:content], length: 120)
|
||||||
end
|
end
|
||||||
|
|
||||||
result = result.sort_by { |k| k[:matches] }.reverse rescue []
|
result = result.sort_by { |k| k[:matches] }.reverse rescue []
|
||||||
|
|
|
@ -3,14 +3,14 @@ class Page < Item
|
||||||
include Impressionist::Impressionable
|
include Impressionist::Impressionable
|
||||||
include ParserFrontEnd
|
include ParserFrontEnd
|
||||||
|
|
||||||
is_impressionable :counter_cache => { :column_name => :view_count }
|
is_impressionable
|
||||||
|
|
||||||
field :content, localize: true
|
field :content, localize: true
|
||||||
field :app_frontend_url
|
field :app_frontend_url
|
||||||
# field :theme_id, :type => BSON::ObjectId, :default => nil
|
# field :theme_id, :type => BSON::ObjectId, :default => nil
|
||||||
field :category,type: Array, :default => []
|
field :category,type: Array, :default => []
|
||||||
field :tag, type: Array,:default => []
|
field :tag, type: Array,:default => []
|
||||||
field :view_count, :type => Integer, :default => 0
|
# field :view_count, :type => Integer, :default => 0
|
||||||
field :page_title, localize: true
|
field :page_title, localize: true
|
||||||
|
|
||||||
field :frontend_style
|
field :frontend_style
|
||||||
|
@ -65,6 +65,10 @@ class Page < Item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def view_count
|
||||||
|
self.impression_count
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def create_parts
|
def create_parts
|
||||||
|
@ -97,15 +101,15 @@ class Page < Item
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_empty_frontend_field
|
def delete_empty_frontend_field
|
||||||
if self.frontend_field
|
if self.frontend_field
|
||||||
self.frontend_field.reject! { |ff| (ff[0].blank? || ff[1].blank?) }
|
self.frontend_field.reject! { |ff| (ff[0].blank? || ff[1].blank?) }
|
||||||
# self.frontend_field.each do | ff |
|
# self.frontend_field.each do | ff |
|
||||||
# if ff[0].blank? || ff[1].blank?
|
# if ff[0].blank? || ff[1].blank?
|
||||||
# self.frontend_field.delete("") if self.frontend_field
|
# self.frontend_field.delete("") if self.frontend_field
|
||||||
# self.frontend_field.delete(ff)
|
# self.frontend_field.delete(ff)
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_html
|
def generate_html
|
||||||
|
|
|
@ -3,18 +3,28 @@
|
||||||
<button type="button" id="search_close" class="close pull-left">×</button>
|
<button type="button" id="search_close" class="close pull-left">×</button>
|
||||||
<div id='search_time'></div>
|
<div id='search_time'></div>
|
||||||
</div>
|
</div>
|
||||||
<div id='search_results'></div>
|
<div id='search_results'>
|
||||||
<div id='search_footer'></div>
|
</div>
|
||||||
|
<div id='search_footer'>
|
||||||
|
<div class="pagination pagination-centered"><div class="pagination">
|
||||||
|
<ul id="search_pagination">
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
var interval = 0;
|
||||||
|
var keyword;
|
||||||
|
var searchLock=false;
|
||||||
|
var results;
|
||||||
|
|
||||||
var Search = function(){
|
var Search = function(){
|
||||||
var s = this;
|
var s = this;
|
||||||
var interval = 0;
|
|
||||||
var keyword;
|
|
||||||
var processLock=false;
|
|
||||||
this.init = function(){
|
this.init = function(){
|
||||||
$("#q").keyup(function(){s.queueSearch();});
|
$("#q").bind("input", function() {s.queueSearch();});
|
||||||
|
|
||||||
$("#search_form").submit(function(){s.queueSearch(); return false; });
|
$("#search_form").submit(function(){s.queueSearch(); return false; });
|
||||||
$("#search_close").click(function(){$("#search_container").fadeOut(300);});
|
$("#search_close").click(function(){$("#search_container").fadeOut(300);});
|
||||||
}
|
}
|
||||||
|
@ -23,44 +33,88 @@ var Search = function(){
|
||||||
if($("#q").val() != keyword && $("#q").val()!=""){
|
if($("#q").val() != keyword && $("#q").val()!=""){
|
||||||
keyword = $("#q").val();
|
keyword = $("#q").val();
|
||||||
interval=500;
|
interval=500;
|
||||||
if(!processLock) s.processSearch();
|
if(!searchLock) s.processSearch();
|
||||||
}else if($("#q").val()==""){
|
}else if($("#q").val()==""){
|
||||||
keyword = ""
|
keyword = "";
|
||||||
$("#search_container").fadeOut(300);
|
$("#search_container").slideUp(300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.processSearch = function(){
|
this.processSearch = function(){
|
||||||
keyword_tmp = keyword;
|
keyword_tmp = keyword;
|
||||||
processLock = true;
|
searchLock = true;
|
||||||
if(interval==0 && keyword!=""){
|
if(interval==0 && keyword!=""){
|
||||||
|
$("#search_time").html("");
|
||||||
|
$("#search_results").scrollTop(0);
|
||||||
|
$("#search_results").html('<img src="http://ridepal.com/images/homeimg/preloader_transparent.gif" width="50">');
|
||||||
|
$("#search_pagination").html("");
|
||||||
|
$("#search_container").slideDown(300);
|
||||||
|
|
||||||
$.getJSON("/site_search", {"keywords" : keyword}, function(data){
|
$.getJSON("/site_search", {"keywords" : keyword}, function(data){
|
||||||
if(keyword_tmp != keyword) {
|
if(keyword_tmp != keyword) {
|
||||||
processLock = false;
|
searchLock = false;
|
||||||
s.processSearch();
|
s.processSearch();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$("#search_results").scrollTop(0);
|
|
||||||
$("#search_results").html("");
|
results = data.results;
|
||||||
$("#search_time").html("Found "+data.results.length+" Results, Search Time: "+data.time+"ms");
|
|
||||||
$.each(data.results,function(key,res){
|
$("#search_time").html("Found "+results.length+" Results, Search Time: "+data.time+"ms");
|
||||||
search_result =
|
|
||||||
"<div class='search_result'>"+
|
renderResults(1);
|
||||||
"<a href='"+res.url+"' target='_blank'>"+
|
searchLock = false;
|
||||||
"<div class='seach_title'>"+res.title+"</div>"+
|
|
||||||
"</a>"+
|
|
||||||
"<span>"+res.content+"</span>"+
|
|
||||||
"</div>";
|
|
||||||
$("#search_results").append(search_result);
|
|
||||||
});
|
|
||||||
$("#search_container").fadeIn(300);
|
|
||||||
processLock = false;
|
|
||||||
});
|
});
|
||||||
}else if(interval>0){
|
}else if(interval>0){
|
||||||
interval -= 100;
|
interval -= 100;
|
||||||
setTimeout(s.processSearch,100);
|
setTimeout(s.processSearch,100);
|
||||||
|
}else if(keyword==""){
|
||||||
|
searchLock = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.init();
|
s.init();
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
function renderResults(page){
|
||||||
|
var rangeStart = ((page-1)==0) ? 0 : ((page-1)*5)-1;
|
||||||
|
var tmpResults = results.slice(rangeStart, rangeStart+5);
|
||||||
|
|
||||||
|
$("#search_results").scrollTop(0);
|
||||||
|
$("#search_results").html("");
|
||||||
|
$.each(tmpResults,function(key,res){
|
||||||
|
search_result = "<div class='search_result'>"+
|
||||||
|
"<a href='"+res.url+"' target='_blank'>"+
|
||||||
|
"<div class='seach_title'>"+res.title+"</div>"+
|
||||||
|
"</a>"+
|
||||||
|
"<span>"+res.content+"</span>"+
|
||||||
|
"</div>";
|
||||||
|
$("#search_results").append(search_result);
|
||||||
|
});
|
||||||
|
renderPagination(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderPagination(page){
|
||||||
|
var totalPages = Math.round(results.length/5);
|
||||||
|
var startPage = ((page-5)<=0) ? 1 : page-5;
|
||||||
|
var ednPage = ( (startPage+10)>totalPages ) ? totalPages : (startPage+10);
|
||||||
|
|
||||||
|
if( (ednPage-startPage)<10 && totalPages>10 ){
|
||||||
|
startPage = ednPage-10;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#search_pagination").html("");
|
||||||
|
|
||||||
|
for(var i=startPage;i<=ednPage;i++){
|
||||||
|
var active = (i==page) ? "active" : "";
|
||||||
|
$("#search_pagination").append('<li class="page '+active+'"><a href="#" onclick="renderResults('+i+');">'+i+'</a></li>');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(page<totalPages){
|
||||||
|
$("#search_pagination").append('<li class="next"><a href="#" onclick="renderResults('+(page+1)+');"><span>Next</span></a></li>');
|
||||||
|
$("#search_pagination").append('<li class="last"><a href="#" onclick="renderResults('+totalPages+');"><span>Last</span></a></li>');
|
||||||
|
}
|
||||||
|
if(page!=1){
|
||||||
|
$("#search_pagination").prepend('<li class="first"><a href="#" onclick="renderResults('+1+');"><span>First</span></a></li>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue