Limit and offset added to search criteria.

This commit is contained in:
tomas 2005-01-18 00:17:44 +00:00
parent 357d1b29c0
commit 2c3a0f9b39
3 changed files with 35 additions and 18 deletions

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.19 $ Version : $Revision: 1.20 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -50,7 +50,7 @@ require_once "StoredFile.php";
* Core of LiveSupport file storage module * Core of LiveSupport file storage module
* *
* @author $Author: tomas $ * @author $Author: tomas $
* @version $Revision: 1.19 $ * @version $Revision: 1.20 $
* @see Alib * @see Alib
*/ */
class BasicStor extends Alib{ class BasicStor extends Alib{
@ -565,7 +565,7 @@ class BasicStor extends Alib{
* @return hash, field 'results' is an array with gunid strings * @return hash, field 'results' is an array with gunid strings
* of files have been found * of files have been found
*/ */
function bsLocalSearch($criteria) function bsLocalSearch($criteria, $limit, $offset)
{ {
$operators = array('and'=>'AND', 'or'=>'OR'); $operators = array('and'=>'AND', 'or'=>'OR');
$ops = array('full'=>"='%s'", 'partial'=>"like '%%%s%%'", 'prefix'=>"like '%s%%'", $ops = array('full'=>"='%s'", 'partial'=>"like '%%%s%%'", 'prefix'=>"like '%s%%'",
@ -589,6 +589,7 @@ class BasicStor extends Alib{
$whereArr[] = "$sqlCond"; $whereArr[] = "$sqlCond";
} }
$selPart = "SELECT DISTINCT to_hex(f.gunid)as gunid, f.ftype as filetype"; $selPart = "SELECT DISTINCT to_hex(f.gunid)as gunid, f.ftype as filetype";
$limitPart = ($limit != 0 ? " LIMIT $limit" : '' ).($offset != 0 ? " OFFSET $offset" : '' );
$ftypeCond = " AND f.ftype='$filetype'"; $ftypeCond = " AND f.ftype='$filetype'";
if($operator == 'and'){ if($operator == 'and'){
// operator: and // operator: and
@ -616,11 +617,12 @@ class BasicStor extends Alib{
"INNER JOIN {$this->filesTable} f ON md.gunid=f.gunid $ftypeCond\n". "INNER JOIN {$this->filesTable} f ON md.gunid=f.gunid $ftypeCond\n".
"WHERE ".join(' OR ', $whereArr); "WHERE ".join(' OR ', $whereArr);
} }
$res = $this->dbc->getCol($sql); $rh = $this->dbc->query($sql); $cnt = $rh->numRows(); $rh->free();
$res = $this->dbc->getCol($sql.$limitPart);
if(!is_array($res)) $res = array(); if(!is_array($res)) $res = array();
$res = array_map(array("StoredFile", "_normalizeGunid"), $res); $res = array_map(array("StoredFile", "_normalizeGunid"), $res);
# return array('sql'=>$sql, 'results'=>$res); # return array('sql'=>$sql, 'results'=>$res);
return array('results'=>$res); return array('results'=>$res, 'cnt'=>$cnt);
} }
/* --------------------------------------------------------- info methods */ /* --------------------------------------------------------- info methods */

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.21 $ Version : $Revision: 1.22 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -273,25 +273,38 @@ class LocStor extends BasicStor{
*/ */
function searchMetadata($sessid, $criteria) function searchMetadata($sessid, $criteria)
{ {
if(($res = $this->_authorize('read', $this->storId, $sessid)) !== TRUE)
return $res;
$filetype = strtolower($criteria['filetype']); $filetype = strtolower($criteria['filetype']);
$limit = intval($criteria['limit']);
$offset = intval($criteria['offset']);
if($filetype=='all'){ if($filetype=='all'){
$criteriaAC = $criteria; $criteriaAC['filetype'] = 'audioclip'; $criteriaAC = $criteria; $criteriaAC['filetype'] = 'audioclip';
$criteriaPL = $criteria; $criteriaPL['filetype'] = 'playlist'; $criteriaPL = $criteria; $criteriaPL['filetype'] = 'playlist';
$resAC = $this->bsLocalSearch($criteriaAC); $resAC = $this->bsLocalSearch($criteriaAC, $limit, $offset);
$resPL = $this->bsLocalSearch($criteriaPL); $resPL = $this->bsLocalSearch($criteriaPL, $limit, $offset);
return array( return array(
'audioClipResults' => $resAC['results'], 'audioClipResults' => $resAC['results'],
'playlistResults' => $resPL['results'] 'audioClipCnt' => $resAC['cnt'],
'playlistResults' => $resPL['results'],
'playlistCnt' => $resPL['cnt'],
); );
} }
$srchRes = $this->bsLocalSearch($criteria); $srchRes = $this->bsLocalSearch($criteria, $limit, $offset);
$res = array('audioClipResults'=>NULL, 'playlistResults'=>NULL); $res = array(
'audioClipResults' => array(),
'audioClipCnt' => 0,
'playlistResults' => array(),
'playlistCnt' => 0,
);
switch($filetype){ switch($filetype){
case"audioclip": case"audioclip":
$res['audioClipResults'] = $srchRes['results']; $res['audioClipResults'] = $srchRes['results'];
$res['audioClipCnt'] = $srchRes['cnt'];
break; break;
case"playlist": case"playlist":
$res['playlistResults'] = $srchRes['results']; $res['playlistResults'] = $srchRes['results'];
$res['playlistCnt'] = $srchRes['cnt'];
break; break;
} }
return $res; return $res;

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -1120,21 +1120,23 @@ class XR_LocStor extends LocStor{
* <li> sessid : string - session id </li> * <li> sessid : string - session id </li>
* <li> criteria : struct, with following fields:<br> * <li> criteria : struct, with following fields:<br>
* <ul> * <ul>
* <li>filetype - string, type of searched files, * <li>filetype : string - type of searched files,
* meaningful values: 'audioclip', 'playlist', 'all'</li> * meaningful values: 'audioclip', 'playlist', 'all'</li>
* <li>operator - string, type of conditions join * <li>operator : string - type of conditions join
* (any condition matches / all conditions match), * (any condition matches / all conditions match),
* meaningful values: 'and', 'or', '' * meaningful values: 'and', 'or', ''
* (may be empty or ommited only with less then 2 items in * (may be empty or ommited only with less then 2 items in
* &quot;conditions&quot; field) * &quot;conditions&quot; field)
* </li> * </li>
* <li>conditions - array of struct with fields: * <li>limit : int - limit for result arrays (0 means unlimited)</li>
* <li>offset : int - starting point (0 means without offset)</li>
* <li>conditions : array of struct with fields:
* <ul> * <ul>
* <li>cat - string, metadata category name</li> * <li>cat : string - metadata category name</li>
* <li>op - string, operator - meaningful values: * <li>op : string - operator, meaningful values:
* 'full', 'partial', 'prefix', '=', '&lt;', '&lt;=', * 'full', 'partial', 'prefix', '=', '&lt;', '&lt;=',
* '&gt;', '&gt;='</li> * '&gt;', '&gt;='</li>
* <li>val - string, search value</li> * <li>val : string - search value</li>
* </ul> * </ul>
* </li> * </li>
* </ul> * </ul>