XS
包 | XS |
---|---|
继承关系 | class XS » XSComponent |
版本 | 1.0.0 |
源代码 | sdk/php/lib/XS.class.php |
XS 搜索项目主类
Public 属性
名称 | 类型 | 描述 | 定义于 |
---|---|---|---|
allFields | XSFieldMeta[] | 获取项目所有字段结构设置 | XS |
defaultCharset | string | 获取项目的默认字符集 | XS |
fieldBody | XSFieldMeta | 获取当前内容字段 | XS |
fieldId | XSFieldMeta | 获取当前主键字段 | XS |
fieldTitle | XSFieldMeta | 获取当前标题字段 | XS |
index | XSIndex | 获取索引操作对象 | XS |
name | string | 获取当前项目名称 | XS |
scheme | XSFieldScheme | 获取当前在用的字段方案 | XS |
scwsServer | XSServer | 创建 scws 分词连接 | XS |
search | XSSearch | 获取搜索操作对象 | XS |
Public 方法
名称 | 描述 | 定义于 |
---|---|---|
__construct() | 构造函数 | XS |
__destruct() | 析构函数 | XS |
__get() | 魔术方法 __get | XSComponent |
__isset() | 魔术方法 __isset | XSComponent |
__set() | 魔术方法 __set | XSComponent |
__unset() | 魔术方法 __unset | XSComponent |
autoload() | 智能加载类库文件 | XS |
convert() | 字符集转换 | XS |
getAllFields() | 获取项目所有字段结构设置 | XS |
getDefaultCharset() | 获取项目的默认字符集 | XS |
getField() | 获取项目字段元数据 | XS |
getFieldBody() | 获取当前内容字段 | XS |
getFieldId() | 获取当前主键字段 | XS |
getFieldTitle() | 获取当前标题字段 | XS |
getIndex() | 获取索引操作对象 | XS |
getLastXS() | 获取最新的 XS 实例 | XS |
getName() | 获取当前项目名称 | XS |
getScheme() | 获取当前在用的字段方案 | XS |
getScwsServer() | 创建 scws 分词连接 | XS |
getSearch() | 获取搜索操作对象 | XS |
restoreScheme() | 还原字段方案为项目绑定方案 | XS |
setDefaultCharset() | 改变项目的默认字符集 | XS |
setName() | 修改当前项目名称 | XS |
setScheme() | 设置当前在用的字段方案 | XS |
属性明细
allFields
属性
只读
public XSFieldMeta[] getAllFields()
获取项目所有字段结构设置
defaultCharset
属性
获取项目的默认字符集
fieldBody
属性
只读
public XSFieldMeta getFieldBody()
获取当前内容字段
fieldId
属性
只读
public XSFieldMeta getFieldId()
获取当前主键字段
fieldTitle
属性
只读
public XSFieldMeta getFieldTitle()
获取当前标题字段
index
属性
只读
获取索引操作对象
name
属性
获取当前项目名称
scheme
属性
获取当前在用的字段方案 通用于搜索结果文档和修改、添加的索引文档
scwsServer
属性
只读
public XSServer getScwsServer()
创建 scws 分词连接
search
属性
只读
获取搜索操作对象
方法明细
__construct()
方法
public void __construct(string $file)
| ||
$file | string | 要加载的项目配置文件 |
源码: sdk/php/lib/XS.class.php#L280 (显示)
public function __construct($file)
{
if (strlen($file) < 255 && !is_file($file))
{
$file2 = XS_LIB_ROOT . '/../app/' . $file . '.ini';
if (is_file($file2))
$file = $file2;
}
$this->loadIniFile($file);
self::$_lastXS = $this;
}
构造函数 特别说明一个小技巧, 参数 $file 可以直接是配置文件的内容, 还可以是仅仅是文件名, 如果只是文件名会自动查找 XS_LIB_ROOT/../app/$file.ini
__destruct()
方法
public void __destruct()
|
源码: sdk/php/lib/XS.class.php#L296 (显示)
public function __destruct()
{
$this->_index = null;
$this->_search = null;
}
析构函数 由于对象交叉引用, 如需提前销毁对象, 请强制调用该函数
autoload()
方法
public static void autoload(string $name)
| ||
$name | string | 类的名称 |
源码: sdk/php/lib/XS.class.php#L486 (显示)
public static function autoload($name)
{
$file = XS_LIB_ROOT . '/' . $name . '.class.php';
if (file_exists($file))
require_once $file;
}
智能加载类库文件 要求以 Name.class.php 命名并与本文件存放在同一目录, 如: XSTokenizerXxx.class.php
convert()
方法
public static mixed convert(mixed $data, string $to, string $from)
| ||
$data | mixed | 需要转换的数据, 支持 string 和 array, 数组会自动递归转换 |
$to | string | 转换后的字符集 |
$from | string | 转换前的字符集 |
{return} | mixed | 转换后的数据 |
源码: sdk/php/lib/XS.class.php#L502 (显示)
public static function convert($data, $to, $from)
{
// need not convert
if ($to == $from)
return $data;
// array traverse
if (is_array($data))
{
foreach ($data as $key => $value)
{
$data[$key] = self::convert($value, $to, $from);
}
return $data;
}
// string contain 8bit characters
if (is_string($data) && preg_match('/[\x81-\xfe]/', $data))
{
// mbstring, iconv, throw ...
if (function_exists('mb_convert_encoding'))
return mb_convert_encoding($data, $to, $from);
else if (function_exists('iconv'))
return iconv($from, $to . '//TRANSLIT', $data);
else
throw new XSException('Cann\'t find the mbstring or iconv extension to convert encoding');
}
return $data;
}
字符集转换 要求安装有 mbstring, iconv 中的一种
getAllFields()
方法
public XSFieldMeta[] getAllFields()
| ||
{return} | XSFieldMeta[] |
源码: sdk/php/lib/XS.class.php#L476 (显示)
public function getAllFields()
{
return $this->_scheme->getAllFields();
}
获取项目所有字段结构设置
getDefaultCharset()
方法
public string getDefaultCharset()
| ||
{return} | string | 默认字符集(已大写) |
源码: sdk/php/lib/XS.class.php#L370 (显示)
public function getDefaultCharset()
{
return isset($this->_config['project.default_charset']) ?
strtoupper($this->_config['project.default_charset']) : 'UTF-8';
}
获取项目的默认字符集
getField()
方法
public XSFieldMeta getField(mixed $name, bool $throw=true)
| ||
$name | mixed | 字段名称(string) 或字段序号(vno, int) |
$throw | bool | 当字段不存在时是否抛出异常, 默认为 true |
{return} | XSFieldMeta | 字段元数据对象 |
源码: sdk/php/lib/XS.class.php#L467 (显示)
public function getField($name, $throw = true)
{
return $this->_scheme->getField($name, $throw);
}
获取项目字段元数据
getFieldBody()
方法
public XSFieldMeta getFieldBody()
| ||
{return} | XSFieldMeta | 类型为 BODY 的字段 |
源码: sdk/php/lib/XS.class.php#L454 (显示)
public function getFieldBody()
{
return $this->_scheme->getFieldBody();
}
获取当前内容字段
getFieldId()
方法
public XSFieldMeta getFieldId()
| ||
{return} | XSFieldMeta | 类型为 ID 的字段 |
源码: sdk/php/lib/XS.class.php#L434 (显示)
public function getFieldId()
{
return $this->_scheme->getFieldId();
}
获取当前主键字段
getFieldTitle()
方法
public XSFieldMeta getFieldTitle()
| ||
{return} | XSFieldMeta | 类型为 TITLE 的字段 |
源码: sdk/php/lib/XS.class.php#L444 (显示)
public function getFieldTitle()
{
return $this->_scheme->getFieldTitle();
}
获取当前标题字段
getIndex()
方法
public XSIndex getIndex()
| ||
{return} | XSIndex | 索引操作对象 |
源码: sdk/php/lib/XS.class.php#L389 (显示)
public function getIndex()
{
if ($this->_index === null)
{
$conn = isset($this->_config['server.index']) ? $this->_config['server.index'] : 8383;
$this->_index = new XSIndex($conn, $this);
$this->_index->setTimeout(0);
}
return $this->_index;
}
获取索引操作对象
getLastXS()
方法
public static XS getLastXS()
| ||
{return} | XS | 最近创建的 XS 对象 |
获取最新的 XS 实例
getName()
方法
public string getName()
| ||
{return} | string | 当前项目名称 |
源码: sdk/php/lib/XS.class.php#L351 (显示)
public function getName()
{
return $this->_config['project.name'];
}
获取当前项目名称
getScheme()
方法
public XSFieldScheme getScheme()
| ||
{return} | XSFieldScheme | 当前字段方案 |
获取当前在用的字段方案 通用于搜索结果文档和修改、添加的索引文档
getScwsServer()
方法
public XSServer getScwsServer()
| ||
{return} | XSServer | 分词服务器 |
源码: sdk/php/lib/XS.class.php#L419 (显示)
public function getScwsServer()
{
if ($this->_scws === null)
{
$conn = isset($this->_config['server.search']) ? $this->_config['server.search'] : 8384;
$this->_scws = new XSServer($conn, $this);
}
return $this->_scws;
}
创建 scws 分词连接
getSearch()
方法
public XSSearch getSearch()
| ||
{return} | XSSearch | 搜索操作对象 |
源码: sdk/php/lib/XS.class.php#L404 (显示)
public function getSearch()
{
if ($this->_search === null)
{
$conn = isset($this->_config['server.search']) ? $this->_config['server.search'] : 8384;
$this->_search = new XSSearch($conn, $this);
$this->_search->setCharset($this->getDefaultCharset());
}
return $this->_search;
}
获取搜索操作对象
restoreScheme()
方法
public void restoreScheme()
|
源码: sdk/php/lib/XS.class.php#L337 (显示)
public function restoreScheme()
{
if ($this->_scheme !== $this->_bindScheme)
{
$this->_scheme = $this->_bindScheme;
if ($this->_search !== null)
$this->_search->markResetScheme(true);
}
}
还原字段方案为项目绑定方案
setDefaultCharset()
方法
public void setDefaultCharset(string $charset)
| ||
$charset | string | 修改后的字符集 |
源码: sdk/php/lib/XS.class.php#L380 (显示)
public function setDefaultCharset($charset)
{
$this->_config['project.default_charset'] = strtoupper($charset);
}
改变项目的默认字符集
setName()
方法
public void setName(string $name)
| ||
$name | string | 项目名称 |
源码: sdk/php/lib/XS.class.php#L361 (显示)
public function setName($name)
{
$this->_config['project.name'] = $name;
}
修改当前项目名称 注意,必须在 getSearch 和 getIndex 前调用才能起作用
setScheme()
方法
public void setScheme(XSFieldScheme $fs)
| ||
$fs | XSFieldScheme | 一个有效的字段方案对象 |
源码: sdk/php/lib/XS.class.php#L326 (显示)
public function setScheme(XSFieldScheme $fs)
{
$fs->checkValid(true);
$this->_scheme = $fs;
if ($this->_search !== null)
$this->_search->markResetScheme();
}
设置当前在用的字段方案