Why isn't my ElasticSearch server returning keyword results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.9.2p290 :015 > Entity.leads_search({"keywords"=> ["plumbing supply", "bath and kitchen supply"]}) | |
=> #<Tire::Results::Collection:0x007fb57ed366d0 @response={"took"=>145, "timed_out"=>false, "_shards"=>{"total"=>5, "successful"=>5, "failed"=>0}, "hits"=>{"total"=>0, "max_score"=>nil, "hits"=>[]}}, @options={:load=>true, :page=>nil, :per_page=>nil}, @time=145, @total=0, @facets=nil, @wrapper=Tire::Results::Item> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Entity | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
# removed field definitions for brevity | |
index :twitter, :sparse => true | |
index :found_at_url, :sparse => true | |
index :host_names | |
index "new_profiles.username" | |
index [["facebook", Mongo::ASCENDING], ["name", Mongo::ASCENDING]] | |
index [["new_profiles.service", Mongo::ASCENDING],["new_profiles.username", Mongo::ASCENDING]] | |
# ElasticSearch Components | |
include Tire::Model::Search | |
include Tire::Model::Callbacks | |
index_name ::BONSAI_INDEX_NAME | |
tire.mapping do | |
indexes :name, :analyzer => "snowball" | |
indexes :keywords, :type => 'string', :analyzer => 'keyword' | |
indexes :presence_score, :type => 'integer', :index => :not_analyzed | |
indexes :name, :analyzer => "snowball" | |
indexes :description, :analyzer => "snowball" | |
end | |
def to_indexed_json | |
# cleanup existing stuff for indexation | |
rv = new_profiles.map {|x| x["service"] }.uniq rescue [] | |
shares = share_counts_stat rescue {} | |
fb_clicks = shares["Facebook"]["click_count"] rescue nil | |
fb_comments = shares["Facebook"]["comment_count"] rescue nil | |
fb_likes = shares["Facebook"]["like_count"] rescue nil | |
fb_shares = shares["Facebook"]["share_count"] rescue nil | |
{ | |
:id => id.to_s, | |
:type => 'entity', | |
:name => name, | |
:tags => tags, | |
:keywords => keywords, | |
:reachable_via => rv, | |
:description => description, | |
:ignore_project_ids => ignore_project_ids, | |
:project_listeners => project_listeners, | |
:presence_score => presence_score, | |
:created_at => created_at, | |
:updated_at => updated_at, | |
:found_at_url => found_at_url, | |
:twitter => twitter, | |
:facebook => facebook, | |
:profiles_retrieved => profiles_retrieved, | |
:stumble_upon => shares["StumbleUpon"], | |
:reddit => shares["Reddit"], | |
:facebook_clicks => fb_clicks, | |
:facebook_comments => fb_comments, | |
:facebook_likes => fb_likes, | |
:facebook_shares => fb_shares, | |
:delicious_share => shares["Delicious"], | |
:plus_one_share => shares["GooglePlusOne"], | |
:twitter_share => shares["Twitter"], | |
:pinterest_share => shares["Pinterest"], | |
:linked_in_share => shares["LinkedIn"], | |
:project_time_additions => project_time_additions | |
}.to_json | |
end | |
def self.leads_search(params) | |
tire.search(load: true, page: params[:page], per_page: params[:per_page]) do | |
query do | |
boolean do | |
must { term :keywords, params[:keywords] } | |
must { term :profiles_retrieved, true } | |
must_not { terms :ignore_project_ids, [params[:current_project_id]] } if params[:current_project_id] | |
end | |
end | |
sort { by :presence_score, "desc" } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment