Forums / Extensions / ez Find filter by date

ez Find filter by date

Author Message

Lars Eirik R

Friday 08 October 2010 8:35:29 am

hi.

I would like to be able to only show upcoming events, not the once that have already taken place.

i have tried to use the following in the hash using ezfind search.

filter','event/from_time:[NOW-60DAY TO NOW/DAY+20DAY]

I am unable to get this to work for me.

When i however run 'filter','published[NOW......] it works.

How should i go about handling filtering for my dates?

Any example is greatly appreciated.

Christian Rößler

Friday 08 October 2010 10:03:55 am

Hy Lars,

try this to implement a range match...

{... , hash( ...,
            'filter', array( 'and',
                             'event/from_time:[xxx TO *]',
                             'event/from_time:[* TO xxx]' ) ) )}

But this still leaves you to determine the xxx variables (now - xx days).

I'm still looking for some documentation on solr date/time fields. I guess date and datetime fields in ezpublish are translated into unix timestamps which are also timestamps in solr. So instead of writing 'NOW-60DAYs' you could use some timestamp value? But thats just a guess. I am looking throu the solr documentation which ezfind relies on.

cheers,

chris

Hannover, Germany
eZ-Certified http://auth.ez.no/certification/verify/395613

Christian Rößler

Friday 08 October 2010 10:19:48 am

ok, found the page: http://lucene.apache.org/solr/api/org/apache/solr/util/DateMathParser.html

I think it should be:

... 'filter','event/from_time:[-60DAY TO +20DAY]' ...

because the solr documentation says:

 -1DAY      ... Exactly 1 day prior to now

Thats interesting. Can you verify/check that please? Well... you got that already according to this link here: http://wiki.apache.org/solr/SolrQuerySyntax

timestamp:[* TO NOW]
createdate:[1976-03-06T23:59:59.999Z TO *]
createdate:[1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z]
pubdate:[NOW-1YEAR/DAY TO NOW/DAY+1DAY]
createdate:[1976-03-06T23:59:59.999Z TO 1976-03-06T23:59:59.999Z+1YEAR]
createdate:[1976-03-06T23:59:59.999Z/YEAR TO 1976-03-06T23:59:59.999Z]

You are already using the correct syntax. Are there any solr-parser errors in the error.log ?

Hannover, Germany
eZ-Certified http://auth.ez.no/certification/verify/395613

Christian Rößler

Friday 08 October 2010 10:57:09 am

gnaaahhh, I feel so noobish - sorry for spamming such posts here.

I managed to create a demo search on my current data with this tempalte code snippet:

{def $x = fetch( 'ezfind', 'search', hash( 'class_id', 'product',                                  
                                           'filter', array( 'product/publish_date:[NOW-60DAY TO NOW+20DAY]' ) ) )}
{$x|attribute('show')}

And it works and returns the articles/objects/products i need.

What does NOT work and returns errors:

[-60DAY TO +20DAY]  ->   Invalid Date String:'-1DAY'

So hopefully it could help you!

Chris

Hannover, Germany
eZ-Certified http://auth.ez.no/certification/verify/395613

Lars Eirik R

Sunday 10 October 2010 11:40:28 pm

{def $results =fetch(ezfind, search, hash('query','',
'class_id',array('event'),
'limit',10,
'subtree_array',$subtree_array,
'filter',array('event/from_time:[NOW-2DAY TO NOW+20DAY]')
))}

I tried the following now, and i get no result nodes, although they should exist.

Please anyone else have experience with using a date_time attribute and doing search with ezfind?

Thanks for all the help Christian.

Christian Rößler

Monday 11 October 2010 12:12:39 am

Well, but now the date/time filter is correct. If you still don't get results, check the following:

  • ezpublish errorlog
  • is ezfind up and running
  • has ezfind an up-to-date index on your contentobjects
  • what is in the variable $subtree_array you pass to the fetch-function
  • are your event-objects filled with from_time values

cheers,
chris

Hannover, Germany
eZ-Certified http://auth.ez.no/certification/verify/395613

Lars Eirik R

Monday 11 October 2010 1:11:29 am

Thanks again Christian. Just had a look at this installation. I am new on this existing project, and it turns out that the from_time attribute is not indicated to be searchable.. Waiting for the reindexing to take place..

Could this be the reason why is has ignored my search?

Will post follow up soon.

Lars Eirik R

Monday 11 October 2010 1:37:12 am

I would like to extend my gratitude to Christian:)

It turned out that the old site was not configured to allow searching for the datatfield i was referring to. This was because it was a pre-ezfind installation originally. I have now upgraded this to ezpublishenterprise4.4 and the field is now searchable and it now works like expected:)

Christian Rößler

Monday 11 October 2010 2:11:10 am

Awesome! I'm glad it works now.

Indeed, any class-attribute that is not marked as 'is searchable' ezFind ignores and thus you cannot search for those attributes.

You did right: enabling the search for this attribute and re-index the content.

And this is a common problem I face often: attributes not marked as 'is searchable' and I always spend hours to figure out why my code does not find anything ;-)

Hannover, Germany
eZ-Certified http://auth.ez.no/certification/verify/395613

eZ debug

Timing: Jan 17 2025 23:58:19
Script start
Timing: Jan 17 2025 23:58:19
Module start 'content'
Timing: Jan 17 2025 23:58:20
Module end 'content'
Timing: Jan 17 2025 23:58:20
Script end

Main resources:

Total runtime1.1893 sec
Peak memory usage4,096.0000 KB
Database Queries213

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0071 587.7031180.8516
Module start 'content' 0.00711.0191 768.5547624.2891
Module end 'content' 1.02630.1629 1,392.8438344.4453
Script end 1.1892  1,737.2891 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00450.3743210.0002
Check MTime0.00160.1319210.0001
Mysql Total
Database connection0.00090.072010.0009
Mysqli_queries1.094592.03412130.0051
Looping result0.00230.19542110.0000
Template Total1.153397.020.5767
Template load0.00210.177720.0011
Template processing1.151296.797820.5756
Template load and register function0.00010.008810.0001
states
state_id_array0.00250.214410.0025
state_identifier_array0.00300.248320.0015
Override
Cache load0.00190.1633750.0000
Sytem overhead
Fetch class attribute can translate value0.00160.135730.0005
Fetch class attribute name0.00110.0966100.0001
XML
Image XML parsing0.00080.066430.0003
class_abstraction
Instantiating content class attribute0.00000.0018130.0000
General
dbfile0.00710.5964270.0003
String conversion0.00000.000730.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
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
16content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 43
 Number of unique templates used: 10

Time used to render debug report: 0.0002 secs