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

eZ debug

Timing: Jan 31 2025 04:24:24
Script start
Timing: Jan 31 2025 04:24:24
Module start 'content'
Timing: Jan 31 2025 04:24:24
Module end 'content'
Timing: Jan 31 2025 04:24:24
Script end

Main resources:

Total runtime0.1441 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 587.9297180.8359
Module start 'content' 0.00590.0055 768.7656101.9922
Module end 'content' 0.01130.1327 870.7578530.5234
Script end 0.1440  1,401.2813 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00312.1726200.0002
Check MTime0.00130.9021200.0001
Mysql Total
Database connection0.00090.626110.0009
Mysqli_queries0.097167.40971410.0007
Looping result0.00100.71581390.0000
Template Total0.132491.910.1324
Template load0.00070.495510.0007
Template processing0.131691.353110.1316
Override
Cache load0.00050.343510.0005
Sytem overhead
Fetch class attribute can translate value0.00080.554410.0008
XML
Image XML parsing0.00030.184510.0003
General
dbfile0.01077.3962200.0005
String conversion0.00000.003630.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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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