예제 #1
0
 /**
  * Performs the search, the display and writing stats
  *
  * @param array $search the search parameters, an associative array
  * @return void
  * @dontvalidate $search
  */
 public function searchAction($search = array())
 {
     $searchData = $this->initialize($search);
     // Find free index uid:
     $freeIndexUid = $searchData['freeIndexUid'];
     if ($freeIndexUid == -2) {
         $freeIndexUid = $this->settings['defaultFreeIndexUidList'];
     } elseif (!isset($searchData['freeIndexUid'])) {
         // index configuration is disabled
         $freeIndexUid = -1;
     }
     $indexCfgs = GeneralUtility::intExplode(',', $freeIndexUid);
     $resultsets = array();
     foreach ($indexCfgs as $freeIndexUid) {
         // Get result rows
         $tstamp1 = GeneralUtility::milliseconds();
         if ($hookObj = $this->hookRequest('getResultRows')) {
             $resultData = $hookObj->getResultRows($this->searchWords, $freeIndexUid);
         } else {
             $resultData = $this->searchRepository->doSearch($this->searchWords, $freeIndexUid);
         }
         // Display search results
         $tstamp2 = GeneralUtility::milliseconds();
         if ($hookObj = $this->hookRequest('getDisplayResults')) {
             $resultsets[$freeIndexUid] = $hookObj->getDisplayResults($this->searchWords, $resultData, $freeIndexUid);
         } else {
             $resultsets[$freeIndexUid] = $this->getDisplayResults($this->searchWords, $resultData, $freeIndexUid);
         }
         $tstamp3 = GeneralUtility::milliseconds();
         // Create header if we are searching more than one indexing configuration
         if (count($indexCfgs) > 1) {
             if ($freeIndexUid > 0) {
                 $indexCfgRec = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('title', 'index_config', 'uid=' . (int) $freeIndexUid . $GLOBALS['TSFE']->cObj->enableFields('index_config'));
                 $categoryTitle = $indexCfgRec['title'];
             } else {
                 $categoryTitle = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('indexingConfigurationHeader.' . $freeIndexUid, 'indexed_search');
             }
             $resultsets[$freeIndexUid]['categoryTitle'] = $categoryTitle;
         }
         // Write search statistics
         $this->writeSearchStat($searchData, $this->searchWords, $resultData['count'], array($tstamp1, $tstamp2, $tstamp3));
     }
     $this->view->assign('resultsets', $resultsets);
     $this->view->assign('searchParams', $searchData);
     $this->view->assign('searchWords', $this->searchWords);
 }
    /**
     * Execute final query, based on phash integer list. The main point is sorting the result in the right order.
     *
     * @param array $searchData Array with search string, boolean indicator, and fulltext index reference
     * @param int $freeIndexUid Pointer to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content.
     * @return bool|\mysqli_result|object MySQLi result object / DBAL object
     */
    protected function execFinalQuery_fulltext($searchData, $freeIndexUid = -1)
    {
        // Setting up methods of filtering results based on page types, access, etc.
        $pageJoin = '';
        // Indexing configuration clause:
        $freeIndexUidClause = $this->pObj->freeIndexUidWhere($freeIndexUid);
        // Calling hook for alternative creation of page ID list
        $searchRootPageIdList = $this->pObj->getSearchRootPageIdList();
        if ($hookObj =& $this->pObj->hookRequest('execFinalQuery_idList')) {
            $pageWhere = $hookObj->execFinalQuery_idList('');
        } elseif ($this->pObj->getJoinPagesForQuery()) {
            // Alternative to getting all page ids by ->getTreeList() where "excludeSubpages" is NOT respected.
            $pageJoin = ',
				pages';
            $pageWhere = 'pages.uid = ISEC.page_id
				' . $GLOBALS['TSFE']->cObj->enableFields('pages') . '
				AND pages.no_search=0
				AND pages.doktype<200
			';
        } elseif ($searchRootPageIdList[0] >= 0) {
            // Collecting all pages IDs in which to search;
            // filtering out ALL pages that are not accessible due to enableFields. Does NOT look for "no_search" field!
            $idList = array();
            foreach ($searchRootPageIdList as $rootId) {
                /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */
                $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
                $idList[] = $cObj->getTreeList(-1 * $rootId, 9999);
            }
            $pageWhere = ' ISEC.page_id IN (' . implode(',', $idList) . ')';
        } else {
            // Disable everything... (select all)
            $pageWhere = ' 1=1';
        }
        $searchBoolean = '';
        if ($searchData['searchBoolean']) {
            $searchBoolean = ' IN BOOLEAN MODE';
        }
        $resource = $GLOBALS['TYPO3_DB']->exec_SELECTquery('index_fulltext.*, ISEC.*, IP.*', 'index_fulltext, index_section ISEC, index_phash IP' . $pageJoin, 'MATCH (' . $searchData['fulltextIndex'] . ')
                AGAINST (' . $GLOBALS['TYPO3_DB']->fullQuoteStr($searchData['searchString'], 'index_fulltext') . $searchBoolean . ') ' . $this->pObj->mediaTypeWhere() . ' ' . $this->pObj->languageWhere() . $freeIndexUidClause . '
                AND index_fulltext.phash = IP.phash
                AND ISEC.phash = IP.phash
                AND ' . $pageWhere . $this->pObj->sectionTableWhere(), 'IP.phash,ISEC.phash,ISEC.phash_t3,ISEC.rl0,ISEC.rl1,ISEC.rl2,ISEC.page_id,ISEC.uniqid,IP.phash_grouping,IP.data_filename ,IP.data_page_id ,IP.data_page_reg1,IP.data_page_type,IP.data_page_mp,IP.gr_list,IP.item_type,IP.item_title,IP.item_description,IP.item_mtime,IP.tstamp,IP.item_size,IP.contentHash,IP.crdate,IP.parsetime,IP.sys_language_uid,IP.item_crdate,IP.cHashParams,IP.externalUrl,IP.recordUid,IP.freeIndexUid,IP.freeIndexSetId');
        return $resource;
    }