Xunsearch PHP-SDK v1.0.1b1 API 参考文档

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

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
getName() 获取当前项目名称 XS
getScheme() 获取当前在用的字段方案 XS
getSearch() 获取搜索操作对象 XS
restoreScheme() 还原字段方案为项目绑定方案 XS
setScheme() 设置当前在用的字段方案 XS

属性明细

allFields 属性 只读
public XSFieldMeta[] getAllFields()

获取项目所有字段结构设置

defaultCharset 属性 只读
public string getDefaultCharset()

获取项目的默认字符集

fieldBody 属性 只读

获取当前内容字段

fieldId 属性 只读

获取当前主键字段

fieldTitle 属性 只读

获取当前标题字段

index 属性 只读
public XSIndex getIndex()

获取索引操作对象

name 属性 只读
public string getName()

获取当前项目名称

scheme 属性

获取当前在用的字段方案 通用于搜索结果文档和修改、添加的索引文档

search 属性 只读

获取搜索操作对象

方法明细

__construct() 方法
public void __construct(string $file)
$file string 要加载的项目配置文件
源码: sdk/php/lib/XS.class.php#L262 (显示)
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);
}

构造函数 特别说明一个小技巧, 参数 $file 可以直接是配置文件的内容, 还可以是仅仅是文件名, 如果只是文件名会自动查找 XS_LIB_ROOT/../app/$file.ini

__destruct() 方法
public void __destruct()
源码: sdk/php/lib/XS.class.php#L277 (显示)
public function __destruct()
{
    
$this->_index null;
    
$this->_search null;
}

析构函数 由于对象交叉引用, 如需提前销毁对象, 请强制调用该函数

autoload() 方法
public static void autoload(string $name)
$name string 类的名称
源码: sdk/php/lib/XS.class.php#L424 (显示)
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#L440 (显示)
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#L414 (显示)
public function getAllFields()
{
    return 
$this->_scheme->getAllFields();
}

获取项目所有字段结构设置

getDefaultCharset() 方法
public string getDefaultCharset()
{return} string 默认字符集(已大写)
源码: sdk/php/lib/XS.class.php#L332 (显示)
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#L405 (显示)
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#L392 (显示)
public function getFieldBody()
{
    return 
$this->_scheme->getFieldBody();
}

获取当前内容字段

getFieldId() 方法
public XSFieldMeta getFieldId()
{return} XSFieldMeta 类型为 ID 的字段
源码: sdk/php/lib/XS.class.php#L372 (显示)
public function getFieldId()
{
    return 
$this->_scheme->getFieldId();
}

获取当前主键字段

getFieldTitle() 方法
public XSFieldMeta getFieldTitle()
{return} XSFieldMeta 类型为 TITLE 的字段
源码: sdk/php/lib/XS.class.php#L382 (显示)
public function getFieldTitle()
{
    return 
$this->_scheme->getFieldTitle();
}

获取当前标题字段

getIndex() 方法
public XSIndex getIndex()
{return} XSIndex 索引操作对象
源码: sdk/php/lib/XS.class.php#L342 (显示)
public function getIndex()
{
    if (
$this->_index === null)
    {
        
$conn = isset($this->_config['server.index']) ? $this->_config['server.index'] : 8383;
        
$this->_index = new XSIndex($conn$this);
    }
    return 
$this->_index;
}

获取索引操作对象

getName() 方法
public string getName()
{return} string 当前项目名称
源码: sdk/php/lib/XS.class.php#L323 (显示)
public function getName()
{
    return 
$this->_config['project.name'];
}

获取当前项目名称

getScheme() 方法
public XSFieldScheme getScheme()
{return} XSFieldScheme 当前字段方案
源码: sdk/php/lib/XS.class.php#L288 (显示)
public function getScheme()
{
    return 
$this->_scheme;
}

获取当前在用的字段方案 通用于搜索结果文档和修改、添加的索引文档

getSearch() 方法
public XSSearch getSearch()
{return} XSSearch 搜索操作对象
源码: sdk/php/lib/XS.class.php#L356 (显示)
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#L309 (显示)
public function restoreScheme()
{
    if (
$this->_scheme !== $this->_bindScheme)
    {
        
$this->_scheme $this->_bindScheme;
        if (
$this->_search !== null)
            
$this->_search->markResetScheme(true);
    }
}

还原字段方案为项目绑定方案

setScheme() 方法
public void setScheme(XSFieldScheme $fs)
$fs XSFieldScheme 一个有效的字段方案对象
源码: sdk/php/lib/XS.class.php#L298 (显示)
public function setScheme(XSFieldScheme $fs)
{
    
$fs->checkValid(true);
    
$this->_scheme $fs;
    if (
$this->_search !== null)
        
$this->_search->markResetScheme();
}

设置当前在用的字段方案

Copyright © 2008-2011 by 杭州云圣网络科技有限公司
All Rights Reserved.