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

📄 class.tx_indexedsearch.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 5 页
字号:
			case '-2':		// All external documents				$out = 'AND IP.item_type!='.$GLOBALS['TYPO3_DB']->fullQuoteStr('0', 'index_phash');;			break;			case '-1':	// All content				$out='';			break;			default:				$out = 'AND IP.item_type='.$GLOBALS['TYPO3_DB']->fullQuoteStr($this->piVars['media'], 'index_phash');			break;		}		return $out;	}	/**	 * Returns AND statement for selection of langauge	 *	 * @return	string		AND statement for selection of langauge	 */	function languageWhere()	{		if ($this->piVars['lang']>=0)	{	// -1 is the same as ALL language.			return 'AND IP.sys_language_uid='.intval($this->piVars['lang']);		}	}	/**	 * Where-clause for free index-uid value.	 *	 * @param	integer		Free Index UID value to limit search to.	 * @return	string		WHERE SQL clause part.	 */	function freeIndexUidWhere($freeIndexUid)	{		if ($freeIndexUid>=0)	{				// First, look if the freeIndexUid is a meta configuration:			list($indexCfgRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('indexcfgs','index_config','type=5 AND uid='.intval($freeIndexUid).$this->cObj->enableFields('index_config'));			if (is_array($indexCfgRec))	{				$refs = t3lib_div::trimExplode(',',$indexCfgRec['indexcfgs']);				$list = array(-99);	// Default value to protect against empty array.				foreach ($refs as $ref)	{					list($table,$uid) = t3lib_div::revExplode('_',$ref,2);					switch ($table)	{						case 'index_config':							list($idxRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid','index_config','uid='.intval($uid).$this->cObj->enableFields('index_config'));							if ($idxRec)	$list[] = $uid;						break;						case 'pages':							$indexCfgRecordsFromPid = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid','index_config','pid='.intval($uid).$this->cObj->enableFields('index_config'));							foreach ($indexCfgRecordsFromPid as $idxRec)	{								$list[] = $idxRec['uid'];							}						break;					}				}				$list = array_unique($list);			} else {				$list = array(intval($freeIndexUid));			}			return ' AND IP.freeIndexUid IN ('.implode(',',$list).')';		}	}	/**	 * Execute final query, based on phash integer list. The main point is sorting the result in the right order.	 *	 * @param	string		List of phash integers which match the search.	 * @param	integer		Pointer to which indexing configuration you want to search in. -1 means no filtering. 0 means only regular indexed content.	 * @return	pointer		Query result pointer	 */	function execFinalQuery($list,$freeIndexUid=-1)	{			// Setting up methods of filtering results based on page types, access, etc.		$page_join = '';		$page_where = '';			// Indexing configuration clause:		$freeIndexUidClause = $this->freeIndexUidWhere($freeIndexUid);			// Calling hook for alternative creation of page ID list		if ($hookObj = &$this->hookRequest('execFinalQuery_idList'))	{			$page_where = $hookObj->execFinalQuery_idList($list);		} elseif ($this->join_pages)	{	// Alternative to getting all page ids by ->getTreeList() where "excludeSubpages" is NOT respected.			$page_join = ',				pages';			$page_where = 'pages.uid = ISEC.page_id				'.$this->cObj->enableFields('pages').'				AND pages.no_search=0				AND pages.doktype<200			';		} elseif ($this->wholeSiteIdList>=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!			$siteIdNumbers = t3lib_div::intExplode(',',$this->wholeSiteIdList);			$id_list=array();			while(list(,$rootId)=each($siteIdNumbers))	{				$id_list[] = $this->cObj->getTreeList($rootId,9999,0,0,'','').$rootId;			}			$page_where = 'ISEC.page_id IN ('.implode(',',$id_list).')';		} else {	// Disable everything... (select all)			$page_where = ' 1=1 ';		}			// If any of the ranking sortings are selected, we must make a join with the word/rel-table again, because we need to calculate ranking based on all search-words found.		if (substr($this->piVars['order'],0,5)=='rank_')	{				/*					 OK there were some fancy calculations promoted by Graeme Merrall:					"However, regarding relevance you probably want to look at something like					Salton's formula which is a good easy way to measure relevance.					Oracle Intermedia uses this and it's pretty simple:					Score can be between 0 and 100, but the top-scoring document in the query					will not necessarily have a score of 100 -- scoring is relative, not					absolute. This means that scores are not comparable across indexes, or even					across different queries on the same index. Score for each document is					computed using the standard Salton formula:					    3f(1+log(N/n))					Where f is the frequency of the search term in the document, N is the total					number of rows in the table, and n is the number of rows which contain the					search term. This is converted into an integer in the range 0 - 100.					There's a good doc on it at					http://ls6-www.informatik.uni-dortmund.de/bib/fulltext/ir/Pfeifer:97/					although it may be a little complex for what you require so just pick the					relevant parts out.					"					However I chose not to go with this for several reasons.					I do not claim that my ways of calculating importance here is the best.					ANY (better) suggestion for ranking calculation is accepted! (as long as they are shipped with tested code in exchange for this.)				*/			switch($this->piVars['order'])	{				case 'rank_flag':	// This gives priority to word-position (max-value) so that words in title, keywords, description counts more than in content.									// The ordering is refined with the frequency sum as well.					$grsel = 'MAX(IR.flags) AS order_val1, SUM(IR.freq) AS order_val2';					$orderBy = 'order_val1'.$this->isDescending().',order_val2'.$this->isDescending();				break;				case 'rank_first':	// Results in average position of search words on page. Must be inversely sorted (low numbers are closer to top)					$grsel = 'AVG(IR.first) AS order_val';					$orderBy = 'order_val'.$this->isDescending(1);				break;				case 'rank_count':	// Number of words found					$grsel = 'SUM(IR.count) AS order_val';					$orderBy = 'order_val'.$this->isDescending();				break;				default:	// Frequency sum. I'm not sure if this is the best way to do it (make a sum...). Or should it be the average?					$grsel = 'SUM(IR.freq) AS order_val';					$orderBy = 'order_val'.$this->isDescending();				break;			}				// So, words are imploded into an OR statement (no "sentence search" should be done here - may deselect results)			$wordSel='('.implode(' OR ',$this->wSelClauses).') AND ';			return $GLOBALS['TYPO3_DB']->exec_SELECTquery(						'ISEC.*, IP.*, '						.$grsel,						'index_words IW,							index_rel IR,							index_section ISEC,							index_phash IP'.							$page_join,						$wordSel.'							IP.phash IN ('.$list.') '.							$this->mediaTypeWhere().' '.							$this->languageWhere().							$freeIndexUidClause.'							AND IW.wid=IR.wid							AND ISEC.phash = IR.phash							AND IP.phash = IR.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					);		} else {	// Otherwise, if sorting are done with the pages table or other fields, there is no need for joining with the rel/word tables:			$orderBy = '';			switch((string)$this->piVars['order'])	{				case 'title':					$orderBy = 'IP.item_title'.$this->isDescending();				break;				case 'crdate':					$orderBy = 'IP.item_crdate'.$this->isDescending();				break;				case 'mtime':					$orderBy = 'IP.item_mtime'.$this->isDescending();				break;			}			return $GLOBALS['TYPO3_DB']->exec_SELECTquery(						'ISEC.*, IP.*',						'index_phash IP,index_section ISEC'.$page_join,						'IP.phash IN ('.$list.') '.							$this->mediaTypeWhere().' '.							$this->languageWhere().							$freeIndexUidClause.'							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					);		}	}	/**	 * Checking if the resume can be shown for the search result (depending on whether the rights are OK)	 * ? Should it also check for gr_list "0,-1"?	 *	 * @param	array		Result row array.	 * @return	boolean		Returns true if resume can safely be shown	 */	function checkResume($row)	{			// If the record is indexed by an indexing configuration, just show it.			// At least this is needed for external URLs and files.			// For records we might need to extend this - for instance block display if record is access restricted.		if ($row['freeIndexUid'])	{			return TRUE;		}			// Evaluate regularly indexed pages based on item_type:		if ($row['item_type'])	{	// External media:				// For external media we will check the access of the parent page on which the media was linked from.				// "phash_t3" is the phash of the parent TYPO3 page row which initiated the indexing of the documents in this section.				// So, selecting for the grlist records belonging to the parent phash-row where the current users gr_list exists will help us to know.				// If this is NOT found, there is still a theoretical possibility that another user accessible page would display a link, so maybe the resume of such a document here may be unjustified hidden. But better safe than sorry.			$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('phash', 'index_grlist', 'phash='.intval($row['phash_t3']).' AND gr_list='.$GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['TSFE']->gr_list, 'index_grlist'));			if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))	{				#debug("Look up for external media '".$row['data_filename']."': phash:".$row['phash_t3'].' YES - ('.$GLOBALS['TSFE']->gr_list.")!",1);				return TRUE;			} else {				#debug("Look up for external media '".$row['data_filename']."': phash:".$row['phash_t3'].' NO - ('.$GLOBALS['TSFE']->gr_list.")!",1);				return FALSE;			}		} else {	// Ordinary TYPO3 pages:			if (strcmp($row['gr_list'],$GLOBALS['TSFE']->gr_list))	{					// Selecting for the grlist records belonging to the phash-row where the current users gr_list exists. If it is found it is proof that this user has direct access to the phash-rows content although he did not himself initiate the indexing...				$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('phash', 'index_grlist', 'phash='.intval($row['phash']).' AND gr_list='.$GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['TSFE']->gr_list, 'index_grlist'));				if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))	{					#debug('Checking on it ...'.$row['item_title'].'/'.$row['phash'].' - YES ('.$GLOBALS['TSFE']->gr_list.")",1);					return TRUE;				} else {					#debug('Checking on it ...'.$row['item_title'].'/'.$row['phash']." - NOPE",1);					return FALSE;				}			} else {					#debug('Resume can be shown, because the document was in fact indexed by this combination of groups!'.$GLOBALS['TSFE']->gr_list.' - '.$row['item_title'].'/'.$row['phash'],1);				return TRUE;			}		}	}	/**	 * Returns "DESC" or "" depending on the settings of the incoming highest/lowest result order (piVars['desc']	 *	 * @param	boolean		If true, inverse the order which is defined by piVars['desc']	 * @return	string		" DESC" or ""	 */	function isDescending($inverse=FALSE)	{		$desc = $this->piVars['desc'];		if ($inverse)	$desc=!$desc;		return !$desc ? ' DESC':'';	}	/**	 * Write statistics information to database for the search operation	 *	 * @param	array		Search Word array	 * @param	integer		Number of hits	 * @param	integer		Milliseconds the search took	 * @return	void	 */	function writeSearchStat($sWArr,$count,$pt)	{		$insertFields = array(			'searchstring' => $this->piVars['sword'],			'searchoptions' => serialize(array($this->piVars,$sWArr,$pt)),			'feuser_id' => intval($this->fe_user->user['uid']),			// fe_user id, integer			'cookie' => $this->fe_user->id,						// cookie as set or retrieve. If people has cookies disabled this will vary all the time...			'IP' => t3lib_div::getIndpEnv('REMOTE_ADDR'),		// Remote IP address			'hits' => intval($count),							// Number of hits on the search.			'tstamp' => $GLOBALS['EXEC_TIME']					// Time stamp		);		$GLOBALS['TYPO3_DB']->exec_INSERTquery('index_stat_search', $insertFields);		$newId = $GLOBALS['TYPO3_DB']->sql_insert_id();		if ($newId)	{			foreach ($sWArr as $val)	{				$insertFields = array(					'word' => $val['sword'],		// $GLOBALS['TSFE']->csConvObj->conv_case('utf-8', $val['sword'], 'toLower'),					'index_stat_search_id' => $newId,					'tstamp' => $GLOBALS['EXEC_TIME'],		// Time stamp					'pageid' => $GLOBALS['TSFE']->id	//search page id for indexed search stats				);				$GLOBALS['TYPO3_DB']->exec_INSERTquery('index_stat_word', $insertFields);			}		}	}	/***********************************	 *	 * HTML output functions	 *	 ***********************************/	/**	 * Make search form HTML	 *

⌨️ 快捷键说明

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