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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 00:54:45
Script start
Timing: Jan 30 2025 00:54:45
Module start 'layout'
Timing: Jan 30 2025 00:54:45
Module start 'content'
Timing: Jan 30 2025 00:54:45
Module end 'content'
Timing: Jan 30 2025 00:54:45
Script end

Main resources:

Total runtime0.0180 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0081 588.1250151.2109
Module start 'layout' 0.00810.0043 739.335936.6563
Module start 'content' 0.01240.0043 775.9922102.8594
Module end 'content' 0.01670.0012 878.851641.9766
Script end 0.0179  920.8281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002815.8184140.0002
Check MTime0.00137.3561140.0001
Mysql Total
Database connection0.00116.292410.0011
Mysqli_queries0.004525.294130.0015
Looping result0.00000.122010.0000
Template Total0.00095.010.0009
Template load0.00073.810710.0007
Template processing0.00021.134110.0002
Override
Cache load0.00052.514810.0005
General
dbfile0.00041.968480.0000
String conversion0.00000.078340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs