Limit and offset added to search criteria.
This commit is contained in:
parent
357d1b29c0
commit
2c3a0f9b39
3 changed files with 35 additions and 18 deletions
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
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 $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -50,7 +50,7 @@ require_once "StoredFile.php";
|
|||
* Core of LiveSupport file storage module
|
||||
*
|
||||
* @author $Author: tomas $
|
||||
* @version $Revision: 1.19 $
|
||||
* @version $Revision: 1.20 $
|
||||
* @see Alib
|
||||
*/
|
||||
class BasicStor extends Alib{
|
||||
|
@ -565,7 +565,7 @@ class BasicStor extends Alib{
|
|||
* @return hash, field 'results' is an array with gunid strings
|
||||
* of files have been found
|
||||
*/
|
||||
function bsLocalSearch($criteria)
|
||||
function bsLocalSearch($criteria, $limit, $offset)
|
||||
{
|
||||
$operators = array('and'=>'AND', 'or'=>'OR');
|
||||
$ops = array('full'=>"='%s'", 'partial'=>"like '%%%s%%'", 'prefix'=>"like '%s%%'",
|
||||
|
@ -589,6 +589,7 @@ class BasicStor extends Alib{
|
|||
$whereArr[] = "$sqlCond";
|
||||
}
|
||||
$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'";
|
||||
if($operator == 'and'){
|
||||
// operator: and
|
||||
|
@ -616,11 +617,12 @@ class BasicStor extends Alib{
|
|||
"INNER JOIN {$this->filesTable} f ON md.gunid=f.gunid $ftypeCond\n".
|
||||
"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();
|
||||
$res = array_map(array("StoredFile", "_normalizeGunid"), $res);
|
||||
# return array('sql'=>$sql, 'results'=>$res);
|
||||
return array('results'=>$res);
|
||||
return array('results'=>$res, 'cnt'=>$cnt);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------- info methods */
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
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 $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -273,25 +273,38 @@ class LocStor extends BasicStor{
|
|||
*/
|
||||
function searchMetadata($sessid, $criteria)
|
||||
{
|
||||
if(($res = $this->_authorize('read', $this->storId, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$filetype = strtolower($criteria['filetype']);
|
||||
$limit = intval($criteria['limit']);
|
||||
$offset = intval($criteria['offset']);
|
||||
if($filetype=='all'){
|
||||
$criteriaAC = $criteria; $criteriaAC['filetype'] = 'audioclip';
|
||||
$criteriaPL = $criteria; $criteriaPL['filetype'] = 'playlist';
|
||||
$resAC = $this->bsLocalSearch($criteriaAC);
|
||||
$resPL = $this->bsLocalSearch($criteriaPL);
|
||||
$resAC = $this->bsLocalSearch($criteriaAC, $limit, $offset);
|
||||
$resPL = $this->bsLocalSearch($criteriaPL, $limit, $offset);
|
||||
return array(
|
||||
'audioClipResults' => $resAC['results'],
|
||||
'playlistResults' => $resPL['results']
|
||||
'audioClipCnt' => $resAC['cnt'],
|
||||
'playlistResults' => $resPL['results'],
|
||||
'playlistCnt' => $resPL['cnt'],
|
||||
);
|
||||
}
|
||||
$srchRes = $this->bsLocalSearch($criteria);
|
||||
$res = array('audioClipResults'=>NULL, 'playlistResults'=>NULL);
|
||||
$srchRes = $this->bsLocalSearch($criteria, $limit, $offset);
|
||||
$res = array(
|
||||
'audioClipResults' => array(),
|
||||
'audioClipCnt' => 0,
|
||||
'playlistResults' => array(),
|
||||
'playlistCnt' => 0,
|
||||
);
|
||||
switch($filetype){
|
||||
case"audioclip":
|
||||
$res['audioClipResults'] = $srchRes['results'];
|
||||
$res['audioClipCnt'] = $srchRes['cnt'];
|
||||
break;
|
||||
case"playlist":
|
||||
$res['playlistResults'] = $srchRes['results'];
|
||||
$res['playlistCnt'] = $srchRes['cnt'];
|
||||
break;
|
||||
}
|
||||
return $res;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
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 $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -1120,21 +1120,23 @@ class XR_LocStor extends LocStor{
|
|||
* <li> sessid : string - session id </li>
|
||||
* <li> criteria : struct, with following fields:<br>
|
||||
* <ul>
|
||||
* <li>filetype - string, type of searched files,
|
||||
* <li>filetype : string - type of searched files,
|
||||
* 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),
|
||||
* meaningful values: 'and', 'or', ''
|
||||
* (may be empty or ommited only with less then 2 items in
|
||||
* "conditions" field)
|
||||
* </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>
|
||||
* <li>cat - string, metadata category name</li>
|
||||
* <li>op - string, operator - meaningful values:
|
||||
* <li>cat : string - metadata category name</li>
|
||||
* <li>op : string - operator, meaningful values:
|
||||
* 'full', 'partial', 'prefix', '=', '<', '<=',
|
||||
* '>', '>='</li>
|
||||
* <li>val - string, search value</li>
|
||||
* <li>val : string - search value</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue