Skip to content

Instantly share code, notes, and snippets.

@kidpollo
Created July 2, 2009 16:55
Show Gist options
  • Save kidpollo/139593 to your computer and use it in GitHub Desktop.
Save kidpollo/139593 to your computer and use it in GitHub Desktop.
def search(options = {})
search = false
blocked_domains_filter = ""
blocked_channels_filter = ""
if options[:jobseeker]
blocked_domains_filter = " not ( " + options[:jobseeker].blocked_domains.map{|bd| bd.domain}.join(" or ") + " )" unless options[:jobseeker].blocked_domains.empty? || self.keywords.blank?
blocked_channels_filter = " not ( " + options[:jobseeker].blocked_channels.map{|bd| bd.channel}.join(" or ") + " )" unless options[:jobseeker].blocked_channels.empty? || self.keywords.blank?
end
#begin
if !self.placemark.nil?
search = Ultrasphinx::Search.new(
:query => self.keywords + blocked_domains_filter + blocked_channels_filter,
:sort_mode => 'extended',
:sort_by => 'distance asc',
:class_names => "Job",
:weights => {:title=>10, :description=>2, :company_name=>5},
:per_page => options[:per_page] || TweetyJobs::Settings["pagination"]["default"],
:page => options[:page] || 1,
:filters => {'distance'=>0..96560.64, :hibernated => [0]}.merge(options[:filters] || {}),
:location => {
:units => 'degrees',
:lat => self.placemark.x,
:long => self.placemark.y
}
)
else
search = Ultrasphinx::Search.new(
:query => self.keywords + blocked_domains_filter + blocked_channels_filter,
:sort_mode => 'relevance',
:class_names => "Job",
:weights => {:title=>10, :description=>2, :company_name=>5},
:per_page => options[:per_page] || TweetyJobs::Settings["pagination"]["default"],
:page => options[:page] || 1,
:filters => {:hibernated => [0]}.merge(options[:filters] || {})
)
#else
# raise I18n.t("agents.invalid_search_agent")
end
#rescue Ultrasphinx::Search::SphinxInternalError => e
# raise "#{I18n.t("agents.invalid_search_agent")} #{e}" #if ultrasphinx Search.new fails
#end
search #return
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment