Strange date query behavior

97 views
Skip to first unread message

Mauro Servienti

unread,
Apr 10, 2012, 4:59:53 AM4/10/12
to rav...@googlegroups.com

Hi,

 

Running 701, cannot update to a newer build at the moment.

 

I have an index that produces a projection that has a lot of properties among which there are some date/time properties:

 

"LastMessageDeliveredAt": "2012-04-10T08:42:27.8296290+00:00"

(in json seen from the studio)

 

Now, issuing this query (from the studio):

LastMessageDeliveredAt: [20100201 TO 20120201]

 

Does _not_ filter out the document that has the above value, if I issue this query

LastMessageDeliveredAt: [20100201 TO 20110201]

 

Changing the year from 2012 to 2011 documents are correctly filtered.

 

Any idea?

.m

 

 

Mauro Servienti

unread,
Apr 10, 2012, 5:20:48 AM4/10/12
to rav...@googlegroups.com

If I change the Lucene query to this:

LastMessageDeliveredAt: [2010-02-01 TO 2012-02-01]

 

It works as expected, now running the same using Linq:

 

var limit = DateTimeOffset.Now.AddMonths( -2 ).Date;

mailboxSession.Query<BlaBla, BlaBla>().Where( c => c.LastMessageDeliveredAt <= limit )

 

does not work, how can I see which Lucene query gets produced?

 

.m

Matt Warren

unread,
Apr 10, 2012, 5:22:42 AM4/10/12
to rav...@googlegroups.com
To see the Lucene query you can do this:

var queryText = mailboxSession.Query<BlaBla, BlaBla>()
                                          .Where(c => c.LastMessageDeliveredAt <= limit)
                                          .ToString();

Matt Warren

unread,
Apr 10, 2012, 5:36:29 AM4/10/12
to rav...@googlegroups.com
Also you might want to use the Raven.Abstractions DateTools class to do the conversion for you, see https://github.com/ayende/ravendb/blob/master/Raven.Abstractions/Linq/DateTools.cs. That way you'll know the dates are converted properly.

Oren Eini (Ayende Rahien)

unread,
Apr 10, 2012, 5:38:52 AM4/10/12
to rav...@googlegroups.com
What index is this using? The only time the index would retain dates in this format:  : [2010-02-01 TO 2012-02-01] 
is when you are saving the dates using not analyzed.

Mauro Servienti

unread,
Apr 10, 2012, 5:42:01 AM4/10/12
to rav...@googlegroups.com

Amazing, that did the trick, I did not know.

What should be the value? Analyzed or Default?

Oren Eini (Ayende Rahien)

unread,
Apr 10, 2012, 5:43:11 AM4/10/12
to rav...@googlegroups.com
For dates, probably default.
Reply all
Reply to author
Forward
0 new messages