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); }
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 wikiplugin_list($data, $params) { $unifiedsearchlib = TikiLib::lib('unifiedsearch'); $alternate = null; $output = null; $subPlugins = array(); $query = new Search_Query; $query->setWeightCalculator($unifiedsearchlib->getWeightCalculator()); if (isset($_REQUEST['maxRecords'])) { if (isset($_REQUEST['offset'])) { $query->setRange($_REQUEST['offset'], $_REQUEST['maxRecords']); } else { $query->setRange(0, $_REQUEST['maxRecords']); } } elseif (isset($_REQUEST['offset'])) { $query->setRange($_REQUEST['offset']); } $matches = WikiParser_PluginMatcher::match($data); $argumentParser = new WikiParser_PluginArgumentParser; $onclick = ''; $offset_jsvar = ''; foreach ($matches as $match) { $name = $match->getName(); $arguments = $argumentParser->parse($match->getArguments()); foreach ($arguments as $key => $value) { $function = "wpquery_{$name}_{$key}"; if (function_exists($function)) { $function($query, $value, $arguments); } $function = "wpformat_{$name}_{$key}"; if (function_exists($function)) { $function($subPlugins, $value, $match->getBody()); } } if ($name == 'output') { $output = $match; } if ($name == 'alternate') { $alternate = $match->getBody(); } if ($name == 'pagination' && isset($arguments['onclick'])) { $onclick = $arguments['onclick']; } if ($name == 'pagination' && isset($arguments['offset_jsvar'])) { $offset_jsvar = $arguments['offset_jsvar']; } } if (! Perms::get()->admin) { $query->filterPermissions(Perms::get()->getGroups()); } if (!empty($_REQUEST['sort_mode'])) { $query->setOrder($_REQUEST['sort_mode']); } $index = $unifiedsearchlib->getIndex(); $result = $query->search($index); if (count($result)) { if (!empty($output)) { $arguments = $argumentParser->parse($output->getArguments()); if (isset($arguments['template'])) { if ($arguments['template'] == 'table') { $arguments['template'] = dirname(__FILE__) . '/../../templates/table.tpl'; } else if (!file_exists($arguments['template'])) { TikiLib::lib('errorreport')->report(tr('Missing template "%0"', $arguments['template'])); return ''; } $builder = new Search_Formatter_ArrayBuilder; $templateData = $builder->getData($output->getBody()); $plugin = new Search_Formatter_Plugin_SmartyTemplate($arguments['template']); $plugin->setData($templateData); $plugin->setFields(wp_list_findfields($templateData)); } elseif (isset($arguments['wiki']) && TikiLib::lib('tiki')->page_exists($arguments['wiki'])) { $wikitpl = "tplwiki:" . $arguments['wiki']; $wikicontent = TikiLib::lib('smarty')->fetch($wikitpl); $plugin = new Search_Formatter_Plugin_WikiTemplate($wikicontent); } else { $plugin = new Search_Formatter_Plugin_WikiTemplate($output->getBody()); } if (isset($arguments['pagination'])) { $plugin = new WikiPlugin_List_AppendPagination($plugin, $onclick, $offset_jsvar); } } else { $plugin = new Search_Formatter_Plugin_WikiTemplate("* {display name=title format=objectlink}\n"); } $formatter = new Search_Formatter($plugin); $formatter->setDataSource($unifiedsearchlib->getDataSource()); foreach ($subPlugins as $key => $plugin) { $formatter->addSubFormatter($key, $plugin); } $out = $formatter->format($result); } elseif (!empty($alternate)) { $out = $alternate; } else { $out = '^' . tra('No results for query.') . '^'; } return $out; }
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; }