Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [PATCH] Natural language date searches
@ 2007-10-26 22:10 Marcus Williams
  2007-10-27 21:10 ` Marcus Williams
  0 siblings, 1 reply; 7+ messages in thread
From: Marcus Williams @ 2007-10-26 22:10 UTC (permalink / raw)


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 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [sup-talk] [PATCH] Natural language date searches
  2007-10-26 22:10 [sup-talk] [PATCH] Natural language date searches Marcus Williams
@ 2007-10-27 21:10 ` Marcus Williams
  2007-11-09 18:46   ` William Morgan
  0 siblings, 1 reply; 7+ messages in thread
From: Marcus Williams @ 2007-10-27 21:10 UTC (permalink / raw)


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 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [sup-talk] [PATCH] Natural language date searches
  2007-10-27 21:10 ` Marcus Williams
@ 2007-11-09 18:46   ` William Morgan
  2007-11-09 20:29     ` Marcus Williams
  0 siblings, 1 reply; 7+ messages in thread
From: William Morgan @ 2007-11-09 18:46 UTC (permalink / raw)


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>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [sup-talk] [PATCH] Natural language date searches
  2007-11-09 18:46   ` William Morgan
@ 2007-11-09 20:29     ` Marcus Williams
  2007-11-09 20:44       ` Marcus Williams
  0 siblings, 1 reply; 7+ messages in thread
From: Marcus Williams @ 2007-11-09 20:29 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [sup-talk] [PATCH] Natural language date searches
  2007-11-09 20:29     ` Marcus Williams
@ 2007-11-09 20:44       ` Marcus Williams
  2007-11-09 21:20         ` Marcus Williams
  0 siblings, 1 reply; 7+ messages in thread
From: Marcus Williams @ 2007-11-09 20:44 UTC (permalink / raw)


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).begin

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 

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 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [sup-talk] [PATCH] Natural language date searches
  2007-11-09 20:44       ` Marcus Williams
@ 2007-11-09 21:20         ` Marcus Williams
  2007-11-12 18:01           ` William Morgan
  0 siblings, 1 reply; 7+ messages in thread
From: Marcus Williams @ 2007-11-09 21:20 UTC (permalink / raw)


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 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [sup-talk] [PATCH] Natural language date searches
  2007-11-09 21:20         ` Marcus Williams
@ 2007-11-12 18:01           ` William Morgan
  0 siblings, 0 replies; 7+ messages in thread
From: William Morgan @ 2007-11-12 18:01 UTC (permalink / raw)


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>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-11-12 18:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-26 22:10 [sup-talk] [PATCH] Natural language date searches Marcus Williams
2007-10-27 21:10 ` Marcus Williams
2007-11-09 18:46   ` William Morgan
2007-11-09 20:29     ` Marcus Williams
2007-11-09 20:44       ` Marcus Williams
2007-11-09 21:20         ` Marcus Williams
2007-11-12 18:01           ` William Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox