⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.tx_indexedsearch.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 5 页
字号:
			// This is the id of the site root. This value may be a commalist of integer (prepared for this)		$this->wholeSiteIdList = intval($GLOBALS['TSFE']->config['rootLine'][0]['uid']);			// Creating levels for section menu:			// This selects the first and secondary menus for the "sections" selector - so we can search in sections and sub sections.		if ($this->conf['show.']['L1sections'])	{			$firstLevelMenu = $this->getMenu($this->wholeSiteIdList);			while(list($kk,$mR) = each($firstLevelMenu))	{				if ($mR['doktype']!=5)	{					$this->optValues['sections']['rl1_'.$mR['uid']] = trim($this->pi_getLL('opt_RL1').' '.$mR['title']);					if ($this->conf['show.']['L2sections'])	{						$secondLevelMenu = $this->getMenu($mR['uid']);						while(list($kk2,$mR2) = each($secondLevelMenu))	{							if ($mR['doktype']!=5)	{								$this->optValues['sections']['rl2_'.$mR2['uid']] = trim($this->pi_getLL('opt_RL2').' '.$mR2['title']);							} else unset($secondLevelMenu[$kk2]);						}						$this->optValues['sections']['rl2_'.implode(',',array_keys($secondLevelMenu))] = $this->pi_getLL('opt_RL2ALL');					}				} else unset($firstLevelMenu[$kk]);			}			$this->optValues['sections']['rl1_'.implode(',',array_keys($firstLevelMenu))] = $this->pi_getLL('opt_RL1ALL');		}			// Setting the list of root PIDs for the search. Notice, these page IDs MUST have a TypoScript template with root flag on them! Basically this list is used to select on the "rl0" field and page ids are registered as "rl0" only if a TypoScript template record with root flag is there.			// This happens AFTER the use of $this->wholeSiteIdList above because the above will then fetch the menu for the CURRENT site - regardless of this kind of searching here. Thus a general search will lookup in the WHOLE database while a specific section search will take the current sections...		if ($this->conf['search.']['rootPidList'])	{			$this->wholeSiteIdList = implode(',',t3lib_div::intExplode(',',$this->conf['search.']['rootPidList']));		}			// Load the template		$this->templateCode = $this->cObj->fileResource($this->conf['templateFile']);			// Add search languages:		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_language', '1=1'.$this->cObj->enableFields('sys_language'));		while($lR = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{			$this->optValues['lang'][$lR['uid']] = $lR['title'];		}			// Calling hook for modification of initialized content		if ($hookObj = &$this->hookRequest('initialize_postProc'))	{			$hookObj->initialize_postProc();		}			// Default values set:			// Setting first values in optValues as default values IF there is not corresponding piVar value set already.		foreach ($this->optValues as $kk => $vv)	{			if (!isset($this->piVars[$kk]))	{				reset($vv);				$this->piVars[$kk] = key($vv);			}		}			// Blind selectors:		if (is_array($this->conf['blind.']))	{			foreach ($this->conf['blind.'] as $kk => $vv)	{				if (is_array($vv))	{					foreach ($vv as $kkk => $vvv)	{						if (!is_array($vvv) && $vvv && is_array($this->optValues[substr($kk,0,-1)]))	{							unset($this->optValues[substr($kk,0,-1)][$kkk]);						}					}				} elseif ($vv) {	// If value is not set, unset the option array.					unset($this->optValues[$kk]);				}			}		}			// This gets the search-words into the $sWArr:		$this->sWArr = $this->getSearchWords($this->piVars['defOp']);	}	/**	 * Splits the search word input into an array where each word is represented by an array with key "sword" holding the search word and key "oper" holds the SQL operator (eg. AND, OR)	 *	 * Only words with 2 or more characters are accepted	 * Max 200 chars total	 * Space is used to split words, "" can be used search for a whole string (not indexed search then)	 * AND, OR and NOT are prefix words, overruling the default operator	 * +/|/- equals AND, OR and NOT as operators.	 * All search words are converted to lowercase.	 *	 * $defOp is the default operator. 1=OR, 0=AND	 *	 * @param	boolean		If true, the default operator will be OR, not AND	 * @return	array		Returns array with search words if any found	 */	function getSearchWords($defOp)	{			// Shorten search-word string to max 200 bytes (does NOT take multibyte charsets into account - but never mind, shortening the string here is only a run-away feature!)		$inSW = substr($this->piVars['sword'],0,200);			// Convert to UTF-8 + conv. entities (was also converted during indexing!)		$inSW = $GLOBALS['TSFE']->csConvObj->utf8_encode($inSW, $GLOBALS['TSFE']->metaCharset);		$inSW = $GLOBALS['TSFE']->csConvObj->entities_to_utf8($inSW,TRUE);		if ($hookObj = &$this->hookRequest('getSearchWords'))	{			return $hookObj->getSearchWords_splitSWords($inSW, $defOp);		} else {			if ($this->piVars['type']==20)	{				return array(array('sword'=>trim($inSW), 'oper'=>'AND'));			} else {				$search = t3lib_div::makeInstance('tslib_search');				$search->default_operator = $defOp==1 ? 'OR' : 'AND';				$search->operator_translate_table = $this->operator_translate_table;				$search->register_and_explode_search_string($inSW);				if (is_array($search->sword_array))	{					return $this->procSearchWordsByLexer($search->sword_array);				}			}		}	}	/**	 * Post-process the search word array so it will match the words that was indexed (including case-folding if any)	 * If any words are splitted into multiple words (eg. CJK will be!) the operator of the main word will remain.	 *	 * @param	array		Search word array	 * @return	array		Search word array, processed through lexer	 */	function procSearchWordsByLexer($SWArr)	{			// Init output variable:		$newSWArr = array();			// Traverse the search word array:		foreach ($SWArr as $wordDef)	{			if (!strstr($wordDef['sword'],' '))	{	// No space in word (otherwise it might be a sentense in quotes like "there is").					// Split the search word by lexer:				$res = $this->lexerObj->split2Words($wordDef['sword']);					// Traverse lexer result and add all words again:				foreach ($res as $word)	{					$newSWArr[] = array('sword'=>$word, 'oper'=>$wordDef['oper']);				}			} else {				$newSWArr[] = $wordDef;			}		}			// Return result:		return $newSWArr;	}	/*****************************	 *	 * Main functions	 *	 *****************************/	/**	 * Performs the search, the display and writing stats	 *	 * @param	array		Search words in array, see ->getSearchWords() for details	 * @return	string		HTML for result display.	 */	function doSearch($sWArr)	{			// Find free index uid:		$freeIndexUid = $this->piVars['freeIndexUid'];		if ($freeIndexUid==-2)	{			$freeIndexUid = $this->conf['search.']['defaultFreeIndexUidList'];		}		$indexCfgs = t3lib_div::intExplode(',',$freeIndexUid);		$accumulatedContent = '';		foreach ($indexCfgs as $freeIndexUid)	{				// Get result rows:			$pt1 = t3lib_div::milliseconds();			if ($hookObj = &$this->hookRequest('getResultRows'))	{				$resData = $hookObj->getResultRows($sWArr,$freeIndexUid);			} else {				$resData = $this->getResultRows($sWArr,$freeIndexUid);			}				// Display search results:			$pt2 = t3lib_div::milliseconds();			if ($hookObj = &$this->hookRequest('getDisplayResults'))	{				$content = $hookObj->getDisplayResults($sWArr, $resData, $freeIndexUid);			} else {				$content = $this->getDisplayResults($sWArr, $resData, $freeIndexUid);			}			$pt3 = t3lib_div::milliseconds();				// Create header if we are searching more than one indexing configuration:			if (count($indexCfgs)>1)	{				if ($freeIndexUid>0)	{					list($indexCfgRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('title','index_config','uid='.intval($freeIndexUid).$this->cObj->enableFields('index_config'));					$titleString = $indexCfgRec['title'];				} else {					$titleString = $this->pi_getLL('opt_freeIndexUid_header_'.$freeIndexUid);				}				$content = '<h1 class="tx-indexedsearch-category">'.htmlspecialchars($titleString).'</h1>'.$content;			}			$accumulatedContent.=$content;		}			// Write search statistics		$this->writeSearchStat($sWArr,$resData['count'],array($pt1,$pt2,$pt3));			// Return content:		return $accumulatedContent;	}	/**	 * Get search result rows / data from database. Returned as data in array.	 *	 * @param	array		Search word array	 * @param	integer		Pointer to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content.	 * @return	array		False if no result, otherwise an array with keys for first row, result rows and total number of results found.	 */	function getResultRows($sWArr,$freeIndexUid=-1)	{			// Getting SQL result pointer:			$GLOBALS['TT']->push('Searching result');		$res = $this->getResultRows_SQLpointer($sWArr,$freeIndexUid);			$GLOBALS['TT']->pull();			// Organize and process result:		if ($res)	{			$count = $GLOBALS['TYPO3_DB']->sql_num_rows($res);	// Total search-result count			$pointer = t3lib_div::intInRange($this->piVars['pointer'], 0, floor($count/$this->piVars['results']));	// The pointer is set to the result page that is currently being viewed				// Initialize result accumulation variables:			$c = 0;	// Result pointer: Counts up the position in the current search-result			$grouping_phashes = array();	// Used to filter out duplicates.			$grouping_chashes = array();	// Used to filter out duplicates BASED ON cHash.			$firstRow = Array();	// Will hold the first row in result - used to calculate relative hit-ratings.			$resultRows = Array();	// Will hold the results rows for display.				// Now, traverse result and put the rows to be displayed into an array				// Each row should contain the fields from 'ISEC.*, IP.*' combined + artificial fields "show_resume" (boolean) and "result_number" (counter)			while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))	{					// Set first row:				if (!$c)	{					$firstRow = $row;				}				$row['show_resume'] = $this->checkResume($row);	// Tells whether we can link directly to a document or not (depends on possible right problems)				$phashGr = !in_array($row['phash_grouping'], $grouping_phashes);				$chashGr = !in_array($row['contentHash'].'.'.$row['data_page_id'], $grouping_chashes);				if ($phashGr && $chashGr)	{					if ($row['show_resume'] || $this->conf['show.']['forbiddenRecords'])	{	// Only if the resume may be shown are we going to filter out duplicates...						if (!$this->multiplePagesType($row['item_type']))	{	// Only on documents which are not multiple pages documents							$grouping_phashes[] = $row['phash_grouping'];						}						$grouping_chashes[] = $row['contentHash'].'.'.$row['data_page_id'];						$c++;	// Increase the result pointer							// All rows for display is put into resultRows[]						if ($c > $pointer * $this->piVars['results'])	{							$row['result_number'] = $c;							$resultRows[] = $row;								// This may lead to a problem: If the result check is not stopped here, the search will take longer. However the result counter will not filter out grouped cHashes/pHashes that were not processed yet.							if (($c+1) > ($pointer+1)*$this->piVars['results'])	break;						}					} else {						$count--;	// Skip this row if the user cannot view it (missing permission)					}				} else {					$count--;	// For each time a phash_grouping document is found (which is thus not displayed) the search-result count is reduced, so that it matches the number of rows displayed.				}			}			return array(						'resultRows' => $resultRows,						'firstRow' => $firstRow,						'count' => $count					);		} else {	// No results found:			return FALSE;		}	}	/**	 * Gets a SQL result pointer to traverse for the search records.	 *	 * @param	array		Search words	 * @param	integer		Pointer to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content.	 * @return	pointer	 */	function getResultRows_SQLpointer($sWArr,$freeIndexUid=-1)	{				// This SEARCHES for the searchwords in $sWArr AND returns a COMPLETE list of phash-integers of the matches.		$list = $this->getPhashList($sWArr);			// Perform SQL Search / collection of result rows array:		if ($list)	{				// Do the search:			$GLOBALS['TT']->push('execFinalQuery');			$res = $this->execFinalQuery($list,$freeIndexUid);			$GLOBALS['TT']->pull();			return $res;		} else {			return FALSE;		}	}	/**	 * Compiles the HTML display of the incoming array of result rows.	 *	 * @param	array		Search words array (for display of text describing what was searched for)	 * @param	array		Array with result rows, count, first row.	 * @param	integer		Pointer to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content.	 * @return	string		HTML content to display result.	 */	function getDisplayResults($sWArr, $resData, $freeIndexUid=-1)	{			// Perform display of result rows array:		if ($resData)	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -