add support for searching for filesize

This commit is contained in:
Uwe Steinmann 2024-10-02 14:56:25 +02:00
parent 8bcf76ca8c
commit 9a972c2c44
2 changed files with 62 additions and 3 deletions

View File

@ -126,6 +126,21 @@ if(!empty($_GET["modified"]["to"])) {
}
/* }}} */
/* Filesize {{{ */
$filesizestart = 0;
$filesizeend = 0;
$filesize['from'] = null;
$filesize['to'] = null;
if(!empty($_GET["filesize"]["from"])) {
$filesizestart = $_GET["filesize"]["from"];
$filesize['from'] = $_GET["filesize"]["from"];
}
if(!empty($_GET["filesize"]["to"])) {
$filesizeend = $_GET["filesize"]["to"];
$filesize['to'] = $_GET["filesize"]["to"];
}
/* }}} */
// Check to see if the search has been restricted to a particular
// document owner.
// $_GET['owner'] can be a name of an array of names or ids {{{
@ -358,7 +373,7 @@ if($fullsearch) {
$terms = $index->terms($lastterm, $settings->_suggestTerms);
}
$lucenesearch = $fulltextservice->Search();
$searchresult = $lucenesearch->search($query, array('record_type'=>$record_type, 'owner'=>$ownernames, 'status'=>$status, 'category'=>$categorynames, 'user'=>$user->isAdmin() ? [] : [$user->getLogin()], 'mimetype'=>$mimetype, 'startFolder'=>$startFolder, 'rootFolder'=>$rootFolder, 'created_start'=>$createstartts, 'created_end'=>$createendts, 'modified_start'=>$modifystartts, 'modified_end'=>$modifyendts, 'attributes'=>$attributes), ($pageNumber == 'all' ? array() : array('limit'=>$limit, 'offset'=>$limit * ($pageNumber-1))), $order);
$searchresult = $lucenesearch->search($query, array('record_type'=>$record_type, 'owner'=>$ownernames, 'status'=>$status, 'category'=>$categorynames, 'user'=>$user->isAdmin() ? [] : [$user->getLogin()], 'mimetype'=>$mimetype, 'startFolder'=>$startFolder, 'rootFolder'=>$rootFolder, 'created_start'=>$createstartts, 'created_end'=>$createendts, 'modified_start'=>$modifystartts, 'modified_end'=>$modifyendts, 'filesize_start'=>$filesizestart, 'filesize_end'=>$filesizeend, 'attributes'=>$attributes), ($pageNumber == 'all' ? array() : array('limit'=>$limit, 'offset'=>$limit * ($pageNumber-1))), $order);
if($searchresult === false) {
$session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_invalid_searchterm')));
$dcount = 0;
@ -646,6 +661,8 @@ if($fullsearch) {
'creationenddate'=>$created['to'], //$createenddate ? $createenddate : array(),
'modificationstartdate'=>$modified['from'],
'modificationenddate'=>$modified['to'],
'filesizestart'=>$filesize['from'],
'filesizeend'=>$filesize['to'],
'categories'=>$categories,
'attributes'=>$attributes,
'mode'=>$resultmode,
@ -754,6 +771,9 @@ if($settings->_showSingleSearchHit && count($entries) == 1) {
$view->setParam('modifystartdate', $modifystartts);
$view->setParam('modifyenddate', $modifyendts);
$view->setParam('modified', $modified);
$view->setParam('filesizestart', $filesizestart);
$view->setParam('filesizeend', $filesizeend);
$view->setParam('filesize', $filesize);
$view->setParam('expstartdate', !empty($expstartdate) ? getReadableDate($expstartts) : '');
$view->setParam('expenddate', !empty($expenddate) ? getReadableDate($expendts) : '');
$view->setParam('statusstartdate', !empty($statusstartdate) ? getReadableDate($statusstartts) : '');

View File

@ -479,6 +479,7 @@ $(document).ready(function() {
$modifystartdate = $this->params['modifystartdate'];
$modifyenddate = $this->params['modifyenddate'];
$modified = $this->params['modified'];
$filesize = $this->params['filesize'];
$expstartdate = $this->params['expstartdate'];
$expenddate = $this->params['expenddate'];
$statusstartdate = $this->params['statusstartdate'];
@ -888,6 +889,24 @@ $(document).ready(function() {
getMLText("modification_date")." (".getMLText('to').")",
$this->getDateChooser(!empty($modified['to']) ? getReadableDate($modified['to']) : null, "modified[to]", $this->params['session']->getLanguage())
);
$this->formField(
getMLText("filesize")." (".getMLText('from').")",
array(
'element'=>'input',
'type'=>'number',
'name'=>'filesize[from]',
'value'=>$filesize['from']
)
);
$this->formField(
getMLText("filesize")." (".getMLText('to').")",
array(
'element'=>'input',
'type'=>'number',
'name'=>'filesize[to]',
'value'=>$filesize['to']
)
);
if(!isset($facets['owner'])) {
$options = array();
foreach ($allUsers as $currUser) {
@ -1009,7 +1028,7 @@ $(document).ready(function() {
$option[] = array(array('data-subtitle', $c.' ×'));
$options[] = $option;
}
} elseif(substr($facetname, 0, 5) == 'attr_' || $facetname == 'created' || $facetname == 'modified') {
} elseif(substr($facetname, 0, 5) == 'attr_' || $facetname == 'created' || $facetname == 'modified' || $facetname == 'filesize') {
/* Do not even create a list of options, because it isn't used */
} else {
foreach($values as $v=>$c) {
@ -1022,7 +1041,7 @@ $(document).ready(function() {
$options[] = $option;
}
}
if(substr($facetname, 0, 5) != 'attr_' && $facetname != 'created' && $facetname != 'modified') {
if(substr($facetname, 0, 5) != 'attr_' && $facetname != 'created' && $facetname != 'modified' && $facetname != 'filesize') {
$this->formField(
getMLText($facetname),
array(
@ -1239,6 +1258,14 @@ $(document).ready(function() {
$oldvalue = null;
}
break;
case 'filesize':
if(!empty($allparams[$facetname]['from']) || !empty($allparams[$facetname]['to'])) {
$oldvalue = $allparams[$facetname];
$oldtransval = $oldvalue; //$oldvalue['from'].' TO '.$oldvalue['to'];
} else {
$oldvalue = null;
}
break;
default:
$oldvalue = is_array($allparams[$facetname]) ? $allparams[$facetname] : [$allparams[$facetname]];
$oldtransval = $oldvalue;
@ -1371,6 +1398,18 @@ $(document).ready(function() {
$this->printAccordion(getMLText('modification_date'), $content);
}
}
} elseif($facetname == 'filesize') {
if(empty($allparams[$facetname]['from']) && empty($allparams[$facetname]['to'])) {
$tt = array_keys($values);
$content = '<div class="input-group">';
$content .= '<span class="input-group-text" style="border-right: 0;"> from </span>';
$content .= '<input class="form-control" name="'.$facetname.'[from]" type="text" value="">';
$content .= '<span class="input-group-text" style="border-left: 0; border-right: 0;"> to </span>';
$content .= '<input class="form-control" name="'.$facetname.'[to]" type="text" value="">';
$content .= '<button class="btn btn-primary" type="submit">Set</button>';
$content .= '</div>';
$this->printAccordion(getMLText('filesize'), $content);
}
} else {
/* Further filter makes only sense if the facet has more than 1 value
* or in case of 1 value, if that value has a count < $total. That second