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 Floyd Wu <fl...@gmail.com> on 2011/07/26 06:23:48 UTC

How to make a valid date facet query?

Hi all,

I need to make date faceted query and I tried to use facet.range but can't
get result I need.

I want to make 4 facet like following.

1 Months,3 Months, 6Months, more than 1 Year

The onlinedate field in schema.xml like this

<field name="onlinedate" type="tdate" indexed="true" stored="true"/>

I hit the solr by this url

http://localhost:8983/solr/select/?q=*%3A*
&start=0
&rows=10
&indent=on
&facet=true
&facet.range=onlinedate
&f.onlinedate.facet.range.start=NOW-1YEARS
&f.onlinedate.facet.range.end=NOW%2B1YEARS
&f.onlinedate.facet.range.gap=NOW-1MONTHS, NOW-3MONTHS,
NOW-6MONTHS,NOW-1YEAR

But the solr complained Exception during facet.range of onlinedate
org.apache.solr.common.SolrException: Can't add gap NOW-1MONTHS,
NOW-3MONTHS, NOW-6MONTHS,NOW-1YEAR to value Mon Jul 26 11:56:40 CST 2010 for
....

What is correct way to make this requirement to realized? Please help on
this.
Floyd

Re: How to make a valid date facet query?

Posted by Tomás Fernández Löbbe <to...@gmail.com>.
Hi Floyd, yes, those queries are supported. Make sure you use the
right encoding for the plus sign:

facet.query=onlinedate:[NOW/YEAR-3YEARS TO NOW/YEAR%2B5YEARS]

the result of this facet query will be the number of documents in the result
set that match that range. You'll have to use different facet queries for
the different ranges to achieve what you want.

Regards,

Tomás

On Wed, Jul 27, 2011 at 12:43 AM, Floyd Wu <fl...@gmail.com> wrote:

> Hi Tomás
>
> Is facet queries support following queries?
>
> facet.query=onlinedate:[NOW/YEAR-3YEARS TO NOW/YEAR+5YEARS]
>
> I tried this but returned result was not correct.
>
> Am I missing something?
>
> Floyd
>
> 2011/7/26 Tomás Fernández Löbbe <to...@gmail.com>
>
> > Hi Floyd, I don't think the feature that allows to use multiple gaps for
> a
> > range facet is committed. See
> > https://issues.apache.org/jira/browse/SOLR-2366
> > You can achieve a similar functionality by using facet.query. see:
> >
> >
> http://wiki.apache.org/solr/SimpleFacetParameters#Facet_Fields_and_Facet_Queries
> >
> > Regards,
> >
> > Tomás
> > On Tue, Jul 26, 2011 at 1:23 AM, Floyd Wu <fl...@gmail.com> wrote:
> >
> > > Hi all,
> > >
> > > I need to make date faceted query and I tried to use facet.range but
> > can't
> > > get result I need.
> > >
> > > I want to make 4 facet like following.
> > >
> > > 1 Months,3 Months, 6Months, more than 1 Year
> > >
> > > The onlinedate field in schema.xml like this
> > >
> > > <field name="onlinedate" type="tdate" indexed="true" stored="true"/>
> > >
> > > I hit the solr by this url
> > >
> > > http://localhost:8983/solr/select/?q=*%3A*
> > > &start=0
> > > &rows=10
> > > &indent=on
> > > &facet=true
> > > &facet.range=onlinedate
> > > &f.onlinedate.facet.range.start=NOW-1YEARS
> > > &f.onlinedate.facet.range.end=NOW%2B1YEARS
> > > &f.onlinedate.facet.range.gap=NOW-1MONTHS, NOW-3MONTHS,
> > > NOW-6MONTHS,NOW-1YEAR
> > >
> > > But the solr complained Exception during facet.range of onlinedate
> > > org.apache.solr.common.SolrException: Can't add gap NOW-1MONTHS,
> > > NOW-3MONTHS, NOW-6MONTHS,NOW-1YEAR to value Mon Jul 26 11:56:40 CST
> 2010
> > > for
> > > ....
> > >
> > > What is correct way to make this requirement to realized? Please help
> on
> > > this.
> > > Floyd
> > >
> >
>

Re: How to make a valid date facet query?

Posted by Floyd Wu <fl...@gmail.com>.
Hi Tomás

Is facet queries support following queries?

facet.query=onlinedate:[NOW/YEAR-3YEARS TO NOW/YEAR+5YEARS]

I tried this but returned result was not correct.

Am I missing something?

Floyd

2011/7/26 Tomás Fernández Löbbe <to...@gmail.com>

> Hi Floyd, I don't think the feature that allows to use multiple gaps for a
> range facet is committed. See
> https://issues.apache.org/jira/browse/SOLR-2366
> You can achieve a similar functionality by using facet.query. see:
>
> http://wiki.apache.org/solr/SimpleFacetParameters#Facet_Fields_and_Facet_Queries
>
> Regards,
>
> Tomás
> On Tue, Jul 26, 2011 at 1:23 AM, Floyd Wu <fl...@gmail.com> wrote:
>
> > Hi all,
> >
> > I need to make date faceted query and I tried to use facet.range but
> can't
> > get result I need.
> >
> > I want to make 4 facet like following.
> >
> > 1 Months,3 Months, 6Months, more than 1 Year
> >
> > The onlinedate field in schema.xml like this
> >
> > <field name="onlinedate" type="tdate" indexed="true" stored="true"/>
> >
> > I hit the solr by this url
> >
> > http://localhost:8983/solr/select/?q=*%3A*
> > &start=0
> > &rows=10
> > &indent=on
> > &facet=true
> > &facet.range=onlinedate
> > &f.onlinedate.facet.range.start=NOW-1YEARS
> > &f.onlinedate.facet.range.end=NOW%2B1YEARS
> > &f.onlinedate.facet.range.gap=NOW-1MONTHS, NOW-3MONTHS,
> > NOW-6MONTHS,NOW-1YEAR
> >
> > But the solr complained Exception during facet.range of onlinedate
> > org.apache.solr.common.SolrException: Can't add gap NOW-1MONTHS,
> > NOW-3MONTHS, NOW-6MONTHS,NOW-1YEAR to value Mon Jul 26 11:56:40 CST 2010
> > for
> > ....
> >
> > What is correct way to make this requirement to realized? Please help on
> > this.
> > Floyd
> >
>

Re: How to make a valid date facet query?

Posted by Tomás Fernández Löbbe <to...@gmail.com>.
Hi Floyd, I don't think the feature that allows to use multiple gaps for a
range facet is committed. See
https://issues.apache.org/jira/browse/SOLR-2366
You can achieve a similar functionality by using facet.query. see:
http://wiki.apache.org/solr/SimpleFacetParameters#Facet_Fields_and_Facet_Queries

Regards,

Tomás
On Tue, Jul 26, 2011 at 1:23 AM, Floyd Wu <fl...@gmail.com> wrote:

> Hi all,
>
> I need to make date faceted query and I tried to use facet.range but can't
> get result I need.
>
> I want to make 4 facet like following.
>
> 1 Months,3 Months, 6Months, more than 1 Year
>
> The onlinedate field in schema.xml like this
>
> <field name="onlinedate" type="tdate" indexed="true" stored="true"/>
>
> I hit the solr by this url
>
> http://localhost:8983/solr/select/?q=*%3A*
> &start=0
> &rows=10
> &indent=on
> &facet=true
> &facet.range=onlinedate
> &f.onlinedate.facet.range.start=NOW-1YEARS
> &f.onlinedate.facet.range.end=NOW%2B1YEARS
> &f.onlinedate.facet.range.gap=NOW-1MONTHS, NOW-3MONTHS,
> NOW-6MONTHS,NOW-1YEAR
>
> But the solr complained Exception during facet.range of onlinedate
> org.apache.solr.common.SolrException: Can't add gap NOW-1MONTHS,
> NOW-3MONTHS, NOW-6MONTHS,NOW-1YEAR to value Mon Jul 26 11:56:40 CST 2010
> for
> ....
>
> What is correct way to make this requirement to realized? Please help on
> this.
> Floyd
>