4

I have an event table which has start date and end date like this

==============================================
id   |   name       | start_date |  end_date
==============================================
1    | Test Event 1 | 2011-11-20 | 2011-12-20 
----------------------------------------------
2    | My Event 2   | 2011-12-05 | 2011-12-26 
----------------------------------------------
3    | My Event 3   | 2012-12-26 | 2012-01-11
----------------------------------------------

Now I want to have a solr facet which looks like this and i can't seem to get the params right.

==================
Dates 
------------------
Today [2]
This Week [2]
This Month [2]
Next Month [1]

Please note that the facet has to consider both start date and end date. Sort of gouping ?

What should be the faceting parameters for this ?

Thanks in advance for any help.

Mahbub
  • 3,108
  • 24
  • 29
  • 1
    which version of solr you are using? And maybe you should include your example of query – ajreal Dec 05 '11 at 11:50
  • I'm using apache solr 3.40 with Solarium client for PHP. Solarium doesn't have built in functionality like this grouped facted search but once i get the parameters right and see it's working on the web interface i can make it work. – Mahbub Dec 05 '11 at 13:12
  • How do you define the 'today' facet? Is it an event that *started* today but may finish tomorrow? Is it an event that is completely contained (start and end) today? Is it an event that has any intersection with today (be it start or end)? – Mauricio Scheffer Dec 06 '11 at 20:23
  • Yes, Today means stared today but may finish tomorrow or even 7 days later. I mean today is between start_date and end_date (like sql query). Similarly This month means any event date started any day last month but will finish this month or start and finish within this month. It's about the span of start_date and end_date which falls under current date or current month, next month etc. – Mahbub Dec 07 '11 at 06:39

2 Answers2

3

I finally got it working using solarium libraries Facet Multi Query based on the example http://wiki.solarium-project.org/index.php/V2:Facet_multiquery

The part in my Zend App looks like

$dateFacetSet = $query->getFacetSet();
$dateFacet = $dateFacetSet->createFacetMultiQuery('dates');
$dateFacet->createQuery('Today', 'type:event AND sdate:[* TO NOW/DAY] AND edate:[NOW/DAY TO * ]');
$dateFacet->createQuery('This-Week', 'type:event AND sdate:[* TO ' . $this->view->date_w["end"] . 'T23:59:59Z] AND edate:[' . $this->view->date_w["start"] . 'T00:00:00Z TO * ]');
$dateFacet->createQuery('This-Month', 'type:event AND sdate:[* TO ' . $this->view->date_m["end"] . 'T23:59:59Z] AND edate:[' . $this->view->date_m["start"] . 'T00:00:00Z TO * ]');

If anyone wants to know more, please let me know.

These params catch what i needed so far but haven't tested extensively.

Mahbub
  • 3,108
  • 24
  • 29
0

You can put $startdate.'T01:00:59Z' $enddate.'T23:59:59Z'

Jay Bharat
  • 691
  • 7
  • 6