function Search($search_string, $module, SEARCHFilter $filter = NULL, $opts = false) { $search_data = $this->ParseString($search_string, $module, $opts); $res = new SEARCHResults($filter, $this, $module); // get list, loop $list = $this->GetList($search_data, $module, $opts); if ($list) { foreach ($list as $key => $info) { $rating = $this->CheckString($info, $search_data, $module, $opts); if ($rating) { $res->Append($info, $rating, $key); } } } if ($res->HaveResults()) { return $res; } return false; }
function Search($string = false, $modules = false, $threshold = false, $limits = false, $opts = false) { if ($string === false) { $string = $this->req->props['search']; } if (preg_match("/^\\s*{([^}]*)}\\s*(.*)\$/", $string, $m)) { $modules = $m[1]; $string = $m[2]; } if (!$opts) { $opts = array(); } if (preg_match("/^\\s*\\[([^\\]]*)\\]\\s*(.*)\$/", $string, $m)) { $opts_string = $m[1]; if (stripos($opts_string, "=") !== false) { $opts['match'] = SEARCH::EXACT_MATCH; } else { if (stripos($opts_string, "w") !== false) { $opts['match'] = SEARCH::WORD_MATCH; } else { if (stripos($opts_string, "~") !== false) { $opts['match'] = SEARCH::FUZZY_MATCH; } } } } if ($threshold === false && isset($this->req->props['search_threshold'])) { $threshold = $this->req->props['search_threshold']; } if ($modules === false && $this->req->props['search_modules']) { $modules = $this->req->props['search_modules']; } else { // try detection } // Extracting limits part if (!is_array($limits)) { $limits = array(); } $parts = preg_split("/:/", $string); if (sizeof($parts) > 1) { if (!preg_match("/^(.*)\\s*(\\b[\\w\\d_]+)\$/", $parts[0], $matches)) { throw new ADEIException(translate("Invalid search string %s", $string)); } $key = $matches[2]; for ($i = 1; $i < sizeof($parts) - 1; $i++) { if (!preg_match("/^(.*)\\s*(\\b[\\w\\d_]+)\$/", $parts[$i], $m)) { throw new ADEIException(translate("Invalid search string %s", $string)); } $limits[$key] = $m[1]; $key = $m[2]; } $limits[$key] = $parts[$i]; $string = $matches[1]; } $filter = new SEARCHFilter($threshold, $limits); // extracting module information if ($modules && is_string($modules)) { if (strpos($modules, "{") === false) { $mstr = explode(",", $modules); $modules = array(); foreach ($mstr as $mod) { if (preg_match("/^([\\w\\d_]+)(\\((.*)\\))?\$/", $mod, $m)) { $module = $m[1]; $modules[$module] = array(); if ($m[2]) { $params = explode(";", $m[3]); foreach ($params as $param) { if (preg_match("/^([^=]+)=(.*)\$/", $param, $m)) { $modules[$module][$m[1]] = $m[2]; } else { $modules[$module][$param] = true; } } } } } } else { $modules = json_decode($modules); } } if (!$modules) { $modules = $this->DetectModules($string); } $result = new SEARCHResults(); if ($modules) { foreach ($modules as $module => $opts) { if (isset($this->modules[$module])) { $modres = $this->modules[$module]->Search($string, $module, $filter, $opts); if ($modres) { $result->Combine($modres); } } else { throw new ADEIException(translate("The requested search module (%s) is not provided by any of search engines", $module)); } } } else { // Detect what is needed foreach ($this->engines as $engine) { $modres = $engine->EngineSearch($string, $filter, $opts); if ($modres) { $result->Combine($modres); } } } if ($result->HaveResults()) { return $result; } return false; }
static function Merge() { $res = new SEARCHResults(); for ($i = 0; $i < func_num_args(); $i++) { $mres = func_get_arg($i); if ($mres instanceof SEARCHResults) { $res->Combine($mres); } else { if ($mres !== false) { throw new ADEIException("Internal error: Only SEARCHResult could be merged"); } } } if ($res->HaveResults()) { return $res; } return false; }