eZ Community » Forums » Extensions » eZ Find » Attribute Filter on Date
expandshrink

Attribute Filter on Date

Attribute Filter on Date

Monday 16 March 2009 8:09:13 am - 15 replies

Our search results currently show articles before they are available to the general public. To control when items are visible there is a publish_date that is set by our editors.

I have not had any success with this thus far. My best guess is I would filter on the publish date (although I worry this will lose the search capabilities on other classes?). From the documentation the only way I can think to try is:
'filter', 'article/publish_date:[* TO 1237186789]' (where 1237... is the current timestamp). I built the filter using concat

{def $filter = concat('article/publish_date:[* TO ', currentdate() ,']')}

With the

    {set $search=fetch( ezfind,search,
                        hash( 'query', $search_text,
                              'filter', array($filter),
                              'offset', $view_parameters.offset,
                              'limit', $page_limit,
                              'sort_by', hash( 'score', 'desc' ),
                              'facet', $facetParameters ))}

If this worked (which it doesn't) I worry that the results will still be unacceptable since all other classes are lost.

Any help would be greatly appreciated.

Monday 16 March 2009 6:30:09 pm

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.

Monday 16 March 2009 7:16:44 pm

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 ) ) }

Modified on Monday 16 March 2009 7:17:11 pm by Greg Lakomy

Monday 16 March 2009 11:24:18 pm

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

Tuesday 17 March 2009 12:24:15 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

Wednesday 25 March 2009 10: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?

Friday 27 March 2009 6:35:17 pm

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)}

Friday 15 October 2010 2:25:05 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

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.

Monday 22 November 2010 7:23:36 pm

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.

Tuesday 26 April 2011 12:29:48 pm

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) ) )

}

Modified on Tuesday 26 April 2011 2:10:40 pm by Ronan Guilloux

Thursday 16 February 2012 1:00:33 pm

Hello,

today I'm struggling with the same date datatype filter issue. I'm not able to do any search using date attribute at all and I don't know why sad.gif Emoticon

I'm trying to filter objects with attributes, that values are between today.

start_date < NOW &end_date > NOW

ezfind creates filter string and passes to solr:

( meta_contentclass_id_si:48 AND attr_date_de_fin_de_l_evenement_dt:\[NOW TO \*\] ) AND ( meta_contentclass_id_si:48 AND attr_date_de_debut_de_l_evenement_dt:\[\* TO NOW\] )

but solr retuns error:

>Error 400 Invalid Date String:'[NOW'

Well, it seems that adding slashes to this filter can be a problem, I tried to make the same query in solr/admin and had the same error when passing qf with slashes, and it work perfectly without them. I'm not 100% sure if they are needed here, maybe for specific chars, but not for  [ ] * probably. Maybe, problem is completly different.

I also tried with formated date as in above examples, still without luck.

Can somebody help me ? I'm using eZFind 2.7.0-dev with eZPublish 2011.12 installed on Ubuntu, php 5.3.5

Monday 05 March 2012 1:27:41 pm

Hello Bartek

I upgrade ezfind to 2.6 and I have exactly the same problem as you :

 subattr_class_atc___name____s:Manifestations culturelles AND attr_date_fin_dt:\[NOW TO \*\]

Did you find a solution ?

Thanks

Monday 05 March 2012 1:38:54 pm

Hi Solène,

Yes, solution is described in the following thread: http://share.ez.no/forums/extensions/ez-find/resolved-issue-187041-breaks-example-code-using-range-filters

Good luck

Monday 05 March 2012 1:57:54 pm

Bartek

Thank you for your response. I replaced the constant CHARS_TO_ESCAPE in ezfezpsolrquerybuilder.php, and now I have :

 AND meta_published_dt:[NOW TO \*]

I saw that you had the same filter as me, so did you find a solution for your [* TO NOW] filter ???

Thank you

Monday 05 March 2012 2:04:28 pm

Sorry I'm stupid !!!

I removed the char * from the contant CHARS_TO_ESCAPE and it works !

Thanks for your help

Wednesday 29 August 2012 8:57:18 pm

Quote from Richard Bayet :

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.

Regarding the Solr date format, this has now been added as a pre-set format for the datetime template operator in this pull request:

https://github.com/ezsystems/ezfind/pull/68

Usage in a template:

{$unix_timestamp|datetime( 'solr' )}

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from