private function processObjects($function, $categId, $objects)
 {
     $unifiedsearchlib = TikiLib::lib('unifiedsearch');
     foreach ($objects as $object) {
         $type = $object['type'];
         $id = $object['id'];
         $this->{$function}($categId, $type, $id);
         $unifiedsearchlib->invalidateObject($type, $id);
     }
     $unifiedsearchlib->processUpdateQueue(count($objects) * 2);
     $query = new Search_Query();
     $query->filterCategory((string) $categId);
     $query->filterPermissions(Perms::get()->getGroups());
     $query->setRange(0, 1);
     $result = $query->search($unifiedsearchlib->getIndex());
     return array('categId' => $categId, 'count' => count($result), 'objects' => $objects, 'confirm' => 1);
 }
Exemple #2
0
 function testSubQueryCreatesOrStatement()
 {
     $index = new Search_Index_Memory();
     $query = new Search_Query();
     $query->getSubQuery('abc')->filterContent('hello');
     $query->getSubQuery('abc')->filterCategory('1 and 2');
     $query->filterPermissions(array('Registered'));
     $query->search($index);
     $expr = new Search_Expr_And(array(new Search_Expr_Or(array(new Search_Expr_Token('hello', 'plaintext', 'contents'), new Search_Expr_And(array(new Search_Expr_Token('1', 'multivalue', 'categories'), new Search_Expr_Token('2', 'multivalue', 'categories'))))), new Search_Expr_Or(array(new Search_Expr_Token('Registered', 'multivalue', 'allowed_groups')))));
     $this->assertEquals($expr, $index->getLastQuery());
     $this->assertEquals(array('hello'), $query->getTerms());
 }
 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());
 }
 function initQuery(Search_Query $query)
 {
     global $prefs;
     $query->setWeightCalculator($this->getWeightCalculator());
     $query->setIdentifierFields($prefs['unified_identifier_fields']);
     if (!Perms::get()->admin) {
         $query->filterPermissions(Perms::get()->getGroups());
     }
     $categlib = TikiLib::lib('categ');
     if ($jail = $categlib->get_jail()) {
         $query->filterCategory(implode(' or ', $jail), true);
     }
 }
 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;
 }