Note that there are some explanatory texts on larger screens.

plurals
  1. POIndexing old data with Neo4j and jRuby on Rails
    primarykey
    data
    text
    <p>We recently switched to JRuby on Rails so that we can use Neo4j, and even though we've only scratched the surface of what Neo4j can do, it's already pretty great. That said, I just ran into a rather vexing problem with indexing and finding.</p> <p>I just added ':index => :exact' to my User model's created_at field and my Post model's created_at field (there already was an index on my Post model's custom_date field):</p> <pre><code>class User &lt; Neo4j::Rails::Model property :created_at, :type =&gt; DateTime, :index =&gt; :exact class Post &lt; Neo4j::Rails::Model property :created_at, :type =&gt; DateTime, :index =&gt; :exact property :custom_date, :type =&gt; DateTime, :index =&gt; :exact </code></pre> <p>I then went into rails console to tried this code (which I adapted from <a href="https://github.com/andreasronge/neo4j/wiki/Neo4j%3a%3aWrapper-Lucene" rel="nofollow">the documentation</a>):</p> <pre><code>User.find( :all, :created_at =&gt; 7.days.ago .. DateTime.now ).count </code></pre> <p>And it returned 0, which I know isn't the case as this code:</p> <pre><code>new_users = [] User.all.each{ |user| new_users &lt;&lt; user if user.created_at &gt; 7.days.ago } new_users.count </code></pre> <p>Returns 104.</p> <p>Similarly, when I run</p> <pre><code>Post.find( :all, :created_at =&gt; 7.days.ago .. DateTime.now ).count </code></pre> <p>I get 0, but when I run</p> <pre><code>Post.find( :all, :custom_date =&gt; 7.days.ago .. DateTime.now ).count </code></pre> <p>I get 305. (A post's custom_date is initially set to the posts's created_at.) The only difference is I had the index in place on the Post model's custom_date field when we ported over the old database, whereas I only just added the index to the created_at field.</p> <p>Here's my question: how do I search my users and posts by their created_at times?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload