Created
June 22, 2012 12:00
-
-
Save plotti/2972340 to your computer and use it in GitHub Desktop.
Solr at search
This file contains hidden or 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
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