Forums / Extensions / eZ Find / Attribute Filter on Date

Attribute Filter on Date

Author Message

A Costello

Monday 16 March 2009 12:09:13 am

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.

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

eZ debug

Timing: Jan 17 2025 23:50:58
Script start
Timing: Jan 17 2025 23:50:58
Module start 'content'
Timing: Jan 17 2025 23:50:59
Module end 'content'
Timing: Jan 17 2025 23:50:59
Script end

Main resources:

Total runtime0.7405 sec
Peak memory usage4,096.0000 KB
Database Queries227

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0072 587.7422180.7813
Module start 'content' 0.00720.6126 768.5234835.5938
Module end 'content' 0.61990.1205 1,604.1172353.3047
Script end 0.7404  1,957.4219 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00440.5940210.0002
Check MTime0.00150.2082210.0001
Mysql Total
Database connection0.00070.098710.0007
Mysqli_queries0.645687.17742270.0028
Looping result0.00240.32982250.0000
Template Total0.714996.520.3575
Template load0.00220.293020.0011
Template processing0.712796.245120.3564
Template load and register function0.00030.034710.0003
states
state_id_array0.00050.069010.0005
state_identifier_array0.00090.125620.0005
Override
Cache load0.00200.2741730.0000
Sytem overhead
Fetch class attribute can translate value0.00220.300780.0003
Fetch class attribute name0.00140.1824140.0001
XML
Image XML parsing0.00280.377080.0003
class_abstraction
Instantiating content class attribute0.00000.0038150.0000
General
dbfile0.00250.3416450.0001
String conversion0.00000.000830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
10content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
21content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
5content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 53
 Number of unique templates used: 8

Time used to render debug report: 0.0002 secs