Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

using thumbnails

  • Loading branch information...
commit 4262c8a6e4238b807b732c914e78f95da633b263 1 parent dab62fa
@maxdemarzi authored
View
19 lib/ngs/parser/ngs_cypher.rb
@@ -47,6 +47,14 @@ def to_cypher
end
end
+ class Lives < Treetop::Runtime::SyntaxNode
+ def to_cypher
+ return {:start => "place = node:places({place})",
+ :match => "people -[:lives]-> place",
+ :params => {"place" => "name: " + self.text_value.split("in").last.to_s.strip + "*" } }
+ end
+ end
+
class LikeAnd < Treetop::Runtime::SyntaxNode
def to_cypher
return {:start => "thing1 = node:things({thing1}), thing2 = node:things({thing2})",
@@ -55,6 +63,14 @@ def to_cypher
end
end
+ class LikeAndLives < Treetop::Runtime::SyntaxNode
+ def to_cypher
+ return {:start => "thing = node:things({thing}), place = node:places({place})",
+ :match => "people -[:likes]-> thing, people -[:lives]-> place",
+ :params => {"thing" => "name: " + self.elements[1].text_value, "place" => "name: " + self.elements.last.text_value.split("in").last.to_s.strip + "*"} }
+ end
+ end
+
class Thing < Treetop::Runtime::SyntaxNode
def to_cypher
return {:start => "thing = node:things({thing})",
@@ -64,7 +80,8 @@ def to_cypher
class People < Treetop::Runtime::SyntaxNode
def to_cypher
- return {:return => "people"}
+ return {#:start => "people = node:people(\"name:*\")",
+ :return => "people"}
end
end
View
15 lib/ngs/parser/ngs_parser.treetop
@@ -5,7 +5,7 @@ rule expression
end
rule body
- (expression / me / (friends / people) / likeand / likes / thing / space )* <Body>
+ (expression / me / (friends / people) / likeandlives / likeand / likes / lives / thing / space )* <Body>
end
rule me
@@ -20,14 +20,27 @@ rule likes
"who like" <Likes>
end
+rule lives
+ ("who live in" / "live in" ) space place <Lives>
+end
+
rule likeand
likes space thing space "and" space thing <LikeAnd>
end
+rule likeandlives
+ likes space thing space "and" space lives <LikeAndLives>
+end
+
rule thing
[a-zA-Z0-9]+ <Thing>
end
+rule place
+ [a-zA-Z0-9]+
+end
+
+
rule people
"people" <People>
end
View
11 ngs_app.rb
@@ -4,7 +4,7 @@ class App < Sinatra::Base
$stdout.sync = true
configure :development do |config|
register Sinatra::Reloader
- config.also_reload "lib/ngs/**/*.rb"
+ config.also_reload "lib/ngs/**/*"
end
use Rack::Session::Cookie , :secret => (ENV['SESSION_SECRET'] || "82e042cd6fde2bf1764f777236db799e")
@@ -70,16 +70,17 @@ class App < Sinatra::Base
get '/user/:id/search' do
@user = user(params[:id])
@q = params[:q] || "friends"
+ @q = "friends" if @q == "people"
begin
@cypher = NGS::Parser.parse("(#{@q})")
@cypher[0] = @cypher[0] + " , people.uid, people.name, people.image_url LIMIT 100"
- @cypher[1].merge!({"me" => @user.neo_id})
+ @cypher[1].merge!({"me" => @user.neo_id}) if @cypher[1].has_key?("me")
@people = $neo_server.execute_query(@cypher[0].to_s, @cypher[1])["data"]
@cypher[0].gsub!("MATCH", "<br>MATCH")
@cypher[0].gsub!("RETURN", "<br>RETURN")
- @cypher[0].gsub!("LIMIT", "<br>RETURN")
- rescue
- @cypher = ["Sorry, I didn't understand, please try again.",nil]
+ @cypher[0].gsub!("LIMIT", "<br>LIMIT")
+ rescue Exception => e
+ @cypher = ["Sorry, I didn't understand, please try a different search."]
@people = []
end
haml :'user/search'
View
24 spec/ngs/parser_spec.rb
@@ -40,22 +40,16 @@
NGS::Parser.parse("(people who like cheese and crackers)").should == [cypher, params]
end
- it "can return people who like cyling and live in Florida" do
- cypher = "START thing = node:things({thing}), place = node:places({place}) MATCH people -[:likes]-> thing1, people -[:lives]-> place RETURN DISTINCT people"
- params = {"thing" => "name: cheese", "place" => "name: Florida"}
- NGS::Parser.parse("(people who like cheese and live in Florida)").should == [cypher, params]
+ it "can return people who live in FLorida" do
+ cypher = "START place = node:places({place}) MATCH people -[:lives]-> place RETURN DISTINCT people"
+ params = {"place" => "name: Florida*"}
+ NGS::Parser.parse("(people who live in Florida)").should == [cypher, params]
end
-# People who like Cycling
-# People who like Cycling and are from my hometown
-# People who like Cycling and live in Seattle, Washington
-# Photos I like
-# Photos before 1990
-# Photos of my friends in New York
-# Music my friends like
-# Cities my family visited
-# Restaurants in London my friends have been to
-
-
+ it "can return people who like cyling and live in Florida" do
+ cypher = "START thing = node:things({thing}), place = node:places({place}) MATCH people -[:likes]-> thing, people -[:lives]-> place RETURN DISTINCT people"
+ params = {"thing" => "name: cycling", "place" => "name: Florida*"}
+ NGS::Parser.parse("(people who like cycling and live in Florida)").should == [cypher, params]
+ end
end
end
View
50 views/user/search.haml
@@ -7,21 +7,41 @@
.input-append
%input.span5.search-query{:type => "text", :value => @q, :name => "q"}
%button.btn Search
- Try "friends who like wine", "people who like wine and cheese"
+ Try:
+ %a{:href => "/user/#{current_user.uid}/search?q=friends+who+like+wine"}
+ friends who like wine
+ ,
+ %a{:href => "/user/#{current_user.uid}/search?q=people+who+like+wine+and+cheese"}
+ people who like wine and cheese
+ ,
+ %a{:href => "/user/#{current_user.uid}/search?q=people+who+like+cycling+and+live+in+Florida"}
+ people who like cycling and live in Florida
.row
- %h2="Cypher Query:"
- = @cypher[0]
- %br
- Parameters:
- = @cypher[1]
-
+ .span6
+ .well
+ %h2="Cypher Query:"
+ = @cypher[0]
+ %br
+ -if @cypher[1]
+ Parameters:
+ = @cypher[1]
+ .span6
+ .well
+ Want your own Graph Search? Contact
+ %a{:href => "http://maxdemarzi.com/about/"}
+ me
+ and learn more about
+ %a{:href => "http://neo4j.org"}
+ Neo4j
+ and
+ %a{:href => "http://neotechnology.com"}
+ NeoTechnology
.row
- %table{:class => "table table-striped"}
- %tbody
- - @people.each do |person|
- %tr
- %td
- %a{:href => "/user/#{person[1]}"}
- %img{:src => (person[3] == "" ? "/images/icon_no_photo_80x80.png" : person[3]) }
- =person[2]
+ %ul.thumbnails
+ - @people.each do |person|
+ %li.span3
+ .thumbnail
+ %a{:href => "/user/#{person[1]}"}
+ %img{:src => (person[3] == "" ? "/images/icon_no_photo_80x80.png" : person[3] ) }
+ =person[2]
Please sign in to comment.
Something went wrong with that request. Please try again.