Ejemplo n.º 1
0
 function find(Search_Expr_Interface $query, Search_Query_Order $sortOrder, $resultStart, $resultCount)
 {
     $data = $this->internalFind($query, $sortOrder);
     $result = array_slice($data['result'], $resultStart, $resultCount);
     $resultSet = new Search_ResultSet($result, count($data['result']), $resultStart, $resultCount);
     $resultSet->setEstimate($data['count']);
     if ($this->highlight) {
         $resultSet->setHighlightHelper(new Search_Index_Lucene_HighlightHelper($query));
     } else {
         $resultSet->setHighlightHelper(new Search_ResultSet_SnippetHelper());
     }
     return $resultSet;
 }
Ejemplo n.º 2
0
 function testHighlightRequested()
 {
     $plugin = new Search_Formatter_Plugin_WikiTemplate('{display name=highlight}');
     $resultSet = new Search_ResultSet(array(array('object_type' => 'wiki page', 'object_id' => 'HomePage', 'content' => 'Hello World'), array('object_type' => 'wiki page', 'object_id' => 'SomePage', 'content' => 'Test')), 22, 20, 10);
     $resultSet->setHighlightHelper(new Search_FormatterTest_HighlightHelper());
     $formatter = new Search_Formatter($plugin);
     $output = $formatter->format($resultSet);
     $this->assertContains('<strong>Hello</strong>', $output);
 }
Ejemplo n.º 3
0
 function find(Search_Query_Interface $query, $resultStart, $resultCount)
 {
     try {
         $words = $this->getWords($query->getExpr());
         $condition = $this->builder->build($query->getExpr());
         $conditions = empty($condition) ? array() : array($this->table->expr($condition));
         $scoreField = null;
         $indexes = $this->builder->getRequiredIndexes();
         foreach ($indexes as $index) {
             $this->table->ensureHasIndex($index['field'], $index['type']);
             if (!$scoreField && $index['type'] == 'fulltext') {
                 $scoreField = $index['field'];
             }
         }
         $this->table->flush();
         $order = $this->getOrderClause($query, (bool) $scoreField);
         $selectFields = $this->table->all();
         if ($scoreField) {
             $str = $this->db->qstr(implode(' ', $words));
             $selectFields['score'] = $this->table->expr("ROUND(MATCH(`{$scoreField}`) AGAINST ({$str}),2)");
         }
         $count = $this->table->fetchCount($conditions);
         $entries = $this->table->fetchAll($selectFields, $conditions, $resultCount, $resultStart, $order);
         $resultSet = new Search_ResultSet($entries, $count, $resultStart, $resultCount);
         $resultSet->setHighlightHelper(new Search_MySql_HighlightHelper($words));
         return $resultSet;
     } catch (Search_MySql_QueryException $e) {
         $resultSet = new Search_ResultSet(array(), 0, $resultStart, $resultCount);
         return $resultSet;
     }
 }