Skip to content

Commit

Permalink
people working
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 26, 2013
1 parent 7b1a973 commit 0fdc8ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/ngs/parser/ngs_cypher.rb
Expand Up @@ -7,7 +7,7 @@ def to_cypher
cypher_string << "START " + cypher_hash[:start].join(", ")
cypher_string << " MATCH " + cypher_hash[:match].join(", ") unless cypher_hash[:match].empty?
cypher_string << " RETURN DISTINCT " + cypher_hash[:return].join(", ")
params = cypher_hash[:params].empty? ? nil : cypher_hash[:params].inject {|a,h| a.merge(h)}
params = cypher_hash[:params].empty? ? {} : cypher_hash[:params].inject {|a,h| a.merge(h)}
return [cypher_string, params].compact
end
end
Expand Down Expand Up @@ -49,22 +49,23 @@ def to_cypher

class LikeAnd < Treetop::Runtime::SyntaxNode
def to_cypher
return {:start => "thing1 = node:things({thing1}), thing2 = node:things({thing2})",
:match => "friends -[:likes]-> thing1, friends -[:likes]-> thing2",
return {:start => "thing1 = node:things({thing1}), thing2 = node:things({thing2})",
:match => "friends -[:likes]-> thing1, friends -[:likes]-> thing2",
:params => {"thing1" => "name: " + self.elements[1].text_value, "thing2" => "name: " + self.elements.last.text_value} }
end
end

class Thing < Treetop::Runtime::SyntaxNode
def to_cypher
return {:start => "thing = node:things({thing})",
return {:start => "thing = node:things({thing})",
:params => {"thing" => "name: " + self.text_value } }
end
end

class People < Treetop::Runtime::SyntaxNode
def to_cypher
return {:return => "friends"}
return {:start => "friends = node:people(\"name:*\")",
:return => "friends"}
end
end

Expand Down
2 changes: 1 addition & 1 deletion ngs_app.rb
Expand Up @@ -71,7 +71,7 @@ class App < Sinatra::Base
@user = user(params[:id])
@q = params[:q] || "friends"
@cypher = NGS::Parser.parse("(#{@q})")
@cypher[0] = @cypher[0] + " , friends.uid, friends.name, friends.image_url"
@cypher[0] = @cypher[0] + " , friends.uid, friends.name, friends.image_url LIMIT 100"
@cypher[1].merge!({"me" => @user.neo_id})
@friends = $neo_server.execute_query(@cypher[0].to_s, @cypher[1])["data"]
haml :'user/search'
Expand Down

0 comments on commit 0fdc8ec

Please sign in to comment.