Share » Forums » Extensions » eZ Find » Attribute Filter on Date

Attribute Filter on Date

Attribute Filter on Date

Monday 16 March 2009 12:09:13 am - 9 replies

Author Message

Greg Lakomy

Monday 16 March 2009 10:30:09 am

Hi,

I need to filter on a date attribute as well. I've used concat() to build a filter which ends up in this format: "event_page/event_start_date:[1237179600 TO 1239816199]"
But, it doesn't seem to work either.

Any solutions?

Greg.

Developer
http://www.duoconsulting.com

Greg Lakomy

Monday 16 March 2009 11:16:44 am

I found a solution. See this page for more details http://wiki.apache.org/solr/SolrQuerySyntax

Here is my code that works:

{set $search = fetch( ezfind, search,
		hash( 'query', $search_text,
		'sort_by', hash('event_page/event_start_date', asc),
		'offset', $view_parameters.offset,
		'section_id', 10,
		'subtree_array', $search_subtree_array,
		'filter', 'event_page/event_end_date:[NOW TO NOW/DAY+30DAY]',
		'class_id', array( '48' ),
		'class_attribute_id', $search_field,
		'limit', $page_limit ) ) }

Developer
http://www.duoconsulting.com

A Costello

Monday 16 March 2009 3:24:18 pm

Very much appreciated.
I am very hopeful as the information in that link and your example look great.

Paul Borgermans

Monday 16 March 2009 4:24:15 pm

Since eZ Find 2.0, dates you specify explicitly need to be in in a dedicated format, ISO 8601 Date (more or less)

example: 20089-03-17T23:59:59.999Z

You can use the template operators to construct a date from a timestamp returned by published date or other source

The Solr syntax date math constructs are indeed pretty powerful ... like the rest of Solr

hth
Paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Sylvain Gogel

Wednesday 25 March 2009 2:18:15 am

very nice,
can i use this
'filter', 'event_page/event_end_date:[NOW TO NOW/DAY+30DAY]'

for the published attribute? i.e. something not in the data_map?

--
http://www.ecedi.fr
Agence Web, Créa/Conseils, Accessibilité
eZPublish, Drupal, Zend, Symfony

Sylvain Gogel

Friday 27 March 2009 10:35:17 am

Works with $node.published!!

{def $searchHash = hash(
	'query', $search_text,
	'offset', $view_parameters.offset,
	'limit', $page_limit,
	'sort_by', hash('published', 'desc', 'relevance', 'desc' ),
	'spell_check', array( true(), 'default' ),
	'section_id', ezini('SectionSettings', 'StandardSectionId', 'content.ini')),
        'filter' 'published:[NOW-90DAY TO NOW/DAY+1DAY]'}

{set $search_data = fetch( 'ezfind', 'search', $searchHash)}

--
http://www.ecedi.fr
Agence Web, Créa/Conseils, Accessibilité
eZPublish, Drupal, Zend, Symfony

Philipp Kamps

Friday 15 October 2010 5:25:05 am

Since eZ Find 2.0, dates you specify explicitly need to be in in a dedicated format, ISO 8601 Date (more or less)

example: 20089-03-17T23:59:59.999Z

You can use the template operators to construct a date from a timestamp returned by published date or other source

The Solr syntax date math constructs are indeed pretty powerful ... like the rest of Solr

hth
Paul

Would be nice if the ezfind extension would have a function which translate a unix timestamp to the ISO 8601 date format.

The PHP interpretation of ISO 8601 "date( 'c' )" doesn't work.

http://www.mugo.ca
Mugo Web, eZ Partner in Vancouver, Canada

Richard Bayet

Monday 22 November 2010 10:23:36 am

Would be nice if the ezfind extension would have a function which translate a unix timestamp to the ISO 8601 date format.

The PHP interpretation of ISO 8601 "date( 'c' )" doesn't work.

In eZ Find 2.2 (haven't check in previous version), it does.

extension/ezfind/classes/ezfsolrdocumentfieldbase.php

/**
     * Convert timestamp to Solr date
     * See also: http://www.w3.org/TR/xmlschema-2/#dateTime
     *
     * @param int Timestamp
     *
     * @return string Solr datetime
     */
    static function convertTimestampToDate( $timestamp )
    {

        return strftime( '%Y-%m-%dT%H:%M:%S.000Z', (int)$timestamp );
    }

It's used internaly by ezfSolrDocumentFieldBase::preProcessValue from ezfeZPSolrQueryBuilder::buildSearch when a "SearchDate" param is passed to the fetch.

Regards.

Ronan Guilloux

Tuesday 26 April 2011 3:29:48 am

Here is an example to fetch today's events with mandatory from / to dates,

{def
$picked_date_array = ezhttp('choisissez_votre_jour','get')|explode('/')
$date_to_now = sum(-86400, maketime( 23,59,59, $picked_date_array.1, $picked_date_array.0, $picked_date_array.2))|datetime( 'custom', '%Y-%m-%dT%H:%i:%s.000Z' )

$date_from_now = maketime( 0,0,1, $picked_date_array.1, $picked_date_array.0,$picked_date_array.2)|datetime( 'custom', '%Y-%m-%dT%H:%i:%s.000Z' )

$filter_date_to_now = concat( 'date/from_date:[* TO ', $date_to_now, ']' )
$filter_date_from_now = concat( 'date/to_date:[', $date_from_now,' TO *]' )
$event_list = fetch( 'ezfind', 'search', hash( 'class_id', array('event', 'date'), 'sort_by', hash( 'date/from_date', 'asc' ), 'filter', array(and,$filter_date_to_now, $filter_date_from_now) ) )

}

--
Ronan Guilloux

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu