From 42ec0bf45e8d9b2dffb40f091baa60e8c55705db Mon Sep 17 00:00:00 2001
From: JAE <hj.q@qq.com>
Date: Thu, 10 Jul 2014 11:20:20 +0800
Subject: [PATCH] =?UTF-8?q?Searcher=E6=96=B0=E5=A2=9E=E6=90=9C=E7=8B=97?=
 =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=BC=95=E6=93=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 demo/Searcher.class.php | 49 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 6 deletions(-)

diff --git a/demo/Searcher.class.php b/demo/Searcher.class.php
index 4d52815..1ce41d5 100644
--- a/demo/Searcher.class.php
+++ b/demo/Searcher.class.php
@@ -1,4 +1,22 @@
 <?php
+/**
+ * Searcher
+ *
+ * 一个基于QueryList的搜索引擎类
+ *
+ * @author      Jaeger
+ * @email       734708094@qq.com
+ * @link        http://git.oschina.net/jae/QueryList
+ * @version     1.5.0  
+ *
+ *@example 
+ *
+ $hj = Searcher::S('site:pan.baidu.com torrent','sogou',20,2);
+  print_r( $hj->jsonArr);
+
+ $json = Searcher::S('QueryList交流')->getJSON();
+  print_r($json);
+ */
 require '../QueryList.class.php';
    class Searcher
    {
@@ -10,8 +28,18 @@ require '../QueryList.class.php';
        private $regRange ;
        private $regZnum;
        public $jsonArr;
+       private static $s;
 
-       function Searcher($searcher,$key,$num,$page)
+       public static function S($key,$searcher = 'baidu',$num = 10,$page = 1)
+       {
+          if(!(self::$s instanceof self))
+          {
+            self::$s = new self();
+          }
+          self::$s->query($key,$searcher,$num,$page);
+          return self::$s;
+       }
+       private function query($key,$searcher,$num,$page)
        {
            if($searcher=='baidu')
            {
@@ -25,6 +53,12 @@ require '../QueryList.class.php';
                $this->regRange = 'li.g';
                $this->regZnum=array("zNum"=>array("div#resultStats","text"));
            }
+           else if($searcher=='sogou')
+           {
+               $this->regArr = array("title"=>array("h3 a","text"),"tCon"=>array("div.ft","text"),"url"=>array("h3 a","href"));
+               $this->regRange = '[id^=rb_]';
+               $this->regZnum=array("zNum"=>array("div.mun","text"));
+           }
            $this->searcher = $searcher;
            $this->key = $key;
            $this->num  = $num;
@@ -48,6 +82,11 @@ require '../QueryList.class.php';
                $reg_znum='/([\d,]+) result(s)?/';
                $getHtmlWay = 'curl';
            }
+           else if($this->searcher=='sogou')
+           {
+              $url="http://www.sogou.com/web?query=$s&num=$num&page=".$this->page;
+              $reg_znum='/[\d,]+/';
+           }
            $searcherObj = QueryList::Query($url,$this->regArr,$this->regRange,$getHtmlWay,false);
            for($i=0;$i<count($searcherObj->jsonArr);$i++)
            {
@@ -62,8 +101,6 @@ require '../QueryList.class.php';
            }
            $this->jsonArr = $searcherObj->jsonArr ;
 
-
-
            //获取总共结果条数
 
            $searcherObj->setQuery($this->regZnum);
@@ -76,7 +113,7 @@ require '../QueryList.class.php';
 
 
        }
-       function getJSON()
+      public function getJSON()
        {
            return json_encode($this->jsonArr);
        }
@@ -109,5 +146,5 @@ require '../QueryList.class.php';
        }
    }
    
-$hj = new Searcher('baidu','site:pan.baidu.com torrent',20,2);
- print_r( $hj->jsonArr);
+
+