Search Engine remove result not matched

This commit is contained in:
Manson Wang 2014-03-19 15:24:29 +08:00
parent 2f4c2c721a
commit 92d882703b
1 changed files with 6 additions and 4 deletions

View File

@ -19,7 +19,7 @@ class SiteSearchController < ApplicationController
context = PageContext.where(:page_id=>page.id).first.context rescue nil
next if title.nil? and context.nil?
context = context.gsub(/<\/?[^>]*>/, "").gsub(/&nbsp;/i," ") rescue ""
context = context.gsub(/<\/?[^>]*>/, "").gsub(/&nbsp;/i,"") rescue ""
title_matches = title.match(regex)
context_matches = context.match(regex)
if title_matches or context_matches
@ -71,8 +71,10 @@ class SiteSearchController < ApplicationController
res[:content].gsub!(/(#{k})/i, '<b>\1</b>') rescue ""
end
result.delete(res) if res[:matches]==0
next if res[:matches]==0
if res[:matches]==0
result = result - [res]
next
end
index = res[:content].index '<b>'
unless index.nil?
@ -80,7 +82,7 @@ class SiteSearchController < ApplicationController
deadline = 150
res[:content] = res[:content][index, deadline]
else
res[:content] = res[:content][0, 150]
res[:content] = res[:content][0, 100]
end
end