function Search($search_string, $module, SEARCHFilter $filter = NULL, $opts = false) { global $ADEI; $xml = $this->GetOption("xml", $opts); $xslt = $this->GetOption("xslt", $opts, "null"); $noprops = $this->GetOption("noprops", $opts); $nolimits = $this->GetOption("nolimits", $opts); $searchprop = $this->GetOption("searchprop", $opts, false); if ($xml) { if (preg_match("/^(services\\/)?([\\w\\d_]+\\.php)(\\?(.*))?\$/", $xml, $m)) { $adei_url = $ADEI->GetBaseURL(); $xml_url = "{$adei_url}services/" . $m[2]; $xml_props = $m[4]; } else { if ($opts && $opts['xml']) { throw new ADEIException(translate("Proxy-search is allowed to ADEI-services only")); } else { list($xml_url, $xml_props) = preg_split("/\\?/", $xml, 2); } } } else { throw new ADEIException(translate("The proxy URL is required by search module")); } if ($noprops) { $props = array(); } else { $props = $this->req->GetProps(); unset($props['search']); unset($props['search_modules']); } if ($filter && !$nolimits) { $ivl_filter = $filter->GetLimit('interval'); if ($ivl_filter) { $props['window'] = $ivl_filter; } } if ($searchprop === false) { $props['search'] = $search_string; } else { if ($searchprop) { $props[$searchprop] = $search_string; } } if ($props) { $req = new REQUEST($props); $xml_props = $req->GetQueryString($xml_props); $xml = $xml_url . "?" . $xml_props; } else { if ($xml_props) { $xml = $xml_url . "?" . $xml_props; } else { $xml = $xml_url; } } $html = $ADEI->TransformXML($xslt, $xml); $result = new SEARCHResults(NULL, $this, $module, ""); $result->Append(preg_replace("/^\\s*<\\?xml.*\$/m", "", $html)); return $result; }
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; }
function EngineSearch($search_string, SEARCHFilter $filter = NULL, $opts = false) { $res = false; if ($this->engine_search) { foreach ($this->engine_search as $module) { $mres = $this->Search($search_string, $module, $filter, $opts); if ($mres) { if (!$res) { $res = new SEARCHResults(); } $res->Combine($mres); } } } return $res; }
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; }