コード例 #1
0
    /**
     * Returns a COMPLETE list of phash-integers matching the search-result composed of the search-words in the sWArr array.
     * The list of phash integers are unsorted and should be used for subsequent selection of index_phash records for display of the result.
     *
     * @param	array		Search word array
     * @return	string		List of integers
     */
    function getPhashList($sWArr)
    {
        // Initialize variables:
        $c = 0;
        $totalHashList = array();
        // This array accumulates the phash-values
        $this->wSelClauses = array();
        // Traverse searchwords; for each, select all phash integers and merge/diff/intersect them with previous word (based on operator)
        foreach ($sWArr as $k => $v) {
            // Making the query for a single search word based on the search-type
            $sWord = $v['sword'];
            // $GLOBALS['TSFE']->csConvObj->conv_case('utf-8',$v['sword'],'toLower');	// lower-case all of them...
            $theType = (string) $this->piVars['type'];
            if (strstr($sWord, ' ')) {
                $theType = 20;
            }
            // If there are spaces in the search-word, make a full text search instead.
            $GLOBALS['TT']->push('SearchWord "' . $sWord . '" - $theType=' . $theType);
            $res = '';
            $wSel = '';
            // Perform search for word:
            switch ($theType) {
                case '1':
                    // Part of word
                    $wSel = "IW.baseword LIKE '%" . $GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_words') . "%'";
                    $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0');
                    break;
                case '2':
                    // First part of word
                    $wSel = "IW.baseword LIKE '" . $GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_words') . "%'";
                    $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0');
                    break;
                case '3':
                    // Last part of word
                    $wSel = "IW.baseword LIKE '%" . $GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_words') . "'";
                    $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0');
                    break;
                case '10':
                    // Sounds like
                    $wSel = 'IW.metaphone = ' . $this->indexerObj->metaphone($sWord);
                    $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0');
                    break;
                case '20':
                    // Sentence
                    $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
									ISEC.phash = IFT.phash
									' . $this->sectionTableWhere(), 'ISEC.phash');
                    $wSel = '1=1';
                    if ($this->piVars['type'] == 20) {
                        $this->piVars['order'] = 'mtime';
                    }
                    // If there is a fulltext search for a sentence there is a likeliness that sorting cannot be done by the rankings from the rel-table (because no relations will exist for the sentence in the word-table). So therefore mtime is used instaed. It is not required, but otherwise some hits may be left out.
                    break;
                default:
                    // Distinct word
                    $wSel = 'IW.wid = ' . ($hash = $this->indexerObj->md5inthash($sWord));
                    $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0');
                    break;
            }
            // Accumulate the word-select clauses
            $this->wSelClauses[] = $wSel;
            // If there was a query to do, then select all phash-integers which resulted from this.
            if ($res) {
                // Get phash list by searching for it:
                $phashList = array();
                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                    $phashList[] = $row['phash'];
                }
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
                // Here the phash list are merged with the existing result based on whether we are dealing with OR, NOT or AND operations.
                if ($c) {
                    switch ($v['oper']) {
                        case 'OR':
                            $totalHashList = array_unique(array_merge($phashList, $totalHashList));
                            break;
                        case 'AND NOT':
                            $totalHashList = array_diff($totalHashList, $phashList);
                            break;
                        default:
                            // AND...
                            $totalHashList = array_intersect($totalHashList, $phashList);
                            break;
                    }
                } else {
                    $totalHashList = $phashList;
                    // First search
                }
            }
            $GLOBALS['TT']->pull();
            $c++;
        }
        return implode(',', $totalHashList);
    }
コード例 #2
0
    /**
     * Show details for metaphone value
     *
     * @param	integer		Metaphone integer hash
     * @return	string		HTML content
     */
    function showDetailsForMetaphone($metaphone)
    {
        // Finding top-20 on frequency for this phash:
        $ftrows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('index_words.*', 'index_words', 'index_words.metaphone = ' . intval($metaphone), '', 'index_words.baseword', '');
        if (count($ftrows)) {
            $content .= '<h4>Metaphone: ' . $this->indexerObj->metaphone($ftrows[0]['baseword'], 1) . '</h4>';
            $content .= '
				<tr class="tableheader bgColor5">
					<td>Word</td>
					<td>Is stopword?</td>
				</tr>';
            if (is_array($ftrows)) {
                foreach ($ftrows as $wDat) {
                    $content .= '
						<tr class="bgColor4">
							<td>' . $this->linkWordDetails(htmlspecialchars($wDat['baseword']), $wDat['wid']) . '</td>
							<td>' . htmlspecialchars($wDat['is_stopword'] ? 'YES' : 'No') . '</td>
						</tr>';
                }
            }
            $content = '
				<table border="0" cellspacing="1" cellpadding="2" class="c-list">' . $content . '
				</table>';
            if ($this->indexerObj->metaphone($ftrows[0]['baseword']) != $metaphone) {
                $content .= 'ERROR: Metaphone string and hash did not match for some reason!?';
            }
            // Add go-back link:
            $content = $content . $this->linkList();
        }
        return $content;
    }