With the help of the fantastic Chronic gem, this patch adds date based searches to sup with natural language. So you can do after:(1 week ago) after:(yesterday at 22:00) and before:(today at 5:00) and even combine them. For more examples see the Chronic docs at [1]. The brackets are important... watch the logs for oddities like: after:(yesterday) which probably wont do what you think as chronic sets a time of midday on the converted date. Specify a time if you need to or use "24 hours ago" or something. Marcus [1] http://chronic.rubyforge.org/ -------------- next part -------------- A non-text attachment was scrubbed... Name: date-search-diff Type: application/octet-stream Size: 912 bytes Desc: not available Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071026/312f7611/attachment.obj
On 26/10/2007, Marcus Williams wrote:> With the help of the fantastic Chronic gem, this patch adds date based > searches to sup with natural language. So you can do > > after:(1 week ago) > after:(yesterday at 22:00) > > and > > before:(today at 5:00)Attached is a tweaked patch so that you dont get an error if you pass a query string that Chronic cant parse. Currently it removes the query from the query string if it cant parse it and warns the user. It probably needs a change to bin/sup to ignore the query if parse_user_query_string returns an empty query, but this patch doesnt include that. Marcus -------------- next part -------------- A non-text attachment was scrubbed... Name: date-search-diff Type: application/octet-stream Size: 1085 bytes Desc: not available Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071027/61248a8e/attachment.obj
Excerpts from Marcus Williams''s message of Sat Oct 27 14:10:35 -0700 2007:> Attached is a tweaked patch so that you dont get an error if you pass > a query string that Chronic cant parse.Modified to skip parsing if Chronic isn''t available, and applied. Thanks! Also made it accept one-word Chronic tokens without parentheses, although "after:yesterday" means "after yesterday noon", which maybe is not so useful... -- William <wmorgan-sup at masanjin.net>
On 9.11.2007, William Morgan wrote:> Modified to skip parsing if Chronic isn''t available, and applied. > Thanks! > > Also made it accept one-word Chronic tokens without parentheses, > although "after:yesterday" means "after yesterday noon", which maybe is > not so useful...I think I may have worked out how to fix that - change the parse method to be: realdate = Chronic.parse(datestr, :guess => false).begin If guess is set to false it looks like Chronic always returns a span and you can just select the beginning of the span. At the moment I''m pretty sure you always want the beginning of the span in search situations. Certainly makes the single tokens more usable: irb(main):003:0> Chronic.parse("november", :guess => false).begin => Thu Nov 01 00:00:00 +0000 2007 irb(main):004:0> Chronic.parse("monday", :guess => false).begin => Mon Nov 12 00:00:00 +0000 2007 irb(main):005:0> Chronic.parse("24 hours ago", :guess => false).begin => Thu Nov 08 20:24:14 +0000 2007 irb(main):006:0> Chronic.parse("sunday", :guess => false).begin => Sun Nov 11 00:00:00 +0000 2007 irb(main):008:0> Chronic.parse("last sunday", :guess => false).begin => Sun Nov 04 00:00:00 +0000 2007 irb(main):010:0> Chronic.parse("first monday of november", :guess => false).begin => Mon Nov 05 00:00:00 +0000 2007 Marcus
On 9.11.2007, Marcus Williams wrote:> On 9.11.2007, William Morgan wrote: > > Modified to skip parsing if Chronic isn''t available, and applied. > > Thanks! > > > > Also made it accept one-word Chronic tokens without parentheses, > > although "after:yesterday" means "after yesterday noon", which maybe is > > not so useful... > > I think I may have worked out how to fix that - change the parse > method to be: > > realdate = Chronic.parse(datestr, :guess => false).beginMmmm - in fact it might be that you want to use .begin when you are searching "before", but .end when you are searching "after" That way searches like after:yesterday or after:(last monday) do what you expect. Patch attached Marcus -------------- next part -------------- A non-text attachment was scrubbed... Name: search-patch Type: application/octet-stream Size: 1111 bytes Desc: not available Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071109/1631a80b/attachment.obj
On 9.11.2007, Marcus Williams wrote:> Mmmm - in fact it might be that you want to use .begin when you are > searching "before", but .end when you are searching "after" > > That way searches like after:yesterday or after:(last monday) do what > you expect. Patch attached... on a roll here :) ... which means you can also have some sugar for single date search allowing "on:monday" or "on:(11th november)" saving you typing "after:(10th november) before:(12th november)". "on" probably isnt the best choice of words (on:november?) - so I added the alias "in" that does the same thing so you can type in:november. Updated patch attached. Marcus -------------- next part -------------- A non-text attachment was scrubbed... Name: search-patch Type: application/octet-stream Size: 1480 bytes Desc: not available Url : http://rubyforge.org/pipermail/sup-talk/attachments/20071109/075e087c/attachment.obj
Excerpts from Marcus Williams''s message of Fri Nov 09 13:20:33 -0800 2007:> ... on a roll here :) ... which means you can also have some sugar for > single date search allowing "on:monday" or "on:(11th november)" saving > you typing "after:(10th november) before:(12th november)". "on" > probably isnt the best choice of words (on:november?) - so I added the > alias "in" that does the same thing so you can type in:november.This is great stuff. Thanks, Marcus. Applied! -- William <wmorgan-sup at masanjin.net>