109 $this->frontendUserGroupList =
$GLOBALS[
'TSFE']->gr_list;
111 if ($settings[
'searchSkipExtendToSubpagesChecking']) {
112 $this->joinPagesForQuery = 1;
114 if ($settings[
'exactCount']) {
115 $this->useExactCount = TRUE;
117 if ($settings[
'displayForbiddenRecords']) {
118 $this->displayForbiddenRecords = TRUE;
120 $this->sections = $searchData[
'sections'];
121 $this->searchType = $searchData[
'searchType'];
122 $this->languageUid = $searchData[
'languageUid'];
123 $this->mediaType = isset($searchData[
'mediaType']) ? $searchData[
'mediaType'] : FALSE;
124 $this->sortOrder = $searchData[
'sortOrder'];
125 $this->descendingSortOrderFlag = $searchData[
'desc'];
126 $this->resultpagePointer = $searchData[
'pointer'];
127 if (isset($searchData[
'numberOfResults']) && is_numeric($searchData[
'numberOfResults'])) {
128 $this->numberOfResults = (int)$searchData[
'numberOfResults'];
139 public function doSearch($searchWords, $freeIndexUid = -1) {
141 $GLOBALS[
'TT']->push(
'Searching result');
142 if ($hookObj = &$this->
hookRequest(
'getResultRows_SQLpointer')) {
143 $res = $hookObj->getResultRows_SQLpointer($searchWords, $freeIndexUid);
151 $count =
$GLOBALS[
'TYPO3_DB']->sql_num_rows($res);
157 $grouping_phashes = array();
159 $grouping_chashes = array();
163 $resultRows = array();
168 while ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) {
176 $phashGr = !in_array($row[
'phash_grouping'], $grouping_phashes);
177 $chashGr = !in_array(($row[
'contentHash'] .
'.' . $row[
'data_page_id']), $grouping_chashes);
178 if ($phashGr && $chashGr) {
180 if ($row[
'show_resume'] || $this->displayForbiddenRecords) {
183 $grouping_phashes[] = $row[
'phash_grouping'];
185 $grouping_chashes[] = $row[
'contentHash'] .
'.' . $row[
'data_page_id'];
189 if ($c > $pointer * $this->numberOfResults && $c <= $pointer * $this->numberOfResults + $this->numberOfResults) {
190 $row[
'result_number'] = $c;
191 $resultRows[] = $row;
195 if (!$this->useExactCount && $c + 1 > ($pointer + 1) * $this->numberOfResults) {
212 'resultRows' => $resultRows,
213 'firstRow' => $firstRow,
232 $list = $this->getPhashList($searchWords);
236 $GLOBALS[
'TT']->push(
'execFinalQuery');
257 protected function getPhashList($searchWords) {
261 $totalHashList = array();
262 $this->wSelClauses = array();
264 foreach ($searchWords as $k => $v) {
266 $sWord = $v[
'sword'];
267 $theType = (string) $this->searchType;
269 if (strstr($sWord,
' ')) {
272 $GLOBALS[
'TT']->push(
'SearchWord "' . $sWord .
'" - $theType=' . $theType);
278 $res = $this->
searchWord($sWord, self::WILDCARD_LEFT | self::WILDCARD_RIGHT);
282 $res = $this->
searchWord($sWord, self::WILDCARD_RIGHT);
286 $res = $this->
searchWord($sWord, self::WILDCARD_LEFT);
297 $storeMetaphoneInfoAsWords = !$this->
isTableUsed(
'index_words');
309 $this->sortOrder =
'mtime';
318 $phashList = array();
319 while ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) {
320 $phashList[] = $row[
'phash'];
322 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
325 switch ($v[
'oper']) {
327 $totalHashList = array_unique(array_merge($phashList, $totalHashList));
330 $totalHashList = array_diff($totalHashList, $phashList);
334 $totalHashList = array_intersect($totalHashList, $phashList);
338 $totalHashList = $phashList;
344 return implode(
',', $totalHashList);
355 return $GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'IR.phash',
'index_words IW, 357 index_section ISEC', $wordSel .
' 359 AND ISEC.phash=IR.phash 361 ' . $additionalWhereClause,
'IR.phash');
372 $wildcard_left = $mode & self::WILDCARD_LEFT ?
'%' :
'';
373 $wildcard_right = $mode & self::WILDCARD_RIGHT ?
'%' :
'';
374 $wSel =
'IW.baseword LIKE \'' . $wildcard_left .
$GLOBALS[
'TYPO3_DB']->quoteStr($sWord,
'index_words') . $wildcard_right .
'\'';
375 $this->wSelClauses[] = $wSel;
387 $wSel =
'IW.wid=' . $this->
md5inthash($sWord);
388 $this->wSelClauses[] = $wSel;
400 $this->wSelClauses[] =
'1=1';
401 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'ISEC.phash',
'index_section ISEC, index_fulltext IFT',
'IFT.fulltextdata LIKE \'%' .
$GLOBALS[
'TYPO3_DB']->quoteStr($sWord,
'index_fulltext') .
'%\' AND 402 ISEC.phash = IFT.phash 414 $wSel =
'IW.metaphone=' . $sWord;
415 $this->wSelClauses[] = $wSel;
428 if (!($this->searchRootPageIdList < 0)) {
429 $whereClause =
' AND ISEC.rl0 IN (' . $this->searchRootPageIdList .
') ';
431 if (substr($this->sections, 0, 4) ==
'rl1_') {
433 $whereClause .=
' AND ISEC.rl1 IN (' . $list .
')';
435 } elseif (substr($this->sections, 0, 4) ==
'rl2_') {
437 $whereClause .=
' AND ISEC.rl2 IN (' . $list .
')';
439 } elseif (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'indexed_search'][
'addRootLineFields'])) {
441 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'indexed_search'][
'addRootLineFields'] as $fieldName => $rootLineLevel) {
442 if (substr($this->sections, 0, strlen($fieldName) + 1) == $fieldName .
'_') {
444 $whereClause .=
' AND ISEC.' . $fieldName .
' IN (' . $list .
')';
452 switch ((
string) $this->sections) {
454 $whereClause .=
' AND ISEC.page_id=' .
$GLOBALS[
'TSFE']->id;
457 $whereClause .=
' AND ISEC.rl2=0';
460 $whereClause .=
' AND ISEC.rl2>0';
474 switch ($this->mediaType) {
477 $whereClause =
' AND IP.item_type=' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr(
'0',
'index_phash');
481 $whereClause =
' AND IP.item_type!=' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr(
'0',
'index_phash');
490 $whereClause =
' AND IP.item_type=' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($this->mediaType,
'index_phash');
502 if ($this->languageUid >= 0) {
503 return ' AND IP.sys_language_uid=' . (int)$this->languageUid;
514 $freeIndexUid = (int)$freeIndexUid;
515 if ($freeIndexUid >= 0) {
517 $indexCfgRec =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetSingleRow(
'indexcfgs',
'index_config',
'type=5 AND uid=' . $freeIndexUid . $this->
enableFields(
'index_config'));
518 if (is_array($indexCfgRec)) {
522 foreach ($refs as $ref) {
527 $idxRec =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetSingleRow(
'uid',
'index_config',
'uid=' .
$uid . $this->
enableFields(
'index_config'));
533 $indexCfgRecordsFromPid =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetRows(
'uid',
'index_config',
'pid=' .
$uid . $this->
enableFields(
'index_config'));
534 foreach ($indexCfgRecordsFromPid as $idxRec) {
535 $list[] = $idxRec[
'uid'];
540 $list = array_unique($list);
542 $list = array($freeIndexUid);
544 return ' AND IP.freeIndexUid IN (' . implode(
',', $list) .
')';
563 if ($hookObj = $this->
hookRequest(
'execFinalQuery_idList')) {
564 $page_where = $hookObj->execFinalQuery_idList($list);
565 } elseif ($this->joinPagesForQuery) {
570 $page_where =
'pages.uid = ISEC.page_id 572 AND pages.no_search=0 573 AND pages.doktype<200 575 } elseif ($this->searchRootPageIdList >= 0) {
580 $pageIdList = array();
581 foreach ($siteIdNumbers as $rootId) {
582 $pageIdList[] =
$GLOBALS[
'TSFE']->cObj->getTreeList(-1 * $rootId, 9999);
584 $page_where =
'ISEC.page_id IN (' . implode(
',', $pageIdList) .
')';
593 if (substr($this->sortOrder, 0, 5) ==
'rank_') {
594 switch ($this->sortOrder) {
598 $grsel =
'MAX(IR.flags) AS order_val1, SUM(IR.freq) AS order_val2';
604 $grsel =
'AVG(IR.first) AS order_val';
609 $grsel =
'SUM(IR.count) AS order_val';
615 $grsel =
'SUM(IR.freq) AS order_val';
619 if (!empty($this->wSelClauses)) {
621 $wordSel =
'(' . implode(
' OR ', $this->wSelClauses) .
') AND ';
623 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
624 'ISEC.*, IP.*, ' . $grsel,
628 index_phash IP' . $page_join,
630 'IP.phash IN (' . $list .
') ' .
633 AND ISEC.phash = IR.phash 634 AND IP.phash = IR.phash 636 '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',
643 switch ((
string) $this->sortOrder) {
654 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'ISEC.*, IP.*',
'index_phash IP,index_section ISEC' . $page_join,
'IP.phash IN (' . $list .
') ' . $this->
mediaTypeWhere() . $this->
languageWhere() . $freeIndexUidClause .
' 655 AND IP.phash = ISEC.phash AND ' . $page_where,
'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', $orderBy);
672 if ($row[
'freeIndexUid']) {
677 if ($row[
'item_type']) {
683 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'phash',
'index_grlist',
'phash=' . (
int)$row[
'phash_t3'] .
' AND gr_list=' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($this->frontendUserGroupList,
'index_grlist'));
687 if ($res &&
$GLOBALS[
'TYPO3_DB']->sql_num_rows($res)) {
694 if ((
string)$row[
'gr_list'] !== (
string)$this->frontendUserGroupList) {
697 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'phash',
'index_grlist',
'phash=' . (
int)$row[
'phash'] .
' AND gr_list=' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($this->frontendUserGroupList,
'index_grlist'));
701 if ($res &&
$GLOBALS[
'TYPO3_DB']->sql_num_rows($res)) {
725 return !$desc ?
' DESC' :
'';
744 return $GLOBALS[
'TSFE']->sys_page->enableFields($table, $table ==
'pages' ?
$GLOBALS[
'TSFE']->showHiddenPage :
$GLOBALS[
'TSFE']->showHiddenRecords);
754 return is_object($this->externalParsers[$itemType]) && $this->externalParsers[$itemType]->isMultiplePageExtension($itemType);
767 return \TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility::md5inthash($str);
779 return \TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility::isTableUsed($table_list);
790 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'indexed_search'][
'pi1_hooks'][$functionName]) {
792 if (method_exists($hookObj, $functionName)) {
793 $hookObj->pObj = $this;
815 return \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(
',', $this->searchRootPageIdList);
initialize($settings, $searchData, $externalParsers, $searchRootPageIdList)
searchWord($sWord, $mode)
execFinalQuery($list, $freeIndexUid=-1)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
getDescendingSortOrderFlag($inverse=FALSE)
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static makeInstance($className)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
multiplePagesType($itemType)
getSearchRootPageIdList()
freeIndexUidWhere($freeIndexUid)
doSearch($searchWords, $freeIndexUid=-1)
execPHashListQuery($wordSel, $additionalWhereClause='')
getResultRows_SQLpointer($searchWords, $freeIndexUid=-1)
hookRequest($functionName)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static revExplode($delimiter, $string, $count=0)