diff --git a/README.rdoc b/README.rdoc index eca0a7a..40d429c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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]) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 +

+ Used tags + <% @user.used_tags.each do |tag| %> + <%= link_to tag.name, tag %>
+ <% end %> +

+ +

Knows:
<% @knows.each do |user| %> diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index bb7e58d..9d63db9 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -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]) @@ -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 @@ -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 diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index c2fcdec..bfa4456 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e5dc9f5..1acb768 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 0185520..c4a34f4 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -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 diff --git a/app/views/tweets/index.html.erb b/app/views/tweets/index.html.erb index 6ee71ee..8a7dae6 100644 --- a/app/views/tweets/index.html.erb +++ b/app/views/tweets/index.html.erb @@ -1,5 +1,13 @@

Listing tweets

+ + <%= form_for(:tweets, :method => :get) do |f| %> +
+ <%= text_field_tag :query %> + <%= f.submit "Search" %> +
+ <% end %> + @@ -26,4 +34,6 @@
+<%= will_paginate(@tweets) %> + <%= link_to 'New Tweet', new_tweet_path %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 18b9991..f62c85a 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -10,6 +10,13 @@ <%= @user.link %>

+

+ Used tags + <% @user.used_tags.each do |tag| %> + <%= link_to tag.name, tag %>
+ <% end %> +

+

Knows:

Text