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 prerna07 <pk...@sapient.com> on 2009/01/13 09:44:20 UTC

Issue in Facet on date field

Hi,

I have to create two facets on a date field:
1) First Facet will have results between two date range , i.e. [NOW TO
NOW+45DAYS]
2) Second Facet will have results between two date range , i.e. [NOW-45DAYS
TO NOW]

I want both results in a single query. The query i am using is mentioned
below :

&facet=true&facet.date=productPublicationDate_product_dt&f.productPublicationDate_product_dt.facet.date.start=NOW&f.productPublicationDate_product_dt.facet.date.end=NOW+45DAYS&f.productPublicationDate_product_dt.facet.date.gap=%2B45DAYS&facet.date=productPublicationDate_product_dt&f.productPublicationDate_product_dt.facet.date.start=NOW-45DAYS&f.productPublicationDate_product_dt.facet.date.end=NOW&f.productPublicationDate_product_dt.facet.date.gap=%2B45DAYS

ISSUE:
I am getting same response in two nodes, one query is overriding the
response of second facet:

- <lst name="facet_counts">
  <lst name="facet_queries" /> 
  <lst name="facet_fields" /> 
- <lst name="facet_dates">
- <lst name="productPublicationDate_product_dt">
  <int name="2009-01-13T08:37:26.662Z">0</int> 
  <str name="gap">+45DAYS</str> 
  <date name="end">2009-02-27T08:37:26.662Z</date> 
  </lst>
- <lst name="productPublicationDate_product_dt">
  <int name="2009-01-13T08:37:26.662Z">0</int> 
  <str name="gap">+45DAYS</str> 
  <date name="end">2009-02-27T08:37:26.662Z</date> 
  </lst>
  </lst>
  </lst>

Please suggest the way by which i can differentiate these two facet.field in
the query ?
-- 
View this message in context: http://www.nabble.com/Issue-in-Facet-on-date-field-tp21431422p21431422.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Issue in Facet on date field

Posted by prerna07 <pk...@sapient.com>.

There can be two other options:
1) To make 2 solr queries to get two facets
2) Use copy field of schema.xml.

Thanks,
Prerna


Marc Sturlese wrote:
> 
> Hey,
> That's because Solr just looks for one start,end and gap params in
> solrconfig.xml. It just allows you to do datefaceting for differents
> fields but just in one range period. 
> I was in the same situation as you are, what I did was modify the function
> getFacetDateCounts() from Simplefacets.class to make it get as match
> params (stard/end/gap) as I want. Once it's done I do date faceting in all
> time periods.
> Result would look like:
> 
> <lst name="facet_dates">
> <lst name="source_date">
> <int name="2008-10-13T00:00:00Z">2238</int>
> <str name="gap">+3MONTH</str>
> <date name="end">2009-01-13T00:00:00Z</date>
> <int name="2008-07-13T00:00:00Z">3822</int>
> <str name="gap">+6MONTH</str>
> <date name="end">2009-01-13T00:00:00Z</date>
> <int name="2008-01-13T00:00:00Z">3864</int>
> <str name="gap">+1YEAR</str>
> <date name="end">2009-01-13T00:00:00Z</date>
> </lst>
> </lst>
> 
> Doing facets for the last year, 6 month and 3 month.
> I don't think there's a way to do that without modifiying the source (if
> you find it let me know :D)
> 
> 
> 
> prerna07 wrote:
>> 
>> Hi,
>> 
>> I have to create two facets on a date field:
>> 1) First Facet will have results between two date range , i.e. [NOW TO
>> NOW+45DAYS]
>> 2) Second Facet will have results between two date range , i.e.
>> [NOW-45DAYS TO NOW]
>> 
>> I want both results in a single query. The query i am using is mentioned
>> below :
>> 
>> &facet=true&facet.date=productPublicationDate_product_dt&f.productPublicationDate_product_dt.facet.date.start=NOW&f.productPublicationDate_product_dt.facet.date.end=NOW+45DAYS&f.productPublicationDate_product_dt.facet.date.gap=%2B45DAYS&facet.date=productPublicationDate_product_dt&f.productPublicationDate_product_dt.facet.date.start=NOW-45DAYS&f.productPublicationDate_product_dt.facet.date.end=NOW&f.productPublicationDate_product_dt.facet.date.gap=%2B45DAYS
>> 
>> ISSUE:
>> I am getting same response in two nodes, one query is overriding the
>> response of second facet:
>> 
>> - <lst name="facet_counts">
>>   <lst name="facet_queries" /> 
>>   <lst name="facet_fields" /> 
>> - <lst name="facet_dates">
>> - <lst name="productPublicationDate_product_dt">
>>   <int name="2009-01-13T08:37:26.662Z">0</int> 
>>   <str name="gap">+45DAYS</str> 
>>   <date name="end">2009-02-27T08:37:26.662Z</date> 
>>   </lst>
>> - <lst name="productPublicationDate_product_dt">
>>   <int name="2009-01-13T08:37:26.662Z">0</int> 
>>   <str name="gap">+45DAYS</str> 
>>   <date name="end">2009-02-27T08:37:26.662Z</date> 
>>   </lst>
>>   </lst>
>>   </lst>
>> 
>> Please suggest the way by which i can differentiate these two facet.field
>> in the query ?
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Issue-in-Facet-on-date-field-tp21431422p21431934.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Issue in Facet on date field

Posted by Marc Sturlese <ma...@gmail.com>.
Hey,
That's because Solr just looks for one start,end and gap params in
solrconfig.xml. It just allows you to do datefaceting for differents fields
but just in one range period. 
I was in the same situation as you are, what I did was modify the function
getFacetDateCounts() from Simplefacets.class to make it get as match params
(stard/end/gap) as I want. Once it's done I do date faceting in all time
periods.
Result would look like:

<lst name="facet_dates">
<lst name="source_date">
<int name="2008-10-13T00:00:00Z">2238</int>
<str name="gap">+3MONTH</str>
<date name="end">2009-01-13T00:00:00Z</date>
<int name="2008-07-13T00:00:00Z">3822</int>
<str name="gap">+6MONTH</str>
<date name="end">2009-01-13T00:00:00Z</date>
<int name="2008-01-13T00:00:00Z">3864</int>
<str name="gap">+1YEAR</str>
<date name="end">2009-01-13T00:00:00Z</date>
</lst>
</lst>

Doing facets for the last year, 6 month and 3 month.
I don't think there's a way to do that without modifiying the source (if you
find it let me know :D)



prerna07 wrote:
> 
> Hi,
> 
> I have to create two facets on a date field:
> 1) First Facet will have results between two date range , i.e. [NOW TO
> NOW+45DAYS]
> 2) Second Facet will have results between two date range , i.e.
> [NOW-45DAYS TO NOW]
> 
> I want both results in a single query. The query i am using is mentioned
> below :
> 
> &facet=true&facet.date=productPublicationDate_product_dt&f.productPublicationDate_product_dt.facet.date.start=NOW&f.productPublicationDate_product_dt.facet.date.end=NOW+45DAYS&f.productPublicationDate_product_dt.facet.date.gap=%2B45DAYS&facet.date=productPublicationDate_product_dt&f.productPublicationDate_product_dt.facet.date.start=NOW-45DAYS&f.productPublicationDate_product_dt.facet.date.end=NOW&f.productPublicationDate_product_dt.facet.date.gap=%2B45DAYS
> 
> ISSUE:
> I am getting same response in two nodes, one query is overriding the
> response of second facet:
> 
> - <lst name="facet_counts">
>   <lst name="facet_queries" /> 
>   <lst name="facet_fields" /> 
> - <lst name="facet_dates">
> - <lst name="productPublicationDate_product_dt">
>   <int name="2009-01-13T08:37:26.662Z">0</int> 
>   <str name="gap">+45DAYS</str> 
>   <date name="end">2009-02-27T08:37:26.662Z</date> 
>   </lst>
> - <lst name="productPublicationDate_product_dt">
>   <int name="2009-01-13T08:37:26.662Z">0</int> 
>   <str name="gap">+45DAYS</str> 
>   <date name="end">2009-02-27T08:37:26.662Z</date> 
>   </lst>
>   </lst>
>   </lst>
> 
> Please suggest the way by which i can differentiate these two facet.field
> in the query ?
> 

-- 
View this message in context: http://www.nabble.com/Issue-in-Facet-on-date-field-tp21431422p21431727.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Issue in Facet on date field

Posted by Chris Hostetter <ho...@fucit.org>.
: I have to create two facets on a date field:
: 1) First Facet will have results between two date range , i.e. [NOW TO
: NOW+45DAYS]
: 2) Second Facet will have results between two date range , i.e. [NOW-45DAYS
: TO NOW]

the date faceting code is designed to generate counts for regular 
intervals of times (specified by "gap") between a fixed start and end.  
you could probably get what you want with something like...

  facet.date.start = NOW-45DAYS
  facet.date.end = NOW+45DAYS
  facet.date.gap = +45DAYS

...but to be perfectly honest, if you know you want exactly two counts, 
one for hte last 45 days and one for the next 45 days, then date faceting 
is overkill (and overly complicated) for your use case ... just use facet 
queries...

  facet.query=productPublicationDate_product_dt:[NOW-45DAYS TO NOW]
  facet.query=productPublicationDate_product_dt:[NOW TO NOW+45DAYS]

BTW: you'll probably want to replace "NOW" with "NOW/DAY" or "NOW/HOUR" to 
round down and get better cache utilization.


-Hoss