initial support for attributes in full text search

This commit is contained in:
Uwe Steinmann 2023-03-04 09:04:58 +01:00
parent 39026ef4a8
commit 9e36d82873
2 changed files with 45 additions and 13 deletions

View File

@ -161,6 +161,11 @@ if($fullsearch) {
else else
$record_type = array(); $record_type = array();
if (isset($_GET["attributes"]))
$attributes = $_GET["attributes"];
else
$attributes = array();
// Check to see if the search has been restricted to a particular sub-tree in // Check to see if the search has been restricted to a particular sub-tree in
// the folder hierarchy. // the folder hierarchy.
$startFolder = null; $startFolder = null;
@ -193,7 +198,7 @@ if($fullsearch) {
if($index) { if($index) {
// $terms = $index->terms($_GET['query']); // $terms = $index->terms($_GET['query']);
$lucenesearch = $fulltextservice->Search(); $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), ($pageNumber == 'all' ? array() : array('limit'=>$limit, 'offset'=>$limit * ($pageNumber-1)))); $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, 'attributes'=>$attributes), ($pageNumber == 'all' ? array() : array('limit'=>$limit, 'offset'=>$limit * ($pageNumber-1))));
if($searchresult === false) { if($searchresult === false) {
$session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_invalid_searchterm'))); $session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_invalid_searchterm')));
$dcount = 0; $dcount = 0;

View File

@ -877,6 +877,13 @@ function typeahead() { /* {{{ */
$option[] = true; $option[] = true;
$options[] = $option; $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;
$options[] = $option;
}
} else { } else {
foreach($values as $v=>$c) { foreach($values as $v=>$c) {
$option = array($v, $v.' ('.$c.')'); $option = array($v, $v.' ('.$c.')');
@ -885,18 +892,38 @@ function typeahead() { /* {{{ */
$options[] = $option; $options[] = $option;
} }
} }
$this->formField( if(substr($facetname, 0, 5) == 'attr_') {
getMLText($facetname), $tmp = explode('_', $facetname);
array( if($attrdef = $dms->getAttributeDefinition($tmp[1]))
'element'=>'select', $dispname = $attrdef->getName();
'id'=>$facetname, else
'name'=>$facetname."[]", $dispname = getMLText($facetname);
'class'=>'chzn-select', $this->formField(
'attributes'=>array(array('data-placeholder', getMLText('select_'.$facetname)), array('data-allow-clear', 'true')), $dispname,
'options'=>$options, array(
'multiple'=>$multiple '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 {
$this->formField(
getMLText($facetname),
array(
'element'=>'select',
'id'=>$facetname,
'name'=>$facetname."[]",
'class'=>'chzn-select',
'attributes'=>array(array('data-placeholder', getMLText('select_'.$facetname)), array('data-allow-clear', 'true')),
'options'=>$options,
'multiple'=>$multiple
)
);
}
} }
} }
$this->contentContainerEnd(); $this->contentContainerEnd();