Forum und email

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: » https://swish-e.org.

Warning

這個延伸是實驗性質的。這個延伸的行為 -- 包括函數名稱和包含此延伸的任何其它文件 -- 在未來PHP的發行中可能會在不通知的情況改變。使用此延伸需自行承擔風險。

需求

PECL/swish requires PHP 5.1.3 or newer.

安裝

Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: » https://pecl.php.net/package/swish.

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

執行時期組態

php.ini中沒有定義此延伸的組態指令。

範例

Example#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";
}

?>

The above example will output something similar to:

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

Properties

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

Methods

  • 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

Methods

SwishResults

Properties

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

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

Methods

SwishResult

Properties

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

Methods

  • 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 Exceptions for more details.

Table of Contents