Sorting

107 views
Skip to first unread message

Andreas Ronge

unread,
Apr 5, 2013, 7:39:57 AM4/5/13
to neo...@googlegroups.com
Hi

Reposting a private mail regarding sort and range queries:

"
...
Neo4j with Rails, using the "between" method. Can you please give me an example? I have a model, Show.rb, with some basic information: show_name, show_date, other things that don't matter. In my controller, I want to find show nodes based on their show_date, a range we can say is from a year ago until today. I want to order them in Asc. Whenever I try to do this, I get an error: 

undefined method `between' for...
"

Here is an example how to do this using lucene

require 'rubygems'
require 'neo4j'


class Show < Neo4j::Rails::Model
  property :since, :type => Date, :index => :exact
end

a = Show.create(since: 2.day.ago, name: 'a')
b = Show.create(since: 1.days.ago, name: 'b')
c = Show.create(since: 5.days.ago, name: 'c')
d = Show.create(since: 3.days.ago, name: 'd')

found = Show.find(:all, :conditions => {since: 4.days.ago ... 0.day.ago}, :sort => {:since => :desc})

puts "Found #{found.to_a.count}"

found.each do |item|
  puts item[:name]
end

CLG

unread,
Apr 5, 2013, 9:38:33 AM4/5/13
to neo...@googlegroups.com
Thanks for replying to my message! I get a syntax error when I try this: (using "show_date" instead of "since")

syntax error, unexpected ':'

    @shows = Show.find(:all, :conditions => {show_date: 4.years.ago ... 0.days.ago}, :sort => { :show_date => :desc })
                                                      ^

CLG

unread,
Apr 5, 2013, 10:16:35 AM4/5/13
to neo...@googlegroups.com
Changing the syntax to:

    @shows = Show.find(:all, :conditions => {:show_date => 4.years.ago ... 0.days.ago}, :sort => { :show_date => :desc })

(using :show_date with hash rocket instead of show_date:) lets it go through, though it's not returning results. I will try it a bit more with specific timestamps instead of the friendlier "4.years.ago" stuff. 

Andreas Ronge

unread,
Apr 5, 2013, 10:48:53 AM4/5/13
to neo...@googlegroups.com

It's ruby 1.9 syntax

--
You received this message because you are subscribed to the Google Groups "neo4jrb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4jrb+u...@googlegroups.com.
To post to this group, send email to neo...@googlegroups.com.
Visit this group at http://groups.google.com/group/neo4jrb?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

CLG

unread,
Apr 5, 2013, 11:41:12 AM4/5/13
to neo...@googlegroups.com
Got it, I think! It was not working, even with the old hash rocket syntax, in jruby-1.6.7.2. Confirmed working in jruby-1.7.3 with both forms of the command. Thank you!
Reply all
Reply to author
Forward
0 new messages