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