Esempio n. 1
0
 protected function analyzeScore(array $resultDocument)
 {
     $highScores = array();
     $debugData = $this->search->getDebugResponse()->explain->{$resultDocument['id']};
     /* TODO Provide better parsing
      *
      * parsing could be done line by line,
      * 		* recording indentation level
      * 		* replacing abbreviations
      * 		* replacing phrases like "product of" by mathematical symbols (* or x)
      * 		* ...
      */
     // matches search term weights, ex: 0.42218783 = (MATCH) weight(content:iPod^40.0 in 43), product of:
     $pattern = '/(.*) = \\(MATCH\\) weight\\((.*)\\^/';
     $matches = array();
     preg_match_all($pattern, $debugData, $matches);
     foreach ($matches[0] as $key => $value) {
         // split field from search term
         list($field, $searchTerm) = explode(':', $matches[2][$key]);
         // keep track of highest score per search term
         if (!isset($highScores[$field]) || $highScores[$field]['score'] < $matches[1][$key]) {
             $highScores[$field] = array('score' => $matches[1][$key], 'field' => $field, 'searchTerm' => $searchTerm);
         }
     }
     return $highScores;
 }