add new search tag with facetted full text search

This commit is contained in:
Uwe Steinmann 2023-04-23 19:03:51 +02:00
parent 36a51e9606
commit 7172aad62b

View File

@ -394,7 +394,9 @@ $(document).ready(function() {
function show() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$request = $this->params['request'];
$fullsearch = $this->params['fullsearch'];
$facetsearch = $this->params['facetsearch'];
$total = $this->params['total'];
$totaldocs = $this->params['totaldocs'];
$totalfolders = $this->params['totalfolders'];
@ -405,6 +407,7 @@ $(document).ready(function() {
$resultmode = $this->params['resultmode'];
$workflowmode = $this->params['workflowmode'];
$enablefullsearch = $this->params['enablefullsearch'];
$enablefacetsearch = true;
$enableclipboard = $this->params['enableclipboard'];
$attributes = $this->params['attributes'];
$categories = $this->params['categories'];
@ -457,7 +460,12 @@ $(document).ready(function() {
<?php
if($enablefullsearch) {
?>
<li class="nav-item <?php echo ($fullsearch == true) ? 'active' : ''; ?>"><a class="nav-link <?php echo ($fullsearch == true) ? 'active' : ''; ?>" data-target="#fulltext" data-toggle="tab" role="button"><?php printMLText('fullsearch'); ?></a></li>
<li class="nav-item <?php echo ($fullsearch == true && $facetsearch == false) ? 'active' : ''; ?>"><a class="nav-link <?php echo ($fullsearch == true && $facetsearch == false) ? 'active' : ''; ?>" data-target="#fulltext" data-toggle="tab" role="button"><?php printMLText('fullsearch'); ?></a></li>
<?php
}
if($enablefacetsearch) {
?>
<li class="nav-item <?php echo ($facetsearch == true && $facetsearch == true) ? 'active' : ''; ?>"><a class="nav-link <?php echo ($facetsearch == true && $facetsearch == true) ? 'active' : ''; ?>" data-target="#facetfulltext" data-toggle="tab" role="button"><?php printMLText('facetfullsearch'); ?></a></li>
<?php
}
?>
@ -758,7 +766,7 @@ $(document).ready(function() {
// Fulltext search Form {{{
if($enablefullsearch) {
echo "<div class=\"tab-pane ".(($fullsearch == true) ? 'active' : '')."\" id=\"fulltext\">\n";
echo "<div class=\"tab-pane ".(($fullsearch == true && $facetsearch == false) ? 'active' : '')."\" id=\"fulltext\">\n";
?>
<form class="form-horizontal" action="<?= $this->params['settings']->_httpRoot ?>out/out.Search.php" name="form2" style="min-height: 330px;">
<input type="hidden" name="fullsearch" value="1" />
@ -773,7 +781,7 @@ $(document).ready(function() {
'value'=>htmlspecialchars($this->query)
)
);
$this->formField(getMLText("under_folder"), $this->getFolderChooserHtml("form1", M_READ, -1, $startfolder, 'folderfullsearchid'));
$this->formField(getMLText("under_folder"), $this->getFolderChooserHtml("form2", M_READ, -1, $startfolder, 'folderfullsearchid'));
$this->formField(
getMLText("creation_date")." (".getMLText('from').")",
$this->getDateChooser($createstartdate, "createstart", $this->params['session']->getLanguage())
@ -866,14 +874,12 @@ $(document).ready(function() {
if($facets) {
foreach($facets as $facetname=>$values) {
$multiple = true;
// if(in_array($facetname, ['owner', 'status', 'mimetype']))
// $multiple = false;
$options = array();
if($facetname == 'owner') {
foreach($values as $v=>$c) {
$uu = $dms->getUserByLogin($v);
if($uu) {
$option = array($uu->getId(), $v/*.' ('.$c.')'*/);
$option = array($uu->getId(), $v);
if(isset(${$facetname}) && in_array($uu->getId(), ${$facetname}))
$option[] = true;
else
@ -886,7 +892,7 @@ $(document).ready(function() {
foreach($values as $v=>$c) {
$cat = $dms->getDocumentCategoryByName($v);
if($cat) {
$option = array($cat->getId(), $v/*.' ('.$c.')'*/);
$option = array($cat->getId(), $v);
if(isset(${$facetname}) && in_array($cat->getId(), ${$facetname}))
$option[] = true;
else
@ -895,6 +901,7 @@ $(document).ready(function() {
$options[] = $option;
}
}
} elseif(substr($facetname, 0, 5) == 'attr_') {
} elseif($facetname == 'status') {
foreach($values as $v=>$c) {
$option = array($v, getOverallStatusText($v)/*.' ('.$c.')'*/);
@ -905,19 +912,9 @@ $(document).ready(function() {
$option[] = array(array('data-subtitle', $c.' ×'));
$options[] = $option;
}
} elseif(substr($facetname, 0, 5) == 'attr_') {
foreach($values as $v=>$c) {
$option = array($v, $v/*.' ('.$c.')'*/);
if(isset($attributes[$facetname]) && in_array($v, $attributes[$facetname]))
$option[] = true;
else
$option[] = false;
$option[] = array(array('data-subtitle', $c.' ×'));
$options[] = $option;
}
} else {
foreach($values as $v=>$c) {
$option = array($v, $v.' ('.$c.')');
$option = array($v, $v);
if(isset(${$facetname}) && in_array($v, ${$facetname}))
$option[] = true;
else
@ -926,27 +923,7 @@ $(document).ready(function() {
$options[] = $option;
}
}
if(substr($facetname, 0, 5) == 'attr_') {
if($options) {
$tmp = explode('_', $facetname);
if($attrdef = $dms->getAttributeDefinition($tmp[1]))
$dispname = $attrdef->getName();
else
$dispname = getMLText($facetname);
$this->formField(
$dispname,
array(
'element'=>'select',
'id'=>$facetname,
'name'=>'attributes['.$facetname.'][]',
'class'=>'chzn-select',
'attributes'=>array(array('data-placeholder', $dispname), array('data-allow-clear', 'true')),
'options'=>$options,
'multiple'=>$multiple
)
);
}
} else {
if(substr($facetname, 0, 5) != 'attr_') {
$this->formField(
getMLText($facetname),
array(
@ -961,11 +938,179 @@ $(document).ready(function() {
);
}
}
foreach($facets as $facetname=>$values) {
if(substr($facetname, 0, 5) == 'attr_') {
/* If the facet is empty, don't show the input field */
if($values) {
$tmp = explode('_', $facetname);
if($attrdef = $dms->getAttributeDefinition($tmp[1])) {
$dispname = $attrdef->getName();
switch($attrdef->getType()) {
case 556: //SeedDMS_Core_AttributeDefinition::type_int:
$this->formField(
$dispname.' ('.getMLText('from').')',
array(
'element'=>'input',
'type'=>'number',
'id'=>$facetname,
'name'=>'attributes['.$facetname.'][from]',
'placeholder'=>implode(' ', array_keys($values)),
)
);
$this->formField(
$dispname.' ('.getMLText('to').')',
array(
'element'=>'input',
'type'=>'number',
'id'=>$facetname,
'name'=>'attributes['.$facetname.'][to]',
'placeholder'=>implode(' ', array_keys($values)),
)
);
break;
default:
$options = [];
foreach($values as $v=>$c) {
$option = array($v, $v);
if(isset($attributes[$facetname]) && in_array($v, $attributes[$facetname]))
$option[] = true;
else
$option[] = false;
$option[] = array(array('data-subtitle', $c.' ×'));
$options[] = $option;
}
if($options) {
$this->formField(
$dispname,
array(
'element'=>'select',
'id'=>$facetname,
'name'=>'attributes['.$facetname.'][]',
'class'=>'chzn-select',
'attributes'=>array(array('data-placeholder', $dispname), array('data-allow-clear', 'true')),
'options'=>$options,
'multiple'=>$multiple
)
);
}
}
}
}
}
}
}
$this->contentContainerEnd();
$this->formSubmit("<i class=\"fa fa-search\"></i> ".getMLText('search'));
?>
</form>
<?php
echo "</div>\n";
}
// }}}
// Fulltext search with facets Form {{{
if($enablefacetsearch) {
echo "<div class=\"tab-pane ".(($fullsearch == true && $facetsearch == true) ? 'active' : '')."\" id=\"facetfulltext\">\n";
?>
<form class="form-horizontal" action="<?= $this->params['settings']->_httpRoot ?>out/out.Search.php" name="form2" style="min-height: 330px;">
<input type="hidden" name="fullsearch" value="1" />
<input type="hidden" name="facetsearch" value="1" />
<?php
$this->contentContainerStart();
$this->formField(
getMLText("search_query"),
array(
'element'=>'input',
'type'=>'search',
'name'=>'query',
'value'=>htmlspecialchars($this->query),
'placeholder'=>'Search in title, comments, keywords, content',
)
);
$this->formField(getMLText("under_folder"), $this->getFolderChooserHtml("form3", M_READ, -1, $startfolder, 'folderfullsearchid'));
$this->contentContainerEnd();
$this->formSubmit("<i class=\"fa fa-search\"></i> ".getMLText('search'));
echo "<p></p>";
if($facets) {
$menuitems = [];
foreach($facets as $facetname=>$values) {
if(substr($facetname, 0, 5) == 'attr_') {
$tmp = explode('_', $facetname);
if($attrdef = $dms->getAttributeDefinition($tmp[1])) {
$dispname = $attrdef->getName();
/* Create a link to remove the filter */
$allparams = $request->query->all();
if(isset($allparams['attributes'][$facetname])) {
$oldvalue = is_array($allparams['attributes'][$facetname]) ? implode(',', $allparams['attributes'][$facetname]) : $allparams['attributes'][$facetname];
unset($allparams['attributes'][$facetname]);
$newrequest = Symfony\Component\HttpFoundation\Request::create($request->getBaseUrl(), 'GET', $allparams);
$menuitems[] = array('label'=>$dispname.' = '.$oldvalue, 'link'=>$newrequest->getRequestUri(), 'attributes'=>[['title', 'Click to remove']], '_badge'=>'x');
}
}
} else {
/* Create a link to remove the filter */
$allparams = $request->query->all();
if(isset($allparams[$facetname])) {
$oldvalue = is_array($allparams[$facetname]) ? implode(',', $allparams[$facetname]) : $allparams[$facetname];
unset($allparams[$facetname]);
$newrequest = Symfony\Component\HttpFoundation\Request::create($request->getBaseUrl(), 'GET', $allparams);
$menuitems[] = array('label'=>getMLText($facetname).' = '.$oldvalue, 'link'=>$newrequest->getRequestUri(), 'attributes'=>[['title', 'Click to remove']], '_badge'=>'x');
}
}
}
if($menuitems) {
ob_start();
self::showNavigationListWithBadges($menuitems);
$content = ob_get_clean();
$this->printAccordion(getMLText('current_filter'), $content, true);
}
foreach($facets as $facetname=>$values) {
if(substr($facetname, 0, 5) == 'attr_') {
$tmp = explode('_', $facetname);
if($attrdef = $dms->getAttributeDefinition($tmp[1])) {
$dispname = $attrdef->getName();
/* See below on an explaination for the if statement */
if($values && (count($values) > 1 || reset($values) < $total)) {
$menuitems = array();
arsort($values);
foreach($values as $v=>$c) {
$menuitems[] = array('label'=>htmlspecialchars($v), 'link'=>$request->getRequestUri().'&attributes['.$facetname.'][]='.urlencode($v), 'badge'=>$c, 'attributes'=>array(array('data-href', $request->getRequestUri().'&'.$facetname.'='.$v), array('data-action', "printOpenTasksList")));
}
ob_start();
self::showNavigationListWithBadges($menuitems);
$content = ob_get_clean();
$this->printAccordion($dispname, $content);
}
}
} else {
/* Further filter makes onle sense if the facet has mor than 1 value
* or in case of 1 value that value has a count < $total. That second
* case will reduce the result set on those objects which the field
* actually set.
*/
if($values && (count($values) > 1 || reset($values) < $total)) {
$menuitems = array();
arsort($values);
foreach($values as $v=>$c) {
$menuitems[] = array('label'=>htmlspecialchars($v), 'link'=>$request->getRequestUri().'&'.$facetname.'[]='.urlencode($v), 'badge'=>$c, 'attributes'=>array(array('data-href', "#initlist"), array('data-action', "printOpenTasksList")));
}
ob_start();
self::showNavigationListWithBadges($menuitems);
$content = ob_get_clean();
$this->printAccordion(getMLText($facetname), $content);
}
}
}
}
// echo "<pre>";
// print_r($facets);
// echo "</pre>";
?>
</form>
<?php
echo "</div>\n";
}