Skip to content

Commit

Permalink
Fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasronge committed Nov 3, 2011
1 parent 954ac3a commit d40dcae
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
34 changes: 23 additions & 11 deletions README.rdoc
Expand Up @@ -60,8 +60,7 @@ It creates and connects the Tweet, Link, User and Tag model classes.
result = search.hashtag(@tag.name)

curr_page = 0
found_old_tweet = false
while curr_page < 2 && !found_old_tweet do
while curr_page < 2 do
result.each do |item|
parsed_tweet_hash = Tweet.parse(item)
next if Tweet.find_by_tweet_id(parsed_tweet_hash[:tweet_id])
Expand Down Expand Up @@ -96,6 +95,8 @@ It creates and connects the Tweet, Link, User and Tag model classes.
t = t[1..-1].downcase
tag = Tag.find_or_create_by(:name => t)
tweet.tags << tag unless tweet.tags.include?(tag)
user.used_tags << tag unless user.used_tags.include?(tag)
user.save
when /https?:.+/
link = Link.find_or_create_by(:url => t)
tweet.links << link.redirected_link || link
Expand Down Expand Up @@ -135,6 +136,7 @@ to
==== app/views/tags/show.html.erb

Add a button to the view:

<%= button_to "Search", [:search, @tag], :method => :get %>

Test the application now by open a browser http://localhost:3000/tags
Expand Down Expand Up @@ -216,6 +218,8 @@ To only return the real URLs we can use rules, which is a bit similar to scope i
This means that it will group all links under the rule :real which does not have a redirected_link
To return all those nodes, use the class method #real.

Btw, the Neo4j::Rails::Model#all method is also implemented as a rule.

==== app/controllers/links_controller.rb

def index
Expand Down Expand Up @@ -399,7 +403,7 @@ Add the following at the bottom of the file

==== app/assets/javascripts/application.js

Make sure things are loading in the correct order
Make sure things are loading in the correct order.
Add a require d3 before requiring everything else.

//= require jquery
Expand All @@ -410,15 +414,15 @@ Add a require d3 before requiring everything else.

==== app/assets/stylesheets/application.css

circle.node {
stroke: #fff;
stroke-width: 1.5px;
}
circle.node {
stroke: #fff;
stroke-width: 1.5px;
}

line.link {
stroke: #999;
stroke-opacity: .6;
}
line.link {
stroke: #999;
stroke-opacity: .6;
}

==== Test it

Expand All @@ -430,6 +434,14 @@ Open a browser http://localhost:3000/users and scroll down
==== app/views/users/show.erb
Add the following before the link_to lines

<p>
<b>Used tags</b>
<% @user.used_tags.each do |tag| %>
<%= link_to tag.name, tag %> <br/>
<% end %>
</p>


<p>
<b>Knows:</b><br/>
<% @knows.each do |user| %>
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/tags_controller.rb
Expand Up @@ -90,8 +90,7 @@ def search
result = search.hashtag(@tag.name)

curr_page = 0
found_old_tweet = false
while curr_page < 10 && !found_old_tweet do
while curr_page < 15 do
result.each do |item|
parsed_tweet_hash = Tweet.parse(item)
next if Tweet.find_by_tweet_id(parsed_tweet_hash[:tweet_id])
Expand All @@ -117,7 +116,6 @@ def parse_tweet(tweet, user)
case t
when /^@.+/
t = t[1..-1].downcase
next if t.nil?
other = User.find_or_create_by(:twid => t)
user.knows << other unless t == user.twid || user.knows.include?(other)
user.save
Expand All @@ -126,6 +124,8 @@ def parse_tweet(tweet, user)
t = t[1..-1].downcase
tag = Tag.find_or_create_by(:name => t)
tweet.tags << tag unless tweet.tags.include?(tag)
user.used_tags << tag unless user.used_tags.include?(tag)
user.save
when /https?:.+/
link = Link.find_or_create_by(:url => t)
tweet.links << link.redirected_link || link
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/tweets_controller.rb
Expand Up @@ -2,7 +2,12 @@ class TweetsController < ApplicationController
# GET /tweets
# GET /tweets.json
def index
@tweets = Tweet.all
query = params[:query]
if query && !query.empty?
@tweets = Tweet.all("text:#{query}", :type => :fulltext).paginate(:page => params[:page], :per_page => 10)
else
@tweets = Tweet.all.paginate(:page => params[:page], :per_page => 10)
end

respond_to do |format|
format.html # index.html.erb
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/users_controller.rb
Expand Up @@ -90,4 +90,12 @@ def destroy
format.json { head :ok }
end
end

def recommend
@user = User.find(params[:id])
my_tags = @user.used_tags.to_a

# find other users using these tags
other_people_tags = @user._java_node.outgoing(:knows).incoming(:knows).outgoing(:used_tags).depth(5).filter{|path| path.lastRelationship.rel_type == 'used_tags'}
end
end
2 changes: 2 additions & 0 deletions app/models/tweet.rb
Expand Up @@ -5,6 +5,8 @@ class Tweet < Neo4j::Rails::Model
property :tweet_id, :type => String

index :tweet_id
index :date
index :text, :type => :fulltext

has_n :tags
has_n :mentions
Expand Down
10 changes: 10 additions & 0 deletions app/views/tweets/index.html.erb
@@ -1,5 +1,13 @@
<h1>Listing tweets</h1>


<%= form_for(:tweets, :method => :get) do |f| %>
<div class="field">
<%= text_field_tag :query %>
<%= f.submit "Search" %>
</div>
<% end %>

<table>
<tr>
<th>Text</th>
Expand All @@ -26,4 +34,6 @@

<br />

<%= will_paginate(@tweets) %>
<%= link_to 'New Tweet', new_tweet_path %>
7 changes: 7 additions & 0 deletions app/views/users/show.html.erb
Expand Up @@ -10,6 +10,13 @@
<%= @user.link %>
</p>

<p>
<b>Used tags</b>
<% @user.used_tags.each do |tag| %>
<%= link_to tag.name, tag %> <br/>
<% end %>
</p>


<p>
<b>Knows:</b><br/>
Expand Down

0 comments on commit d40dcae

Please sign in to comment.