Example #1
0
function db_execute($query, $fetchStyle = PDO::FETCH_BOTH)
{
    DebugInfo::resetClock();
    $result = ORM::get_db()->query($query, $fetchStyle);
    DebugInfo::stopClock("Low-level query: {$query}");
    return $result;
}
 public static function searchFullText($words, $hasDiacritics)
 {
     $intersection = null;
     $matchingLexems = array();
     foreach ($words as $word) {
         $lexems = Lexem::searchInflectedForms($word, $hasDiacritics);
         $lexemIds = array();
         foreach ($lexems as $lexem) {
             $lexemIds[] = $lexem->id;
         }
         $matchingLexems[] = $lexemIds;
     }
     foreach ($words as $i => $word) {
         // Load all the definitions for any possible lexem for this word.
         $lexemIds = $matchingLexems[$i];
         $defIds = FullTextIndex::loadDefinitionIdsForLexems($lexemIds);
         DebugInfo::resetClock();
         $intersection = $intersection === null ? $defIds : util_intersectArrays($intersection, $defIds);
         DebugInfo::stopClock("Intersected with lexems for {$word}");
     }
     if ($intersection === null) {
         // This can happen when the query is all stopwords
         $intersection = array();
     }
     $shortestInvervals = array();
     DebugInfo::resetClock();
     // Now compute a score for every definition
     foreach ($intersection as $defId) {
         // Compute the position matrix (for every word, load all the matching
         // positions)
         $p = array();
         foreach ($matchingLexems as $lexemIds) {
             $p[] = FullTextIndex::loadPositionsByLexemIdsDefinitionId($lexemIds, $defId);
         }
         $shortestIntervals[] = util_findSnippet($p);
     }
     if ($intersection) {
         array_multisort($shortestIntervals, $intersection);
     }
     DebugInfo::stopClock("Computed score for every definition");
     return $intersection;
 }
Example #3
0
 public static function searchFullText($words, $hasDiacritics, $sourceId)
 {
     $field = $hasDiacritics ? 'formNoAccent' : 'formUtf8General';
     $intersection = null;
     $stopWords = array();
     $lmMap = array();
     foreach ($words as $word) {
         // Get all LexemModels generating this form
         $lms = Model::factory('LexemModel')->table_alias('L')->select('L.id')->distinct()->join('InflectedForm', 'I.lexemModelId = L.id', 'I')->where("I.{$field}", $word)->find_many();
         $lmIds = util_objectProperty($lms, 'id');
         $lmMap[] = $lmIds;
         // Get the FullTextIndex records for each LexemModels. Note that the FTI excludes stop words.
         $defIds = FullTextIndex::loadDefinitionIdsForLexemModels($lmIds, $sourceId);
         // Determine whether the word is a stop word.
         if (empty($defIds)) {
             $isStopWord = Model::factory('InflectedForm')->table_alias('I')->join('LexemModel', 'I.lexemModelId = LM.id', 'LM')->join('Lexem', 'LM.lexemId = L.id', 'L')->where("I.{$field}", $word)->where('L.stopWord', 1)->count();
         } else {
             $isStopWord = false;
         }
         if ($isStopWord) {
             $stopWords[] = $word;
         } else {
             $intersection = $intersection === null ? $defIds : util_intersectArrays($intersection, $defIds);
         }
     }
     if (empty($intersection)) {
         // This can happen when the query is all stopwords or the source selection produces no results
         return array(array(), $stopWords);
     }
     if (count($words) == 1) {
         // For single-word queries, skip the ordering part.
         // We could sort the definitions by lexicon, but it is very expensive.
         return array($intersection, $stopWords);
     }
     // Now compute a score for every definition
     DebugInfo::resetClock();
     $positionMap = FullTextIndex::loadPositionsByLexemIdsDefinitionIds($lmMap, $intersection);
     $shortestIntervals = array();
     foreach ($intersection as $defId) {
         $shortestIntervals[] = util_findSnippet($positionMap[$defId]);
     }
     if ($intersection) {
         array_multisort($shortestIntervals, $intersection);
     }
     DebugInfo::stopClock("Computed score for every definition");
     return array($intersection, $stopWords);
 }