Skip to content

Instantly share code, notes, and snippets.

@plotti
Created June 22, 2012 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plotti/2972340 to your computer and use it in GitHub Desktop.
Save plotti/2972340 to your computer and use it in GitHub Desktop.
Solr at search
def find_solr_at_connections
users = {}
persons.each do |person|
users[person.id] = person.username
end
values = []
i = 0
persons.each do |person|
i += 1
t1 = Time.now
search = FeedEntry.search do
without(:person_id,person.id) # No self referencing
fulltext "@#{person.username}" #Find those Feeds that mention this person
paginate :page => 1, :per_page => 1000000 #Make sure we dont paginate
end
j = 0
search.results.each do |result|
if users.keys.include?(result.person_id) && result.person_id != person.id # No self @
if result.retweet_ids == [] && !result.text.include?("RT") && result.text.include?("@#{person.username} ")
j += 1
values << [users[result.person_id], person.username, 1]
end
end
end
t2 = Time.now
puts "Person #{i} #{person.username}. Time per person: #{t2- t1}. Total pages #{search.results.total_pages}. Total results #{search.total}. Filtered: #{j}"
end
#Aggregate
hash = values.group_by { |first, second, third| [first,second] }
hash.map{|k,v| [k,v.count].flatten}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment