tag:support.flying-sphinx.com,2011-01-05:/discussions/problems/88-indexing-on-created_at-timestamp-issueFlying Sphinx: Discussion 2016-08-11T01:31:28Ztag:support.flying-sphinx.com,2011-01-05:Comment/124003172011-12-26T06:17:49Z2011-12-26T06:17:50ZIndexing on created_at timestamp issue<div><p>So I'm attempting to get flying-sphinx running on my Rails 3
application on Heroku and I am running into an issue<br>
when indexing the 'created_at' and 'updated_at' attributes for
sorting purposes. Sphinx seems to stop partying<br>
when this occurs:</p>
<p>ERROR: index 'post_delta': sql_range_query: ERROR: invalid input
syntax for type timestamp: ""<br>
The index definitions in my model look like:</p>
<p>define_index do</p>
<pre>
<code>indexes title
indexes content
indexes slug
indexes month
indexes year
indexes created_at, :sortable => true
indexes updated_at, :sortable => true
set_property :delta => true</code>
</pre>
<p>end</p>
<p>Removing the index on created_at and updated_at allows indexing
to succeed. I'm not sure what is wrong. Anyone run into this and
have a solution?</p></div>Joel Andritschtag:support.flying-sphinx.com,2011-01-05:Comment/124003172011-12-26T09:21:16Z2011-12-26T09:21:16ZIndexing on created_at timestamp issue<div><p>Hi Joel</p>
<p>If the only reason you're referencing created_at and updated_at
is for sorting (and I'd be surprised if you need them as text data
in fields), then attributes is what you should be using
instead.</p>
<p>This means you'll want to use the <code>has</code> method
instead of <code>indexes</code>:</p>
<pre>
<code>has created_at, updated_at</code>
</pre>
<p>Attributes are always sortable (that's one of their main
purposes in Sphinx - indeed, when you specify :sortable for a
field, it just creates a matching attribute under the hood).</p>
<p>You can find more information here:<br>
<a href=
"http://freelancing-god.github.com/ts/en/sphinx_basics.html">http://freelancing-god.github.com/ts/en/sphinx_basics.html</a><br>
<a href=
"http://freelancing-god.github.com/ts/en/indexing.html#attributes">http://freelancing-god.github.com/ts/en/indexing.html#attributes</a></p>
<p>Also, given this is a Sphinx/Thinking Sphinx issue, not Flying
Sphinx, you can run it all locally and you'll hit the same issues -
though I don't mind the questions being asked here anyway :)</p>
<p>Any more questions, don't hesitate to ask.</p>
<p>Pat</p></div>Pat Allan