Forums / Developer / Search byrange with 2 dates

Search byrange with 2 dates

Author Message

Fabien Mas

Friday 31 August 2007 7:16:49 am

I try to implement a search form with 2 dates in a directory
I have a "from" date and a "to" date in my form

I want to search with 2 dates in my datas (d1 & d2)
if (from <=d1<=to) or (from <=d2<=to), this directory element should be returned

I tried to hack the advancedsearch.php, ezsearchengine.php and ezsearch.php files but with no success

any one has already done it ?

thx,
Fabien

Heath

Monday 03 September 2007 1:00:58 am

I'm certain this could be done!

Perhaps it would require a custom 'search plugin',
take a look at the doxygen documentation and existing search plugins available.

<i>http://pubsvn.ez.no/doxygen/trunk/html/classeZSearch.html</i>
<i>http://pubsvn.ez.no/nextgen/trunk/kernel/search/plugins/ezsearchengine/ezsearchengine.php</i>
This is a stub on the topic of search, <i>http://ezpedia.org/wiki/en/ez/search</i>

It sure looks like you can pass an array of datetime stamps to the default search plugin search method to perform the type of search you looking to use.

if ( $searchTimestamp )
                {
                    if ( is_array( $searchTimestamp ) )
                    {
                        $publishedDate = $searchTimestamp[0];
                        $publishedDateStop = $searchTimestamp[1];
                    }
                    else
                        $publishedDate = $searchTimestamp;
                }

From:
<i>http://pubsvn.ez.no/nextgen/trunk/kernel/search/plugins/ezsearchengine/ezsearchengine.php</i>

Here is a custom example of using the search method (but it does not use timestamps)

function search_ezcontenttree( $searchStr )
{
  include_once( "kernel/classes/ezsearch.php" );

  // TODO: Replace these with ini settings, bcsoapsearch.ini.append.php

  // $maximumSearchLimit = $ini->variable( 'SearchSettings', 'MaximumSearchLimit' );
  $searchText = $searchStr;

  $searchSectionID = -1;
  $searchType = "fulltext";

  $searchTimestamp = false;
  // $subTreeArray = array();
  $subTreeArray[] = 1;

  $pageLimit = 5;
  $Offset = 0;

  $searchResult = eZSearch::search( $searchText, array( "SearchType" => $searchType,
							"SearchSectionID" => $searchSectionID,
							"SearchSubTreeArray" => $subTreeArray,
							'SearchTimestamp' => $searchTimestamp,
							"SearchLimit" => $pageLimit,
							"SearchOffset" => $Offset ) );

  // print_r( $searchResult );
  // return $searchResult;
  return $searchResult['SearchResult'];
  }

From: <i>http://svn.projects.ez.no/bcsoapsearch/trunk/extension/bcsoapsearch/services/bcsoapsearch.php</i>

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

André R.

Monday 03 September 2007 1:16:20 am

You don't need to hack anything to accomplish this, you just need to read the doc.

For searching, you can set the 'publish_timestamp' ( or 'SearchTimestamp' if you use the php api ), from the doc:

The "publish_timestamp" parameter makes it possible to search objects with the specified publishing date/time. This value must be a UNIX timestamp. You can also use an array of two elements in order to search within the given range.

If the date you are referring to is not the publish date but dates in a content object data map, you can use a fetch with attribute filter instead, examples of that can be found in the calendar code:
http://zev.ez.no/svn/extensions/ezwebin/trunk/packages/ezwebin_extension/ezextension/ezwebin/design/ezwebin/override/templates/full/event_view_calendar.tpl

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Fabien Mas

Monday 03 September 2007 5:15:06 am

Andre,
I am not sure to do it with your answer.
I can not fetch object attributes, I do a search with a lot of criteria, not only with dates and in fulltext mode those informations are stored in the ezsearch_word* tables ...

My object class (event) :
City
Description
Beginning_date
Ending_date
Place ...

My search criteria
full text on City, Description ..
date (from/to) on Beginning_date, Ending_date

Fabien Mas

Monday 03 September 2007 5:37:34 am

I use the Content_search_attribute_byrange_classattribute_id, with 2 values, but the only one (the first) is taken ..

André R.

Monday 03 September 2007 6:11:35 am

It would be easier to help you if you posted your search code.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Fabien Mas

Thursday 06 September 2007 1:05:35 am

It's too complicated to post my code.
I have finally done it, but with a lot of hacks in ezsearchengine.php ..

thx for your help, Fabien