PHP 手册
上一页 |  | 下一页

# CLXIII. Swish Functions

# 简介

The swish extension provides the bindings for Swish-e API. Swish-e stands for "Simple Web Indexing System for Humans - Enhanced" and is an open source system for indexing and search. Swish-e itself is licensed under GPL license, but uses a clause that allows applications to link against the library if every copy of the combined work is accompanied by the URL to Swish-e source code. Here it is: http://swish-e.org.

警告
本扩展模块是实验性的。本模块的行为，包括其函数的名称以及其它任何关于此模块的文档可能会在没有通知的情况下随 PHP 以后的发布而改变。使用本扩展模块风险自担。

# 需求

PECL/swish requires PHP 5.1.3 or newer.

# 安装

安装此 PECL 扩展库的信息可在手册中标题为 PECL 扩展库安装的一章中找到。 更多信息如新版本，下载，源文件，维护者信息以及更新日志等可以在这里找到： http://pecl.php.net/package/swish.

The latest PECL/swish Win32 DLL can be downloaded here: php_swish.dll.

# 运行时配置

本扩展模块在 `php.ini` 中未定义任何配置选项。

# 范例

例 1. Basic search query

`<?php try { $swish = new Swish("index.swish-e"); $results = $swish->query("test OR text"); echo "Found ", $results->hits, " results\n"; while ($result = $results->nextResult()) { var_dump($result); break; //break after the first result } } catch (SwishException $e) { echo "Error: ", $e->getMessage(), "\n"; } ?>`

上例的输出类似于：

    Found 9 results
    object(SwishResult)#3 (8) {
      ["swishreccount"]=>
      int(1)
      ["swishrank"]=>
      int(1000)
      ["swishfilenum"]=>
      int(10)
      ["swishdbfile"]=>
      string(13) "index.swish-e"
      ["swishdocpath"]=>
      string(23) "README.SUBMITTING_PATCH"
      ["swishtitle"]=>
      NULL
      ["swishdocsize"]=>
      int(4557)
      ["swishlastmodified"]=>
      int(1072136752)
    }

# 预定义常量

以下常量由本扩展模块定义，因此只有在本扩展模块被编译到 PHP 中，或者在运行时被动态加载后才有效。

`Swish::META_TYPE_UNDEF` (integer)

`Swish::META_TYPE_STRING` (integer)

`Swish::META_TYPE_ULONG` (integer)

`Swish::META_TYPE_DATE` (integer)

`Swish::IN_FILE_BIT` (integer)

`Swish::IN_TITLE_BIT` (integer)

`Swish::IN_HEAD_BIT` (integer)

`Swish::IN_BODY_BIT` (integer)

`Swish::IN_COMMENTS_BIT` (integer)

`Swish::IN_HEADER_BIT` (integer)

`Swish::IN_EMPHASIZED_BIT` (integer)

`Swish::IN_META_BIT` (integer)

`Swish::IN_FILE` (integer)

`Swish::IN_TITLE` (integer)

`Swish::IN_HEAD` (integer)

`Swish::IN_BODY` (integer)

`Swish::IN_COMMENTS` (integer)

`Swish::IN_HEADER` (integer)

`Swish::IN_EMPHASIZED` (integer)

`Swish::IN_META` (integer)

`Swish::IN_ALL` (integer)

# 预定义类

### Swish

#### 属性

- indexes - the array of indexes used and their properties. Certain list of properties depends on Swish-e version.

#### 方法

- Swish::__construct - constructs new Swish object. Throws SwishException on error.

- Swish->prepare - prepares and returns SwishSearch object. Throws SwishException on error.

- Swish->query - executes the query and returns SwishResults object. Throws SwishException on error.

- Swish->getMetaList - returns an array of meta entries for the given index file.

- Swish->getPropertyList - returns an array of properties for the given index file.

### SwishSearch

#### 方法

- SwishSearch->setStructure - sets the structure flag in the search object. This flag is used to limit search to certain parts of HTML documents.

- SwishSearch->setPhraseDelimiter - sets the phrase delimiter character. The default delimiter is double-quotes.

- SwishSearch->setSort - sets the sort order of the results.

- SwishSearch->setLimit - sets the limits for the search. Throws SwishException on error.

- SwishSearch->resetLimit - resets the limits.

- SwishSearch->execute - executes the query and returns SwishResults object. Throws SwishException on error.

### SwishResults

#### 属性

- hits - the number of results in this SwishResults object.

- indexes - the array of indexes used in the search.

#### 方法

- SwishResults->nextResult - returns next SwishResult object or `FALSE` if no more results are available.

- SwishResults->seekResult - sets the current seek position in the SwishResults object. Throws SwishException on error.

- SwishResults->getParsedWords - returns an array of words in the query with stopwords removed.

- SwishResults->getRemovedStopwords - returns an array of removed stopwords.

### SwishResult

#### 属性

- Properties list depends on Swish-e version, see examples.

#### 方法

- SwishResult->getMetaList - returns an array of meta entries for the index used in this result.

- SwishResult->stem - stems the word and returns result as an array of strings. Throws SwishException on error.

### SwishException

SwishException extends the built in Exception class and possesses the same set of properties and methods. See the 节 called 扩展 PHP 内置的异常处理类 于 µÚ 20 章 for more details.

上一页 | 起始页 | 下一页
swf_viewport | 上一级 | Swish::__construct