Beispiel #1
0
 private function index_search($data, $type = 'add')
 {
     $conf = realpath(CUR_CONF_PATH . 'conf/search_vod.ini');
     if ($conf) {
         try {
             include_once ROOT_PATH . 'lib/xunsearch/XS.php';
             $xs = new XS($conf);
             // 建立 XS 对象,项目名称为:demo
             $index = $xs->index;
             // 获取 索引对象
         } catch (XSException $e) {
             return false;
         }
         if ($type == 'del') {
             $index->{$type}($data);
             return;
         }
         if ($data) {
             if (!is_array($data)) {
                 $sql = "SELECT *  FROM " . DB_PREFIX . 'vodinfo WHERE id=' . $data;
                 $data = $this->db->query_first($sql);
             }
             $data = array('id' => $data['id'], 'title' => $data['title'], 'subtitle' => $data['subtitle'], 'comment' => $data['comment'], 'channel_id' => $data['channel_id'], 'vod_sort_id' => $data['vod_sort_id'], 'status' => $data['status'], 'vod_leixing' => $data['vod_leixing'], 'is_allow' => $data['is_allow'], 'from_appid' => $data['from_appid'], 'from_appname' => $data['from_appname'], 'duration' => $data['duration'], 'trans_use_time' => $data['trans_use_time'], 'mark_collect_id' => $data['mark_collect_id'], 'create_time' => $data['create_time'], 'playcount' => $data['playcount'], 'click_count' => $data['click_count'], 'downcount' => $data['downcount'], 'keywords' => $data['keywords'], 'bitrate' => $data['bitrate'], 'author' => $data['author'], 'video_order_id' => $data['video_order_id']);
             // 创建文档对象
             $doc = new XSDocument();
             $doc->setFields($data);
             // 添加到索引数据库中
             $index->{$type}($doc);
         }
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $articles = Article::all();
     $xs = new \XS('inspirer');
     $xsindex = $xs->index;
     $xsindex->clean();
     foreach ($articles as $article) {
         $doc = new \XSDocument();
         $this->output->writeln(sprintf("<comment>[Add]</comment> article [id:<info>%d</info>] - %s", $article->id, $article->title));
         $doc->setFields(['id' => $article->id, 'title' => $article->title, 'name' => $article->name, 'description' => $article->description, 'keyword' => $article->keywords, 'content' => $article->content]);
         $xsindex->add($doc);
     }
 }
Beispiel #3
0
 public function xs_index()
 {
     $data = $this->input['data'];
     $type = $this->input['type'] ? $this->input['type'] : 'add';
     $conf = realpath(CUR_CONF_PATH . 'data/' . $this->filename . '.ini');
     if ($conf) {
         try {
             include_once CUR_CONF_PATH . 'lib/xunsearch/XS.php';
             $xs = new XS($conf);
             // 建立 XS 对象,项目名称为:demo
             $index = $xs->index;
             // 获取 索引对象
         } catch (XSException $e) {
             $this->errorOutput('ERROR');
         }
         if ($type == 'clean') {
             $index->clean();
             $this->addItem('true');
             $this->output();
         }
         if (empty($data)) {
             $this->errorOutput('NO_DATA');
         }
         switch ($type) {
             case 'add':
                 $doc = new XSDocument();
                 $doc->setFields($data);
                 $index->add($doc);
                 break;
             case 'update':
                 $doc = new XSDocument();
                 $doc->setFields($data);
                 $index->update($doc);
                 break;
             case 'del':
                 $index->del($data);
                 break;
             case 'rebuild':
                 $doc = new XSDocument();
                 $doc->setFields($data);
                 $index->beginRebuild();
                 $index->add($doc);
                 $index->endRebuild();
                 break;
         }
         $this->addItem('true');
         $this->output();
     } else {
         $this->errorOutput('NO_***.INI');
     }
 }
Beispiel #4
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     $xs_unicom = new \XS('unicom');
     $xs_index = $xs_unicom->index;
     $xs_data = array('id' => $this->id, 'question' => $this->question, 'answer' => $this->answer, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at);
     $xs_doc = new \XSDocument();
     $xs_doc->setFields($xs_data);
     if ($insert) {
         $xs_index->add($xs_doc);
     } else {
         $xs_index->update($xs_doc);
     }
 }
Beispiel #5
0
 public static function setUpBeforeClass()
 {
     $data = array(array('pid' => 3, 'subject' => '关于 xunsearch 的 DEMO 项目测试', 'message' => '项目测试是一个很有意思的行为!', 'chrono' => 214336158, 'other' => 'master'), array('pid' => 11, 'subject' => '测试第二篇', 'message' => '这里是第二篇文章的内容', 'chrono' => 1314336168, 'other' => 'slave'), array('pid' => 21, 'subject' => '项目测试第三篇', 'message' => '俗话说,无三不成礼,所以就有了第三篇', 'chrono' => 314336178, 'other' => 'master'));
     // create object
     self::$xs = new XS(end($GLOBALS['fixIniData']));
     $index = self::$xs->index;
     // create testing data
     $doc = new XSDocument('utf-8');
     foreach ($data as $tmp) {
         $doc->setFields(null);
         $doc->setFields($tmp);
         $index->add($doc);
     }
     $index->addSynonym('project', '项目');
     $index->flushIndex();
     // create another db
     $index->setDb('db2');
     foreach ($data as $tmp) {
         $tmp['pid'] += 1000;
         $doc->setFields(null);
         $doc->setFields($tmp);
         $index->add($doc);
     }
     // create synonyms on db2
     $synonyms = array('test' => '测试', 'hello world' => '有意思', '迅搜' => 'xunsearch');
     $index->openBuffer();
     foreach ($synonyms as $raw => $syn) {
         $index->addSynonym($raw, $syn);
     }
     $index->addSynonym('test', 'quiz');
     $index->closeBuffer();
     // flush index & logging
     $index->flushIndex();
     sleep(2);
     $index->flushLogging();
     sleep(2);
 }
Beispiel #6
0
 /**
  * 添加或更新items
  *
  * @param string $dbName 库名称
  * @param array $datas 单行数据(一维数组) | 多行数据(多维数组)
  * @param bool $add 是否是添加,为提高效率,如果确定是新增,设置为true
  */
 public static function addOrUpdateItems($dbName, $datas, $add = FALSE)
 {
     self::init();
     if (!is_array($datas) || empty($datas)) {
         return;
     }
     $datas = is_array($datas[0]) ? $datas : array($datas);
     $index = self::_getIndex($dbName);
     $index->openBuffer();
     foreach ($datas as $data) {
         $doc = new \XSDocument();
         $doc->setFields($data);
         // 更新
         $index->update($doc, $add);
     }
     $index->closeBuffer();
 }
 public function index()
 {
     require './Vendor/xunsearch/lib/XS.php';
     $xs = new \XS('test');
     // 建立 XS 对象,项目名称为:demo
     $index = $xs->index;
     // 获取 索引对象
     $dbJob = M('job', 'dg_', 'REMOTE_TEST_DB_DSN');
     $lists = $dbJob->order('create_time desc')->select();
     // 创建文档对象
     $doc = new \XSDocument();
     foreach ($lists as $val) {
         $data = array('job_id' => $val['job_id'], 'title' => $val['title'], 'work_type' => $val['work_type'], 'sex' => $val['sex'], 'money_way' => $val['money_way'], 'pay_way_money' => $val['pay_way_money'], 'province' => $val['province'], 'city' => $val['city'], 'create_time' => $val['create_time'], 'desc' => $val['desc']);
         $doc->setFields($data);
         // 添加到索引数据库中
         $index->add($doc);
     }
 }
Beispiel #8
0
 $index->openBuffer();
 while ($data = $src->getData()) {
     $doc = new XSDocument($dcs);
     if ($source == 'csv') {
         $data = csvTransform($data);
         if (is_null($data)) {
             continue;
         }
     }
     $pk = $data[$fid->name];
     if ($filter !== null && ($data = $filter->process($data, $dcs)) === false) {
         $total++;
         echo "警告:过滤器忽略了第 {$total} 条数据, 主键为:" . $pk . "\n";
         continue;
     }
     $doc->setFields($data);
     try {
         if ($filter !== null && method_exists($filter, 'processDoc')) {
             $filter->processDoc($doc);
         }
         $total++;
         $index->update($doc);
         $total_ok++;
     } catch (XSException $e) {
         echo "警告:添加第 {$total} 条数据失败 - " . $e->getMessage() . "\n";
         echo $e->getTraceAsString();
         $total_failed++;
     }
     if ($total % 10000 == 0) {
         echo "报告:累计已处理数据 {$total} 条 ...\n";
     }
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function update($id, Request $request)
 {
     $check = Validator::make($request->all(), ['title' => ['required', 'min:1', 'max: 255'], 'category_id' => ['required', 'numeric'], 'sort' => ['numeric'], 'name' => ['alpha_dash'], 'tag' => ['array'], 'display' => ['boolean']]);
     if ($check->fails()) {
         return redirect()->back()->withErrors($check->errors())->withInput();
     }
     $article = Article::findOrFail($id);
     $insert = $request->only('title', 'category_id', 'keywords', 'sort', 'name', 'display');
     $insert = array_merge($insert, ArticleProcess::convertArticle($request->input('content')));
     $insert['description'] = $request->has('description') ? $request->input('description') : strip_tags((new Parsedown())->text($insert['description']));
     extract($insert);
     $article->title = $title;
     $article->category_id = $category_id;
     $article->keywords = $keywords;
     $article->content = $content;
     $article->description = $description;
     $article->sort = $sort;
     $article->display = $display;
     if (isset($name)) {
         $article->name = $name;
     }
     $article->modified_at = date("Y-m-d H:i:s", time());
     $article->save();
     $xs = new \XS('inspirer');
     // 保存至全文搜索索引
     $doc = new \XSDocument();
     $doc->setFields(['id' => $article->id, 'title' => $article->title, 'name' => $article->name, 'description' => $article->description, 'keyword' => $article->keywords, 'content' => $article->content]);
     $xs->index->update($doc);
     $article->tags()->sync($request->input('tag', []));
     return redirect()->back();
 }
Beispiel #10
0
 function makeindex()
 {
     if ($this->base->setting['xunsearch_open']) {
         $this->index->clean();
         $query = $this->db->query("SELECT * FROM " . DB_TABLEPRE . "question ");
         while ($question = $this->db->fetch_array($query)) {
             $data = array();
             $data['id'] = $question['id'];
             $data['cid'] = $question['cid'];
             $data['cid1'] = $question['cid1'];
             $data['cid2'] = $question['cid2'];
             $data['cid3'] = $question['cid3'];
             $data['author'] = $question['author'];
             $data['authorid'] = $question['authorid'];
             $data['answers'] = $question['answers'];
             $data['status'] = $question['status'];
             $data['time'] = $question['time'];
             $data['title'] = $question['title'];
             $data['description'] = $question['description'];
             $doc = new XSDocument();
             $doc->setFields($data);
             $this->index->add($doc);
         }
     }
 }
 public function update($runValidation = true, $attributeNames = null)
 {
     if ($runValidation && !$this->validate($attributes)) {
         return false;
     }
     if (!$this->beforeSave(true)) {
         return false;
     }
     $db = static::getDb();
     $values = $this->getDirtyAttributes($attributes);
     $doc = new XSDocument();
     $doc->setFields($values);
     $db = static::getDb();
     $db->getIndex()->update($doc);
     $changedAttributes = array_fill_keys(array_keys($values), null);
     $this->setOldAttributes($values);
     $this->afterSave(true, $changedAttributes);
     return true;
 }