Exemplo n.º 1
0
 function testWeightImpact()
 {
     $query = new Search_Query();
     $query->setWeightCalculator(new Search_Query_WeightCalculator_Field(array('text_field' => 100, 'other_field' => 0.0001)));
     $query->filterContent('foobar', array('text_field', 'other_field'));
     $results = $query->search($this->index);
     $this->assertOrderIs('BA', $results);
 }
Exemplo n.º 2
0
 function testFieldSpecificSearch()
 {
     $off = new Search_Query();
     $off->filterContent('description', 'wiki_content');
     $found = new Search_Query();
     $found->filterContent('description', 'description');
     $this->assertGreaterThan(0, count($found->search($this->index)));
     $this->assertEquals(0, count($off->search($this->index)));
 }
Exemplo n.º 3
0
 function testCamelCaseNotEnabled()
 {
     $index = new Search_Elastic_Index($this->connection, 'test_index');
     $index->destroy();
     $typeFactory = $index->getTypeFactory();
     $index->addDocument(['object_type' => $typeFactory->identifier('wiki page'), 'object_id' => $typeFactory->identifier('CamelCase Words'), 'title' => $typeFactory->plaintext('CamelCase Words')]);
     $query = new Search_Query();
     $query->filterContent('Camel AND Word', 'title');
     $this->assertEquals(0, count($query->search($index)));
 }
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;
}
Exemplo n.º 5
0
 function testApplyWeight()
 {
     $index = new Search_Index_Memory();
     $query = new Search_Query();
     $query->setWeightCalculator(new Search_Query_WeightCalculator_Field(array('title' => 5.5, 'allowed_groups' => 0.0001)));
     $query->filterContent('hello', array('contents', 'title'));
     $query->filterPermissions(array('Anonymous'));
     $query->search($index);
     $expr = new Search_Expr_And(array(new Search_Expr_Or(array(new Search_Expr_Token('hello', 'plaintext', 'contents', 1.0), new Search_Expr_Token('hello', 'plaintext', 'title', 5.5))), new Search_Expr_Or(array(new Search_Expr_Token('Anonymous', 'multivalue', 'allowed_groups', 0.0001)))));
     $this->assertEquals($expr, $index->getLastQuery());
 }
Exemplo n.º 6
0
 private function assertResultCount($count, $argument)
 {
     $query = new Search_Query();
     $query->filterContent($argument);
     $this->assertEquals($count, count($query->search($this->index)));
 }
Exemplo n.º 7
0
 function testHebrewString()
 {
     $query = new Search_Query();
     $query->filterContent('מחשב', 'hebrew');
     $this->assertEquals(1, count($query->search($this->index)));
 }
Exemplo n.º 8
0
 function applyContentConditions(\Search_Query $query, $content)
 {
     $query->filterContent('y', 'searchable');
     $query->filterContent($content, ['title', 'contents']);
     $this->applyRaw($query);
 }
Exemplo n.º 9
0
 function applyContentConditions(\Search_Query $query, $content)
 {
     $query->filterContent($content, ['file']);
 }
Exemplo n.º 10
0
 function buildQuery(array $filter)
 {
     $categlib = TikiLib::lib('categ');
     $query = new Search_Query();
     $query->setWeightCalculator($this->getWeightCalculator());
     if (!Perms::get()->admin) {
         $query->filterPermissions(Perms::get()->getGroups());
     }
     $jail_query = '';
     if ($jail = $categlib->get_jail()) {
         $i = 0;
         foreach ($jail as $cat) {
             $i++;
             $jail_query .= $cat;
             if ($i < count($jail)) {
                 $jail_query .= ' or ';
             }
         }
         $query->filterCategory($jail_query, true);
     }
     if (isset($filter['type']) && $filter['type']) {
         $query->filterType($filter['type']);
     }
     if (isset($filter['categories']) && $filter['categories']) {
         $query->filterCategory($filter['categories'], isset($filter['deep']));
     }
     if (isset($filter['tags']) && $filter['tags']) {
         $query->filterTags($filter['tags']);
     }
     if (isset($filter['content']) && $filter['content']) {
         $query->filterContent($filter['content'], TikiLib::lib('tiki')->get_preference('unified_default_content', array('contents'), true));
     }
     if (isset($filter['autocomplete']) && $filter['autocomplete']) {
         $query->filterInitial($filter['autocomplete']);
     }
     if (isset($filter['language']) && $filter['language']) {
         $q = $filter['language'];
         if (preg_match('/^\\w+\\-\\w+$/', $q)) {
             $q = "\"{$q}\"";
         }
         if (isset($filter['language_unspecified'])) {
             $q = "({$q}) or unknown";
         }
         $query->filterLanguage($q);
     }
     unset($filter['type']);
     unset($filter['categories']);
     unset($filter['deep']);
     unset($filter['tags']);
     unset($filter['content']);
     unset($filter['language']);
     unset($filter['autocomplete']);
     foreach ($filter as $key => $value) {
         if ($value) {
             $query->filterContent($value, $key);
         }
     }
     return $query;
 }