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 Marc Sturlese <ma...@gmail.com> on 2009/04/28 10:48:02 UTC

Multiple Facet Dates

Hey there,
I needed to have a multiple date facet functionality. Like say for example
to show the latests results in the last day, last week and last month. I
wanted to do it with just one query. 
The date facet part of solrconfig.xml would look like:

      <str name="facet.date">date_field</str>
      <str name="facet.date.start">NOW/DAY-1DAY</str>
      <str name="facet.date.start">NOW/DAY-7DAY</str>
      <str name="facet.date.start">NOW/DAY-30DAY</str>

      <str name="facet.date.end">NOW/DAY+1DAY</str>
      <str name="facet.date.end">NOW/DAY+1DAY</str>
      <str name="facet.date.end">NOW/DAY+1DAY</str>

      <str name="facet.date.gap">+2DAY</str>
      <str name="facet.date.gap">+8DAY</str>
      <str name="facet.date.gap">+31DAY</str>

What I have done to have it working is do some changes at
getFacetdateCounts() in SimpleFacets.java

Instead of getting start,end and gap params as String I get them as array of
strings. 
I would have 3 array. In the first position of each would have the first
start, the first ends and the firs gap. Same for the second and thirth( in
my example )
Once I have them I do exactly what the function did before but for every
position of the array.

The resultant output looks like this:

<lst name="facet_dates">
  <lst name="date_field">
    <int name="2009-04-27T00:00:00Z">21</int>
    <str name="gap">+2DAY</str>
    <date name="end">2009-04-29T00:00:00Z</date>
    <int name="2009-04-21T00:00:00Z">86</int>
    <str name="gap">+8DAY</str>
    <date name="end">2009-04-29T00:00:00Z</date>
    <int name="2009-03-29T00:00:00Z">316</int>
    <str name="gap">+31DAY</str>
    <date name="end">2009-04-29T00:00:00Z</date>
  </lst>
</lst>

I am doing it just for testing. This works for me but maybe would be
confusing to parse the output for other examples (let's say when you need to
repeat the gap to cover all the range).

Does someone think that could be good to have this functionality? In case
yes I could post what I have and do it in the right way it in case someone
points me in the right direction.

Thanks in advance

-- 
View this message in context: http://www.nabble.com/Multiple-Facet-Dates-tp23272868p23272868.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Multiple Facet Dates

Posted by Marc Sturlese <ma...@gmail.com>.
Good solution without touching any code! Thank you very much.
I have already used the "key function" for query facets. I use it to send to
the xml response a different word/sentence than the one I use to do the
proper faceting. It has been really useful
Thank you.


Erik Hatcher wrote:
> 
> 
> On May 1, 2009, at 8:23 PM, Yonik Seeley wrote:
>> On Fri, May 1, 2009 at 8:06 PM, Chris Hostetter
>> <ho...@fucit.org> wrote:
>>>        facet.date.gap = +1MONTH
>>>        facet.date = {!key=begin_month}begin_df
>>>        f.begin_month.date.start = NOW/MONTH-1YEAR
>>>        f.begin_month.date.end = NOW/MONTH+1MONTH
>>
>> Another syntax alternative is to allow start/end as local params:
>>
>> facet.date={!key=begin_month start=NOW/MONTH-1YEAR
>> end=NOW/MONTH+1MONTH}begin_df
> 
> +1, I like it.
> 
> 	Erik
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Multiple-Facet-Dates-tp23272868p23366696.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Multiple Facet Dates

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On May 1, 2009, at 8:23 PM, Yonik Seeley wrote:
> On Fri, May 1, 2009 at 8:06 PM, Chris Hostetter
> <ho...@fucit.org> wrote:
>>        facet.date.gap = +1MONTH
>>        facet.date = {!key=begin_month}begin_df
>>        f.begin_month.date.start = NOW/MONTH-1YEAR
>>        f.begin_month.date.end = NOW/MONTH+1MONTH
>
> Another syntax alternative is to allow start/end as local params:
>
> facet.date={!key=begin_month start=NOW/MONTH-1YEAR
> end=NOW/MONTH+1MONTH}begin_df

+1, I like it.

	Erik


Re: Multiple Facet Dates

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Fri, May 1, 2009 at 8:06 PM, Chris Hostetter
<ho...@fucit.org> wrote:
>        facet.date.gap = +1MONTH
>        facet.date = {!key=begin_month}begin_df
>        f.begin_month.date.start = NOW/MONTH-1YEAR
>        f.begin_month.date.end = NOW/MONTH+1MONTH

Another syntax alternative is to allow start/end as local params:

 facet.date={!key=begin_month start=NOW/MONTH-1YEAR
end=NOW/MONTH+1MONTH}begin_df

-Yonik
http://www.lucidimagination.com

Re: Multiple Facet Dates

Posted by Chris Hostetter <ho...@fucit.org>.
: I needed to have a multiple date facet functionality. Like say for example
: to show the latests results in the last day, last week and last month. I
: wanted to do it with just one query. 
: The date facet part of solrconfig.xml would look like:
: 
:       <str name="facet.date">date_field</str>
:       <str name="facet.date.start">NOW/DAY-1DAY</str>
:       <str name="facet.date.start">NOW/DAY-7DAY</str>
:       <str name="facet.date.start">NOW/DAY-30DAY</str>
	...
: Instead of getting start,end and gap params as String I get them as array of
: strings. 
: I would have 3 array. In the first position of each would have the first
: start, the first ends and the firs gap. Same for the second and thirth( in
: my example )

Be careful here, you need to consider what happens when your new code 
interacts with per field overrides (ie: date faceting on multipe date 
fields) which is currently supported...

	facet.date.gap = +1DAY
	facet.date = begin_df
	f.begin_df.date.start = NOW/DAY-10DAY
	f.begin_df.date.end = NOW/DAY+1DAY
	facet.date = finish_df
	f.finish_df.date.start = NOW/DAY
	f.finish_df.date.end = NOW/DAY+10DAY

...note that people can mix and match, some fields may have specific 
values for some params, but other fields might get the "common" param 
value.  

(Ideally people should be able to do the same type of "field" specific 
override for certain instances of the faceting on a specific field.)

We've discussed how hard something like this would be on the list before, 
but your post has got me thinking about it again...

What would probably work a bit cleaner then trying to do parallel array 
walking of the various params, would be to borrow the "key" syntax yonik 
introduced with field faceting, and do something similar...

	facet.date.gap = +1MONTH
	facet.date = {!key=begin_month}begin_df
	f.begin_month.date.start = NOW/MONTH-1YEAR
	f.begin_month.date.end = NOW/MONTH+1MONTH
	// begin_month inherits facet.date.gap
	facet.date = {!key=begin_day}begin_df
        f.begin_day.date.start = NOW/DAY-1MONTH
        f.begin_day.date.end = NOW/DAY+1DAY
        f.begin_day.date.gap = +1DAY
	facet.date = {!key=finish_month}begin_df
	f.finish_month.date.start = NOW/MONTH
	f.finish_month.date.end = NOW/MONTH+1YEAR
	// finish_month inherits facet.date.gap
	facet.date = {!key=begin_day}begin_df
        f.finish_day.date.start = NOW/DAY
        f.finish_day.date.end = NOW/DAY+1MONTH
        f.finish_day.date.gap = +1DAY

..that would also solve the ambiguity of the output -- because they "key" 
can be used as the key in the  facet_dates NamedList.

what do you think?



-Hoss