Index: branches/5.2.x/core/units/categories/categories_event_handler.php =================================================================== diff -u -N -r15390 -r15417 --- branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 15390) +++ branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 15417) @@ -1,6 +1,6 @@ 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 Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r15354 -r15417 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 15354) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 15417) @@ -1,6 +1,6 @@ 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);