contributions/sphinx/start.inc.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * @defgroup Sphinx 00004 * 00005 * Database driver for the Sphinx full text search engine (http://www.sphinxsearch.com/). 00006 * 00007 * @section Usage 00008 * 00009 * To use the Sphinx full text index, you may continue using the data access objects as 00010 * you are used to be. Your DAO instance should be derived from DataObjectSphinx, though. 00011 * 00012 * When declaring your table object, pass the Sphinx driver name, like so: 00013 * 00014 * @code 00015 * protected function create_table_object() { 00016 * return new DBTable( 00017 * '{indexname}', 00018 * array( 00019 * ... index fields ... 00020 * ), 00021 * {primary key} 00022 * array(), 00023 * array(), 00024 * DBDriverSphinx::DEFAULT_CONNECTION_NAME 00025 * ); 00026 * } 00027 * @endcode 00028 * 00029 * In your config, define these constants: 00030 * 00031 * @li APP_SPHINX_DB_HOST: both host and (optional) port of your sphinx daemon. If you ommit the port, Sphinx default port 9312 00032 * is used. This constant is optional, default value is "localhost" 00033 * @li APP_SPHINX_DB_NAME: A string that gets prefixed to all index names 00034 * @li APP_SPHINX_INDEXER_INVOKE: Path and optional arguments to the sphinx indexer, e.g '/usr/local/bin/indexer -c /path/to/sphinx.conf'); 00035 * @li APP_SPHINX_MAX_MATCHES: Value of the max_matches config option (optional, 1,000 by default) 00036 * 00037 * @section Features 00038 * 00039 * This module supports querying by full text fields and by attributes. If you want to full text search over all 00040 * indexed fields, use the property "sphinx_all_fields": 00041 * 00042 * @code 00043 * $dao = .. create DAO for index .. 00044 * $dao->sphinx_all_fields = 'search term'; 00045 * @endcode 00046 * 00047 * You may also use the wildcard instead: 00048 * 00049 * @code 00050 * $dao = .. create DAO for index .. 00051 * $dao->add_where('*', '=', 'search term'); 00052 * @endcode 00053 * 00054 * Sphinx virtual columns are available for sorting or filtering: 00055 * 00056 * @code 00057 * public function get_sortable_columns() { 00058 * return array( 00059 * 'relevance' => new DBSortColumn('@relevance', tr('Relevance'), DBSortColumn::TYPE_MATCH, DBSortColumn::ORDER_FORWARD, true), 00060 * 'title' => new DBSortColumn('title', tr('Title'), DBSortColumn::TYPE_TEXT) 00061 * ); 00062 * } 00063 * @endcode 00064 * 00065 * @section Notes Additional notes 00066 * 00067 * This module is build against version 0.9.9 of Sphinx. You may download it here: http://www.sphinxsearch.com/downloads.html 00068 * 00069 * Sphinx is publicly distributed under GNU General Public License (GPL), version 2. 00070 */ 00071 00072 if (!class_exists('SphinxClient')) { 00073 // If PECL extension is not loaded, use PHP file 00074 require_once dirname(__FILE__) . '/3rdparty/sphinx/sphinxapi.php'; 00075 } 00076 if (!defined('APP_SPHINX_MAX_MATCHES')) define ('APP_SPHINX_MAX_MATCHES', 1000); 00077 if (!defined('APP_SPHINX_DB_HOST')) define ('APP_SPHINX_DB_HOST', 'localhost'); 00078 DB::create_connection('sphinx', 'sphinx', APP_SPHINX_DB_NAME, false, false, APP_SPHINX_DB_HOST);