Index: kernel/db/cat_event_handler.php =================================================================== --- kernel/db/cat_event_handler.php (revision 15359) +++ kernel/db/cat_event_handler.php (working copy) @@ -1261,8 +1261,15 @@ $where_clause = $where_clause . ' AND (' . $items_table . '.Status = ' . STATUS_ACTIVE . ')'; if ($event->MasterEvent && $event->MasterEvent->Name == 'OnListBuild') { - if ($event->MasterEvent->getEventParam('ResultIds')) { - $where_clause .= ' AND '.$items_table.'.ResourceId IN ('.implode(',', $event->MasterEvent->getEventParam('ResultIds')).')'; + $sub_search_ids = $event->MasterEvent->getEventParam('ResultIds'); + + if ( $sub_search_ids !== false ) { + if ( $sub_search_ids ) { + $where_clause .= 'AND (' . $items_table . '.ResourceId IN (' . implode(',', $sub_search_ids) . '))'; + } + else { + $where_clause .= 'AND FALSE'; + } } } @@ -1359,14 +1366,26 @@ */ function OnSubSearch($event) { + // keep search results from other items after doing a sub-search on current item type + $this->Application->SetVar('do_not_drop_search_table', true); + $ids = Array (); $search_table = TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search'; $sql = 'SHOW TABLES LIKE "' . $search_table . '"'; if ( $this->Conn->Query($sql) ) { + $item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); + + // 1. get ids to be used as search bounds $sql = 'SELECT DISTINCT ResourceId - FROM ' . $search_table; + FROM ' . $search_table . ' + WHERE ItemType = ' . $item_type; $ids = $this->Conn->GetCol($sql); + + // 2. delete previously found ids + $sql = 'DELETE FROM ' . $search_table . ' + WHERE ItemType = ' . $item_type; + $this->Conn->Query($sql); } $event->setEventParam('ResultIds', $ids); Index: units/categories/categories_event_handler.php =================================================================== --- units/categories/categories_event_handler.php (revision 15390) +++ units/categories/categories_event_handler.php (working copy) @@ -2494,8 +2494,15 @@ $where_clause = $where_clause . ' AND (' . $items_table . '.Status = ' . STATUS_ACTIVE . ')'; if ($event->MasterEvent && $event->MasterEvent->Name == 'OnListBuild') { - if ($event->MasterEvent->getEventParam('ResultIds')) { - $where_clause .= ' AND '.$items_table.'.ResourceId IN ('.implode(',', $event->MasterEvent->getEventParam('ResultIds')).')'; + $sub_search_ids = $event->MasterEvent->getEventParam('ResultIds'); + + if ( $sub_search_ids !== false ) { + if ( $sub_search_ids ) { + $where_clause .= 'AND (' . $items_table . '.ResourceId IN (' . implode(',', $sub_search_ids) . '))'; + } + else { + $where_clause .= 'AND FALSE'; + } } } @@ -2591,6 +2598,39 @@ } /** + * Enter description here... + * + * @param kEvent $event + */ + function OnSubSearch($event) + { + // keep search results from other items after doing a sub-search on current item type + $this->Application->SetVar('do_not_drop_search_table', true); + + $ids = Array (); + $search_table = TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search'; + $sql = 'SHOW TABLES LIKE "' . $search_table . '"'; + + if ( $this->Conn->Query($sql) ) { + $item_type = $this->Application->getUnitOption($event->Prefix, 'ItemType'); + + // 1. get ids to be used as search bounds + $sql = 'SELECT DISTINCT ResourceId + FROM ' . $search_table . ' + WHERE ItemType = ' . $item_type; + $ids = $this->Conn->GetCol($sql); + + // 2. delete previously found ids + $sql = 'DELETE FROM ' . $search_table . ' + WHERE ItemType = ' . $item_type; + $this->Conn->Query($sql); + } + + $event->setEventParam('ResultIds', $ids); + $event->CallSubEvent('OnSimpleSearch'); + } + + /** * Make record to search log * * @param string $keywords