public function sphinxTest($keyword, $cateid) { $keyword = $this->getSplitWd($keyword); $sphinxConfig = array("host" => "172.17.17.105", "port" => 9093); $conn = new \Foolz\SphinxQL\Connection(); $conn->setParams(array('host' => $sphinxConfig["host"], 'port' => $sphinxConfig["port"])); $query = \Foolz\SphinxQL\SphinxQL::create($conn); $query->select(array("id", "cate3"))->from("product_distri_29"); $query->where("cate3", "=", intval($cateid)); $query->limit(0, 1000); $query->option("max_matches", 4000); try { $facet = Facet::create($conn)->facet('cate3')->limit(10)->orderby("count(*)", "desc"); $query->facet($facet); echo $query->compileSelect()->getCompiled(), "\n"; $sphinxRs = $query->executeBatch(); var_dump($sphinxRs[1]); echo "\n"; $sphinxql = new SphinxQL($conn); $total = $sphinxql->query('show meta'); $total = $this->formatSphQLArray($total->execute()); var_dump($total); exit; } catch (Exception $e) { return array(); } }
function testAction($cateid) { $sphinxConfig = array("host" => "172.17.17.105", "port" => 9020); $conn = new \Foolz\SphinxQL\Connection(); $conn->setParams(array('host' => $sphinxConfig["host"], 'port' => $sphinxConfig["port"])); $query = \Foolz\SphinxQL\SphinxQL::create($conn); $query->select(array("id", "cate3"))->from("product_distri_29"); $query->where("cate3", "=", intval($cateid)); $query->limit(0, 1000); $query->option("max_matches", 4000); try { echo $query->compileSelect()->getCompiled(); echo "\n"; exit; $sphinxRs = $query->execute(); var_dump($sphinxRs); exit; } catch (Exception $e) { return array(); } }
$di->setShared('annotations', function () { return new \Phalcon\Annotations\Adapter\Memory(); }); $di->setShared('response', function () { $response = new \Phalcon\Http\Response(); return $response; }); //注入DB服务 $di->setShared('gcoperator', function () use($di) { $dbclass = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $di['config']->v3opDB->driver; return new $dbclass(array('host' => $di['config']->v3opDB->host, 'username' => $di['config']->v3opDB->username, 'password' => $di['config']->v3opDB->password, 'dbname' => $di['config']->v3opDB->database, 'charset' => $di['config']->v3opDB->charset)); }); //注入sphinx 服务 $di->setShared('sphinxCon', function () use($di) { $conn = new \Foolz\SphinxQL\Connection(); $conn->setParams(array('host' => $di['config']->sphinx->host, 'port' => intval($di['config']->sphinx->port))); return $conn; }); $di->setShared('filter', function () { $filter = new \Phalcon\Filter(); $filter->add('price', function ($value) { return round(abs($value), 2); }); return $filter; }); $di->set('memObj', function () use($di) { $mcObj = new \Xz\Lib\Memcached($di['config']->memcommon); return $mcObj; }); $di->set('request', function () { $request = new \Phalcon\Http\Request();