You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Rakhi Khatwani <rk...@gmail.com> on 2009/12/07 07:34:26 UTC

Converting java date to solr date and querying dates

Hi,
     i am using solrj
      i want to store dates into a date field called publish date in solr.
how do we do it using solrj
      likewise how do we query from solr using java date? do we always have
to convert it into UTC field and then query it?
      How do i query solr for documents published on monday or for documents
published on March etc.
      or in that case even apply range queries on it??
Regards
Raakhi

Re: Converting java date to solr date and querying dates

Posted by Lance Norskog <go...@gmail.com>.
Or add a new field type to Solr. This would accept a date and include
a Java formatting string. The field would parse the date, print it
with that format string, and store the results. You could use any
aspect of the date.

On Tue, Dec 15, 2009 at 1:06 PM, Chris Hostetter
<ho...@fucit.org> wrote:
>
> :       i want to store dates into a date field called publish date in solr.
> : how do we do it using solrj
>
> I'm pretty sure that when indexing docs, you can add Date objects directly
> to the SolrInputDocument as field values -- but 'm not 100% certain (i
> don't use SolrJ much)
>
> :       likewise how do we query from solr using java date? do we always have
> : to convert it into UTC field and then query it?
>
> all of the query APIs are based on query strings -- so yes you need to
> construct hte query string on your client side, and yes that includes
> formatting in UTC.
>
> :       How do i query solr for documents published on monday or for documents
> : published on March etc.
>
> if you mean "march of any year" or "any monday ever" then there isn't any
> built in support for anything like that ... your best bet would either be
> to add "month_of_year" and "day_of_week" fields and populate them in your
> client code, or write an UpdateProcessor to run in solr (that could be
> pretty generic if you wnat ot contribute it back, other people could find
> it useful)
>
> If you mean "published in the most recent march" or "published on hte
> most recent monday" where you don't have to change anything to have the
> query "do what i mean" as time moves on then you'd either need to do that
> when building up your query, or write it as a QParser plugin.
>
> :       or in that case even apply range queries on it??
>
> basic range queries are easy...
>
> http://wiki.apache.org/solr/SolrQuerySyntax
> http://lucene.apache.org/solr/api/org/apache/solr/schema/DateField.html
>
>
>
> -Hoss
>
>



-- 
Lance Norskog
goksron@gmail.com

Re: Converting java date to solr date and querying dates

Posted by Chris Hostetter <ho...@fucit.org>.
:       i want to store dates into a date field called publish date in solr.
: how do we do it using solrj

I'm pretty sure that when indexing docs, you can add Date objects directly 
to the SolrInputDocument as field values -- but 'm not 100% certain (i 
don't use SolrJ much)

:       likewise how do we query from solr using java date? do we always have
: to convert it into UTC field and then query it?

all of the query APIs are based on query strings -- so yes you need to 
construct hte query string on your client side, and yes that includes 
formatting in UTC.

:       How do i query solr for documents published on monday or for documents
: published on March etc.

if you mean "march of any year" or "any monday ever" then there isn't any 
built in support for anything like that ... your best bet would either be 
to add "month_of_year" and "day_of_week" fields and populate them in your 
client code, or write an UpdateProcessor to run in solr (that could be 
pretty generic if you wnat ot contribute it back, other people could find 
it useful)

If you mean "published in the most recent march" or "published on hte 
most recent monday" where you don't have to change anything to have the 
query "do what i mean" as time moves on then you'd either need to do that 
when building up your query, or write it as a QParser plugin.

:       or in that case even apply range queries on it??

basic range queries are easy...

http://wiki.apache.org/solr/SolrQuerySyntax
http://lucene.apache.org/solr/api/org/apache/solr/schema/DateField.html



-Hoss