mirror of https://github.com/MISP/MISP
new: [event:index] Added support of ANDed tag filtering in the backend
In addition of the OR filtering using searchtag:1|2, /events/index now supports AND filtering with searchtag:1&2. The UI has not been updated yet.pull/9677/head
parent
c4c395af31
commit
fc92291092
|
@ -497,6 +497,11 @@ class EventsController extends AppController
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
$pieces = is_array($v) ? $v : explode('|', $v);
|
$pieces = is_array($v) ? $v : explode('|', $v);
|
||||||
|
$isANDed = false;
|
||||||
|
if (count($pieces) == 1 && strpos($pieces[0], '&') !== -1) {
|
||||||
|
$pieces = explode('&', $v);
|
||||||
|
$isANDed = count($pieces) > 1;
|
||||||
|
}
|
||||||
$filterString = "";
|
$filterString = "";
|
||||||
$expectOR = false;
|
$expectOR = false;
|
||||||
$tagRules = [];
|
$tagRules = [];
|
||||||
|
@ -563,10 +568,19 @@ class EventsController extends AppController
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($tagRules['include'])) {
|
if (!empty($tagRules['include'])) {
|
||||||
$include = $this->Event->EventTag->find('column', array(
|
if ($isANDed) {
|
||||||
'conditions' => array('EventTag.tag_id' => $tagRules['include']),
|
$include = $this->Event->EventTag->find('column', array(
|
||||||
'fields' => ['EventTag.event_id'],
|
'conditions' => ['EventTag.tag_id' => $tagRules['include']],
|
||||||
));
|
'fields' => ['EventTag.event_id'],
|
||||||
|
'group' => ['EventTag.event_id'],
|
||||||
|
'having' => ['COUNT(*) =' => count($tagRules['include'])],
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$include = $this->Event->EventTag->find('column', array(
|
||||||
|
'conditions' => array('EventTag.tag_id' => $tagRules['include']),
|
||||||
|
'fields' => ['EventTag.event_id'],
|
||||||
|
));
|
||||||
|
}
|
||||||
if (!empty($include)) {
|
if (!empty($include)) {
|
||||||
$this->paginate['conditions']['AND'][] = 'Event.id IN (' . implode(",", $include) . ')';
|
$this->paginate['conditions']['AND'][] = 'Event.id IN (' . implode(",", $include) . ')';
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue