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
|
||||||
|
|
|
@ -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,28 +33,55 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
results = data.results;
|
||||||
|
|
||||||
|
$("#search_time").html("Found "+results.length+" Results, Search Time: "+data.time+"ms");
|
||||||
|
|
||||||
|
renderResults(1);
|
||||||
|
searchLock = false;
|
||||||
|
});
|
||||||
|
}else if(interval>0){
|
||||||
|
interval -= 100;
|
||||||
|
setTimeout(s.processSearch,100);
|
||||||
|
}else if(keyword==""){
|
||||||
|
searchLock = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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").scrollTop(0);
|
||||||
$("#search_results").html("");
|
$("#search_results").html("");
|
||||||
$("#search_time").html("Found "+data.results.length+" Results, Search Time: "+data.time+"ms");
|
$.each(tmpResults,function(key,res){
|
||||||
$.each(data.results,function(key,res){
|
search_result = "<div class='search_result'>"+
|
||||||
search_result =
|
|
||||||
"<div class='search_result'>"+
|
|
||||||
"<a href='"+res.url+"' target='_blank'>"+
|
"<a href='"+res.url+"' target='_blank'>"+
|
||||||
"<div class='seach_title'>"+res.title+"</div>"+
|
"<div class='seach_title'>"+res.title+"</div>"+
|
||||||
"</a>"+
|
"</a>"+
|
||||||
|
@ -52,15 +89,32 @@ var Search = function(){
|
||||||
"</div>";
|
"</div>";
|
||||||
$("#search_results").append(search_result);
|
$("#search_results").append(search_result);
|
||||||
});
|
});
|
||||||
$("#search_container").fadeIn(300);
|
renderPagination(page);
|
||||||
processLock = false;
|
}
|
||||||
});
|
|
||||||
}else if(interval>0){
|
function renderPagination(page){
|
||||||
interval -= 100;
|
var totalPages = Math.round(results.length/5);
|
||||||
setTimeout(s.processSearch,100);
|
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>');
|
||||||
}
|
}
|
||||||
s.init();
|
|
||||||
}();
|
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