2 namespace TYPO3\CMS\IndexedSearch\Domain\Repository;
20 use TYPO3\CMS\IndexedSearch\Utility;
176 if ($settings[
'searchSkipExtendToSubpagesChecking']) {
177 $this->joinPagesForQuery = 1;
179 if ($settings[
'exactCount']) {
180 $this->useExactCount =
true;
182 if ($settings[
'displayForbiddenRecords']) {
183 $this->displayForbiddenRecords =
true;
185 $this->sections = $searchData[
'sections'];
186 $this->searchType = $searchData[
'searchType'];
187 $this->languageUid = $searchData[
'languageUid'];
188 $this->mediaType = isset($searchData[
'mediaType']) ? $searchData[
'mediaType'] :
false;
189 $this->sortOrder = $searchData[
'sortOrder'];
190 $this->descendingSortOrderFlag = $searchData[
'desc'];
191 $this->resultpagePointer = $searchData[
'pointer'];
192 if (isset($searchData[
'numberOfResults']) && is_numeric($searchData[
'numberOfResults'])) {
193 $this->numberOfResults = (int)$searchData[
'numberOfResults'];
204 public function doSearch($searchWords, $freeIndexUid = -1)
208 if ($hookObj = &$this->
hookRequest(
'getResultRows_SQLpointer')) {
209 $res = $hookObj->getResultRows_SQLpointer($searchWords, $freeIndexUid);
223 $grouping_phashes = array();
225 $grouping_chashes = array();
229 $resultRows = array();
242 $phashGr = !in_array($row[
'phash_grouping'], $grouping_phashes);
243 $chashGr = !in_array(($row[
'contentHash'] .
'.' . $row[
'data_page_id']), $grouping_chashes);
244 if ($phashGr && $chashGr) {
246 if ($row[
'show_resume'] || $this->displayForbiddenRecords) {
248 if (!$this->multiplePagesType($row[
'item_type'])) {
249 $grouping_phashes[] = $row[
'phash_grouping'];
251 $grouping_chashes[] = $row[
'contentHash'] .
'.' . $row[
'data_page_id'];
255 if ($c > $pointer * $this->numberOfResults && $c <= $pointer * $this->numberOfResults + $this->numberOfResults) {
256 $row[
'result_number'] = $c;
257 $resultRows[] = $row;
261 if (!$this->useExactCount && $c + 1 > ($pointer + 1) * $this->numberOfResults) {
281 'resultRows' => $resultRows,
282 'firstRow' => $firstRow,
302 $list = $this->getPhashList($searchWords);
327 protected function getPhashList($searchWords)
332 $totalHashList = array();
333 $this->wSelClauses = array();
335 foreach ($searchWords as $k => $v) {
337 $sWord = $v[
'sword'];
338 $theType = (string)$this->searchType;
340 if (strstr($sWord,
' ')) {
343 $this->
getTimeTracker()->push(
'SearchWord "' . $sWord .
'" - $theType=' . $theType);
367 $storeMetaphoneInfoAsWords = !$this->
isTableUsed(
'index_words');
379 $this->sortOrder =
'mtime';
388 $phashList = array();
390 $phashList[] = $row[
'phash'];
395 switch ($v[
'oper']) {
397 $totalHashList = array_unique(array_merge($phashList, $totalHashList));
400 $totalHashList = array_diff($totalHashList, $phashList);
404 $totalHashList = array_intersect($totalHashList, $phashList);
408 $totalHashList = $phashList;
414 return implode(
',', $totalHashList);
428 'index_words IW, index_rel IR, index_section ISEC',
429 $wordSel .
' AND IW.wid=IR.wid AND ISEC.phash=IR.phash' . $this->
sectionTableWhere() . $additionalWhereClause,
443 $likeWildcard = Utility\LikeWildcard::cast($wildcard);
444 $wSel = $likeWildcard->getLikeQueryPart(
449 $this->wSelClauses[] = $wSel;
461 $wSel =
'IW.wid=' . $this->
md5inthash($sWord);
462 $this->wSelClauses[] = $wSel;
474 $this->wSelClauses[] =
'1=1';
476 $likePart = $likeWildcard->getLikeQueryPart(
484 'index_section ISEC, index_fulltext IFT',
498 $wSel =
'IW.metaphone=' . $sWord;
499 $this->wSelClauses[] = $wSel;
512 if (!($this->searchRootPageIdList < 0)) {
513 $whereClause =
' AND ISEC.rl0 IN (' . $this->searchRootPageIdList .
') ';
515 if (substr($this->sections, 0, 4) ==
'rl1_') {
517 $whereClause .=
' AND ISEC.rl1 IN (' .
$list .
')';
519 }
elseif (substr($this->sections, 0, 4) ==
'rl2_') {
521 $whereClause .=
' AND ISEC.rl2 IN (' .
$list .
')';
523 }
elseif (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'indexed_search'][
'addRootLineFields'])) {
525 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'indexed_search'][
'addRootLineFields'] as $fieldName => $rootLineLevel) {
526 if (substr($this->sections, 0, strlen($fieldName) + 1) == $fieldName .
'_') {
528 $whereClause .=
' AND ISEC.' . $fieldName .
' IN (' .
$list .
')';
536 switch ((
string)$this->sections) {
541 $whereClause .=
' AND ISEC.rl2=0';
544 $whereClause .=
' AND ISEC.rl2>0';
558 switch ($this->mediaType) {
561 $whereClause =
' AND IP.item_type=' . $this->
getDatabaseConnection()->fullQuoteStr(
'0',
'index_phash');
565 $whereClause =
' AND IP.item_type!=' . $this->
getDatabaseConnection()->fullQuoteStr(
'0',
'index_phash');
574 $whereClause =
' AND IP.item_type=' . $this->
getDatabaseConnection()->fullQuoteStr($this->mediaType,
'index_phash');
587 if ($this->languageUid >= 0) {
588 return ' AND IP.sys_language_uid=' . (int)$this->languageUid;
601 $freeIndexUid = (int)$freeIndexUid;
602 if ($freeIndexUid >= 0) {
604 $indexCfgRec = $this->
getDatabaseConnection()->exec_SELECTgetSingleRow(
'indexcfgs',
'index_config',
'type=5 AND uid=' . $freeIndexUid . $this->
enableFields(
'index_config'));
605 if (is_array($indexCfgRec)) {
609 foreach ($refs as $ref) {
621 foreach ($indexCfgRecordsFromPid as $idxRec) {
622 $list[] = $idxRec[
'uid'];
629 $list = array($freeIndexUid);
631 return ' AND IP.freeIndexUid IN (' . implode(
',',
$list) .
')';
651 if ($hookObj = $this->
hookRequest(
'execFinalQuery_idList')) {
652 $page_where = $hookObj->execFinalQuery_idList(
$list);
653 }
elseif ($this->joinPagesForQuery) {
658 $page_where =
'pages.uid = ISEC.page_id
660 AND pages.no_search=0
661 AND pages.doktype<200
663 }
elseif ($this->searchRootPageIdList >= 0) {
668 $pageIdList = array();
669 foreach ($siteIdNumbers as $rootId) {
672 $page_where =
'ISEC.page_id IN (' . implode(
',', $pageIdList) .
')';
681 if (substr($this->sortOrder, 0, 5) ===
'rank_') {
682 switch ($this->sortOrder) {
686 $grsel =
'MAX(IR.flags) AS order_val1, SUM(IR.freq) AS order_val2';
692 $grsel =
'AVG(IR.first) AS order_val';
697 $grsel =
'SUM(IR.count) AS order_val';
703 $grsel =
'SUM(IR.freq) AS order_val';
707 if (!empty($this->wSelClauses)) {
709 $wordSel =
'(' . implode(
' OR ', $this->wSelClauses) .
') AND ';
712 'ISEC.*, IP.*, ' . $grsel,
716 index_phash IP' . $page_join,
718 'IP.phash IN (' .
$list .
') ' .
721 AND ISEC.phash = IR.phash
722 AND IP.phash = IR.phash
724 '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',
731 switch ((
string)$this->sortOrder) {
743 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);
761 if ($row[
'freeIndexUid']) {
766 if ($row[
'item_type']) {
772 $res = $this->
getDatabaseConnection()->exec_SELECTquery(
'phash',
'index_grlist',
'phash=' . (
int)$row[
'phash_t3'] .
' AND gr_list=' . $this->
getDatabaseConnection()->fullQuoteStr($this->frontendUserGroupList,
'index_grlist'));
783 if ((
string)$row[
'gr_list'] !== (
string)$this->frontendUserGroupList) {
786 $res = $this->
getDatabaseConnection()->exec_SELECTquery(
'phash',
'index_grlist',
'phash=' . (
int)$row[
'phash'] .
' AND gr_list=' . $this->
getDatabaseConnection()->fullQuoteStr($this->frontendUserGroupList,
'index_grlist'));
815 return !$desc ?
' DESC' :
'';
843 protected function multiplePagesType($itemType)
846 $fileContentParser = $this->externalParsers[$itemType];
847 return is_object($fileContentParser) && $fileContentParser->isMultiplePageExtension($itemType);
861 return Utility\IndexedSearchUtility::md5inthash($str);
874 return Utility\IndexedSearchUtility::isTableUsed($table_list);
886 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'indexed_search'][
'pi1_hooks'][$functionName]) {
888 if (method_exists($hookObj, $functionName)) {
889 $hookObj->pObj = $this;