2 namespace TYPO3\CMS\IndexedSearchMysql\Hook;
42 $searchData = $this->getSearchString($searchWordsArray);
47 $GLOBALS[
'TT']->push(
'execFinalQuery');
48 $resource = $this->execFinalQuery_fulltext($searchData, $freeIndexUid);
60 public function getSearchString($searchWordArray)
65 $searchBoolean =
false;
66 $fulltextIndex =
'index_fulltext.fulltextdata';
68 $naturalSearchString =
'';
70 $booleanSearchString =
'';
72 $searchType = (string)$this->pObj->getSearchType();
75 foreach ($searchWordArray as $searchWordData) {
77 $searchWord = $searchWordData[
'sword'];
79 if (strstr($searchWord,
' ')) {
80 $searchType = self::SENTENCE;
82 switch ($searchType) {
83 case self::ANY_PART_OF_THE_WORD:
85 case self::LAST_PART_OF_THE_WORD:
87 case self::FIRST_PART_OF_THE_WORD:
91 $searchBoolean =
true;
93 case self::SOUNDS_LIKE:
94 $indexerObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\IndexedSearch\Indexer::class);
97 $searchWord = $indexerObj->metaphone($searchWord, $indexerObj->storeMetaphoneInfoAsWords);
99 $fulltextIndex =
'index_fulltext.metaphonedata';
102 $searchBoolean =
true;
104 $searchWord = trim(str_replace(
'"',
' ', $searchWord));
108 switch ($searchWordData[
'oper']) {
110 $booleanSearchString .=
' -' . $searchWord . $wildcard;
111 $searchBoolean =
true;
114 $booleanSearchString .=
' ' . $searchWord . $wildcard;
115 $searchBoolean =
true;
118 $booleanSearchString .=
' +' . $searchWord . $wildcard;
119 $naturalSearchString .=
' ' . $searchWord;
123 if ($searchType == self::SENTENCE) {
124 $searchString =
'"' . trim($naturalSearchString) .
'"';
125 }
elseif ($searchBoolean) {
126 $searchString = trim($booleanSearchString);
128 $searchString = trim($naturalSearchString);
131 'searchBoolean' => $searchBoolean,
132 'searchString' => $searchString,
133 'fulltextIndex' => $fulltextIndex
144 protected function execFinalQuery_fulltext($searchData, $freeIndexUid = -1)
149 $freeIndexUidClause = $this->pObj->freeIndexUidWhere($freeIndexUid);
151 $searchRootPageIdList = $this->pObj->getSearchRootPageIdList();
152 if ($hookObj = &$this->pObj->hookRequest(
'execFinalQuery_idList')) {
153 $pageWhere = $hookObj->execFinalQuery_idList(
'');
154 }
elseif ($this->pObj->getJoinPagesForQuery()) {
158 $pageWhere =
'pages.uid = ISEC.page_id
159 ' .
$GLOBALS[
'TSFE']->cObj->enableFields(
'pages') .
'
160 AND pages.no_search=0
161 AND pages.doktype<200
163 }
elseif ($searchRootPageIdList[0] >= 0) {
168 foreach ($searchRootPageIdList as $rootId) {
170 $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
171 $idList[] = $cObj->getTreeList(-1 * $rootId, 9999);
173 $pageWhere =
' ISEC.page_id IN (' . implode(
',', $idList) .
')';
179 if ($searchData[
'searchBoolean']) {
180 $searchBoolean =
' IN BOOLEAN MODE';
182 $resource =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
183 'index_fulltext.*, ISEC.*, IP.*',
184 'index_fulltext, index_section ISEC, index_phash IP' . $pageJoin,
185 'MATCH (' . $searchData[
'fulltextIndex'] .
')
186 AGAINST (' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr($searchData[
'searchString'],
'index_fulltext') . $searchBoolean .
') ' .
187 $this->pObj->mediaTypeWhere() .
' ' . $this->pObj->languageWhere() . $freeIndexUidClause .
'
188 AND index_fulltext.phash = IP.phash
189 AND ISEC.phash = IP.phash
191 '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'