[Xunsearch PHP-SDK](http://www.xunsearch.com) v1.4.8 API 參考文檔
# XSCommand
[All Packages](#)| [屬性](#)| [方法(函數)](#)
| 包 | [XS](#) |
|-----|-----|
| 繼承關系 | class XSCommand ?[XSComponent](#) |
| 版本 | 1.0.0 |
| 源代碼 | [sdk/php/lib/XSServer.class.php](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php) |
XSCommand 命令對象是與服務端交互的最基本單位, 命令對象可自動轉換為通訊字符串,命令結構參見 C 代碼中的 struct xs_cmd 定義, 頭部長度為 8字節.
### Public 屬性
[隱去繼承來的屬性](#)
| 名稱 | 類型 | 描述 | 定義于 |
|-----|-----|-----|-----|
| [arg](#) | int | 獲取屬性 arg 的值 | XSCommand |
| [arg1](#) | int | 參數1取值范圍 0~255, 具體含義根據不同的 CMD 而變化 | XSCommand |
| [arg2](#) | int | 參數2取值范圍 0~255, 常用于存儲 value no, 具體參照不同 CMD 而確定 | XSCommand |
| [buf](#) | string | 主數據內容, 最長 2GB | XSCommand |
| [buf1](#) | string | 輔數據內容, 最長 255字節 | XSCommand |
| [cmd](#) | int | 命令代碼通常是預定義常量 CMD_xxx, 取值范圍 0~255 | XSCommand |
### Public 方法
[隱去繼承來的方法](#)
| 名稱 | 描述 | 定義于 |
|-----|-----|-----|
| [__construct()](#) | 構造函數 | XSCommand |
| [__get()](#) | 魔術方法 __get | [XSComponent](#) |
| [__isset()](#) | 魔術方法 __isset | [XSComponent](#) |
| [__set()](#) | 魔術方法 __set | [XSComponent](#) |
| [__toString()](#) | 轉換為封包字符串 | XSCommand |
| [__unset()](#) | 魔術方法 __unset | [XSComponent](#) |
| [getArg()](#) | 獲取屬性 arg 的值 | XSCommand |
| [setArg()](#) | 設置屬性 arg 的值 | XSCommand |
### 屬性明細
arg屬性
public int [**getArg**](#)()
public void [**setArg**](#)(int $arg)
獲取屬性 arg 的值
arg1屬性
public int **$arg1**;
參數1取值范圍 0~255, 具體含義根據不同的 CMD 而變化
arg2屬性
public int **$arg2**;
參數2取值范圍 0~255, 常用于存儲 value no, 具體參照不同 CMD 而確定
buf屬性
public string **$buf**;
主數據內容, 最長 2GB
buf1屬性
public string **$buf1**;
輔數據內容, 最長 255字節
cmd屬性
public int **$cmd**;
命令代碼通常是預定義常量 CMD_xxx, 取值范圍 0~255
### 方法明細
__construct()方法
<table class="summaryTable"><tr><td colspan="3"><div class="signature2">public void <b>__construct</b>(mixed $cmd, int $arg1=0, int $arg2=0, string $buf='', string $buf1='')</div></td></tr><tr><td class="paramNameCol">$cmd</td> <td class="paramTypeCol">mixed</td> <td class="paramDescCol">命令類型或命令數組 當類型為 int 表示命令代碼, 范圍是 1~255, 參見 xs_cmd.inc.php 里的定義 當類型為 array 時忽略其它參數, 可包含 cmd, arg1, arg2, buf, buf1 這些鍵值</td></tr><tr><td class="paramNameCol">$arg1</td> <td class="paramTypeCol">int</td> <td class="paramDescCol">參數1, 其值為 0~255, 具體含義視不同 CMD 而確定</td></tr><tr><td class="paramNameCol">$arg2</td> <td class="paramTypeCol">int</td> <td class="paramDescCol">參數2, 其值為 0~255, 具體含義視不同 CMD 而確定, 常用于存儲 value no</td></tr><tr><td class="paramNameCol">$buf</td> <td class="paramTypeCol">string</td> <td class="paramDescCol">字符串內容, 最大長度為 2GB</td></tr><tr><td class="paramNameCol">$buf1</td> <td class="paramTypeCol">string</td> <td class="paramDescCol">字符串內容1, 最大長度為 255字節</td></tr></table>
**源碼:**[sdk/php/lib/XSServer.class.php#L62](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php#L62) (**[顯示](#)**)
`public?function?__construct($cmd,?$arg1?=?0,?$arg2?=?0,?$buf?=?'',?$buf1?=?'')
{
????if?(is_array($cmd))?{
????????foreach?($cmd?as?$key?=>?$value)?{
????????????if?($key?===?'arg'?||?property_exists($this,?$key))?{
????????????????$this->$key?=?$value;
????????????}
????????}
????}?else?{
????????$this->cmd?=?$cmd;
????????$this->arg1?=?$arg1;
????????$this->arg2?=?$arg2;
????????$this->buf?=?$buf;
????????$this->buf1?=?$buf1;
????}
}`
構造函數
__toString()方法
<table class="summaryTable"><tr><td colspan="3"><div class="signature2">public string <b>__toString</b>()</div></td></tr><tr><td class="paramNameCol">{return}</td> <td class="paramTypeCol">string</td> <td class="paramDescCol">用于服務端交互的字符串</td></tr></table>
**源碼:**[sdk/php/lib/XSServer.class.php#L83](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php#L83) (**[顯示](#)**)
`public?function?__toString()
{
????if?(strlen($this->buf1)?>?0xff)?{
????????$this->buf1?=?substr($this->buf1,?0,?0xff);
????}
????return?pack('CCCCI',?$this->cmd,?$this->arg1,?$this->arg2,?strlen($this->buf1),?strlen($this->buf))?.?$this->buf?.?$this->buf1;
}`
轉換為封包字符串
getArg()方法
<table class="summaryTable"><tr><td colspan="3"><div class="signature2">public int <b>getArg</b>()</div></td></tr><tr><td class="paramNameCol">{return}</td> <td class="paramTypeCol">int</td> <td class="paramDescCol">參數值</td></tr></table>
**源碼:**[sdk/php/lib/XSServer.class.php#L95](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php#L95) (**[顯示](#)**)
`public?function?getArg()
{
????return?$this->arg2?|?($this->arg1?<<?8);
}`
獲取屬性 arg 的值
setArg()方法
<table class="summaryTable"><tr><td colspan="3"><div class="signature2">public void <b>setArg</b>(int $arg)</div></td></tr><tr><td class="paramNameCol">$arg</td> <td class="paramTypeCol">int</td> <td class="paramDescCol">參數值</td></tr></table>
**源碼:**[sdk/php/lib/XSServer.class.php#L104](https://github.com/hightman/xunsearch/blob/master/sdk/php/lib/XSServer.class.php#L104) (**[顯示](#)**)
`public?function?setArg($arg)
{
????$this->arg1?=?($arg?>>?8)?&?0xff;
????$this->arg2?=?$arg?&?0xff;
}`
設置屬性 arg 的值
Copyright ? 2008-2011 by [杭州云圣網絡科技有限公司](http://www.xunsearch.com)
All Rights Reserved.
- 權威指南
- 新手上路
- 最新主要變動
- 概述
- 關于 Xunsearch PHP-SDK
- 安裝、升級
- 體驗 demo 項目
- 開發規范
- 開發流程
- 了解基礎對象
- 基礎對象概述
- XS 項目
- XSException 異常
- XSDocument 文檔
- XSIndex 索引管理
- XSSearch 搜索
- XSTokenizer 分詞接口
- 編寫項目配置文件
- 項目配置詳解
- 自定義分詞器
- 編寫第一個配置文件
- 管理索引
- 索引概述
- 添加文檔
- 更新、修改文檔
- 刪除文檔
- 清空索引
- 平滑重建索引
- 使用索引緩沖區
- 自定義SCWS詞庫
- 使用搜索
- 搜索概述
- 構建搜索語句
- 獲取搜索匹配結果
- 獲取搜索匹配數量
- 獲取熱門搜索詞
- 獲取相關搜索詞
- 搜索建議和糾錯
- 按字段值分面搜索
- 使用輔助工具
- RequiredCheck 運行檢測
- Indexer 索引管理器
- Quest 搜索測試工具
- SearchSkel 生成搜索代碼
- IniWizzard 配置文件向導
- Logger 搜索日志管理
- 專題
- 同義詞搜索功能
- 在SDK中使用SCWS分詞
- API 指南
- XS
- XS
- XSCommand
- XSComponent
- XSDocument
- XSErrorException
- XSException
- XSFieldMeta
- XSFieldScheme
- XSIndex
- XSSearch
- XSServer
- XS.tokenizer
- XSTokenizer
- XSTokenizerFull
- XSTokenizerNone
- XSTokenizerScws
- XSTokenizerSplit
- XSTokenizerXlen
- XSTokenizerXstep
- XS.util
- XSCsvDataSource
- XSDataFilter
- XSDatabaseDataSource
- XSDebugFilter
- XSJsonDataSource
- XSUtil
- XS.util.db
- XSDatabase
- XSDatabaseMySQL
- XSDatabaseMySQLI
- XSDatabasePDO
- XSDatabasePDO_MySQL
- XSDatabasePDO_PgSQL
- XSDatabasePDO_SQLite
- XSDatabasePgSQL
- XSDatabaseSQLite
- XSDatabaseSQLite3
- XS.utilf
- XSDataSource
- 其它文檔
- 關于 xunsearch
- 特色和優勢
- Xunsearch 架構簡圖
- 下載 Xunsearch
- 商業服務與支持
- XunSearch 授權許可證