Exemplo n.º 1
0
 /**
  * @dataProvider sortCases
  */
 function testOrdering($mode, $expected)
 {
     $query = new Search_Query();
     $query->filterType('wiki page');
     $query->setOrder($mode);
     $results = $query->search($this->index);
     $this->assertOrderIs($expected, $results);
 }
Exemplo n.º 2
0
 function testOrderFromString()
 {
     $index = new Search_Index_Memory();
     $query = new Search_Query();
     $query->setOrder('title_asc');
     $query->search($index);
     $this->assertEquals(new Search_Query_Order('title', 'text', 'asc'), $index->getLastOrder());
 }
Exemplo n.º 3
0
 private function assertResultCorrect($count, $from, $perPage, $first, $last)
 {
     $this->addDocuments($count);
     $query = new Search_Query();
     $query->setOrder('object_id_nasc');
     $query->filterType('article');
     $query->setRange($from, $perPage);
     $result = $query->search($this->index);
     $this->assertEquals($count, count($result), 'total count');
     $real = array();
     foreach ($result as $hit) {
         $real[] = $hit;
     }
     $this->assertEquals($first, $real[0]['object_id'], 'first entry');
     $this->assertEquals($last, $real[count($real) - 1]['object_id'], 'last entry');
 }
Exemplo n.º 4
0
/**
 * Apply tablesorter is enabled
 *
 * @param WikiParser_PluginMatcher $matches
 * @param Search_Query $query
 * @return array
 */
function applyTablesorter(WikiParser_PluginMatcher $matches, Search_Query $query)
{
    $ret = ['max' => false, 'tsOn' => false];
    $parser = new WikiParser_PluginArgumentParser();
    foreach ($matches as $match) {
        $name = $match->getName();
        if ($name == 'tablesorter') {
            $tsargs = $parser->parse($match->getArguments());
            $ajax = !empty($tsargs['server']) && $tsargs['server'] === 'y';
            $ret['tsOn'] = Table_Check::isEnabled($ajax);
            if (!$ret['tsOn']) {
                TikiLib::lib('errorreport')->report(tra('List plugin: Feature "jQuery Sortable Tables" (tablesorter) is not enabled'));
                return $ret;
            }
            if (isset($tsargs['tsortcolumns'])) {
                $tsc = Table_Check::parseParam($tsargs['tsortcolumns']);
            }
            if (isset($tsargs['tspaginate'])) {
                $tsp = Table_Check::parseParam($tsargs['tspaginate']);
                if (isset($tsp[0]['max']) && $ajax) {
                    $ret['max'] = (int) $tsp[0]['max'];
                }
            }
        }
    }
    foreach ($matches as $match) {
        $name = $match->getName();
        if ($name == 'column') {
            $cols[] = $match;
            $args[] = $parser->parse($match->getArguments());
        }
    }
    if (Table_Check::isSort()) {
        foreach ($_GET['sort'] as $key => $dir) {
            $n = '';
            switch ($tsc[$key]['type']) {
                case 'digit':
                case 'currency':
                case 'percent':
                case 'time':
                case strpos($tsc[$key]['type'], 'date') !== false:
                    $n = 'n';
                    break;
            }
            $query->setOrder($args[$key]['field'] . '_' . $n . Table_Check::$dir[$dir]);
        }
    }
    if (Table_Check::isFilter()) {
        foreach ($_GET['filter'] as $key => $filter) {
            $query->filterContent($filter, $args[$key]['field']);
        }
    }
    return $ret;
}