From 6a402551d752717a282aceacd452a25a81a498df Mon Sep 17 00:00:00 2001 From: bachy Date: Tue, 12 Mar 2013 15:26:34 +0100 Subject: [PATCH] first import --- CHANGELOG.txt | 89 + INSTALL.txt | 82 + LICENSE.txt | 339 +++ README.txt | 103 + SolrPhpClient/Apache/Solr/Document.php | 367 +++ SolrPhpClient/Apache/Solr/Exception.php | 50 + .../Apache/Solr/HttpTransport/Abstract.php | 89 + .../Apache/Solr/HttpTransport/Curl.php | 198 ++ .../Apache/Solr/HttpTransport/CurlNoReuse.php | 196 ++ .../Solr/HttpTransport/FileGetContents.php | 216 ++ .../Apache/Solr/HttpTransport/Interface.php | 94 + .../Apache/Solr/HttpTransport/Response.php | 255 ++ .../Apache/Solr/HttpTransportException.php | 79 + .../Apache/Solr/InvalidArgumentException.php | 50 + .../Solr/NoServiceAvailableException.php | 50 + SolrPhpClient/Apache/Solr/ParserException.php | 50 + SolrPhpClient/Apache/Solr/Response.php | 247 ++ SolrPhpClient/Apache/Solr/Service.php | 1181 ++++++++ .../Apache/Solr/Service/Balancer.php | 914 ++++++ SolrPhpClient/COPYING | 26 + SolrPhpClient/ChangeLog | 342 +++ .../Apache/Solr/Apache_Solr_Document.html | 901 ++++++ .../Apache/Solr/Apache_Solr_Exception.html | 269 ++ .../Apache_Solr_HttpTransportException.html | 246 ++ .../Apache_Solr_HttpTransport_Abstract.html | 196 ++ .../Solr/Apache_Solr_HttpTransport_Curl.html | 336 +++ ...Apache_Solr_HttpTransport_CurlNoReuse.html | 279 ++ ...he_Solr_HttpTransport_FileGetContents.html | 309 ++ .../Apache_Solr_HttpTransport_Interface.html | 260 ++ .../Apache_Solr_HttpTransport_Response.html | 298 ++ .../Apache_Solr_InvalidArgumentException.html | 144 + ...ache_Solr_NoServiceAvailableException.html | 144 + .../Solr/Apache_Solr_ParserException.html | 144 + .../Apache/Solr/Apache_Solr_Response.html | 621 +++++ .../Apache/Solr/Apache_Solr_Service.html | 2473 +++++++++++++++++ .../Solr/Apache_Solr_Service_Balancer.html | 1606 +++++++++++ .../phpdocs/Apache/Solr/_Document.php.html | 74 + .../phpdocs/Apache/Solr/_Exception.php.html | 63 + .../Solr/_HttpTransport---Abstract.php.html | 74 + .../Solr/_HttpTransport---Curl.php.html | 101 + .../_HttpTransport---CurlNoReuse.php.html | 101 + .../_HttpTransport---FileGetContents.php.html | 101 + .../Solr/_HttpTransport---Interface.php.html | 101 + .../Solr/_HttpTransport---Response.php.html | 74 + .../Solr/_HttpTransportException.php.html | 63 + .../Solr/_InvalidArgumentException.php.html | 63 + .../_NoServiceAvailableException.php.html | 63 + .../Apache/Solr/_ParserException.php.html | 63 + .../phpdocs/Apache/Solr/_Response.php.html | 101 + .../Apache/Solr/_Service---Balancer.php.html | 115 + .../phpdocs/Apache/Solr/_Service.php.html | 171 ++ .../fsource_Apache_Solr_Document.php.html | 387 +++ .../fsource_Apache_Solr_Exception.php.html | 70 + ...Apache_Solr_HttpTransportAbstract.php.html | 109 + ...rce_Apache_Solr_HttpTransportCurl.php.html | 218 ++ ...che_Solr_HttpTransportCurlNoReuse.php.html | 216 ++ ...pache_Solr_HttpTransportException.php.html | 99 + ...Solr_HttpTransportFileGetContents.php.html | 236 ++ ...pache_Solr_HttpTransportInterface.php.html | 114 + ...Apache_Solr_HttpTransportResponse.php.html | 275 ++ ...che_Solr_InvalidArgumentException.php.html | 70 + ..._Solr_NoServiceAvailableException.php.html | 70 + ...ource_Apache_Solr_ParserException.php.html | 70 + .../fsource_Apache_Solr_Response.php.html | 267 ++ .../fsource_Apache_Solr_Service.php.html | 1201 ++++++++ ...ource_Apache_Solr_ServiceBalancer.php.html | 934 +++++++ SolrPhpClient/phpdocs/blank.html | 13 + SolrPhpClient/phpdocs/classtrees_Apache.html | 56 + SolrPhpClient/phpdocs/elementindex.html | 1726 ++++++++++++ .../phpdocs/elementindex_Apache.html | 1723 ++++++++++++ SolrPhpClient/phpdocs/errors.html | 95 + SolrPhpClient/phpdocs/index.html | 24 + SolrPhpClient/phpdocs/li_Apache.html | 72 + SolrPhpClient/phpdocs/media/banner.css | 32 + SolrPhpClient/phpdocs/media/stylesheet.css | 142 + SolrPhpClient/phpdocs/packages.html | 29 + SolrPhpClient/phpdocs/todolist.html | 29 + .../tests/Apache/Solr/DocumentTest.php | 439 +++ .../Solr/HttpTransport/AbstractTest.php | 208 ++ .../Solr/HttpTransport/CurlNoReuseTest.php | 53 + .../Apache/Solr/HttpTransport/CurlTest.php | 53 + .../HttpTransport/FileGetContentsTest.php | 53 + .../Solr/HttpTransport/ResponseTest.php | 164 ++ .../Solr/HttpTransportExceptionTest.php | 58 + .../tests/Apache/Solr/ResponseTest.php | 194 ++ .../Apache/Solr/Service/BalancerTest.php | 47 + .../tests/Apache/Solr/ServiceAbstractTest.php | 139 + .../tests/Apache/Solr/ServiceTest.php | 1119 ++++++++ SolrPhpClient/tests/README | 20 + SolrPhpClient/tests/phpunit.bootstrap.inc | 28 + SolrPhpClient/tests/phpunit.xml | 15 + SolrPhpClient/tests/run.php | 42 + includes/solr_httptransport.inc | 100 + includes/spellcheck.inc | 33 + search_api_solr.api.php | 89 + search_api_solr.info | 18 + search_api_solr.install | 154 + search_api_solr.module | 145 + service.inc | 1655 +++++++++++ solr-conf/1.4/protwords.txt | 7 + solr-conf/1.4/schema.xml | 535 ++++ solr-conf/1.4/solrconfig.xml | 1637 +++++++++++ solr-conf/1.4/solrcore.properties | 8 + solr-conf/3.x/protwords.txt | 7 + solr-conf/3.x/schema.xml | 548 ++++ solr-conf/3.x/solrconfig.xml | 1645 +++++++++++ solr-conf/3.x/solrcore.properties | 10 + solr_connection.inc | 259 ++ solr_field.inc | 185 ++ 109 files changed, 32515 insertions(+) create mode 100644 CHANGELOG.txt create mode 100644 INSTALL.txt create mode 100644 LICENSE.txt create mode 100644 README.txt create mode 100644 SolrPhpClient/Apache/Solr/Document.php create mode 100644 SolrPhpClient/Apache/Solr/Exception.php create mode 100644 SolrPhpClient/Apache/Solr/HttpTransport/Abstract.php create mode 100644 SolrPhpClient/Apache/Solr/HttpTransport/Curl.php create mode 100644 SolrPhpClient/Apache/Solr/HttpTransport/CurlNoReuse.php create mode 100644 SolrPhpClient/Apache/Solr/HttpTransport/FileGetContents.php create mode 100644 SolrPhpClient/Apache/Solr/HttpTransport/Interface.php create mode 100644 SolrPhpClient/Apache/Solr/HttpTransport/Response.php create mode 100644 SolrPhpClient/Apache/Solr/HttpTransportException.php create mode 100644 SolrPhpClient/Apache/Solr/InvalidArgumentException.php create mode 100644 SolrPhpClient/Apache/Solr/NoServiceAvailableException.php create mode 100644 SolrPhpClient/Apache/Solr/ParserException.php create mode 100644 SolrPhpClient/Apache/Solr/Response.php create mode 100644 SolrPhpClient/Apache/Solr/Service.php create mode 100644 SolrPhpClient/Apache/Solr/Service/Balancer.php create mode 100644 SolrPhpClient/COPYING create mode 100644 SolrPhpClient/ChangeLog create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Document.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Exception.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransportException.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Abstract.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Curl.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_CurlNoReuse.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_FileGetContents.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Interface.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Response.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_InvalidArgumentException.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_NoServiceAvailableException.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_ParserException.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Response.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service_Balancer.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_Document.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_Exception.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Abstract.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Curl.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---CurlNoReuse.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---FileGetContents.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Interface.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Response.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_HttpTransportException.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_InvalidArgumentException.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_NoServiceAvailableException.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_ParserException.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_Response.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_Service---Balancer.php.html create mode 100644 SolrPhpClient/phpdocs/Apache/Solr/_Service.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Document.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Exception.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportAbstract.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportCurl.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportCurlNoReuse.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportException.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportFileGetContents.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportInterface.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportResponse.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_InvalidArgumentException.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_NoServiceAvailableException.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_ParserException.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Response.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Service.php.html create mode 100644 SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_ServiceBalancer.php.html create mode 100644 SolrPhpClient/phpdocs/blank.html create mode 100644 SolrPhpClient/phpdocs/classtrees_Apache.html create mode 100644 SolrPhpClient/phpdocs/elementindex.html create mode 100644 SolrPhpClient/phpdocs/elementindex_Apache.html create mode 100644 SolrPhpClient/phpdocs/errors.html create mode 100644 SolrPhpClient/phpdocs/index.html create mode 100644 SolrPhpClient/phpdocs/li_Apache.html create mode 100644 SolrPhpClient/phpdocs/media/banner.css create mode 100644 SolrPhpClient/phpdocs/media/stylesheet.css create mode 100644 SolrPhpClient/phpdocs/packages.html create mode 100644 SolrPhpClient/phpdocs/todolist.html create mode 100644 SolrPhpClient/tests/Apache/Solr/DocumentTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/HttpTransport/AbstractTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/HttpTransport/CurlNoReuseTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/HttpTransport/CurlTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/HttpTransport/FileGetContentsTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/HttpTransport/ResponseTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/HttpTransportExceptionTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/ResponseTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/Service/BalancerTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/ServiceAbstractTest.php create mode 100644 SolrPhpClient/tests/Apache/Solr/ServiceTest.php create mode 100644 SolrPhpClient/tests/README create mode 100644 SolrPhpClient/tests/phpunit.bootstrap.inc create mode 100644 SolrPhpClient/tests/phpunit.xml create mode 100644 SolrPhpClient/tests/run.php create mode 100644 includes/solr_httptransport.inc create mode 100644 includes/spellcheck.inc create mode 100644 search_api_solr.api.php create mode 100644 search_api_solr.info create mode 100644 search_api_solr.install create mode 100644 search_api_solr.module create mode 100644 service.inc create mode 100644 solr-conf/1.4/protwords.txt create mode 100644 solr-conf/1.4/schema.xml create mode 100644 solr-conf/1.4/solrconfig.xml create mode 100644 solr-conf/1.4/solrcore.properties create mode 100644 solr-conf/3.x/protwords.txt create mode 100644 solr-conf/3.x/schema.xml create mode 100644 solr-conf/3.x/solrconfig.xml create mode 100644 solr-conf/3.x/solrcore.properties create mode 100644 solr_connection.inc create mode 100644 solr_field.inc diff --git a/CHANGELOG.txt b/CHANGELOG.txt new file mode 100644 index 00000000..82bea17e --- /dev/null +++ b/CHANGELOG.txt @@ -0,0 +1,89 @@ +Search API Solr search 1.x, dev (xx/xx/xxxx): +--------------------------------------------- + +Search API Solr search 1.0, RC 3 (01/06/2013): +---------------------------------------------- +- #1828260 by drunken monkey: Fixed filtering by index in multi-index searches. +- #1509380 by drunken monkey: Adopt common config files. +- #1815348 by drunken monkey: Fixed queryMultiple() to not use item ID as the + array key. +- #1789204 by Steven Jones: Added way to easily alter the fl parameter. +- #1744250 by mollux, dasjo: Added support for location based search. +- #1813670 by guillaumev: Fixed check for autocomplete configuration in form. +- #1425910 by drunken monkey, mh86: Added setting for maximum occurence + threshold in autocomplete. +- #1691132 by drunken monkey, David Stosik: Fixed calls to watchdog(). +- #1588130 by regilero, David Stosik, drunken monkey: Fixed error handling. +- #1805720 by drunken monkey: Added additional options and improvements for the + autocomplete functionality. +- #1276970 by derhasi, moonray: Fixed large queries break Solr search. +- #1299940 by drunken monkey: Fixed handling of empty response. +- #1507818 by larowlan: Fixed field boosts for standard request handler. + +Search API Solr search 1.0, RC 2 (05/23/2012): +---------------------------------------------- +- Fixed escaping of error messages. +- #1480170 by kotnik: Fixed return value of hook_requirements(). +- #1500210 by ezra-g, acrollet, jsacksick: Fixed errors when installing with + non-default installation profiles. +- #1444432 by Damien Tournoud, jsacksick: Added field-level boosting. +- #1302406 by Steven Jones: Fixed autoload problem during installation. +- #1340244 by drunken monkey, alanomaly: Added more helpful error messages. + +Search API Solr search 1.0, RC 1 (11/10/2011): +---------------------------------------------- +- #1308638 by drunken monkey: Adapted to new structure of field settings. +- #1308498 by zenlan, drunken monkey: Added flexibility for facet fields. +- #1319544 by drunken monkey: Fixed never delete contents of read-only indexes. +- #1309650 by jonhattan, drunken monkey: Added support for the Libraries API. + +Search API Solr search 1.0, Beta 4 (09/08/2011): +------------------------------------------------ +- #1230536 by thegreat, drunken monkey: Added support for OR facets. +- #1184002 by drunken monkey: Fixed support of the latest SolrPhpClient version. +- #1032848 by das-peter, drunken monkey: Added possibility to save SolrPhpClient + to the libraries directory. +- #1225926 by drunken monkey, fago: Fixed performance problems in indexing + workflow. +- #1219310 by drunken monkey: Adapted to recent API change. +- #1203680 by klausi: Fixed use of taxonomy terms for "More like this". +- #1181260 by klausi: Fixed mlt.maxwl in solrconfig.xml. +- #1116896 by drunken monkey: Adapted to newer Solr versions. +- #1190462 by drunken monkey: Added option to directly highlight retrieved data + from Solr. +- #1196514 by drunken monkey, klausi: Fixed case sensitivity of input keys for + autocomplete. +- #1192654 by drunken monkey: Added support for the Autocomplete module. +- #1177648 by drunken monkey: Added option to use Solr's built-in highlighting. +- #1154116 by drunken monkey: Added option for retrieving search results data + directly from Solr. +- #1184002 by drunken monkey: Fixed INSTALL.txt to reflect that the module + doesn't work with the latest Solr PHP Client version. + +Search API Solr search 1.0, Beta 3 (06/06/2011): +------------------------------------------------ +- #1111852 by miiimooo, drunken monkey: Added a 'More like this' feature. +- #1153306 by JoeMcGuire, drunken monkey: Added spellchecking support. +- #1138230 by becw, drunken monkey: Added increased flexibility to the service + class. +- #1127038 by drunken monkey: Fixed handling of date facets. +- #1110820 by becw, drunken monkey: Added support for the Luke request handler. +- #1095956 by drunken monkey: Added Solr-specific index alter hook. + +Search API Solr search 1.0, Beta 2 (03/04/2011): +------------------------------------------------ +- #1071894 by drunken monkey: Fixed incorrect handling of boolean facets. +- #1071796: Add additional help for Solr-specific extensions. +- #1056018: Better document Solr config customization options. +- #1049900: Field values are sometimes not escaped properly. +- #1043586: Allow Solr server URL to be altered. +- #1010610 by mikejoconnor: Fix hook_requirements(). +- #1024146: Don't use file_get_contents() for contacting the Solr server. +- #1010610: More helpful error message when SolrPhpClient is missing. +- #915174: Remove unnecessary files[] declarations from .info file. +- #984134: Add Solr-specific query alter hooks. + +Search API Solr search 1.0, Beta 1 (11/29/2010): +------------------------------------------------ +Basic functionality is in place and quite well-tested, including support for +facets and for multi-index searches. diff --git a/INSTALL.txt b/INSTALL.txt new file mode 100644 index 00000000..18cb6c73 --- /dev/null +++ b/INSTALL.txt @@ -0,0 +1,82 @@ +Prerequisite: +- Java 6 or higher + +Steps necessary: +- Download Solr PHP client +- Setting up Solr + +Download Solr PHP client +------------------------ + +This module uses an external PHP library for communicating with Solr servers. Go +to [1] and download version r60 of this library. (The older version r22 is also +still supported, but this might change in the future.) + +[1] http://code.google.com/p/solr-php-client/downloads/list + +Afterwards, unpack this archive to Drupal's libraries folder, so the directory +tree looks like this: + +DRUPAL_ROOT/sites/all/libraries/ + |- SolrPhpClient + |- Apache/ + |- ChangeLog + ... + +The library should then be found by the module. + +Note: If you have the Libraries API [2] module installed, you can also place the +library into any other directory recognized by the Libraries API, e.g. +(depending on the module version): +- DRUPAL_ROOT/libraries +- DRUPAL_ROOT/profiles/PROFILE/libraries +- DRUPAL_ROOT/sites/CONF_DIR/libraries + +[2] http://drupal.org/project/libraries + +Setting up Solr +--------------- + +In order for this module to work, you will first need to set up a Solr server. +For this, you can either purchase a server from a web Solr hosts or set up your +own Solr server on your web server (if you have the necessary rights to do so). +If you want to use a hosted solution, a number of companies are listed on the +module's project page [3]. Otherwise, please follow the instructions below. + +[3] http://drupal.org/project/search_api_solr + +Download the latest version of Solr 3.x from [4] and unpack the archive +somewhere outside of your web server's document tree. + +[4] http://www.apache.org/dyn/closer.cgi/lucene/solr/ + +This module also supports Solr 1.4, but its use is discouraged due to worse +performance and some features not being supported. Solr 4.x is not supported by +this module yet. + +For small websites, using the example application, located in $SOLR/example/, +usually suffices. In any case, you can use it for developing andd testing. The +following instructions will assume you are using the example application, +otherwise you should be able to substitute the corresponding paths. + +Before starting the Solr server you will have to make sure it uses the proper +configuration files. These are located in the solr-conf/ directory in this +module, in a sub-directory according to the Solr version you are using. Copy all +the files from that directory into Solr's configuration directory +($SOLR/example/solr/conf/ in case of the example application), after backing up +all files that would be overwritten. +You can then start Solr. For the example application, go to $SOLR/example/ and +issue the following command (assuming Java is correctly installed): + +java -jar start.jar + +Afterwards, go to [5] in your web browser to ensure Solr is running correctly. + +[5] http://localhost:8983/solr/admin/ + +You can then enable this module and create a new server, using the "Solr search" +service class. Enter the hostname, port and path corresponding to your Solr +server in the appropriate fields. The default values already correspond to the +example application, so you won't have to change the values if you use that. +If you are using HTTP Authentication to protect your Solr server you also have +to provide the appropriate user and password here. diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..d159169d --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README.txt b/README.txt new file mode 100644 index 00000000..25fbf82d --- /dev/null +++ b/README.txt @@ -0,0 +1,103 @@ +Solr search +----------- + +This module provides an implementation of the Search API which uses an Apache +Solr search server for indexing and searching. Before enabling or using this +module, you'll have to follow the instructions given in INSTALL.txt first. + +Supported optional features +--------------------------- + +All Search API datatypes are supported by using appropriate Solr datatypes for +indexing them. By default, "String"/"URI" and "Integer"/"Duration" are defined +equivalently. However, through manual configuration of the used schema.xml this +can be changed arbitrarily. Using your own Solr extensions is thereby also +possible. + +The "direct" parse mode for queries will result in the keys being directly used +as the query to Solr. For details about Lucene's query syntax, see [1]. There +are also some Solr additions to this, listed at [2]. Note however that, by +default, this module uses the dismax query handler, so searches like +"field:value" won't work with the "direct" mode. + +[1] http://lucene.apache.org/java/2_9_1/queryparsersyntax.html +[2] http://wiki.apache.org/solr/SolrQuerySyntax + +Regarding third-party features, the following are supported: + +- search_api_autocomplete + Introduced by module: search_api_autocomplete + Lets you add autocompletion capabilities to search forms on the site. (See + also "Hidden variables" below for Solr-specific customization.) +- search_api_facets + Introduced by module: search_api_facetapi + Allows you to create facetted searches for dynamically filtering search + results. +- search_api_facets_operator_or + Introduced by module: search_api_facetapi + Allows the creation of OR facets. +- search_api_mlt + Introduced by module: search_api_views + Lets you display items that are similar to a given one. Use, e.g., to create + a "More like this" block for node pages. +- search_api_multi + Introduced by module: search_api_multi + Allows you to search multiple indexes at once, as long as they are on the same + server. You can use this to let users simultaneously search all content on the + site – nodes, comments, user profiles, etc. +- search_api_spellcheck + Introduced by module: search_api_spellcheck + Gives the option to display automatic spellchecking for searches. + +If you feel some service option is missing, or have other ideas for improving +this implementation, please file a feature request in the project's issue queue, +at [3]. + +[3] http://drupal.org/project/issues/search_api_solr + +Specifics +--------- + +Please consider that, since Solr handles tokenizing, stemming and other +preprocessing tasks, activating any preprocessors in a search index' settings is +usually not needed or even cumbersome. If you are adding an index to a Solr +server you should therefore then disable all processors which handle such +classic preprocessing tasks. + +Also, due to the way Solr works, using a single field for fulltext searching +will result in the smallest index size and best search performance, as well as +possibly having other advantages, too. Therefore, if you don't need to search +different sets of fields in different searches on an index, it is adviced that +you collect all fields that should be searchable into a single field using the +“Aggregated fields” data alteration. + +Hidden variables +---------------- + +- search_api_solr_autocomplete_max_occurrences (default: 0.9) + By default, keywords that occur in more than 90% of results are ignored for + autocomplete suggestions. This setting lets you modify that behaviour by + providing your own ratio. Use 1 or greater to use all suggestions. + +Customizing your Solr server +---------------------------- + +The schema.xml and solrconfig.xml files contain extensive comments on how to +add additional features or modify behaviour, e.g., for adding a language- +specific stemmer or a stopword list. +If you are interested in further customizing your Solr server to your needs, +see the Solr wiki at [4] for documentation. When editing the schema.xml and +solrconfig.xml files, please only edit the copies in the Solr configuration +directory, not directly the ones provided with this module. + +[4] http://wiki.apache.org/solr/ + +You'll have to restart your Solr server after making such changes, for them to +take effect. + +Developers +---------- + +The SearchApiSolrService class has a few custom extensions, documented with its +code. Methods of note are deleteItems(), which treats the first argument +differently in certain cases, and the methods at the end of service.inc. diff --git a/SolrPhpClient/Apache/Solr/Document.php b/SolrPhpClient/Apache/Solr/Document.php new file mode 100644 index 00000000..7b9784a7 --- /dev/null +++ b/SolrPhpClient/Apache/Solr/Document.php @@ -0,0 +1,367 @@ + + */ + +/** + * Holds Key / Value pairs that represent a Solr Document along with any associated boost + * values. Field values can be accessed by direct dereferencing such as: + * + * ... + * $document->title = 'Something'; + * echo $document->title; + * ... + * + * + * Additionally, the field values can be iterated with foreach + * + * + * foreach ($document as $fieldName => $fieldValue) + * { + * ... + * } + * + */ +class Apache_Solr_Document implements IteratorAggregate +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: 54 $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: Document.php 54 2011-02-04 16:29:18Z donovan.jimenez $'; + + /** + * Document boost value + * + * @var float + */ + protected $_documentBoost = false; + + /** + * Document field values, indexed by name + * + * @var array + */ + protected $_fields = array(); + + /** + * Document field boost values, indexed by name + * + * @var array array of floats + */ + protected $_fieldBoosts = array(); + + /** + * Clear all boosts and fields from this document + */ + public function clear() + { + $this->_documentBoost = false; + + $this->_fields = array(); + $this->_fieldBoosts = array(); + } + + /** + * Get current document boost + * + * @return mixed will be false for default, or else a float + */ + public function getBoost() + { + return $this->_documentBoost; + } + + /** + * Set document boost factor + * + * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false + */ + public function setBoost($boost) + { + $boost = (float) $boost; + + if ($boost > 0.0) + { + $this->_documentBoost = $boost; + } + else + { + $this->_documentBoost = false; + } + } + + /** + * Add a value to a multi-valued field + * + * NOTE: the solr XML format allows you to specify boosts + * PER value even though the underlying Lucene implementation + * only allows a boost per field. To remedy this, the final + * field boost value will be the product of all specified boosts + * on field values - this is similar to SolrJ's functionality. + * + * + * $doc = new Apache_Solr_Document(); + * + * $doc->addField('foo', 'bar', 2.0); + * $doc->addField('foo', 'baz', 3.0); + * + * // resultant field boost will be 6! + * echo $doc->getFieldBoost('foo'); + * + * + * @param string $key + * @param mixed $value + * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false + */ + public function addField($key, $value, $boost = false) + { + if (!isset($this->_fields[$key])) + { + // create holding array if this is the first value + $this->_fields[$key] = array(); + } + else if (!is_array($this->_fields[$key])) + { + // move existing value into array if it is not already an array + $this->_fields[$key] = array($this->_fields[$key]); + } + + if ($this->getFieldBoost($key) === false) + { + // boost not already set, set it now + $this->setFieldBoost($key, $boost); + } + else if ((float) $boost > 0.0) + { + // multiply passed boost with current field boost - similar to SolrJ implementation + $this->_fieldBoosts[$key] *= (float) $boost; + } + + // add value to array + $this->_fields[$key][] = $value; + } + + /** + * Handle the array manipulation for a multi-valued field + * + * @param string $key + * @param string $value + * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false + * + * @deprecated Use addField(...) instead + */ + public function setMultiValue($key, $value, $boost = false) + { + $this->addField($key, $value, $boost); + } + + /** + * Get field information + * + * @param string $key + * @return mixed associative array of info if field exists, false otherwise + */ + public function getField($key) + { + if (isset($this->_fields[$key])) + { + return array( + 'name' => $key, + 'value' => $this->_fields[$key], + 'boost' => $this->getFieldBoost($key) + ); + } + + return false; + } + + /** + * Set a field value. Multi-valued fields should be set as arrays + * or instead use the addField(...) function which will automatically + * make sure the field is an array. + * + * @param string $key + * @param mixed $value + * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false + */ + public function setField($key, $value, $boost = false) + { + $this->_fields[$key] = $value; + $this->setFieldBoost($key, $boost); + } + + /** + * Get the currently set field boost for a document field + * + * @param string $key + * @return float currently set field boost, false if one is not set + */ + public function getFieldBoost($key) + { + return isset($this->_fieldBoosts[$key]) ? $this->_fieldBoosts[$key] : false; + } + + /** + * Set the field boost for a document field + * + * @param string $key field name for the boost + * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false + */ + public function setFieldBoost($key, $boost) + { + $boost = (float) $boost; + + if ($boost > 0.0) + { + $this->_fieldBoosts[$key] = $boost; + } + else + { + $this->_fieldBoosts[$key] = false; + } + } + + /** + * Return current field boosts, indexed by field name + * + * @return array + */ + public function getFieldBoosts() + { + return $this->_fieldBoosts; + } + + /** + * Get the names of all fields in this document + * + * @return array + */ + public function getFieldNames() + { + return array_keys($this->_fields); + } + + /** + * Get the values of all fields in this document + * + * @return array + */ + public function getFieldValues() + { + return array_values($this->_fields); + } + + /** + * IteratorAggregate implementation function. Allows usage: + * + * + * foreach ($document as $key => $value) + * { + * ... + * } + * + */ + public function getIterator() + { + $arrayObject = new ArrayObject($this->_fields); + + return $arrayObject->getIterator(); + } + + /** + * Magic get for field values + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + if (isset($this->_fields[$key])) + { + return $this->_fields[$key]; + } + + return null; + } + + /** + * Magic set for field values. Multi-valued fields should be set as arrays + * or instead use the addField(...) function which will automatically + * make sure the field is an array. + * + * @param string $key + * @param mixed $value + */ + public function __set($key, $value) + { + $this->setField($key, $value); + } + + /** + * Magic isset for fields values. Do not call directly. Allows usage: + * + * + * isset($document->some_field); + * + * + * @param string $key + * @return boolean + */ + public function __isset($key) + { + return isset($this->_fields[$key]); + } + + /** + * Magic unset for field values. Do not call directly. Allows usage: + * + * + * unset($document->some_field); + * + * + * @param string $key + */ + public function __unset($key) + { + unset($this->_fields[$key]); + unset($this->_fieldBoosts[$key]); + } +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/Exception.php b/SolrPhpClient/Apache/Solr/Exception.php new file mode 100644 index 00000000..e6bc4f4b --- /dev/null +++ b/SolrPhpClient/Apache/Solr/Exception.php @@ -0,0 +1,50 @@ + + */ + +class Apache_Solr_Exception extends Exception +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: 54 $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: Exception.php 54 2011-02-04 16:29:18Z donovan.jimenez $'; +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/HttpTransport/Abstract.php b/SolrPhpClient/Apache/Solr/HttpTransport/Abstract.php new file mode 100644 index 00000000..cf9f76d3 --- /dev/null +++ b/SolrPhpClient/Apache/Solr/HttpTransport/Abstract.php @@ -0,0 +1,89 @@ +, Donovan Jimenez + */ + +/** + * Convenience class that implements the transport implementation. Can be extended by + * real implementations to do some of the common book keeping + */ +abstract class Apache_Solr_HttpTransport_Abstract implements Apache_Solr_HttpTransport_Interface +{ + /** + * Our default timeout value for requests that don't specify a timeout + * + * @var float + */ + private $_defaultTimeout = false; + + /** + * Get the current default timeout setting (initially the default_socket_timeout ini setting) + * in seconds + * + * @return float + */ + public function getDefaultTimeout() + { + // lazy load the default timeout from the ini settings + if ($this->_defaultTimeout === false) + { + $this->_defaultTimeout = (int) ini_get('default_socket_timeout'); + + // double check we didn't get 0 for a timeout + if ($this->_defaultTimeout <= 0) + { + $this->_defaultTimeout = 60; + } + } + + return $this->_defaultTimeout; + } + + /** + * Set the current default timeout for all HTTP requests + * + * @param float $timeout + */ + public function setDefaultTimeout($timeout) + { + $timeout = (float) $timeout; + + if ($timeout >= 0) + { + $this->_defaultTimeout = $timeout; + } + } +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/HttpTransport/Curl.php b/SolrPhpClient/Apache/Solr/HttpTransport/Curl.php new file mode 100644 index 00000000..7cb7743e --- /dev/null +++ b/SolrPhpClient/Apache/Solr/HttpTransport/Curl.php @@ -0,0 +1,198 @@ +, Donovan Jimenez + */ + +// Require Apache_Solr_HttpTransport_Abstract +require_once(dirname(__FILE__) . '/Abstract.php'); + +/** + * A Curl based HTTP transport. Uses a single curl session for all requests. + */ +class Apache_Solr_HttpTransport_Curl extends Apache_Solr_HttpTransport_Abstract +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision:$'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id:$'; + + /** + * Curl Session Handle + * + * @var resource + */ + private $_curl; + + /** + * Initializes a curl session + */ + public function __construct() + { + // initialize a CURL session + $this->_curl = curl_init(); + + // set common options that will not be changed during the session + curl_setopt_array($this->_curl, array( + // return the response body from curl_exec + CURLOPT_RETURNTRANSFER => true, + + // get the output as binary data + CURLOPT_BINARYTRANSFER => true, + + // we do not need the headers in the output, we get everything we need from curl_getinfo + CURLOPT_HEADER => false + )); + } + + /** + * Closes a curl session + */ + function __destruct() + { + // close our curl session + curl_close($this->_curl); + } + + public function performGetRequest($url, $timeout = false) + { + // check the timeout value + if ($timeout === false || $timeout <= 0.0) + { + // use the default timeout + $timeout = $this->getDefaultTimeout(); + } + + // set curl GET options + curl_setopt_array($this->_curl, array( + // make sure we're returning the body + CURLOPT_NOBODY => false, + + // make sure we're GET + CURLOPT_HTTPGET => true, + + // set the URL + CURLOPT_URL => $url, + + // set the timeout + CURLOPT_TIMEOUT => $timeout + )); + + // make the request + $responseBody = curl_exec($this->_curl); + + // get info from the transfer + $statusCode = curl_getinfo($this->_curl, CURLINFO_HTTP_CODE); + $contentType = curl_getinfo($this->_curl, CURLINFO_CONTENT_TYPE); + + return new Apache_Solr_HttpTransport_Response($statusCode, $contentType, $responseBody); + } + + public function performHeadRequest($url, $timeout = false) + { + // check the timeout value + if ($timeout === false || $timeout <= 0.0) + { + // use the default timeout + $timeout = $this->getDefaultTimeout(); + } + + // set curl HEAD options + curl_setopt_array($this->_curl, array( + // this both sets the method to HEAD and says not to return a body + CURLOPT_NOBODY => true, + + // set the URL + CURLOPT_URL => $url, + + // set the timeout + CURLOPT_TIMEOUT => $timeout + )); + + // make the request + $responseBody = curl_exec($this->_curl); + + // get info from the transfer + $statusCode = curl_getinfo($this->_curl, CURLINFO_HTTP_CODE); + $contentType = curl_getinfo($this->_curl, CURLINFO_CONTENT_TYPE); + + return new Apache_Solr_HttpTransport_Response($statusCode, $contentType, $responseBody); + } + + public function performPostRequest($url, $postData, $contentType, $timeout = false) + { + // check the timeout value + if ($timeout === false || $timeout <= 0.0) + { + // use the default timeout + $timeout = $this->getDefaultTimeout(); + } + + // set curl POST options + curl_setopt_array($this->_curl, array( + // make sure we're returning the body + CURLOPT_NOBODY => false, + + // make sure we're POST + CURLOPT_POST => true, + + // set the URL + CURLOPT_URL => $url, + + // set the post data + CURLOPT_POSTFIELDS => $postData, + + // set the content type + CURLOPT_HTTPHEADER => array("Content-Type: {$contentType}"), + + // set the timeout + CURLOPT_TIMEOUT => $timeout + )); + + // make the request + $responseBody = curl_exec($this->_curl); + + // get info from the transfer + $statusCode = curl_getinfo($this->_curl, CURLINFO_HTTP_CODE); + $contentType = curl_getinfo($this->_curl, CURLINFO_CONTENT_TYPE); + + return new Apache_Solr_HttpTransport_Response($statusCode, $contentType, $responseBody); + } +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/HttpTransport/CurlNoReuse.php b/SolrPhpClient/Apache/Solr/HttpTransport/CurlNoReuse.php new file mode 100644 index 00000000..14549588 --- /dev/null +++ b/SolrPhpClient/Apache/Solr/HttpTransport/CurlNoReuse.php @@ -0,0 +1,196 @@ +, Donovan Jimenez + */ + +// Require Apache_Solr_HttpTransport_Abstract +require_once(dirname(__FILE__) . '/Abstract.php'); + +/** + * An alternative Curl HTTP transport that opens and closes a curl session for + * every request. This isn't the recommended way to use curl, but some version of + * PHP have memory issues. + */ +class Apache_Solr_HttpTransport_CurlNoReuse extends Apache_Solr_HttpTransport_Abstract +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision:$'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id:$'; + + public function performGetRequest($url, $timeout = false) + { + // check the timeout value + if ($timeout === false || $timeout <= 0.0) + { + // use the default timeout + $timeout = $this->getDefaultTimeout(); + } + + $curl = curl_init(); + + // set curl GET options + curl_setopt_array($curl, array( + // return the response body from curl_exec + CURLOPT_RETURNTRANSFER => true, + + // get the output as binary data + CURLOPT_BINARYTRANSFER => true, + + // we do not need the headers in the output, we get everything we need from curl_getinfo + CURLOPT_HEADER => false, + + // set the URL + CURLOPT_URL => $url, + + // set the timeout + CURLOPT_TIMEOUT => $timeout + )); + + // make the request + $responseBody = curl_exec($curl); + + // get info from the transfer + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE); + + // close our curl session - we're done with it + curl_close($curl); + + return new Apache_Solr_HttpTransport_Response($statusCode, $contentType, $responseBody); + } + + public function performHeadRequest($url, $timeout = false) + { + // check the timeout value + if ($timeout === false || $timeout <= 0.0) + { + // use the default timeout + $timeout = $this->getDefaultTimeout(); + } + + $curl = curl_init(); + + // set curl HEAD options + curl_setopt_array($curl, array( + // return the response body from curl_exec + CURLOPT_RETURNTRANSFER => true, + + // get the output as binary data + CURLOPT_BINARYTRANSFER => true, + + // we do not need the headers in the output, we get everything we need from curl_getinfo + CURLOPT_HEADER => false, + + // this both sets the method to HEAD and says not to return a body + CURLOPT_NOBODY => true, + + // set the URL + CURLOPT_URL => $url, + + // set the timeout + CURLOPT_TIMEOUT => $timeout + )); + + // make the request + $responseBody = curl_exec($curl); + + // get info from the transfer + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE); + + // close our curl session - we're done with it + curl_close($curl); + + return new Apache_Solr_HttpTransport_Response($statusCode, $contentType, $responseBody); + } + + public function performPostRequest($url, $postData, $contentType, $timeout = false) + { + // check the timeout value + if ($timeout === false || $timeout <= 0.0) + { + // use the default timeout + $timeout = $this->getDefaultTimeout(); + } + + $curl = curl_init(); + + // set curl POST options + curl_setopt_array($curl, array( + // return the response body from curl_exec + CURLOPT_RETURNTRANSFER => true, + + // get the output as binary data + CURLOPT_BINARYTRANSFER => true, + + // we do not need the headers in the output, we get everything we need from curl_getinfo + CURLOPT_HEADER => false, + + // make sure we're POST + CURLOPT_POST => true, + + // set the URL + CURLOPT_URL => $url, + + // set the post data + CURLOPT_POSTFIELDS => $postData, + + // set the content type + CURLOPT_HTTPHEADER => array("Content-Type: {$contentType}"), + + // set the timeout + CURLOPT_TIMEOUT => $timeout + )); + + // make the request + $responseBody = curl_exec($curl); + + // get info from the transfer + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + $contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE); + + // close our curl session - we're done with it + curl_close($curl); + + return new Apache_Solr_HttpTransport_Response($statusCode, $contentType, $responseBody); + } +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/HttpTransport/FileGetContents.php b/SolrPhpClient/Apache/Solr/HttpTransport/FileGetContents.php new file mode 100644 index 00000000..5e01775c --- /dev/null +++ b/SolrPhpClient/Apache/Solr/HttpTransport/FileGetContents.php @@ -0,0 +1,216 @@ + + */ + +// Require Apache_Solr_HttpTransport_Abstract +require_once(dirname(__FILE__) . '/Abstract.php'); + +/** + * HTTP Transport implemenation that uses the builtin http URL wrappers and file_get_contents + */ +class Apache_Solr_HttpTransport_FileGetContents extends Apache_Solr_HttpTransport_Abstract +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: $'; + + /** + * Reusable stream context resources for GET and POST operations + * + * @var resource + */ + private $_getContext, $_headContext, $_postContext; + + /** + * Initializes our reuseable get and post stream contexts + */ + public function __construct() + { + $this->_getContext = stream_context_create(); + $this->_headContext = stream_context_create(); + $this->_postContext = stream_context_create(); + } + + public function performGetRequest($url, $timeout = false) + { + // set the timeout if specified + if ($timeout !== FALSE && $timeout > 0.0) + { + // timeouts with file_get_contents seem to need + // to be halved to work as expected + $timeout = (float) $timeout / 2; + + stream_context_set_option($this->_getContext, 'http', 'timeout', $timeout); + } + else + { + // use the default timeout pulled from default_socket_timeout otherwise + stream_context_set_option($this->_getContext, 'http', 'timeout', $this->getDefaultTimeout()); + } + + // $http_response_headers will be updated by the call to file_get_contents later + // see http://us.php.net/manual/en/wrappers.http.php for documentation + // Unfortunately, it will still create a notice in analyzers if we don't set it here + $http_response_header = null; + $responseBody = @file_get_contents($url, false, $this->_getContext); + + return $this->_getResponseFromParts($responseBody, $http_response_header); + } + + public function performHeadRequest($url, $timeout = false) + { + stream_context_set_option($this->_headContext, array( + 'http' => array( + // set HTTP method + 'method' => 'HEAD', + + // default timeout + 'timeout' => $this->getDefaultTimeout() + ) + ) + ); + + // set the timeout if specified + if ($timeout !== FALSE && $timeout > 0.0) + { + // timeouts with file_get_contents seem to need + // to be halved to work as expected + $timeout = (float) $timeout / 2; + + stream_context_set_option($this->_headContext, 'http', 'timeout', $timeout); + } + + // $http_response_headers will be updated by the call to file_get_contents later + // see http://us.php.net/manual/en/wrappers.http.php for documentation + // Unfortunately, it will still create a notice in analyzers if we don't set it here + $http_response_header = null; + $responseBody = @file_get_contents($url, false, $this->_headContext); + + return $this->_getResponseFromParts($responseBody, $http_response_header); + } + + public function performPostRequest($url, $rawPost, $contentType, $timeout = false) + { + stream_context_set_option($this->_postContext, array( + 'http' => array( + // set HTTP method + 'method' => 'POST', + + // Add our posted content type + 'header' => "Content-Type: $contentType", + + // the posted content + 'content' => $rawPost, + + // default timeout + 'timeout' => $this->getDefaultTimeout() + ) + ) + ); + + // set the timeout if specified + if ($timeout !== FALSE && $timeout > 0.0) + { + // timeouts with file_get_contents seem to need + // to be halved to work as expected + $timeout = (float) $timeout / 2; + + stream_context_set_option($this->_postContext, 'http', 'timeout', $timeout); + } + + // $http_response_header will be updated by the call to file_get_contents later + // see http://us.php.net/manual/en/wrappers.http.php for documentation + // Unfortunately, it will still create a notice in analyzers if we don't set it here + $http_response_header = null; + $responseBody = @file_get_contents($url, false, $this->_postContext); + + // reset content of post context to reclaim memory + stream_context_set_option($this->_postContext, 'http', 'content', ''); + + return $this->_getResponseFromParts($responseBody, $http_response_header); + } + + private function _getResponseFromParts($rawResponse, $httpHeaders) + { + //Assume 0, false as defaults + $status = 0; + $contentType = false; + + //iterate through headers for real status, type, and encoding + if (is_array($httpHeaders) && count($httpHeaders) > 0) + { + //look at the first headers for the HTTP status code + //and message (errors are usually returned this way) + // + //HTTP 100 Continue response can also be returned before + //the REAL status header, so we need look until we find + //the last header starting with HTTP + // + //the spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1 + // + //Thanks to Daniel Andersson for pointing out this oversight + while (isset($httpHeaders[0]) && substr($httpHeaders[0], 0, 4) == 'HTTP') + { + // we can do a intval on status line without the "HTTP/1.X " to get the code + $status = intval(substr($httpHeaders[0], 9)); + + // remove this from the headers so we can check for more + array_shift($httpHeaders); + } + + //Look for the Content-Type response header and determine type + //and encoding from it (if possible - such as 'Content-Type: text/plain; charset=UTF-8') + foreach ($httpHeaders as $header) + { + // look for the header that starts appropriately + if (strncasecmp($header, 'Content-Type:', 13) == 0) + { + $contentType = substr($header, 13); + break; + } + } + } + + return new Apache_Solr_HttpTransport_Response($status, $contentType, $rawResponse); + } +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/HttpTransport/Interface.php b/SolrPhpClient/Apache/Solr/HttpTransport/Interface.php new file mode 100644 index 00000000..090fc27a --- /dev/null +++ b/SolrPhpClient/Apache/Solr/HttpTransport/Interface.php @@ -0,0 +1,94 @@ +, Donovan Jimenez + */ + +// require Apache_Solr_HttpTransport_Response +require_once(dirname(__FILE__) . '/Response.php'); + +/** + * Interface that all Transport (HTTP Requester) implementations must implement. These + * Implementations can then be plugged into the Service instance in order to user their + * the desired method for making HTTP requests + */ +interface Apache_Solr_HttpTransport_Interface +{ + /** + * Get the current default timeout for all HTTP requests + * + * @return float + */ + public function getDefaultTimeout(); + + /** + * Set the current default timeout for all HTTP requests + * + * @param float $timeout + */ + public function setDefaultTimeout($timeout); + + /** + * Perform a GET HTTP operation with an optional timeout and return the response + * contents, use getLastResponseHeaders to retrieve HTTP headers + * + * @param string $url + * @param float $timeout + * @return Apache_Solr_HttpTransport_Response HTTP response + */ + public function performGetRequest($url, $timeout = false); + + /** + * Perform a HEAD HTTP operation with an optional timeout and return the response + * headers - NOTE: head requests have no response body + * + * @param string $url + * @param float $timeout + * @return Apache_Solr_HttpTransport_Response HTTP response + */ + public function performHeadRequest($url, $timeout = false); + + /** + * Perform a POST HTTP operation with an optional timeout and return the response + * contents, use getLastResponseHeaders to retrieve HTTP headers + * + * @param string $url + * @param string $rawPost + * @param string $contentType + * @param float $timeout + * @return Apache_Solr_HttpTransport_Response HTTP response + */ + public function performPostRequest($url, $rawPost, $contentType, $timeout = false); +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/HttpTransport/Response.php b/SolrPhpClient/Apache/Solr/HttpTransport/Response.php new file mode 100644 index 00000000..3f113aee --- /dev/null +++ b/SolrPhpClient/Apache/Solr/HttpTransport/Response.php @@ -0,0 +1,255 @@ + + */ + +/** + * Represents the required pieces of an HTTP response provided by HTTP transport + * implementations and then consumed by the Apache_Solr_Response class which provides + * decoding + */ +class Apache_Solr_HttpTransport_Response +{ + /** + * Status Messages indexed by Status Code + * Obtained from: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html + * + * @var array + */ + static private $_defaultStatusMessages = array( + // Specific to PHP Solr Client + 0 => "Communication Error", + + // Informational 1XX + 100 => "Continue", + 101 => "Switching Protocols", + + // Successful 2XX + 200 => "OK", + 201 => "Created", + 202 => "Accepted", + 203 => "Non-Authoritative Information", + 204 => "No Content", + 205 => "Reset Content", + 206 => "Partial Content", + + // Redirection 3XX + 300 => "Multiple Choices", + 301 => "Moved Permanently", + 302 => "Found", + 303 => "See Other", + 304 => "Not Modified", + 305 => "Use Proxy", + 307 => "Temporary Redirect", + + // Client Error 4XX + 400 => "Bad Request", + 401 => "Unauthorized", + 402 => "Payment Required", + 403 => "Forbidden", + 404 => "Not Found", + 405 => "Method Not Allowed", + 406 => "Not Acceptable", + 407 => "Proxy Authentication Required", + 408 => "Request Timeout", + 409 => "Conflict", + 410 => "Gone", + 411 => "Length Required", + 412 => "Precondition Failed", + 413 => "Request Entity Too Large", + 414 => "Request-URI Too Long", + 415 => "Unsupported Media Type", + 416 => "Request Range Not Satisfiable", + 417 => "Expectation Failed", + + // Server Error 5XX + 500 => "Internal Server Error", + 501 => "Not Implemented", + 502 => "Bad Gateway", + 503 => "Service Unavailable", + 504 => "Gateway Timeout", + 505 => "HTTP Version Not Supported" + ); + + /** + * Get the HTTP status message based on status code + * + * @return string + */ + public static function getDefaultStatusMessage($statusCode) + { + $statusCode = (int) $statusCode; + + if (isset(self::$_defaultStatusMessages[$statusCode])) + { + return self::$_defaultStatusMessages[$statusCode]; + } + + return "Unknown Status"; + } + + /** + * The response's HTTP status code + * + * @var integer + */ + private $_statusCode; + + /** + * The response's HTTP status message + * + * @var string + */ + private $_statusMessage; + + /** + * The response's mime type + * + * @var string + */ + private $_mimeType; + + /** + * The response's character encoding + * + * @var string + */ + private $_encoding; + + /** + * The response's data + * + * @var string + */ + private $_responseBody; + + /** + * Construct a HTTP transport response + * + * @param integer $statusCode The HTTP status code + * @param string $contentType The VALUE of the Content-Type HTTP header + * @param string $responseBody The body of the HTTP response + */ + public function __construct($statusCode, $contentType, $responseBody) + { + // set the status code, make sure its an integer + $this->_statusCode = (int) $statusCode; + + // lookup up status message based on code + $this->_statusMessage = self::getDefaultStatusMessage($this->_statusCode); + + // set the response body, it should always be a string + $this->_responseBody = (string) $responseBody; + + // parse the content type header value for mimetype and encoding + // first set default values that will remain if we can't find + // what we're looking for in the content type + $this->_mimeType = "text/plain"; + $this->_encoding = "UTF-8"; + + if ($contentType) + { + // now break apart the header to see if there's character encoding + $contentTypeParts = explode(';', $contentType, 2); + + if (isset($contentTypeParts[0])) + { + $this->_mimeType = trim($contentTypeParts[0]); + } + + if (isset($contentTypeParts[1])) + { + // we have a second part, split it further + $contentTypeParts = explode('=', $contentTypeParts[1]); + + if (isset($contentTypeParts[1])) + { + $this->_encoding = trim($contentTypeParts[1]); + } + } + } + } + + /** + * Get the status code of the response + * + * @return integer + */ + public function getStatusCode() + { + return $this->_statusCode; + } + + /** + * Get the status message of the response + * + * @return string + */ + public function getStatusMessage() + { + return $this->_statusMessage; + } + + /** + * Get the mimetype of the response body + * + * @return string + */ + public function getMimeType() + { + return $this->_mimeType; + } + + /** + * Get the charset encoding of the response body. + * + * @return string + */ + public function getEncoding() + { + return $this->_encoding; + } + + /** + * Get the raw response body + * + * @return string + */ + public function getBody() + { + return $this->_responseBody; + } +} diff --git a/SolrPhpClient/Apache/Solr/HttpTransportException.php b/SolrPhpClient/Apache/Solr/HttpTransportException.php new file mode 100644 index 00000000..83c0001b --- /dev/null +++ b/SolrPhpClient/Apache/Solr/HttpTransportException.php @@ -0,0 +1,79 @@ + + */ + +class Apache_Solr_HttpTransportException extends Apache_Solr_Exception +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: 54 $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: HttpTransportException.php 54 2011-02-04 16:29:18Z donovan.jimenez $'; + + /** + * Response for which exception was generated + * + * @var Apache_Solr_Response + */ + private $_response; + + /** + * HttpTransportException Constructor + * + * @param Apache_Solr_Response $response + */ + public function __construct(Apache_Solr_Response $response) + { + parent::__construct("'{$response->getHttpStatus()}' Status: {$response->getHttpStatusMessage()}", $response->getHttpStatus()); + + $this->_response = $response; + } + + /** + * Get the response for which this exception was generated + * + * @return Apache_Solr_Response + */ + public function getResponse() + { + return $this->_response; + } +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/InvalidArgumentException.php b/SolrPhpClient/Apache/Solr/InvalidArgumentException.php new file mode 100644 index 00000000..273f3d06 --- /dev/null +++ b/SolrPhpClient/Apache/Solr/InvalidArgumentException.php @@ -0,0 +1,50 @@ + + */ + +class Apache_Solr_InvalidArgumentException extends Apache_Solr_Exception +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: 54 $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $'; +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/NoServiceAvailableException.php b/SolrPhpClient/Apache/Solr/NoServiceAvailableException.php new file mode 100644 index 00000000..eead7320 --- /dev/null +++ b/SolrPhpClient/Apache/Solr/NoServiceAvailableException.php @@ -0,0 +1,50 @@ + + */ + +class Apache_Solr_NoServiceAvailableException extends Apache_Solr_Exception +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: 54 $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $'; +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/ParserException.php b/SolrPhpClient/Apache/Solr/ParserException.php new file mode 100644 index 00000000..29283dbc --- /dev/null +++ b/SolrPhpClient/Apache/Solr/ParserException.php @@ -0,0 +1,50 @@ + + */ + +class Apache_Solr_ParserException extends Apache_Solr_Exception +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: 54 $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $'; +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/Response.php b/SolrPhpClient/Apache/Solr/Response.php new file mode 100644 index 00000000..1a35e568 --- /dev/null +++ b/SolrPhpClient/Apache/Solr/Response.php @@ -0,0 +1,247 @@ + + */ + +require_once(dirname(__FILE__) . '/ParserException.php'); + +/** + * Represents a Solr response. Parses the raw response into a set of stdClass objects + * and associative arrays for easy access. + * + * Currently requires json_decode which is bundled with PHP >= 5.2.0, Alternatively can be + * installed with PECL. Zend Framework also includes a purely PHP solution. + */ +class Apache_Solr_Response +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: 54 $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: Response.php 54 2011-02-04 16:29:18Z donovan.jimenez $'; + + /** + * Holds the raw response used in construction + * + * @var Apache_Solr_HttpTransport_Response HTTP response + */ + protected $_response; + + /** + * Whether the raw response has been parsed + * + * @var boolean + */ + protected $_isParsed = false; + + /** + * Parsed representation of the data + * + * @var mixed + */ + protected $_parsedData; + + /** + * Data parsing flags. Determines what extra processing should be done + * after the data is initially converted to a data structure. + * + * @var boolean + */ + protected $_createDocuments = true, + $_collapseSingleValueArrays = true; + + /** + * Constructor. Takes the raw HTTP response body and the exploded HTTP headers + * + * @return Apache_Solr_HttpTransport_Response HTTP response + * @param boolean $createDocuments Whether to convert the documents json_decoded as stdClass instances to Apache_Solr_Document instances + * @param boolean $collapseSingleValueArrays Whether to make multivalued fields appear as single values + */ + public function __construct(Apache_Solr_HttpTransport_Response $response, $createDocuments = true, $collapseSingleValueArrays = true) + { + $this->_response = $response; + $this->_createDocuments = (bool) $createDocuments; + $this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays; + } + + /** + * Get the HTTP status code + * + * @return integer + */ + public function getHttpStatus() + { + return $this->_response->getStatusCode(); + } + + /** + * Get the HTTP status message of the response + * + * @return string + */ + public function getHttpStatusMessage() + { + return $this->_response->getStatusMessage(); + } + + /** + * Get content type of this Solr response + * + * @return string + */ + public function getType() + { + return $this->_response->getMimeType(); + } + + /** + * Get character encoding of this response. Should usually be utf-8, but just in case + * + * @return string + */ + public function getEncoding() + { + return $this->_response->getEncoding(); + } + + /** + * Get the raw response as it was given to this object + * + * @return string + */ + public function getRawResponse() + { + return $this->_response->getBody(); + } + + /** + * Magic get to expose the parsed data and to lazily load it + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + if (!$this->_isParsed) + { + $this->_parseData(); + $this->_isParsed = true; + } + + if (isset($this->_parsedData->$key)) + { + return $this->_parsedData->$key; + } + + return null; + } + + /** + * Magic function for isset function on parsed data + * + * @param string $key + * @return boolean + */ + public function __isset($key) + { + if (!$this->_isParsed) + { + $this->_parseData(); + $this->_isParsed = true; + } + + return isset($this->_parsedData->$key); + } + + /** + * Parse the raw response into the parsed_data array for access + * + * @throws Apache_Solr_ParserException If the data could not be parsed + */ + protected function _parseData() + { + //An alternative would be to use Zend_Json::decode(...) + $data = json_decode($this->_response->getBody()); + + // check that we receive a valid JSON response - we should never receive a null + if ($data === null) + { + throw new Apache_Solr_ParserException('Solr response does not appear to be valid JSON, please examine the raw response with getRawResponse() method'); + } + + //if we're configured to collapse single valued arrays or to convert them to Apache_Solr_Document objects + //and we have response documents, then try to collapse the values and / or convert them now + if (($this->_createDocuments || $this->_collapseSingleValueArrays) && isset($data->response) && is_array($data->response->docs)) + { + $documents = array(); + + foreach ($data->response->docs as $originalDocument) + { + if ($this->_createDocuments) + { + $document = new Apache_Solr_Document(); + } + else + { + $document = $originalDocument; + } + + foreach ($originalDocument as $key => $value) + { + //If a result is an array with only a single + //value then its nice to be able to access + //it as if it were always a single value + if ($this->_collapseSingleValueArrays && is_array($value) && count($value) <= 1) + { + $value = array_shift($value); + } + + $document->$key = $value; + } + + $documents[] = $document; + } + + $data->response->docs = $documents; + } + + $this->_parsedData = $data; + } +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/Service.php b/SolrPhpClient/Apache/Solr/Service.php new file mode 100644 index 00000000..ea9ae376 --- /dev/null +++ b/SolrPhpClient/Apache/Solr/Service.php @@ -0,0 +1,1181 @@ + + */ + +// See Issue #1 (http://code.google.com/p/solr-php-client/issues/detail?id=1) +// Doesn't follow typical include path conventions, but is more convenient for users +require_once(dirname(__FILE__) . '/Exception.php'); +require_once(dirname(__FILE__) . '/HttpTransportException.php'); +require_once(dirname(__FILE__) . '/InvalidArgumentException.php'); + +require_once(dirname(__FILE__) . '/Document.php'); +require_once(dirname(__FILE__) . '/Response.php'); + +require_once(dirname(__FILE__) . '/HttpTransport/Interface.php'); + +/** + * Starting point for the Solr API. Represents a Solr server resource and has + * methods for pinging, adding, deleting, committing, optimizing and searching. + * + * Example Usage: + * + * ... + * $solr = new Apache_Solr_Service(); //or explicitly new Apache_Solr_Service('localhost', 8180, '/solr') + * + * if ($solr->ping()) + * { + * $solr->deleteByQuery('*:*'); //deletes ALL documents - be careful :) + * + * $document = new Apache_Solr_Document(); + * $document->id = uniqid(); //or something else suitably unique + * + * $document->title = 'Some Title'; + * $document->content = 'Some content for this wonderful document. Blah blah blah.'; + * + * $solr->addDocument($document); //if you're going to be adding documents in bulk using addDocuments + * //with an array of documents is faster + * + * $solr->commit(); //commit to see the deletes and the document + * $solr->optimize(); //merges multiple segments into one + * + * //and the one we all care about, search! + * //any other common or custom parameters to the request handler can go in the + * //optional 4th array argument. + * $solr->search('content:blah', 0, 10, array('sort' => 'timestamp desc')); + * } + * ... + * + * + * @todo Investigate using other HTTP clients other than file_get_contents built-in handler. Could provide performance + * improvements when dealing with multiple requests by using HTTP's keep alive functionality + */ +class Apache_Solr_Service +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: 59 $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: Service.php 59 2011-02-08 20:38:59Z donovan.jimenez $'; + + /** + * Response writer we'll request - JSON. See http://code.google.com/p/solr-php-client/issues/detail?id=6#c1 for reasoning + */ + const SOLR_WRITER = 'json'; + + /** + * NamedList Treatment constants + */ + const NAMED_LIST_FLAT = 'flat'; + const NAMED_LIST_MAP = 'map'; + + /** + * Search HTTP Methods + */ + const METHOD_GET = 'GET'; + const METHOD_POST = 'POST'; + + /** + * Servlet mappings + */ + const PING_SERVLET = 'admin/ping'; + const UPDATE_SERVLET = 'update'; + const SEARCH_SERVLET = 'select'; + const THREADS_SERVLET = 'admin/threads'; + const EXTRACT_SERVLET = 'update/extract'; + + /** + * Server identification strings + * + * @var string + */ + protected $_host, $_port, $_path; + + /** + * Whether {@link Apache_Solr_Response} objects should create {@link Apache_Solr_Document}s in + * the returned parsed data + * + * @var boolean + */ + protected $_createDocuments = true; + + /** + * Whether {@link Apache_Solr_Response} objects should have multivalue fields with only a single value + * collapsed to appear as a single value would. + * + * @var boolean + */ + protected $_collapseSingleValueArrays = true; + + /** + * How NamedLists should be formatted in the output. This specifically effects facet counts. Valid values + * are {@link Apache_Solr_Service::NAMED_LIST_MAP} (default) or {@link Apache_Solr_Service::NAMED_LIST_FLAT}. + * + * @var string + */ + protected $_namedListTreatment = self::NAMED_LIST_MAP; + + /** + * Query delimiters. Someone might want to be able to change + * these (to use & instead of & for example), so I've provided them. + * + * @var string + */ + protected $_queryDelimiter = '?', $_queryStringDelimiter = '&', $_queryBracketsEscaped = true; + + /** + * Constructed servlet full path URLs + * + * @var string + */ + protected $_pingUrl, $_updateUrl, $_searchUrl, $_threadsUrl; + + /** + * Keep track of whether our URLs have been constructed + * + * @var boolean + */ + protected $_urlsInited = false; + + /** + * HTTP Transport implementation (pluggable) + * + * @var Apache_Solr_HttpTransport_Interface + */ + protected $_httpTransport = false; + + /** + * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc. + * + * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead + * + * @param string $value + * @return string + */ + static public function escape($value) + { + //list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters + $pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/'; + $replace = '\\\$1'; + + return preg_replace($pattern, $replace, $value); + } + + /** + * Escape a value meant to be contained in a phrase for special query characters + * + * @param string $value + * @return string + */ + static public function escapePhrase($value) + { + $pattern = '/("|\\\)/'; + $replace = '\\\$1'; + + return preg_replace($pattern, $replace, $value); + } + + /** + * Convenience function for creating phrase syntax from a value + * + * @param string $value + * @return string + */ + static public function phrase($value) + { + return '"' . self::escapePhrase($value) . '"'; + } + + /** + * Constructor. All parameters are optional and will take on default values + * if not specified. + * + * @param string $host + * @param string $port + * @param string $path + * @param Apache_Solr_HttpTransport_Interface $httpTransport + */ + public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $httpTransport = false) + { + $this->setHost($host); + $this->setPort($port); + $this->setPath($path); + + $this->_initUrls(); + + if ($httpTransport) + { + $this->setHttpTransport($httpTransport); + } + + // check that our php version is >= 5.1.3 so we can correct for http_build_query behavior later + $this->_queryBracketsEscaped = version_compare(phpversion(), '5.1.3', '>='); + } + + /** + * Return a valid http URL given this server's host, port and path and a provided servlet name + * + * @param string $servlet + * @return string + */ + protected function _constructUrl($servlet, $params = array()) + { + if (count($params)) + { + //escape all parameters appropriately for inclusion in the query string + $escapedParams = array(); + + foreach ($params as $key => $value) + { + $escapedParams[] = urlencode($key) . '=' . urlencode($value); + } + + $queryString = $this->_queryDelimiter . implode($this->_queryStringDelimiter, $escapedParams); + } + else + { + $queryString = ''; + } + + return 'http://' . $this->_host . ':' . $this->_port . $this->_path . $servlet . $queryString; + } + + /** + * Construct the Full URLs for the three servlets we reference + */ + protected function _initUrls() + { + //Initialize our full servlet URLs now that we have server information + $this->_extractUrl = $this->_constructUrl(self::EXTRACT_SERVLET); + $this->_pingUrl = $this->_constructUrl(self::PING_SERVLET); + $this->_searchUrl = $this->_constructUrl(self::SEARCH_SERVLET); + $this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLET, array('wt' => self::SOLR_WRITER )); + $this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLET, array('wt' => self::SOLR_WRITER )); + + $this->_urlsInited = true; + } + + protected function _generateQueryString($params) + { + // use http_build_query to encode our arguments because its faster + // than urlencoding all the parts ourselves in a loop + // + // because http_build_query treats arrays differently than we want to, correct the query + // string by changing foo[#]=bar (# being an actual number) parameter strings to just + // multiple foo=bar strings. This regex should always work since '=' will be urlencoded + // anywhere else the regex isn't expecting it + // + // NOTE: before php 5.1.3 brackets were not url encoded by http_build query - we've checked + // the php version in the constructor and put the results in the instance variable. Also, before + // 5.1.2 the arg_separator parameter was not available, so don't use it + if ($this->_queryBracketsEscaped) + { + $queryString = http_build_query($params, null, $this->_queryStringDelimiter); + return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString); + } + else + { + $queryString = http_build_query($params); + return preg_replace('/\\[(?:[0-9]|[1-9][0-9]+)\\]=/', '=', $queryString); + } + } + + /** + * Central method for making a get operation against this Solr Server + * + * @param string $url + * @param float $timeout Read timeout in seconds + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned + */ + protected function _sendRawGet($url, $timeout = FALSE) + { + $httpTransport = $this->getHttpTransport(); + + $httpResponse = $httpTransport->performGetRequest($url, $timeout); + $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); + + if ($solrResponse->getHttpStatus() != 200) + { + throw new Apache_Solr_HttpTransportException($solrResponse); + } + + return $solrResponse; + } + + /** + * Central method for making a post operation against this Solr Server + * + * @param string $url + * @param string $rawPost + * @param float $timeout Read timeout in seconds + * @param string $contentType + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned + */ + protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') + { + $httpTransport = $this->getHttpTransport(); + + $httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout); + $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); + + if ($solrResponse->getHttpStatus() != 200) + { + throw new Apache_Solr_HttpTransportException($solrResponse); + } + + return $solrResponse; + } + + /** + * Returns the set host + * + * @return string + */ + public function getHost() + { + return $this->_host; + } + + /** + * Set the host used. If empty will fallback to constants + * + * @param string $host + * + * @throws Apache_Solr_InvalidArgumentException If the host parameter is empty + */ + public function setHost($host) + { + //Use the provided host or use the default + if (empty($host)) + { + throw new Apache_Solr_InvalidArgumentException('Host parameter is empty'); + } + else + { + $this->_host = $host; + } + + if ($this->_urlsInited) + { + $this->_initUrls(); + } + } + + /** + * Get the set port + * + * @return integer + */ + public function getPort() + { + return $this->_port; + } + + /** + * Set the port used. If empty will fallback to constants + * + * @param integer $port + * + * @throws Apache_Solr_InvalidArgumentException If the port parameter is empty + */ + public function setPort($port) + { + //Use the provided port or use the default + $port = (int) $port; + + if ($port <= 0) + { + throw new Apache_Solr_InvalidArgumentException('Port is not a valid port number'); + } + else + { + $this->_port = $port; + } + + if ($this->_urlsInited) + { + $this->_initUrls(); + } + } + + /** + * Get the set path. + * + * @return string + */ + public function getPath() + { + return $this->_path; + } + + /** + * Set the path used. If empty will fallback to constants + * + * @param string $path + */ + public function setPath($path) + { + $path = trim($path, '/'); + + $this->_path = '/' . $path . '/'; + + if ($this->_urlsInited) + { + $this->_initUrls(); + } + } + + /** + * Get the current configured HTTP Transport + * + * @return HttpTransportInterface + */ + public function getHttpTransport() + { + // lazy load a default if one has not be set + if ($this->_httpTransport === false) + { + require_once(dirname(__FILE__) . '/HttpTransport/FileGetContents.php'); + + $this->_httpTransport = new Apache_Solr_HttpTransport_FileGetContents(); + } + + return $this->_httpTransport; + } + + /** + * Set the HTTP Transport implemenation that will be used for all HTTP requests + * + * @param Apache_Solr_HttpTransport_Interface + */ + public function setHttpTransport(Apache_Solr_HttpTransport_Interface $httpTransport) + { + $this->_httpTransport = $httpTransport; + } + + /** + * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will + * parse the response and create {@link Apache_Solr_Document} instances in place. + * + * @param boolean $createDocuments + */ + public function setCreateDocuments($createDocuments) + { + $this->_createDocuments = (bool) $createDocuments; + } + + /** + * Get the current state of teh create documents flag. + * + * @return boolean + */ + public function getCreateDocuments() + { + return $this->_createDocuments; + } + + /** + * Set the collapse single value arrays flag. + * + * @param boolean $collapseSingleValueArrays + */ + public function setCollapseSingleValueArrays($collapseSingleValueArrays) + { + $this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays; + } + + /** + * Get the current state of the collapse single value arrays flag. + * + * @return boolean + */ + public function getCollapseSingleValueArrays() + { + return $this->_collapseSingleValueArrays; + } + + /** + * Get the current default timeout setting (initially the default_socket_timeout ini setting) + * in seconds + * + * @return float + * + * @deprecated Use the getDefaultTimeout method on the HTTP transport implementation + */ + public function getDefaultTimeout() + { + return $this->getHttpTransport()->getDefaultTimeout(); + } + + /** + * Set the default timeout for all calls that aren't passed a specific timeout + * + * @param float $timeout Timeout value in seconds + * + * @deprecated Use the setDefaultTimeout method on the HTTP transport implementation + */ + public function setDefaultTimeout($timeout) + { + $this->getHttpTransport()->setDefaultTimeout($timeout); + } + + /** + * Set how NamedLists should be formatted in the response data. This mainly effects + * the facet counts format. + * + * @param string $namedListTreatment + * @throws Apache_Solr_InvalidArgumentException If invalid option is set + */ + public function setNamedListTreatment($namedListTreatment) + { + switch ((string) $namedListTreatment) + { + case Apache_Solr_Service::NAMED_LIST_FLAT: + $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_FLAT; + break; + + case Apache_Solr_Service::NAMED_LIST_MAP: + $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_MAP; + break; + + default: + throw new Apache_Solr_InvalidArgumentException('Not a valid named list treatement option'); + } + } + + /** + * Get the current setting for named list treatment. + * + * @return string + */ + public function getNamedListTreatment() + { + return $this->_namedListTreatment; + } + + /** + * Set the string used to separate the path form the query string. + * Defaulted to '?' + * + * @param string $queryDelimiter + */ + public function setQueryDelimiter($queryDelimiter) + { + $this->_queryDelimiter = $queryDelimiter; + } + + /** + * Set the string used to separate the parameters in thequery string + * Defaulted to '&' + * + * @param string $queryStringDelimiter + */ + public function setQueryStringDelimiter($queryStringDelimiter) + { + $this->_queryStringDelimiter = $queryStringDelimiter; + } + + /** + * Call the /admin/ping servlet, can be used to quickly tell if a connection to the + * server is able to be made. + * + * @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2) + * @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs + */ + public function ping($timeout = 2) + { + $start = microtime(true); + + $httpTransport = $this->getHttpTransport(); + + $httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout); + $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); + + if ($solrResponse->getHttpStatus() == 200) + { + return microtime(true) - $start; + } + else + { + return false; + } + } + + /** + * Call the /admin/threads servlet and retrieve information about all threads in the + * Solr servlet's thread group. Useful for diagnostics. + * + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function threads() + { + return $this->_sendRawGet($this->_threadsUrl); + } + + /** + * Raw Add Method. Takes a raw post body and sends it to the update service. Post body + * should be a complete and well formed "add" xml document. + * + * @param string $rawPost + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function add($rawPost) + { + return $this->_sendRawPost($this->_updateUrl, $rawPost); + } + + /** + * Add a Solr Document to the index + * + * @param Apache_Solr_Document $document + * @param boolean $allowDups + * @param boolean $overwritePending + * @param boolean $overwriteCommitted + * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details. If left empty this property will not be set in the request. + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0) + { + $dupValue = $allowDups ? 'true' : 'false'; + $pendingValue = $overwritePending ? 'true' : 'false'; + $committedValue = $overwriteCommitted ? 'true' : 'false'; + + $commitWithin = (int) $commitWithin; + $commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : ''; + + $rawPost = ""; + $rawPost .= $this->_documentToXmlFragment($document); + $rawPost .= ''; + + return $this->add($rawPost); + } + + /** + * Add an array of Solr Documents to the index all at once + * + * @param array $documents Should be an array of Apache_Solr_Document instances + * @param boolean $allowDups + * @param boolean $overwritePending + * @param boolean $overwriteCommitted + * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details. If left empty this property will not be set in the request. + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0) + { + $dupValue = $allowDups ? 'true' : 'false'; + $pendingValue = $overwritePending ? 'true' : 'false'; + $committedValue = $overwriteCommitted ? 'true' : 'false'; + + $commitWithin = (int) $commitWithin; + $commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : ''; + + $rawPost = ""; + + foreach ($documents as $document) + { + if ($document instanceof Apache_Solr_Document) + { + $rawPost .= $this->_documentToXmlFragment($document); + } + } + + $rawPost .= ''; + + return $this->add($rawPost); + } + + /** + * Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call + * + * @return string + */ + protected function _documentToXmlFragment(Apache_Solr_Document $document) + { + $xml = 'getBoost() !== false) + { + $xml .= ' boost="' . $document->getBoost() . '"'; + } + + $xml .= '>'; + + foreach ($document as $key => $value) + { + $key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8'); + $fieldBoost = $document->getFieldBoost($key); + + if (is_array($value)) + { + foreach ($value as $multivalue) + { + $xml .= ''; + } + } + else + { + $xml .= ''; + } + } + + $xml .= ''; + + // replace any control characters to avoid Solr XML parser exception + return $this->_stripCtrlChars($xml); + } + + /** + * Replace control (non-printable) characters from string that are invalid to Solr's XML parser with a space. + * + * @param string $string + * @return string + */ + protected function _stripCtrlChars($string) + { + // See: http://w3.org/International/questions/qa-forms-utf-8.html + // Printable utf-8 does not include any of these chars below x7F + return preg_replace('@[\x00-\x08\x0B\x0C\x0E-\x1F]@', ' ', $string); + } + + /** + * Send a commit command. Will be synchronous unless both wait parameters are set to false. + * + * @param boolean $expungeDeletes Defaults to false, merge segments with deletes away + * @param boolean $waitFlush Defaults to true, block until index changes are flushed to disk + * @param boolean $waitSearcher Defaults to true, block until a new searcher is opened and registered as the main query searcher, making the changes visible + * @param float $timeout Maximum expected duration (in seconds) of the commit operation on the server (otherwise, will throw a communication exception). Defaults to 1 hour + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600) + { + $expungeValue = $expungeDeletes ? 'true' : 'false'; + $flushValue = $waitFlush ? 'true' : 'false'; + $searcherValue = $waitSearcher ? 'true' : 'false'; + + $rawPost = ''; + + return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout); + } + + /** + * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be + * a complete and well formed "delete" xml document + * + * @param string $rawPost Expected to be utf-8 encoded xml document + * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function delete($rawPost, $timeout = 3600) + { + return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout); + } + + /** + * Create a delete document based on document ID + * + * @param string $id Expected to be utf-8 encoded + * @param boolean $fromPending + * @param boolean $fromCommitted + * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600) + { + $pendingValue = $fromPending ? 'true' : 'false'; + $committedValue = $fromCommitted ? 'true' : 'false'; + + //escape special xml characters + $id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8'); + + $rawPost = '' . $id . ''; + + return $this->delete($rawPost, $timeout); + } + + /** + * Create and post a delete document based on multiple document IDs. + * + * @param array $ids Expected to be utf-8 encoded strings + * @param boolean $fromPending + * @param boolean $fromCommitted + * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600) + { + $pendingValue = $fromPending ? 'true' : 'false'; + $committedValue = $fromCommitted ? 'true' : 'false'; + + $rawPost = ''; + + foreach ($ids as $id) + { + //escape special xml characters + $id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8'); + + $rawPost .= '' . $id . ''; + } + + $rawPost .= ''; + + return $this->delete($rawPost, $timeout); + } + + /** + * Create a delete document based on a query and submit it + * + * @param string $rawQuery Expected to be utf-8 encoded + * @param boolean $fromPending + * @param boolean $fromCommitted + * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600) + { + $pendingValue = $fromPending ? 'true' : 'false'; + $committedValue = $fromCommitted ? 'true' : 'false'; + + // escape special xml characters + $rawQuery = htmlspecialchars($rawQuery, ENT_NOQUOTES, 'UTF-8'); + + $rawPost = '' . $rawQuery . ''; + + return $this->delete($rawPost, $timeout); + } + + /** + * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how + * to use Solr Cell and what parameters are available. + * + * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." + * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value + * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also + * pass in a document isntance with an "id" field" - the document's value(s) will take precedence). + * + * @param string $file Path to file to extract data from + * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation) + * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params) + * @param string $mimetype optional mimetype specification (for the file being extracted) + * + * @return Apache_Solr_Response + * + * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid. + */ + public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream') + { + // check if $params is an array (allow null for default empty array) + if (!is_null($params)) + { + if (!is_array($params)) + { + throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null"); + } + } + else + { + $params = array(); + } + + // if $file is an http request, defer to extractFromUrl instead + if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://') + { + return $this->extractFromUrl($file, $params, $document, $mimetype); + } + + // read the contents of the file + $contents = @file_get_contents($file); + + if ($contents !== false) + { + // add the resource.name parameter if not specified + if (!isset($params['resource.name'])) + { + $params['resource.name'] = basename($file); + } + + // delegate the rest to extractFromString + return $this->extractFromString($contents, $params, $document, $mimetype); + } + else + { + throw new Apache_Solr_InvalidArgumentException("File '{$file}' is empty or could not be read"); + } + } + + /** + * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how + * to use Solr Cell and what parameters are available. + * + * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." + * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value + * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also + * pass in a document isntance with an "id" field" - the document's value(s) will take precedence). + * + * @param string $data Data that will be passed to Solr Cell + * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation) + * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params) + * @param string $mimetype optional mimetype specification (for the file being extracted) + * + * @return Apache_Solr_Response + * + * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid. + * + * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted. + */ + public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream') + { + // check if $params is an array (allow null for default empty array) + if (!is_null($params)) + { + if (!is_array($params)) + { + throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null"); + } + } + else + { + $params = array(); + } + + // make sure we receive our response in JSON and have proper name list treatment + $params['wt'] = self::SOLR_WRITER; + $params['json.nl'] = $this->_namedListTreatment; + + // check if $document is an Apache_Solr_Document instance + if (!is_null($document) && $document instanceof Apache_Solr_Document) + { + // iterate document, adding literal.* and boost.* fields to $params as appropriate + foreach ($document as $field => $fieldValue) + { + // check if we need to add a boost.* parameters + $fieldBoost = $document->getFieldBoost($field); + + if ($fieldBoost !== false) + { + $params["boost.{$field}"] = $fieldBoost; + } + + // add the literal.* parameter + $params["literal.{$field}"] = $fieldValue; + } + } + + // params will be sent to SOLR in the QUERY STRING + $queryString = $this->_generateQueryString($params); + + // the file contents will be sent to SOLR as the POST BODY - we use application/octect-stream as default mimetype + return $this->_sendRawPost($this->_extractUrl . $this->_queryDelimiter . $queryString, $data, false, $mimetype); + } + + /** + * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how + * to use Solr Cell and what parameters are available. + * + * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." + * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value + * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also + * pass in a document isntance with an "id" field" - the document's value(s) will take precedence). + * + * @param string $url URL + * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation) + * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params) + * @param string $mimetype optional mimetype specification (for the file being extracted) + * + * @return Apache_Solr_Response + * + * @throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid. + */ + public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream') + { + // check if $params is an array (allow null for default empty array) + if (!is_null($params)) + { + if (!is_array($params)) + { + throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null"); + } + } + else + { + $params = array(); + } + + $httpTransport = $this->getHttpTransport(); + + // read the contents of the URL using our configured Http Transport and default timeout + $httpResponse = $httpTransport->performGetRequest($url); + + // check that its a 200 response + if ($httpResponse->getStatusCode() == 200) + { + // add the resource.name parameter if not specified + if (!isset($params['resource.name'])) + { + $params['resource.name'] = $url; + } + + // delegate the rest to extractFromString + return $this->extractFromString($httpResponse->getBody(), $params, $document, $mimetype); + } + else + { + throw new Apache_Solr_InvalidArgumentException("URL '{$url}' returned non 200 response code"); + } + } + + /** + * Send an optimize command. Will be synchronous unless both wait parameters are set + * to false. + * + * @param boolean $waitFlush + * @param boolean $waitSearcher + * @param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600) + { + $flushValue = $waitFlush ? 'true' : 'false'; + $searcherValue = $waitSearcher ? 'true' : 'false'; + + $rawPost = ''; + + return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout); + } + + /** + * Simple Search interface + * + * @param string $query The raw query string + * @param int $offset The starting offset for result documents + * @param int $limit The maximum number of result documents to return + * @param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field) + * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + * @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used + */ + public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET) + { + // ensure params is an array + if (!is_null($params)) + { + if (!is_array($params)) + { + // params was specified but was not an array - invalid + throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null"); + } + } + else + { + $params = array(); + } + + // construct our full parameters + + // common parameters in this interface + $params['wt'] = self::SOLR_WRITER; + $params['json.nl'] = $this->_namedListTreatment; + + $params['q'] = $query; + $params['start'] = $offset; + $params['rows'] = $limit; + + $queryString = $this->_generateQueryString($params); + + if ($method == self::METHOD_GET) + { + return $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString); + } + else if ($method == self::METHOD_POST) + { + return $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded; charset=UTF-8'); + } + else + { + throw new Apache_Solr_InvalidArgumentException("Unsupported method '$method', please use the Apache_Solr_Service::METHOD_* constants"); + } + } +} \ No newline at end of file diff --git a/SolrPhpClient/Apache/Solr/Service/Balancer.php b/SolrPhpClient/Apache/Solr/Service/Balancer.php new file mode 100644 index 00000000..cad57e52 --- /dev/null +++ b/SolrPhpClient/Apache/Solr/Service/Balancer.php @@ -0,0 +1,914 @@ +, Dan Wolfe + */ + +// See Issue #1 (http://code.google.com/p/solr-php-client/issues/detail?id=1) +// Doesn't follow typical include path conventions, but is more convenient for users +require_once(dirname(dirname(__FILE__)) . '/Service.php'); + +require_once(dirname(dirname(__FILE__)) . '/NoServiceAvailableException.php'); + +/** + * Reference Implementation for using multiple Solr services in a distribution. Functionality + * includes: + * routing of read / write operations + * failover (on selection) for multiple read servers + */ +class Apache_Solr_Service_Balancer +{ + /** + * SVN Revision meta data for this class + */ + const SVN_REVISION = '$Revision: 54 $'; + + /** + * SVN ID meta data for this class + */ + const SVN_ID = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $'; + + protected $_createDocuments = true; + + protected $_readableServices = array(); + protected $_writeableServices = array(); + + protected $_currentReadService = null; + protected $_currentWriteService = null; + + protected $_readPingTimeout = 2; + protected $_writePingTimeout = 4; + + // Configuration for server selection backoff intervals + protected $_useBackoff = false; // Set to true to use more resillient write server selection + protected $_backoffLimit = 600; // 10 minute default maximum + protected $_backoffEscalation = 2.0; // Rate at which to increase backoff period + protected $_defaultBackoff = 2.0; // Default backoff interval + + /** + * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc. + * + * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead + * + * @param string $value + * @return string + */ + static public function escape($value) + { + return Apache_Solr_Service::escape($value); + } + + /** + * Escape a value meant to be contained in a phrase for special query characters + * + * @param string $value + * @return string + */ + static public function escapePhrase($value) + { + return Apache_Solr_Service::escapePhrase($value); + } + + /** + * Convenience function for creating phrase syntax from a value + * + * @param string $value + * @return string + */ + static public function phrase($value) + { + return Apache_Solr_Service::phrase($value); + } + + /** + * Constructor. Takes arrays of read and write service instances or descriptions + * + * @param array $readableServices + * @param array $writeableServices + */ + public function __construct($readableServices = array(), $writeableServices = array()) + { + //setup readable services + foreach ($readableServices as $service) + { + $this->addReadService($service); + } + + //setup writeable services + foreach ($writeableServices as $service) + { + $this->addWriteService($service); + } + } + + public function setReadPingTimeout($timeout) + { + $this->_readPingTimeout = $timeout; + } + + public function setWritePingTimeout($timeout) + { + $this->_writePingTimeout = $timeout; + } + + public function setUseBackoff($enable) + { + $this->_useBackoff = $enable; + } + + /** + * Generates a service ID + * + * @param string $host + * @param integer $port + * @param string $path + * @return string + */ + protected function _getServiceId($host, $port, $path) + { + return $host . ':' . $port . $path; + } + + /** + * Adds a service instance or service descriptor (if it is already + * not added) + * + * @param mixed $service + * + * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid + */ + public function addReadService($service) + { + if ($service instanceof Apache_Solr_Service) + { + $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath()); + + $this->_readableServices[$id] = $service; + } + else if (is_array($service)) + { + if (isset($service['host']) && isset($service['port']) && isset($service['path'])) + { + $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']); + + $this->_readableServices[$id] = $service; + } + else + { + throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path'); + } + } + } + + /** + * Removes a service instance or descriptor from the available services + * + * @param mixed $service + * + * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid + */ + public function removeReadService($service) + { + $id = ''; + + if ($service instanceof Apache_Solr_Service) + { + $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath()); + } + else if (is_array($service)) + { + if (isset($service['host']) && isset($service['port']) && isset($service['path'])) + { + $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']); + } + else + { + throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path'); + } + } + else if (is_string($service)) + { + $id = $service; + } + + if ($id && isset($this->_readableServices[$id])) + { + unset($this->_readableServices[$id]); + } + } + + /** + * Adds a service instance or service descriptor (if it is already + * not added) + * + * @param mixed $service + * + * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid + */ + public function addWriteService($service) + { + if ($service instanceof Apache_Solr_Service) + { + $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath()); + + $this->_writeableServices[$id] = $service; + } + else if (is_array($service)) + { + if (isset($service['host']) && isset($service['port']) && isset($service['path'])) + { + $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']); + + $this->_writeableServices[$id] = $service; + } + else + { + throw new Apache_Solr_InvalidArgumentException('A Writeable Service description array does not have all required elements of host, port, and path'); + } + } + } + + /** + * Removes a service instance or descriptor from the available services + * + * @param mixed $service + * + * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid + */ + public function removeWriteService($service) + { + $id = ''; + + if ($service instanceof Apache_Solr_Service) + { + $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath()); + } + else if (is_array($service)) + { + if (isset($service['host']) && isset($service['port']) && isset($service['path'])) + { + $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']); + } + else + { + throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path'); + } + } + else if (is_string($service)) + { + $id = $service; + } + + if ($id && isset($this->_writeableServices[$id])) + { + unset($this->_writeableServices[$id]); + } + } + + /** + * Iterate through available read services and select the first with a ping + * that satisfies configured timeout restrictions (or the default) + * + * @return Apache_Solr_Service + * + * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements + */ + protected function _selectReadService($forceSelect = false) + { + if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect) + { + if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect) + { + // we probably had a communication error, ping the current read service, remove it if it times out + if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false) + { + $this->removeReadService($this->_currentReadService); + } + } + + if (count($this->_readableServices)) + { + // select one of the read services at random + $ids = array_keys($this->_readableServices); + + $id = $ids[rand(0, count($ids) - 1)]; + $service = $this->_readableServices[$id]; + + if (is_array($service)) + { + //convert the array definition to a client object + $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']); + $this->_readableServices[$id] = $service; + } + + $service->setCreateDocuments($this->_createDocuments); + $this->_currentReadService = $id; + } + else + { + throw new Apache_Solr_NoServiceAvailableException('No read services were available'); + } + } + + return $this->_readableServices[$this->_currentReadService]; + } + + /** + * Iterate through available write services and select the first with a ping + * that satisfies configured timeout restrictions (or the default) + * + * @return Apache_Solr_Service + * + * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements + */ + protected function _selectWriteService($forceSelect = false) + { + if($this->_useBackoff) + { + return $this->_selectWriteServiceSafe($forceSelect); + } + + if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect) + { + if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect) + { + // we probably had a communication error, ping the current read service, remove it if it times out + if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === false) + { + $this->removeWriteService($this->_currentWriteService); + } + } + + if (count($this->_writeableServices)) + { + // select one of the read services at random + $ids = array_keys($this->_writeableServices); + + $id = $ids[rand(0, count($ids) - 1)]; + $service = $this->_writeableServices[$id]; + + if (is_array($service)) + { + //convert the array definition to a client object + $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']); + $this->_writeableServices[$id] = $service; + } + + $this->_currentWriteService = $id; + } + else + { + throw new Apache_Solr_NoServiceAvailableException('No write services were available'); + } + } + + return $this->_writeableServices[$this->_currentWriteService]; + } + + /** + * Iterate through available write services and select the first with a ping + * that satisfies configured timeout restrictions (or the default). The + * timeout period will increase until a connection is made or the limit is + * reached. This will allow for increased reliability with heavily loaded + * server(s). + * + * @return Apache_Solr_Service + * + * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements + */ + + protected function _selectWriteServiceSafe($forceSelect = false) + { + if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect) + { + if (count($this->_writeableServices)) + { + $backoff = $this->_defaultBackoff; + + do { + // select one of the read services at random + $ids = array_keys($this->_writeableServices); + + $id = $ids[rand(0, count($ids) - 1)]; + $service = $this->_writeableServices[$id]; + + if (is_array($service)) + { + //convert the array definition to a client object + $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']); + $this->_writeableServices[$id] = $service; + } + + $this->_currentWriteService = $id; + + $backoff *= $this->_backoffEscalation; + + if($backoff > $this->_backoffLimit) + { + throw new Apache_Solr_NoServiceAvailableException('No write services were available. All timeouts exceeded.'); + } + + } while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false); + } + else + { + throw new Apache_Solr_NoServiceAvailableException('No write services were available'); + } + } + + return $this->_writeableServices[$this->_currentWriteService]; + } + + /** + * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will + * parse the response and create {@link Apache_Solr_Document} instances in place. + * + * @param boolean $createDocuments + */ + public function setCreateDocuments($createDocuments) + { + $this->_createDocuments = (bool) $createDocuments; + + // set on current read service + if ($this->_currentReadService) + { + $service = $this->_selectReadService(); + $service->setCreateDocuments($createDocuments); + } + } + + /** + * Get the current state of teh create documents flag. + * + * @return boolean + */ + public function getCreateDocuments() + { + return $this->_createDocuments; + } + + /** + * Raw Add Method. Takes a raw post body and sends it to the update service. Post body + * should be a complete and well formed "add" xml document. + * + * @param string $rawPost + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function add($rawPost) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->add($rawPost); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Add a Solr Document to the index + * + * @param Apache_Solr_Document $document + * @param boolean $allowDups + * @param boolean $overwritePending + * @param boolean $overwriteCommitted + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->addDocument($document, $allowDups, $overwritePending, $overwriteCommitted); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Add an array of Solr Documents to the index all at once + * + * @param array $documents Should be an array of Apache_Solr_Document instances + * @param boolean $allowDups + * @param boolean $overwritePending + * @param boolean $overwriteCommitted + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->addDocuments($documents, $allowDups, $overwritePending, $overwriteCommitted); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Send a commit command. Will be synchronous unless both wait parameters are set + * to false. + * + * @param boolean $waitFlush + * @param boolean $waitSearcher + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->commit($optimize, $waitFlush, $waitSearcher, $timeout); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be + * a complete and well formed "delete" xml document + * + * @param string $rawPost + * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function delete($rawPost, $timeout = 3600) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->delete($rawPost, $timeout); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Create a delete document based on document ID + * + * @param string $id + * @param boolean $fromPending + * @param boolean $fromCommitted + * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->deleteById($id, $fromPending, $fromCommitted, $timeout); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Create and post a delete document based on multiple document IDs. + * + * @param array $ids Expected to be utf-8 encoded strings + * @param boolean $fromPending + * @param boolean $fromCommitted + * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->deleteByMultipleId($ids, $fromPending, $fromCommitted, $timeout); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Create a delete document based on a query and submit it + * + * @param string $rawQuery + * @param boolean $fromPending + * @param boolean $fromCommitted + * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->deleteByQuery($rawQuery, $fromPending, $fromCommitted, $timeout); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how + * to use Solr Cell and what parameters are available. + * + * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." + * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value + * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also + * pass in a document isntance with an "id" field" - the document's value(s) will take precedence). + * + * @param string $file Path to file to extract data from + * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation) + * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params) + * @param string $mimetype optional mimetype specification (for the file being extracted) + * + * @return Apache_Solr_Response + * + * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid. + */ + public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream') + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->extract($file, $params, $document, $mimetype); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how + * to use Solr Cell and what parameters are available. + * + * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." + * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value + * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also + * pass in a document isntance with an "id" field" - the document's value(s) will take precedence). + * + * @param string $data Data that will be passed to Solr Cell + * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation) + * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params) + * @param string $mimetype optional mimetype specification (for the file being extracted) + * + * @return Apache_Solr_Response + * + * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid. + * + * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted. + */ + public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream') + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->extractFromString($data, $params, $document, $mimetype); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Send an optimize command. Will be synchronous unless both wait parameters are set + * to false. + * + * @param boolean $waitFlush + * @param boolean $waitSearcher + * @param float $timeout Maximum expected duration of the optimize operation on the server (otherwise, will throw a communication exception) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->optimize($waitFlush, $waitSearcher, $timeout); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Simple Search interface + * + * @param string $query The raw query string + * @param int $offset The starting offset for result documents + * @param int $limit The maximum number of result documents to return + * @param array $params key / value pairs for query parameters, use arrays for multivalued parameters + * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST) + * @return Apache_Solr_Response + * + * @throws Apache_Solr_HttpTransportException If an error occurs during the service call + */ + public function search($query, $offset = 0, $limit = 10, $params = array(), $method = Apache_Solr_Service::METHOD_GET) + { + $service = $this->_selectReadService(); + + do + { + try + { + return $service->search($query, $offset, $limit, $params, $method); + } + catch (Apache_Solr_HttpTransportException $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectReadService(true); + } while ($service); + + return false; + } +} diff --git a/SolrPhpClient/COPYING b/SolrPhpClient/COPYING new file mode 100644 index 00000000..01522fb1 --- /dev/null +++ b/SolrPhpClient/COPYING @@ -0,0 +1,26 @@ +Copyright (c) 2007-2011, Servigistics, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/SolrPhpClient/ChangeLog b/SolrPhpClient/ChangeLog new file mode 100644 index 00000000..030e40d5 --- /dev/null +++ b/SolrPhpClient/ChangeLog @@ -0,0 +1,342 @@ +2011-02-08 20:38 donovan.jimenez + + * Apache/Solr/Service.php, tests/Apache/Solr/ServiceTest.php: See + issue #59 - Adding service extractFromUrl method. This will use + the configured HTTP transport to request the resource. extract + has been modified to detect a file path that starts with http / + https and to defer to extractFromUrl instead. Also, moved + checking for params parameter to the top of method bodies so we + can fail earlier rather than after we've gotten a file / url's + content. + +2011-02-08 19:28 donovan.jimenez + + * Apache/Solr/Service.php, tests/Apache/Solr/ServiceTest.php: See + issue #43 - Changing optimize parameter of service's commit + method to its correct name: expungeDeletes. Also harded php unit + tests around commit. + + thanks to Liam O'Boyle and Olivier Ricordeau for patches for this + commit and the previous one for issue #51 + +2011-02-08 19:11 donovan.jimenez + + * Apache/Solr/Service.php, tests/Apache/Solr/ServiceTest.php: See + issue #51 - adding commitWithin parameter to addDocument and + addDocuments. Also hardened php unit tests for this functions + +2011-02-04 16:29 donovan.jimenez + + * Apache/Solr/Document.php, Apache/Solr/Exception.php, + Apache/Solr/HttpTransport/Abstract.php, + Apache/Solr/HttpTransport/Curl.php, + Apache/Solr/HttpTransport/CurlNoReuse.php, + Apache/Solr/HttpTransport/FileGetContents.php, + Apache/Solr/HttpTransport/Interface.php, + Apache/Solr/HttpTransport/Response.php, + Apache/Solr/HttpTransportException.php, + Apache/Solr/InvalidArgumentException.php, + Apache/Solr/NoServiceAvailableException.php, + Apache/Solr/ParserException.php, Apache/Solr/Response.php, + Apache/Solr/Service.php, Apache/Solr/Service/Balancer.php, + COPYING, tests/Apache/Solr/DocumentTest.php, + tests/Apache/Solr/HttpTransport/AbstractTest.php, + tests/Apache/Solr/HttpTransport/CurlNoReuseTest.php, + tests/Apache/Solr/HttpTransport/CurlTest.php, + tests/Apache/Solr/HttpTransport/FileGetContentsTest.php, + tests/Apache/Solr/HttpTransport/ResponseTest.php, + tests/Apache/Solr/HttpTransportExceptionTest.php, + tests/Apache/Solr/ResponseTest.php, + tests/Apache/Solr/Service/BalancerTest.php, + tests/Apache/Solr/ServiceAbstractTest.php, + tests/Apache/Solr/ServiceTest.php: Updating licence and copyright + texts in sources to reflect transition from Conduit IT to + Servigistics + +2010-11-02 20:16 donovan.jimenez + + * Apache/Solr/Service.php, Apache/Solr/Service/Balancer.php, + tests/Apache/Solr/ServiceAbstractTest.php, + tests/Apache/Solr/ServiceTest.php: See issue #55 + * Adding an Apache_Solr_Service::extractFromString method + * Adding Apache_Solr_Service_Balancer::extract and + Apache_Solr_Service_Balancer::extractFromString methods + +2010-10-21 15:23 donovan.jimenez + + * ., Apache/Solr/HttpTransport, + Apache/Solr/HttpTransport/Abstract.php, + Apache/Solr/HttpTransport/Curl.php, + Apache/Solr/HttpTransport/CurlNoReuse.php, + Apache/Solr/HttpTransport/FileGetContents.php, + Apache/Solr/HttpTransport/Interface.php, + Apache/Solr/HttpTransport/Response.php, Apache/Solr/Response.php, + Apache/Solr/Service.php, Apache/Solr/Service/Balancer.php, + COPYING, tests/Apache/Solr/DocumentTest.php, + tests/Apache/Solr/HttpTransport, + tests/Apache/Solr/HttpTransport/AbstractTest.php, + tests/Apache/Solr/HttpTransport/CurlNoReuseTest.php, + tests/Apache/Solr/HttpTransport/CurlTest.php, + tests/Apache/Solr/HttpTransport/FileGetContentsTest.php, + tests/Apache/Solr/HttpTransport/ResponseTest.php, + tests/Apache/Solr/HttpTransportExceptionTest.php, + tests/Apache/Solr/ResponseTest.php, + tests/Apache/Solr/Service/BalancerTest.php, + tests/Apache/Solr/Service/TestAll.php, + tests/Apache/Solr/ServiceAbstractTest.php, + tests/Apache/Solr/ServiceTest.php, tests/Apache/Solr/TestAll.php, + tests/phpunit.bootstrap.inc, tests/phpunit.xml, tests/run.php: + Merging the http_requests branch into trunk + + See issue #49 - Service can now have the way it makes HTTP + requests plugged in. + The only requirement is that the plugin implement the new + Apache_Solr_HttpTransport_Interface. There are initial + implementations for using + file_get_contents (what was used previously) and for using the + curl module. Much + thanks to Timo Schmidt for submitting an initial patch. + + If the user does not specifically provide a transport interface + instance, the + file get contents implementation will be used by default. + + There is a compatibility breaking change on the + Apache_Solr_Response + constructor. The Signature has changed. + + The getDefaultTimeout and setDefaultTimeout methods on the + Apache_Solr_Service + class are now deprecated. They simple pass through to the active + transport's + methods of the same name, and I'd rather the user manage it + there. + + Additionally, I have cleaned up and expanded the existing unit + tests - had to + change tests related to the breaking change, and added new ones + for the new + classes as well as expanding existing ones. They should now all + pass. curl tests + should only run if the curl module is enabled. file get contents + tests should + only run if allow_url_fopen is enabled. transport tests do rely + on an internet + connection at this time. + +2010-09-07 14:44 donovan.jimenez + + * Apache/Solr/Document.php: See issue #48, doing an isset check as + part of the magic get. Return null if not. + +2010-09-07 14:34 donovan.jimenez + + * Apache/Solr/Service.php: See issue #47, adding missing argument + to getFieldBoost call in Apache_Solr_Service::extract method + +2010-07-08 22:35 donovan.jimenez + + * Apache/Solr/Service.php: See issue #37 - adding a getter / + setting for the default timeout value. Still initially populated + with the default_socket_timeout ini setting + +2010-07-08 22:21 donovan.jimenez + + * Apache/Solr/Service.php: See issue #42 - Adding missing require + once for ParserException + +2010-04-24 00:44 donovan.jimenez + + * Apache/Solr/HttpTransportException.php, Apache/Solr/Service.php: + See issue #38 - Adding support for Solr Cell (tika) extraction + handler. Thanks to Liam O'Boyle for original patch. + +2010-03-22 23:10 donovan.jimenez + + * Apache/Solr/Service.php: See Issue #39 - send charset for POST + form encoded data so that the servlet container for solr will + interpret data correctly (will usually default to latin1) + +2010-03-22 23:06 donovan.jimenez + + * Apache/Solr/Service.php: Resolving Issue #40 - when using php + with all error output or using a code analyzer, the + http_response_header variable looks as though it won't be + initialized before being used. Initializing it to null to + alleviate the emitted warning. + +2010-03-10 00:28 donovan.jimenez + + * tests, tests/Apache, tests/Apache/Solr, + tests/Apache/Solr/DocumentTest.php, + tests/Apache/Solr/ResponseTest.php, tests/Apache/Solr/Service, + tests/Apache/Solr/Service/BalancerTest.php, + tests/Apache/Solr/Service/TestAll.php, + tests/Apache/Solr/ServiceTest.php, tests/Apache/Solr/TestAll.php, + tests/README, tests/phpunit.bootstrap.inc, tests/phpunit.xml, + tests/run.php: Adding some very dusty unit tests. They are not + complete, and some recent API changes may not be reflected in + them, but they are a start. + +2010-02-20 00:01 donovan.jimenez + + * Apache/Solr/Service/Balancer.php: See Issue #34 - synchronizing + Apache_Solr_Service_Balancer public methods with changes in + Apache_Solr_Service. Specifically, adding some missing optional + timeout parameters and adding the new deleteByMultipleIds method + +2010-02-19 23:47 donovan.jimenez + + * Apache/Solr/Response.php: See Issue #35 - implementing __isset + magic method on Apache_Solr_Response + +2010-02-19 23:36 donovan.jimenez + + * Apache/Solr/Document.php, Apache/Solr/Exception.php, + Apache/Solr/HttpTransportException.php, + Apache/Solr/InvalidArgumentException.php, + Apache/Solr/NoServiceAvailableException.php, + Apache/Solr/ParserException.php, Apache/Solr/Response.php, + Apache/Solr/Service.php, Apache/Solr/Service/Balancer.php: See + Issue #36 - fix usage of generic exceptions, thanks to dennis + vierkant for the patch. + +2009-12-10 03:51 donovan.jimenez + + * Apache/Solr/Service.php: Fixes issue #28 - Fixes typo in + setNamedListTreatment function name. Thanks to alex dunae + +2009-12-10 03:49 donovan.jimenez + + * Apache/Solr/Response.php: Fixes issue #27 - when parsing the JSON + data, add a check for null so we can throw an exception if the + response seems to be invalid. Thanks to thomas rabaix for the + suggestion. + +2009-11-21 02:07 donovan.jimenez + + * Apache/Solr/Service.php: see issue #23 - removing unused (by Sorl + JSON writer) and incorrect (version did not track with Solr + version) version parameter from all requests + +2009-11-21 02:02 donovan.jimenez + + * Apache/Solr/Service.php: Fixes #26 - Do a php version check + against 5.1.3 to determine whether brackets will be url encoded + by http_build_query function. Depending on the result of the + version check use the proper regex for fixing up the query string + before passing it to Solr + +2009-11-09 22:46 donovan.jimenez + + * Apache/Solr/Service.php: Fixes #20 - in previous fix, used + stream_context_set_params when I should have used + stream_context_set_option + +2009-11-09 22:08 donovan.jimenez + + * Apache/Solr/Service.php: Fixes #20 - Reusing a get and post + context for each request instead of creating a new stream context + for each. PHP does not provide a function to delete created + stream contexts and does not appear to clean them up when they go + out of scope, which leads to high memory usage when many solr + requests were issued (typically in indexing usage) + +2009-11-09 21:32 donovan.jimenez + + * Apache/Solr/Service.php: Fixes #21 - Adding method to delete by + multiple IDs. Thanks to pwolanin + +2009-08-12 14:08 donovan.jimenez + + * Apache/Solr/Response.php: The split function is deprecated as of + PHP 5.3. Furthermore, since none of my split's were using a regex + it is better to use explode anyway. Fixes #19 + +2009-08-04 18:23 donovan.jimenez + + * Apache/Solr/Response.php, Apache/Solr/Service.php: Removed todo's + about investigating Serialized PHP and PHP output writer usage. + I've made the decision to stick to usage of JSON output writer + until it can be proven that the other output writers are more + stable or provide a substantially faster implementation. Closes + issue #6 + +2009-08-04 17:53 donovan.jimenez + + * Apache/Solr/Document.php, Apache/Solr/Response.php, + Apache/Solr/Service.php, Apache/Solr/Service/Balancer.php: Adding + useful SVN metadata constants to each Apache_Solr class by svn + keyword substitution. Fixes issue #16 + +2009-08-04 17:14 donovan.jimenez + + * Apache/Solr/Service.php: Fixes issue #5 - Applying patch (with + minor changes) from mkalkbrenner to replace all control + characters in Apache_Solr_Document keys / values with spaces to + avoid an exception from Solr's XML Parser. + +2009-07-20 14:14 donovan.jimenez + + * Apache/Solr/Service.php: See issue #14 + * adding timeout parameters to all delete functions + +2009-05-11 14:51 donovan.jimenez + + * Apache/Solr/Service.php: See issue #8 + * Adding the ability to specify the HTTP method used for sending + a search query (GET or POST) + +2009-03-12 03:46 donovan.jimenez + + * Apache/Solr/Service.php: See + http://code.google.com/p/solr-php-client/issues/detail?id=4 + * Reworking Service::ping() to just use file_get_contents URL + wrappers like we do for other GET's and POST operations + * Reworked Service::_sendRawGet() and Service::_sendRawPost() to + create a new stream context each time. Used for controlled + request timeouts, headers, and POST information + +2009-01-29 00:49 donovan.jimenez + + * Apache/Solr/Document.php: See + http://code.google.com/p/solr-php-client/issues/detail?id=2 + + Attempting to fix null vs. false boost parameter value issue by + always casting to float value first. + + Needs tested. + +2009-01-28 17:11 donovan.jimenez + + * Apache/Solr/Service.php, Apache/Solr/Service/Balancer.php: See + http://code.google.com/p/solr-php-client/issues/detail?id=1 + + Changed require_once statements that expected the Solr Client + library to be on the include path into statements that use the + __FILE__ magic constant to do them as absolute paths. This should + get rid of the requirement for the user to change their include + path configuration or add the library to the include path at + runtime. + + Provided as a convenience for the user. + + +2009-01-22 04:01 donovan.jimenez + + * Apache/Solr/Document.php, Apache/Solr/Response.php, + Apache/Solr/Service.php, Apache/Solr/Service/Balancer.php, + COPYING: Updating license to New BSD for google code hosting. + Also updating copyright message + +2009-01-21 23:50 donovan.jimenez + + * Apache, Apache/Solr, Apache/Solr/Document.php, + Apache/Solr/Response.php, Apache/Solr/Service, + Apache/Solr/Service.php, Apache/Solr/Service/Balancer.php: + Importing Solr PHP client from last released zip file + +2008-11-26 00:26 + + * .: Initial directory structure. + diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Document.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Document.html new file mode 100644 index 00000000..dd3ec0b3 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Document.html @@ -0,0 +1,901 @@ + + + + + + Docs For Class Apache_Solr_Document + + + + +
+

Class Apache_Solr_Document

+ + +
+
Description
+ +
+

+ Implements interfaces: +

    +
  • IteratorAggregate (internal interface)
+

+ +

Holds Key / Value pairs that represent a Solr Document along with any associated boost values. Field values can be accessed by direct dereferencing such as:

+

$document->title = 'Something'; echo $document->title; ... </code>

Additionally, the field values can be iterated with foreach

  1.  foreach ($document as $fieldName => $fieldValue)
  2. +
  3.  {
  4. +
  5.  ...
  6. +
  7.  }
  8. +

+

+ Located in /Document.php (line 58) +

+ + +

+	
+			
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id: Document.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + +
+
+  + SVN_REVISION = '$Revision: 54 $' + +
+
+
+
+ + +
+
Variable Summary
+ +
+
+
+ float + $_documentBoost +
+
+ array + $_fieldBoosts +
+
+ array + $_fields +
+
+
+
+ + +
+
Method Summary
+ +
+
+ +
+ void + addField + (string $key, mixed $value, [mixed $boost = false]) +
+ +
+ void + clear + () +
+ +
+ mixed + getBoost + () +
+ +
+ mixed + getField + (string $key) +
+ +
+ float + getFieldBoost + (string $key) +
+ +
+ array + getFieldBoosts + () +
+ +
+ array + getFieldNames + () +
+ +
+ array + getFieldValues + () +
+ +
+ void + getIterator + () +
+ +
+ void + setBoost + (mixed $boost) +
+ +
+ void + setField + (string $key, mixed $value, [mixed $boost = false]) +
+ +
+ void + setFieldBoost + (string $key, mixed $boost) +
+ +
+ void + setMultiValue + (string $key, string $value, [mixed $boost = false]) +
+ +
+ mixed + __get + (string $key) +
+ +
+ boolean + __isset + (string $key) +
+ +
+ void + __set + (string $key, mixed $value) +
+ +
+ void + __unset + (string $key) +
+
+
+
+ + +
+
Variables
+ +
+ + +
+ +
+ + float + $_documentBoost + = false (line 75) + +
+ + +

Document boost value

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + array + $_fieldBoosts + = array() (line 89) + +
+ + +

Document field boost values, indexed by name

+
    +
  • var: array of floats
  • +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + array + $_fields + = array() (line 82) + +
+ + +

Document field values, indexed by name

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+
+ + +
+
Methods
+ +
+ + +
+ +
+ addField (line 154) +
+ + +

Add a value to a multi-valued field

+

NOTE: the solr XML format allows you to specify boosts PER value even though the underlying Lucene implementation only allows a boost per field. To remedy this, the final field boost value will be the product of all specified boosts on field values - this is similar to SolrJ's functionality.

  1.  $doc new Apache_Solr_Document();
  2. +
  3.  
  4. +
  5.  $doc->addField('foo''bar'2.0);
  6. +
  7.  $doc->addField('foo''baz'3.0);
  8. +
  9.  
  10. +
  11.  // resultant field boost will be 6!
  12. +
  13.  echo $doc->getFieldBoost('foo');
  14. +

+
    +
  • access: public
  • +
+ +
+ void + + addField + + (string $key, mixed $value, [mixed $boost = false]) +
+ +
    +
  • + string + $key
  • +
  • + mixed + $value
  • +
  • + mixed + $boost: Use false for default boost, else cast to float that should be > 0 or will be treated as false
  • +
+ + +
+ +
+ +
+ clear (line 94) +
+ + +

Clear all boosts and fields from this document

+
    +
  • access: public
  • +
+ +
+ void + + clear + + () +
+ + + +
+ +
+ +
+ getBoost (line 107) +
+ + +

Get current document boost

+
    +
  • return: will be false for default, or else a float
  • +
  • access: public
  • +
+ +
+ mixed + + getBoost + + () +
+ + + +
+ +
+ +
+ getField (line 202) +
+ + +

Get field information

+
    +
  • return: associative array of info if field exists, false otherwise
  • +
  • access: public
  • +
+ +
+ mixed + + getField + + (string $key) +
+ +
    +
  • + string + $key
  • +
+ + +
+ +
+ +
+ getFieldBoost (line 237) +
+ + +

Get the currently set field boost for a document field

+
    +
  • return: currently set field boost, false if one is not set
  • +
  • access: public
  • +
+ +
+ float + + getFieldBoost + + (string $key) +
+ +
    +
  • + string + $key
  • +
+ + +
+ +
+ +
+ getFieldBoosts (line 267) +
+ + +

Return current field boosts, indexed by field name

+
    +
  • access: public
  • +
+ +
+ array + + getFieldBoosts + + () +
+ + + +
+ +
+ +
+ getFieldNames (line 277) +
+ + +

Get the names of all fields in this document

+
    +
  • access: public
  • +
+ +
+ array + + getFieldNames + + () +
+ + + +
+ +
+ +
+ getFieldValues (line 287) +
+ + +

Get the values of all fields in this document

+
    +
  • access: public
  • +
+ +
+ array + + getFieldValues + + () +
+ + + +
+ +
+ +
+ getIterator (line 302) +
+ + +

IteratorAggregate implementation function. Allows usage:

+

  1.  foreach ($document as $key => $value)
  2. +
  3.  {
  4. +
  5.      ...
  6. +
  7.  }
  8. +

+
    +
  • access: public
  • +
+ +
+ void + + getIterator + + () +
+ + +
+
Implementation of:
+
+
IteratorAggregate::getIterator
+
+ +
+ +
+ +
+ setBoost (line 117) +
+ + +

Set document boost factor

+
    +
  • access: public
  • +
+ +
+ void + + setBoost + + (mixed $boost) +
+ +
    +
  • + mixed + $boost: Use false for default boost, else cast to float that should be > 0 or will be treated as false
  • +
+ + +
+ +
+ +
+ setField (line 225) +
+ + +

Set a field value. Multi-valued fields should be set as arrays or instead use the addField(...) function which will automatically make sure the field is an array.

+
    +
  • access: public
  • +
+ +
+ void + + setField + + (string $key, mixed $value, [mixed $boost = false]) +
+ +
    +
  • + string + $key
  • +
  • + mixed + $value
  • +
  • + mixed + $boost: Use false for default boost, else cast to float that should be > 0 or will be treated as false
  • +
+ + +
+ +
+ +
+ setFieldBoost (line 248) +
+ + +

Set the field boost for a document field

+
    +
  • access: public
  • +
+ +
+ void + + setFieldBoost + + (string $key, mixed $boost) +
+ +
    +
  • + string + $key: field name for the boost
  • +
  • + mixed + $boost: Use false for default boost, else cast to float that should be > 0 or will be treated as false
  • +
+ + +
+ +
+ +
+ setMultiValue (line 191) +
+ + +

Handle the array manipulation for a multi-valued field

+
    +
  • deprecated: Use addField(...) instead
  • +
  • access: public
  • +
+ +
+ void + + setMultiValue + + (string $key, string $value, [mixed $boost = false]) +
+ +
    +
  • + string + $key
  • +
  • + string + $value
  • +
  • + mixed + $boost: Use false for default boost, else cast to float that should be > 0 or will be treated as false
  • +
+ + +
+ +
+ +
+ __get (line 315) +
+ + +

Magic get for field values

+
    +
  • access: public
  • +
+ +
+ mixed + + __get + + (string $key) +
+ +
    +
  • + string + $key
  • +
+ + +
+ +
+ +
+ __isset (line 348) +
+ + +

Magic isset for fields values. Do not call directly. Allows usage:

+

  1.  isset($document->some_field);
  2. +

+
    +
  • access: public
  • +
+ +
+ boolean + + __isset + + (string $key) +
+ +
    +
  • + string + $key
  • +
+ + +
+ +
+ +
+ __set (line 333) +
+ + +

Magic set for field values. Multi-valued fields should be set as arrays or instead use the addField(...) function which will automatically make sure the field is an array.

+
    +
  • access: public
  • +
+ +
+ void + + __set + + (string $key, mixed $value) +
+ +
    +
  • + string + $key
  • +
  • + mixed + $value
  • +
+ + +
+ +
+ +
+ __unset (line 362) +
+ + +

Magic unset for field values. Do not call directly. Allows usage:

+

  1.  unset($document->some_field);
  2. +

+
    +
  • access: public
  • +
+ +
+ void + + __unset + + (string $key) +
+ +
    +
  • + string + $key
  • +
+ + +
+ +
+
+ + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id: Document.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + (line 68) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: 54 $' + (line 63) + +
+ + +

SVN Revision meta data for this class

+ + +
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:13 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Exception.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Exception.html new file mode 100644 index 00000000..1ff8e678 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Exception.html @@ -0,0 +1,269 @@ + + + + + + Docs For Class Apache_Solr_Exception + + + + +
+

Class Apache_Solr_Exception

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+
    +
  • author: Donovan Jimenez <djimenez@conduit-it.com>
  • +
  • version: $Id: Exception.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  • +
  • copyright: Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  • +
  • license: New BSD
  • +
+

+ Located in /Exception.php (line 39) +

+ + +
Exception
+   |
+   --Apache_Solr_Exception
+ +
+
+ + +
+
Direct descendents
+ +
+ + + + + + + + + + + + + + + + + + + + + +
ClassDescription
Apache_Solr_HttpTransportException + Copyright (c) 2007-2011, Servigistics, Inc. +
Apache_Solr_ParserException + Copyright (c) 2007-2011, Servigistics, Inc. +
Apache_Solr_NoServiceAvailableException + Copyright (c) 2007-2011, Servigistics, Inc. +
Apache_Solr_InvalidArgumentException + Copyright (c) 2007-2011, Servigistics, Inc. +
+
+
+ + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id: Exception.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + +
+
+  + SVN_REVISION = '$Revision: 54 $' + +
+
+
+
+ + + + +
+
Variables
+ +
+ +

Inherited Variables

+ +

Inherited from Exception (Internal Class)

+
+ + $code
+
+ + $file
+
+ + $line
+
+ + $message
+
+ + $previous
+
+ + $string
+
+ + $trace
+
+
+ +
+
+ + +
+
Methods
+ +
+ +

Inherited Methods

+ + +

Inherited From Exception (Internal Class)

+
+ constructor __construct ( [$message = ], [$code = ], [$previous = ] )
+ getCode ( )
+ getFile ( )
+ getLine ( )
+ getMessage ( )
+ getPrevious ( )
+ getTrace ( )
+ getTraceAsString ( )
+ __clone ( )
+ __toString ( )
+
+ +
+
+ + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id: Exception.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + (line 49) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: 54 $' + (line 44) + +
+ + +

SVN Revision meta data for this class

+ + +
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:13 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransportException.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransportException.html new file mode 100644 index 00000000..d154edf8 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransportException.html @@ -0,0 +1,246 @@ + + + + + + Docs For Class Apache_Solr_HttpTransportException + + + + +
+

Class Apache_Solr_HttpTransportException

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+
    +
  • author: Donovan Jimenez <djimenez@conduit-it.com>
  • +
  • version: $Id: HttpTransportException.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  • +
  • copyright: Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  • +
  • license: New BSD
  • +
+

+ Located in /HttpTransportException.php (line 39) +

+ + +
Exception
+   |
+   --Apache_Solr_Exception
+      |
+      --Apache_Solr_HttpTransportException
+ +
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id: HttpTransportException.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + +
+
+  + SVN_REVISION = '$Revision: 54 $' + +
+
+
+
+ + + +
+
Method Summary
+ +
+
+ +
+ Apache_Solr_HttpTransportException + __construct + (Apache_Solr_Response $response) +
+ + +
+
+
+ + + +
+
Methods
+ +
+ + +
+ +
+ Constructor __construct (line 63) +
+ + +

HttpTransportException Constructor

+
    +
  • access: public
  • +
+ +
+ Apache_Solr_HttpTransportException + + __construct + + (Apache_Solr_Response $response) +
+ + + + +
+ +
+ +
+ getResponse (line 75) +
+ + +

Get the response for which this exception was generated

+
    +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + getResponse + + () +
+ + + +
+ +
+
+ + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id: HttpTransportException.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + (line 49) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: 54 $' + (line 44) + +
+ + +

SVN Revision meta data for this class

+ + +
+

Inherited Constants

+ +

Inherited from Apache_Solr_Exception

+
+ + + Apache_Solr_Exception::SVN_ID
+
+ + + Apache_Solr_Exception::SVN_REVISION
+
+
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:14 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Abstract.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Abstract.html new file mode 100644 index 00000000..b9f39cd0 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Abstract.html @@ -0,0 +1,196 @@ + + + + + + Docs For Class Apache_Solr_HttpTransport_Abstract + + + + +
+

Class Apache_Solr_HttpTransport_Abstract

+ + +
+
Description
+ +
+

+ Implements interfaces: +

+

+ +

Convenience class that implements the transport implementation. Can be extended by

+

real implementations to do some of the common book keeping

+
    +
  • abstract:
  • +
+

+ Located in /HttpTransport/Abstract.php (line 43) +

+ + +

+	
+			
+
+ + +
+
Direct descendents
+ +
+ + + + + + + + + + + + + + + + + +
ClassDescription
Apache_Solr_HttpTransport_FileGetContents + HTTP Transport implemenation that uses the builtin http URL wrappers and file_get_contents +
Apache_Solr_HttpTransport_Curl + A Curl based HTTP transport. Uses a single curl session for all requests. +
Apache_Solr_HttpTransport_CurlNoReuse + An alternative Curl HTTP transport that opens and closes a curl session for every request. This isn't the recommended way to use curl, but some version of PHP have memory issues. +
+
+
+ + + + +
+
Method Summary
+ +
+
+ +
+ float + getDefaultTimeout + () +
+ +
+ void + setDefaultTimeout + (float $timeout) +
+
+
+
+ + + +
+
Methods
+ +
+ + +
+ +
+ getDefaultTimeout (line 58) +
+ + +

Get the current default timeout setting (initially the default_socket_timeout ini setting) in seconds

+
    +
  • access: public
  • +
+ +
+ float + + getDefaultTimeout + + () +
+ + +
+
Implementation of:
+
+
Apache_Solr_HttpTransport_Interface::getDefaultTimeout()
+
Get the current default timeout for all HTTP requests
+
+ +
+ +
+ +
+ setDefaultTimeout (line 80) +
+ + +

Set the current default timeout for all HTTP requests

+
    +
  • access: public
  • +
+ +
+ void + + setDefaultTimeout + + (float $timeout) +
+ +
    +
  • + float + $timeout
  • +
+ +
+
Implementation of:
+
+
Apache_Solr_HttpTransport_Interface::setDefaultTimeout()
+
Set the current default timeout for all HTTP requests
+
+ +
+ +
+
+ + +

+ Documentation generated on Wed, 04 May 2011 11:01:08 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Curl.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Curl.html new file mode 100644 index 00000000..e21f6048 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Curl.html @@ -0,0 +1,336 @@ + + + + + + Docs For Class Apache_Solr_HttpTransport_Curl + + + + +
+

Class Apache_Solr_HttpTransport_Curl

+ + +
+
Description
+ +
+ +

A Curl based HTTP transport. Uses a single curl session for all requests.

+

+ Located in /HttpTransport/Curl.php (line 45) +

+ + +
Apache_Solr_HttpTransport_Abstract
+   |
+   --Apache_Solr_HttpTransport_Curl
+ +
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id:$' + +
+
+  + SVN_REVISION = '$Revision:$' + +
+
+
+
+ + + +
+
Method Summary
+ +
+
+ +
+ Apache_Solr_HttpTransport_Curl + __construct + () +
+ +
+ void + __destruct + () +
+ +
+ void + performGetRequest + ( $url, [ $timeout = false]) +
+ +
+ void + performHeadRequest + ( $url, [ $timeout = false]) +
+ +
+ void + performPostRequest + ( $url,  $postData,  $contentType, [ $timeout = false]) +
+
+
+
+ + + +
+
Methods
+ +
+ + +
+ +
+ Constructor __construct (line 67) +
+ + +

Initializes a curl session

+
    +
  • access: public
  • +
+ +
+ Apache_Solr_HttpTransport_Curl + + __construct + + () +
+ + + +
+ +
+ +
+ Destructor __destruct (line 88) +
+ + +

Closes a curl session

+ +
+ void + + __destruct + + () +
+ + + +
+ +
+ +
+ performGetRequest (line 94) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + performGetRequest + + ( $url, [ $timeout = false]) +
+ +
    +
  • + + $url
  • +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ performHeadRequest (line 128) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + performHeadRequest + + ( $url, [ $timeout = false]) +
+ +
    +
  • + + $url
  • +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ performPostRequest (line 159) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + performPostRequest + + ( $url,  $postData,  $contentType, [ $timeout = false]) +
+ +
    +
  • + + $url
  • +
  • + + $postData
  • +
  • + + $contentType
  • +
  • + + $timeout
  • +
+ + +
+

Inherited Methods

+ + +

Inherited From Apache_Solr_HttpTransport_Abstract

+
+ Apache_Solr_HttpTransport_Abstract::getDefaultTimeout()
+ Apache_Solr_HttpTransport_Abstract::setDefaultTimeout()
+
+ +
+
+ + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id:$' + (line 55) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision:$' + (line 50) + +
+ + +

SVN Revision meta data for this class

+ + +
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:12 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_CurlNoReuse.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_CurlNoReuse.html new file mode 100644 index 00000000..9179a0d1 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_CurlNoReuse.html @@ -0,0 +1,279 @@ + + + + + + Docs For Class Apache_Solr_HttpTransport_CurlNoReuse + + + + +
+

Class Apache_Solr_HttpTransport_CurlNoReuse

+ + +
+
Description
+ +
+ +

An alternative Curl HTTP transport that opens and closes a curl session for every request. This isn't the recommended way to use curl, but some version of PHP have memory issues.

+

+ Located in /HttpTransport/CurlNoReuse.php (line 47) +

+ + +
Apache_Solr_HttpTransport_Abstract
+   |
+   --Apache_Solr_HttpTransport_CurlNoReuse
+ +
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id:$' + +
+
+  + SVN_REVISION = '$Revision:$' + +
+
+
+
+ + + +
+
Method Summary
+ +
+
+ +
+ void + performGetRequest + ( $url, [ $timeout = false]) +
+ +
+ void + performHeadRequest + ( $url, [ $timeout = false]) +
+ +
+ void + performPostRequest + ( $url,  $postData,  $contentType, [ $timeout = false]) +
+
+
+
+ + + +
+
Methods
+ +
+ + +
+ +
+ performGetRequest (line 59) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + performGetRequest + + ( $url, [ $timeout = false]) +
+ +
    +
  • + + $url
  • +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ performHeadRequest (line 101) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + performHeadRequest + + ( $url, [ $timeout = false]) +
+ +
    +
  • + + $url
  • +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ performPostRequest (line 146) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + performPostRequest + + ( $url,  $postData,  $contentType, [ $timeout = false]) +
+ +
    +
  • + + $url
  • +
  • + + $postData
  • +
  • + + $contentType
  • +
  • + + $timeout
  • +
+ + +
+

Inherited Methods

+ + +

Inherited From Apache_Solr_HttpTransport_Abstract

+
+ Apache_Solr_HttpTransport_Abstract::getDefaultTimeout()
+ Apache_Solr_HttpTransport_Abstract::setDefaultTimeout()
+
+ +
+
+ + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id:$' + (line 57) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision:$' + (line 52) + +
+ + +

SVN Revision meta data for this class

+ + +
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:13 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_FileGetContents.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_FileGetContents.html new file mode 100644 index 00000000..a43013f6 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_FileGetContents.html @@ -0,0 +1,309 @@ + + + + + + Docs For Class Apache_Solr_HttpTransport_FileGetContents + + + + +
+

Class Apache_Solr_HttpTransport_FileGetContents

+ + +
+
Description
+ +
+ +

HTTP Transport implemenation that uses the builtin http URL wrappers and file_get_contents

+

+ Located in /HttpTransport/FileGetContents.php (line 45) +

+ + +
Apache_Solr_HttpTransport_Abstract
+   |
+   --Apache_Solr_HttpTransport_FileGetContents
+ +
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id: $' + +
+
+  + SVN_REVISION = '$Revision: $' + +
+
+
+
+ + + +
+
Method Summary
+ +
+
+ +
+ Apache_Solr_HttpTransport_FileGetContents + __construct + () +
+ +
+ void + performGetRequest + ( $url, [ $timeout = false]) +
+ +
+ void + performHeadRequest + ( $url, [ $timeout = false]) +
+ +
+ void + performPostRequest + ( $url,  $rawPost,  $contentType, [ $timeout = false]) +
+
+
+
+ + + +
+
Methods
+ +
+ + +
+ +
+ Constructor __construct (line 67) +
+ + +

Initializes our reuseable get and post stream contexts

+
    +
  • access: public
  • +
+ +
+ Apache_Solr_HttpTransport_FileGetContents + + __construct + + () +
+ + + +
+ +
+ +
+ performGetRequest (line 74) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + performGetRequest + + ( $url, [ $timeout = false]) +
+ +
    +
  • + + $url
  • +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ performHeadRequest (line 100) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + performHeadRequest + + ( $url, [ $timeout = false]) +
+ +
    +
  • + + $url
  • +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ performPostRequest (line 132) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + performPostRequest + + ( $url,  $rawPost,  $contentType, [ $timeout = false]) +
+ +
    +
  • + + $url
  • +
  • + + $rawPost
  • +
  • + + $contentType
  • +
  • + + $timeout
  • +
+ + +
+

Inherited Methods

+ + +

Inherited From Apache_Solr_HttpTransport_Abstract

+
+ Apache_Solr_HttpTransport_Abstract::getDefaultTimeout()
+ Apache_Solr_HttpTransport_Abstract::setDefaultTimeout()
+
+ +
+
+ + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id: $' + (line 55) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: $' + (line 50) + +
+ + +

SVN Revision meta data for this class

+ + +
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:14 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Interface.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Interface.html new file mode 100644 index 00000000..c8e50aac --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Interface.html @@ -0,0 +1,260 @@ + + + + + + Docs For Class Apache_Solr_HttpTransport_Interface + + + + +
+

Interface Apache_Solr_HttpTransport_Interface

+ + +
+
Description
+ +
+ +

Interface that all Transport (HTTP Requester) implementations must implement. These

+

Implementations can then be plugged into the Service instance in order to user their the desired method for making HTTP requests

+

+ Located in /HttpTransport/Interface.php (line 47) +

+ + +

+	
+			
+
+ + + + + +
+
Method Summary
+ +
+
+ +
+ float + getDefaultTimeout + () +
+ +
+ Apache_Solr_HttpTransport_Response + performGetRequest + (string $url, [float $timeout = false]) +
+ +
+ Apache_Solr_HttpTransport_Response + performHeadRequest + (string $url, [float $timeout = false]) +
+ +
+ Apache_Solr_HttpTransport_Response + performPostRequest + (string $url, string $rawPost, string $contentType, [float $timeout = false]) +
+ +
+ void + setDefaultTimeout + (float $timeout) +
+
+
+
+ + + +
+
Methods
+ +
+ + +
+ +
+ getDefaultTimeout (line 54) +
+ + +

Get the current default timeout for all HTTP requests

+
    +
  • access: public
  • +
+ +
+ float + + getDefaultTimeout + + () +
+ + + +
+ +
+ +
+ performGetRequest (line 71) +
+ + +

Perform a GET HTTP operation with an optional timeout and return the response contents, use getLastResponseHeaders to retrieve HTTP headers

+
    +
  • return: HTTP response
  • +
  • access: public
  • +
+ +
+ Apache_Solr_HttpTransport_Response + + performGetRequest + + (string $url, [float $timeout = false]) +
+ +
    +
  • + string + $url
  • +
  • + float + $timeout
  • +
+ + +
+ +
+ +
+ performHeadRequest (line 81) +
+ + +

Perform a HEAD HTTP operation with an optional timeout and return the response headers - NOTE: head requests have no response body

+
    +
  • return: HTTP response
  • +
  • access: public
  • +
+ +
+ Apache_Solr_HttpTransport_Response + + performHeadRequest + + (string $url, [float $timeout = false]) +
+ +
    +
  • + string + $url
  • +
  • + float + $timeout
  • +
+ + +
+ +
+ +
+ performPostRequest (line 93) +
+ + +

Perform a POST HTTP operation with an optional timeout and return the response contents, use getLastResponseHeaders to retrieve HTTP headers

+
    +
  • return: HTTP response
  • +
  • access: public
  • +
+ +
+ Apache_Solr_HttpTransport_Response + + performPostRequest + + (string $url, string $rawPost, string $contentType, [float $timeout = false]) +
+ +
    +
  • + string + $url
  • +
  • + string + $rawPost
  • +
  • + string + $contentType
  • +
  • + float + $timeout
  • +
+ + +
+ +
+ +
+ setDefaultTimeout (line 61) +
+ + +

Set the current default timeout for all HTTP requests

+
    +
  • access: public
  • +
+ +
+ void + + setDefaultTimeout + + (float $timeout) +
+ +
    +
  • + float + $timeout
  • +
+ + +
+ +
+
+ + +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Response.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Response.html new file mode 100644 index 00000000..4f0bfd21 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_HttpTransport_Response.html @@ -0,0 +1,298 @@ + + + + + + Docs For Class Apache_Solr_HttpTransport_Response + + + + +
+

Class Apache_Solr_HttpTransport_Response

+ + +
+
Description
+ +
+ +

Represents the required pieces of an HTTP response provided by HTTP transport

+

implementations and then consumed by the Apache_Solr_Response class which provides decoding

+

+ Located in /HttpTransport/Response.php (line 44) +

+ + +

+	
+			
+
+ + + + + +
+
Method Summary
+ +
+
+ +
+ static string + getDefaultStatusMessage + ( $statusCode) +
+ +
+ Apache_Solr_HttpTransport_Response + __construct + (integer $statusCode, string $contentType, string $responseBody) +
+ +
+ string + getBody + () +
+ +
+ string + getEncoding + () +
+ +
+ string + getMimeType + () +
+ +
+ integer + getStatusCode + () +
+ +
+ string + getStatusMessage + () +
+
+
+
+ + + +
+
Methods
+ +
+ + +
+ +
+ static getDefaultStatusMessage (line 112) +
+ + +

Get the HTTP status message based on status code

+
    +
  • access: public
  • +
+ +
+ static string + + getDefaultStatusMessage + + ( $statusCode) +
+ +
    +
  • + + $statusCode
  • +
+ + +
+ +
+ +
+ Constructor __construct (line 166) +
+ + +

Construct a HTTP transport response

+
    +
  • access: public
  • +
+ +
+ Apache_Solr_HttpTransport_Response + + __construct + + (integer $statusCode, string $contentType, string $responseBody) +
+ +
    +
  • + integer + $statusCode: The HTTP status code
  • +
  • + string + $contentType: The VALUE of the Content-Type HTTP header
  • +
  • + string + $responseBody: The body of the HTTP response
  • +
+ + +
+ +
+ +
+ getBody (line 251) +
+ + +

Get the raw response body

+
    +
  • access: public
  • +
+ +
+ string + + getBody + + () +
+ + + +
+ +
+ +
+ getEncoding (line 241) +
+ + +

Get the charset encoding of the response body.

+
    +
  • access: public
  • +
+ +
+ string + + getEncoding + + () +
+ + + +
+ +
+ +
+ getMimeType (line 231) +
+ + +

Get the mimetype of the response body

+
    +
  • access: public
  • +
+ +
+ string + + getMimeType + + () +
+ + + +
+ +
+ +
+ getStatusCode (line 211) +
+ + +

Get the status code of the response

+
    +
  • access: public
  • +
+ +
+ integer + + getStatusCode + + () +
+ + + +
+ +
+ +
+ getStatusMessage (line 221) +
+ + +

Get the status message of the response

+
    +
  • access: public
  • +
+ +
+ string + + getStatusMessage + + () +
+ + + +
+ +
+
+ + +

+ Documentation generated on Wed, 04 May 2011 11:01:16 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_InvalidArgumentException.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_InvalidArgumentException.html new file mode 100644 index 00000000..49d57ee4 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_InvalidArgumentException.html @@ -0,0 +1,144 @@ + + + + + + Docs For Class Apache_Solr_InvalidArgumentException + + + + +
+

Class Apache_Solr_InvalidArgumentException

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+
    +
  • author: Donovan Jimenez <djimenez@conduit-it.com>
  • +
  • version: $Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  • +
  • copyright: Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  • +
  • license: New BSD
  • +
+

+ Located in /InvalidArgumentException.php (line 39) +

+ + +
Exception
+   |
+   --Apache_Solr_Exception
+      |
+      --Apache_Solr_InvalidArgumentException
+ +
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + +
+
+  + SVN_REVISION = '$Revision: 54 $' + +
+
+
+
+ + + + + + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + (line 49) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: 54 $' + (line 44) + +
+ + +

SVN Revision meta data for this class

+ + +
+

Inherited Constants

+ +

Inherited from Apache_Solr_Exception

+
+ + + Apache_Solr_Exception::SVN_ID
+
+ + + Apache_Solr_Exception::SVN_REVISION
+
+
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_NoServiceAvailableException.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_NoServiceAvailableException.html new file mode 100644 index 00000000..402d18b6 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_NoServiceAvailableException.html @@ -0,0 +1,144 @@ + + + + + + Docs For Class Apache_Solr_NoServiceAvailableException + + + + +
+

Class Apache_Solr_NoServiceAvailableException

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+
    +
  • author: Donovan Jimenez <djimenez@conduit-it.com>
  • +
  • version: $Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  • +
  • copyright: Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  • +
  • license: New BSD
  • +
+

+ Located in /NoServiceAvailableException.php (line 39) +

+ + +
Exception
+   |
+   --Apache_Solr_Exception
+      |
+      --Apache_Solr_NoServiceAvailableException
+ +
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + +
+
+  + SVN_REVISION = '$Revision: 54 $' + +
+
+
+
+ + + + + + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + (line 49) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: 54 $' + (line 44) + +
+ + +

SVN Revision meta data for this class

+ + +
+

Inherited Constants

+ +

Inherited from Apache_Solr_Exception

+
+ + + Apache_Solr_Exception::SVN_ID
+
+ + + Apache_Solr_Exception::SVN_REVISION
+
+
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_ParserException.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_ParserException.html new file mode 100644 index 00000000..a751d0d9 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_ParserException.html @@ -0,0 +1,144 @@ + + + + + + Docs For Class Apache_Solr_ParserException + + + + +
+

Class Apache_Solr_ParserException

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+
    +
  • author: Donovan Jimenez <djimenez@conduit-it.com>
  • +
  • version: $Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  • +
  • copyright: Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  • +
  • license: New BSD
  • +
+

+ Located in /ParserException.php (line 39) +

+ + +
Exception
+   |
+   --Apache_Solr_Exception
+      |
+      --Apache_Solr_ParserException
+ +
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + +
+
+  + SVN_REVISION = '$Revision: 54 $' + +
+
+
+
+ + + + + + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + (line 49) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: 54 $' + (line 44) + +
+ + +

SVN Revision meta data for this class

+ + +
+

Inherited Constants

+ +

Inherited from Apache_Solr_Exception

+
+ + + Apache_Solr_Exception::SVN_ID
+
+ + + Apache_Solr_Exception::SVN_REVISION
+
+
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Response.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Response.html new file mode 100644 index 00000000..4ae52838 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Response.html @@ -0,0 +1,621 @@ + + + + + + Docs For Class Apache_Solr_Response + + + + +
+

Class Apache_Solr_Response

+ + +
+
Description
+ +
+ +

Represents a Solr response. Parses the raw response into a set of stdClass objects and associative arrays for easy access.

+

Currently requires json_decode which is bundled with PHP >= 5.2.0, Alternatively can be installed with PECL. Zend Framework also includes a purely PHP solution.

+

+ Located in /Response.php (line 48) +

+ + +

+	
+			
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id: Response.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + +
+
+  + SVN_REVISION = '$Revision: 54 $' + +
+
+
+
+ + +
+
Variable Summary
+ +
+
+ +
+ boolean + $_createDocuments +
+
+ boolean + $_isParsed +
+
+ mixed + $_parsedData +
+ +
+
+
+ + +
+
Method Summary
+ +
+
+ +
+ Apache_Solr_HttpTransport_Response + __construct + (Apache_Solr_HttpTransport_Response $response, [boolean $createDocuments = true], [boolean $collapseSingleValueArrays = true]) +
+ +
+ string + getEncoding + () +
+ +
+ integer + getHttpStatus + () +
+ +
+ string + getHttpStatusMessage + () +
+ +
+ string + getRawResponse + () +
+ +
+ string + getType + () +
+ +
+ void + _parseData + () +
+ +
+ mixed + __get + (string $key) +
+ +
+ boolean + __isset + (string $key) +
+
+
+
+ + +
+
Variables
+ +
+ + +
+ +
+ + mixed + $_collapseSingleValueArrays + = true (line 88) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + boolean + $_createDocuments + = true (line 87) + +
+ + +

Data parsing flags. Determines what extra processing should be done after the data is initially converted to a data structure.

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + boolean + $_isParsed + = false (line 72) + +
+ + +

Whether the raw response has been parsed

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_parsedData + (line 79) + +
+ + +

Parsed representation of the data

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + Apache_Solr_HttpTransport_Response + $_response + (line 65) + +
+ + +

Holds the raw response used in construction

+
    +
  • var: HTTP response
  • +
  • access: protected
  • +
+ + + + + +
+ +
+
+ + +
+
Methods
+ +
+ + +
+ +
+ Constructor __construct (line 97) +
+ + +

Constructor. Takes the raw HTTP response body and the exploded HTTP headers

+
    +
  • return: HTTP response
  • +
  • access: public
  • +
+ +
+ Apache_Solr_HttpTransport_Response + + __construct + + (Apache_Solr_HttpTransport_Response $response, [boolean $createDocuments = true], [boolean $collapseSingleValueArrays = true]) +
+ +
    +
  • + boolean + $createDocuments: Whether to convert the documents json_decoded as stdClass instances to Apache_Solr_Document instances
  • +
  • + boolean + $collapseSingleValueArrays: Whether to make multivalued fields appear as single values
  • +
  • + Apache_Solr_HttpTransport_Response + $response
  • +
+ + +
+ +
+ +
+ getEncoding (line 139) +
+ + +

Get character encoding of this response. Should usually be utf-8, but just in case

+
    +
  • access: public
  • +
+ +
+ string + + getEncoding + + () +
+ + + +
+ +
+ +
+ getHttpStatus (line 109) +
+ + +

Get the HTTP status code

+
    +
  • access: public
  • +
+ +
+ integer + + getHttpStatus + + () +
+ + + +
+ +
+ +
+ getHttpStatusMessage (line 119) +
+ + +

Get the HTTP status message of the response

+
    +
  • access: public
  • +
+ +
+ string + + getHttpStatusMessage + + () +
+ + + +
+ +
+ +
+ getRawResponse (line 149) +
+ + +

Get the raw response as it was given to this object

+
    +
  • access: public
  • +
+ +
+ string + + getRawResponse + + () +
+ + + +
+ +
+ +
+ getType (line 129) +
+ + +

Get content type of this Solr response

+
    +
  • access: public
  • +
+ +
+ string + + getType + + () +
+ + + +
+ +
+ +
+ _parseData (line 198) +
+ + +

Parse the raw response into the parsed_data array for access

+
    +
  • throws: Apache_Solr_ParserException If the data could not be parsed
  • +
  • access: protected
  • +
+ +
+ void + + _parseData + + () +
+ + + +
+ +
+ +
+ __get (line 160) +
+ + +

Magic get to expose the parsed data and to lazily load it

+
    +
  • access: public
  • +
+ +
+ mixed + + __get + + (string $key) +
+ +
    +
  • + string + $key
  • +
+ + +
+ +
+ +
+ __isset (line 182) +
+ + +

Magic function for isset function on parsed data

+
    +
  • access: public
  • +
+ +
+ boolean + + __isset + + (string $key) +
+ +
    +
  • + string + $key
  • +
+ + +
+ +
+
+ + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id: Response.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + (line 58) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: 54 $' + (line 53) + +
+ + +

SVN Revision meta data for this class

+ + +
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service.html new file mode 100644 index 00000000..aff68bee --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service.html @@ -0,0 +1,2473 @@ + + + + + + Docs For Class Apache_Solr_Service + + + + +
+

Class Apache_Solr_Service

+ + +
+
Description
+ +
+ +

Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.

+

Example Usage:

  1.  ...
  2. +
  3.  $solr new Apache_Solr_Service()//or explicitly new Apache_Solr_Service('localhost', 8180, '/solr')
  4. +
  5.  
  6. +
  7.  if ($solr->ping())
  8. +
  9.  {
  10. +
  11.          $solr->deleteByQuery('*:*')//deletes ALL documents - be careful :)
  12. +
  13.  
  14. +
  15.          $document new Apache_Solr_Document();
  16. +
  17.          $document->id uniqid()//or something else suitably unique
  18. +
  19.  
  20. +
  21.          $document->title 'Some Title';
  22. +
  23.          $document->content 'Some content for this wonderful document. Blah blah blah.';
  24. +
  25.  
  26. +
  27.          $solr->addDocument($document);     //if you're going to be adding documents in bulk using addDocuments
  28. +
  29.                                          //with an array of documents is faster
  30. +
  31.  
  32. +
  33.          $solr->commit()//commit to see the deletes and the document
  34. +
  35.          $solr->optimize()//merges multiple segments into one
  36. +
  37.  
  38. +
  39.          //and the one we all care about, search!
  40. +
  41.          //any other common or custom parameters to the request handler can go in the
  42. +
  43.          //optional 4th array argument.
  44. +
  45.          $solr->search('content:blah'010array('sort' => 'timestamp desc'));
  46. +
  47.  }
  48. +
  49.  ...
  50. +

+
    +
  • todo: Investigate using other HTTP clients other than file_get_contents built-in handler. Could provide performance improvements when dealing with multiple requests by using HTTP's keep alive functionality
  • +
+

+ Located in /Service.php (line 86) +

+ + +

+	
+			
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + EXTRACT_SERVLET = 'update/extract' + +
+
+  + METHOD_GET = 'GET' + +
+
+  + METHOD_POST = 'POST' + +
+
+  + NAMED_LIST_FLAT = 'flat' + +
+
+  + NAMED_LIST_MAP = 'map' + +
+
+  + PING_SERVLET = 'admin/ping' + +
+
+  + SEARCH_SERVLET = 'select' + +
+
+  + SOLR_WRITER = 'json' + +
+
+  + SVN_ID = '$Id: Service.php 59 2011-02-08 20:38:59Z donovan.jimenez $' + +
+
+  + SVN_REVISION = '$Revision: 59 $' + +
+
+  + THREADS_SERVLET = 'admin/threads' + +
+
+  + UPDATE_SERVLET = 'update' + +
+
+
+
+ + +
+
Variable Summary
+ +
+
+ +
+ boolean + $_createDocuments +
+
+ string + $_host +
+ +
+ string + $_namedListTreatment +
+
+ mixed + $_path +
+
+ string + $_pingUrl +
+
+ mixed + $_port +
+ +
+ string + $_queryDelimiter +
+ +
+ mixed + $_searchUrl +
+
+ mixed + $_threadsUrl +
+
+ mixed + $_updateUrl +
+
+ boolean + $_urlsInited +
+
+
+
+ + +
+
Method Summary
+ +
+
+ +
+ static string + escape + (string $value) +
+ +
+ static string + escapePhrase + (string $value) +
+ +
+ static string + phrase + (string $value) +
+ +
+ Apache_Solr_Response + add + (string $rawPost) +
+ +
+ Apache_Solr_Response + addDocument + (Apache_Solr_Document $document, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true], [integer $commitWithin = 0]) +
+ +
+ Apache_Solr_Response + addDocuments + (array $documents, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true], [integer $commitWithin = 0]) +
+ +
+ Apache_Solr_Response + commit + ([boolean $expungeDeletes = false], [boolean $waitFlush = true], [boolean $waitSearcher = true], [float $timeout = 3600]) +
+ +
+ Apache_Solr_Response + delete + (string $rawPost, [float $timeout = 3600]) +
+ +
+ Apache_Solr_Response + deleteById + (string $id, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
+ Apache_Solr_Response + deleteByMultipleIds + (array $ids, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
+ Apache_Solr_Response + deleteByQuery + (string $rawQuery, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
+ Apache_Solr_Response + extract + (string $file, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
+ Apache_Solr_Response + extractFromString + (string $data, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
+ Apache_Solr_Response + extractFromUrl + (string $url, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
+ boolean + getCollapseSingleValueArrays + () +
+ +
+ boolean + getCreateDocuments + () +
+ +
+ float + getDefaultTimeout + () +
+ +
+ string + getHost + () +
+ +
+ HttpTransportInterface + getHttpTransport + () +
+ +
+ string + getNamedListTreatment + () +
+ +
+ string + getPath + () +
+ +
+ integer + getPort + () +
+ +
+ Apache_Solr_Service + __construct + ([string $host = 'localhost'], [string $port = 8180], [string $path = '/solr/'], [Apache_Solr_HttpTransport_Interface $httpTransport = false]) +
+ +
+ Apache_Solr_Response + optimize + ([boolean $waitFlush = true], [boolean $waitSearcher = true], [float $timeout = 3600]) +
+ +
+ float + ping + ([float $timeout = 2]) +
+ +
+ Apache_Solr_Response + search + (string $query, [int $offset = 0], [int $limit = 10], [array $params = array()], [string $method = self::METHOD_GET]) +
+ +
+ void + setCollapseSingleValueArrays + (boolean $collapseSingleValueArrays) +
+ +
+ void + setCreateDocuments + (boolean $createDocuments) +
+ +
+ void + setDefaultTimeout + (float $timeout) +
+ +
+ void + setHost + (string $host) +
+ +
+ void + setHttpTransport + (Apache_Solr_HttpTransport_Interface $httpTransport) +
+ +
+ void + setNamedListTreatment + (string $namedListTreatment) +
+ +
+ void + setPath + (string $path) +
+ +
+ void + setPort + (integer $port) +
+ +
+ void + setQueryDelimiter + (string $queryDelimiter) +
+ +
+ void + setQueryStringDelimiter + (string $queryStringDelimiter) +
+ + + +
+ string + _constructUrl + (string $servlet, [ $params = array()]) +
+ +
+ string + _documentToXmlFragment + (Apache_Solr_Document $document) +
+ +
+ void + _generateQueryString + ( $params) +
+ +
+ void + _initUrls + () +
+ +
+ Apache_Solr_Response + _sendRawGet + (string $url, [float $timeout = FALSE]) +
+ +
+ Apache_Solr_Response + _sendRawPost + (string $url, string $rawPost, [float $timeout = FALSE], [string $contentType = 'text/xml; charset=UTF-8']) +
+ +
+ string + _stripCtrlChars + (string $string) +
+
+
+
+ + +
+
Variables
+ +
+ + +
+ +
+ + boolean + $_collapseSingleValueArrays + = true (line 145) + +
+ + +

Whether Apache_Solr_Response objects should have multivalue fields with only a single value collapsed to appear as a single value would.

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + boolean + $_createDocuments + = true (line 137) + +
+ + +

Whether Apache_Solr_Response objects should create Apache_Solr_Documents in the returned parsed data

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + string + $_host + (line 129) + +
+ + +

Server identification strings

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + Apache_Solr_HttpTransport_Interface + $_httpTransport + = false (line 182) + +
+ + +

HTTP Transport implementation (pluggable)

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + string + $_namedListTreatment + = self::NAMED_LIST_MAP (line 153) + +
+ + +

How NamedLists should be formatted in the output. This specifically effects facet counts. Valid values are Apache_Solr_Service::NAMED_LIST_MAP (default) or Apache_Solr_Service::NAMED_LIST_FLAT.

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_path + (line 129) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + string + $_pingUrl + (line 168) + +
+ + +

Constructed servlet full path URLs

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_port + (line 129) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_queryBracketsEscaped + = true (line 161) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + string + $_queryDelimiter + = '?' (line 161) + +
+ + +

Query delimiters. Someone might want to be able to change these (to use &amp; instead of & for example), so I've provided them.

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_queryStringDelimiter + = '&' (line 161) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_searchUrl + (line 168) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_threadsUrl + (line 168) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_updateUrl + (line 168) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + boolean + $_urlsInited + = false (line 175) + +
+ + +

Keep track of whether our URLs have been constructed

+
    +
  • access: protected
  • +
+ + + + + +
+ +
+
+ + +
+
Methods
+ +
+ + +
+ +
+ static escape (line 192) +
+ + +

Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.

+

NOTE: inside a phrase fewer characters need escaped, use Apache_Solr_Service::escapePhrase() instead

+
    +
  • access: public
  • +
+ +
+ static string + + escape + + (string $value) +
+ +
    +
  • + string + $value
  • +
+ + +
+ +
+ +
+ static escapePhrase (line 207) +
+ + +

Escape a value meant to be contained in a phrase for special query characters

+
    +
  • access: public
  • +
+ +
+ static string + + escapePhrase + + (string $value) +
+ +
    +
  • + string + $value
  • +
+ + +
+ +
+ +
+ static phrase (line 221) +
+ + +

Convenience function for creating phrase syntax from a value

+
    +
  • access: public
  • +
+ +
+ static string + + phrase + + (string $value) +
+ +
    +
  • + string + $value
  • +
+ + +
+ +
+ +
+ add (line 667) +
+ + +

Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + add + + (string $rawPost) +
+ +
    +
  • + string + $rawPost
  • +
+ + +
+ +
+ +
+ addDocument (line 684) +
+ + +

Add a Solr Document to the index

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + addDocument + + (Apache_Solr_Document $document, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true], [integer $commitWithin = 0]) +
+ +
    +
  • + Apache_Solr_Document + $document
  • +
  • + boolean + $allowDups
  • +
  • + boolean + $overwritePending
  • +
  • + boolean + $overwriteCommitted
  • +
  • + integer + $commitWithin: The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details. If left empty this property will not be set in the request.
  • +
+ + +
+ +
+ +
+ addDocuments (line 712) +
+ + +

Add an array of Solr Documents to the index all at once

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + addDocuments + + (array $documents, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true], [integer $commitWithin = 0]) +
+ +
    +
  • + array + $documents: Should be an array of Apache_Solr_Document instances
  • +
  • + boolean + $allowDups
  • +
  • + boolean + $overwritePending
  • +
  • + boolean + $overwriteCommitted
  • +
  • + integer + $commitWithin: The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details. If left empty this property will not be set in the request.
  • +
+ + +
+ +
+ +
+ commit (line 821) +
+ + +

Send a commit command. Will be synchronous unless both wait parameters are set to false.

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + commit + + ([boolean $expungeDeletes = false], [boolean $waitFlush = true], [boolean $waitSearcher = true], [float $timeout = 3600]) +
+ +
    +
  • + boolean + $expungeDeletes: Defaults to false, merge segments with deletes away
  • +
  • + boolean + $waitFlush: Defaults to true, block until index changes are flushed to disk
  • +
  • + boolean + $waitSearcher: Defaults to true, block until a new searcher is opened and registered as the main query searcher, making the changes visible
  • +
  • + float + $timeout: Maximum expected duration (in seconds) of the commit operation on the server (otherwise, will throw a communication exception). Defaults to 1 hour
  • +
+ + +
+ +
+ +
+ delete (line 842) +
+ + +

Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + delete + + (string $rawPost, [float $timeout = 3600]) +
+ +
    +
  • + string + $rawPost: Expected to be utf-8 encoded xml document
  • +
  • + float + $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ deleteById (line 858) +
+ + +

Create a delete document based on document ID

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + deleteById + + (string $id, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
    +
  • + string + $id: Expected to be utf-8 encoded
  • +
  • + boolean + $fromPending
  • +
  • + boolean + $fromCommitted
  • +
  • + float + $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ deleteByMultipleIds (line 882) +
+ + +

Create and post a delete document based on multiple document IDs.

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + deleteByMultipleIds + + (array $ids, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
    +
  • + array + $ids: Expected to be utf-8 encoded strings
  • +
  • + boolean + $fromPending
  • +
  • + boolean + $fromCommitted
  • +
  • + float + $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ deleteByQuery (line 913) +
+ + +

Create a delete document based on a query and submit it

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + deleteByQuery + + (string $rawQuery, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
    +
  • + string + $rawQuery: Expected to be utf-8 encoded
  • +
  • + boolean + $fromPending
  • +
  • + boolean + $fromCommitted
  • +
  • + float + $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ extract (line 944) +
+ + +

Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.

+

NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also pass in a document isntance with an "id" field" - the document's value(s) will take precedence).

+
    +
  • throws: Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + extract + + (string $file, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
    +
  • + string + $file: Path to file to extract data from
  • +
  • + array + $params: optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  • +
  • + Apache_Solr_Document + $document: optional document that will be used to generate post parameters (literal.* and boost.* params)
  • +
  • + string + $mimetype: optional mimetype specification (for the file being extracted)
  • +
+ + +
+ +
+ +
+ extractFromString (line 1005) +
+ + +

Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.

+

NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also pass in a document isntance with an "id" field" - the document's value(s) will take precedence).

+
    +
  • todo: Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
  • +
  • throws: Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + extractFromString + + (string $data, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
    +
  • + string + $data: Data that will be passed to Solr Cell
  • +
  • + array + $params: optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  • +
  • + Apache_Solr_Document + $document: optional document that will be used to generate post parameters (literal.* and boost.* params)
  • +
  • + string + $mimetype: optional mimetype specification (for the file being extracted)
  • +
+ + +
+ +
+ +
+ extractFromUrl (line 1068) +
+ + +

Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.

+

NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also pass in a document isntance with an "id" field" - the document's value(s) will take precedence).

+
    +
  • throws: Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid.
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + extractFromUrl + + (string $url, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
    +
  • + string + $url: URL
  • +
  • + array + $params: optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  • +
  • + Apache_Solr_Document + $document: optional document that will be used to generate post parameters (literal.* and boost.* params)
  • +
  • + string + $mimetype: optional mimetype specification (for the file being extracted)
  • +
+ + +
+ +
+ +
+ getCollapseSingleValueArrays (line 533) +
+ + +

Get the current state of the collapse single value arrays flag.

+
    +
  • access: public
  • +
+ +
+ boolean + + getCollapseSingleValueArrays + + () +
+ + + +
+ +
+ +
+ getCreateDocuments (line 513) +
+ + +

Get the current state of teh create documents flag.

+
    +
  • access: public
  • +
+ +
+ boolean + + getCreateDocuments + + () +
+ + + +
+ +
+ +
+ getDefaultTimeout (line 546) +
+ + +

Get the current default timeout setting (initially the default_socket_timeout ini setting) in seconds

+
    +
  • deprecated: Use the getDefaultTimeout method on the HTTP transport implementation
  • +
  • access: public
  • +
+ +
+ float + + getDefaultTimeout + + () +
+ + + +
+ +
+ +
+ getHost (line 375) +
+ + +

Returns the set host

+
    +
  • access: public
  • +
+ +
+ string + + getHost + + () +
+ + + +
+ +
+ +
+ getHttpTransport (line 474) +
+ + +

Get the current configured HTTP Transport

+
    +
  • access: public
  • +
+ +
+ HttpTransportInterface + + getHttpTransport + + () +
+ + + +
+ +
+ +
+ getNamedListTreatment (line 592) +
+ + +

Get the current setting for named list treatment.

+
    +
  • access: public
  • +
+ +
+ string + + getNamedListTreatment + + () +
+ + + +
+ +
+ +
+ getPath (line 447) +
+ + +

Get the set path.

+
    +
  • access: public
  • +
+ +
+ string + + getPath + + () +
+ + + +
+ +
+ +
+ getPort (line 410) +
+ + +

Get the set port

+
    +
  • access: public
  • +
+ +
+ integer + + getPort + + () +
+ + + +
+ +
+ +
+ Constructor __construct (line 235) +
+ + +

Constructor. All parameters are optional and will take on default values if not specified.

+
    +
  • access: public
  • +
+ +
+ Apache_Solr_Service + + __construct + + ([string $host = 'localhost'], [string $port = 8180], [string $path = '/solr/'], [Apache_Solr_HttpTransport_Interface $httpTransport = false]) +
+ + + + +
+ +
+ +
+ optimize (line 1117) +
+ + +

Send an optimize command. Will be synchronous unless both wait parameters are set to false.

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + optimize + + ([boolean $waitFlush = true], [boolean $waitSearcher = true], [float $timeout = 3600]) +
+ +
    +
  • + boolean + $waitFlush
  • +
  • + boolean + $waitSearcher
  • +
  • + float + $timeout: Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ ping (line 626) +
+ + +

Call the /admin/ping servlet, can be used to quickly tell if a connection to the server is able to be made.

+
    +
  • return: Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs
  • +
  • access: public
  • +
+ +
+ float + + ping + + ([float $timeout = 2]) +
+ +
    +
  • + float + $timeout: maximum time to wait for ping in seconds, -1 for unlimited (default is 2)
  • +
+ + +
+ +
+ +
+ search (line 1140) +
+ + +

Simple Search interface

+
    +
  • throws: Apache_Solr_InvalidArgumentException If an invalid HTTP method is used
  • +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + search + + (string $query, [int $offset = 0], [int $limit = 10], [array $params = array()], [string $method = self::METHOD_GET]) +
+ +
    +
  • + string + $query: The raw query string
  • +
  • + int + $offset: The starting offset for result documents
  • +
  • + int + $limit: The maximum number of result documents to return
  • +
  • + array + $params: key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field)
  • +
  • + string + $method: The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
  • +
+ + +
+ +
+ +
+ setCollapseSingleValueArrays (line 523) +
+ + +

Set the collapse single value arrays flag.

+
    +
  • access: public
  • +
+ +
+ void + + setCollapseSingleValueArrays + + (boolean $collapseSingleValueArrays) +
+ +
    +
  • + boolean + $collapseSingleValueArrays
  • +
+ + +
+ +
+ +
+ setCreateDocuments (line 503) +
+ + +

Set the create documents flag. This determines whether Apache_Solr_Response objects will parse the response and create Apache_Solr_Document instances in place.

+
    +
  • access: public
  • +
+ +
+ void + + setCreateDocuments + + (boolean $createDocuments) +
+ +
    +
  • + boolean + $createDocuments
  • +
+ + +
+ +
+ +
+ setDefaultTimeout (line 558) +
+ + +

Set the default timeout for all calls that aren't passed a specific timeout

+
    +
  • deprecated: Use the setDefaultTimeout method on the HTTP transport implementation
  • +
  • access: public
  • +
+ +
+ void + + setDefaultTimeout + + (float $timeout) +
+ +
    +
  • + float + $timeout: Timeout value in seconds
  • +
+ + +
+ +
+ +
+ setHost (line 387) +
+ + +

Set the host used. If empty will fallback to constants

+
    +
  • throws: Apache_Solr_InvalidArgumentException If the host parameter is empty
  • +
  • access: public
  • +
+ +
+ void + + setHost + + (string $host) +
+ +
    +
  • + string + $host
  • +
+ + +
+ +
+ +
+ setHttpTransport (line 492) +
+ + +

Set the HTTP Transport implemenation that will be used for all HTTP requests

+
    +
  • access: public
  • +
+ +
+ void + + setHttpTransport + + (Apache_Solr_HttpTransport_Interface $httpTransport) +
+ + + + +
+ +
+ +
+ setNamedListTreatment (line 570) +
+ + +

Set how NamedLists should be formatted in the response data. This mainly effects the facet counts format.

+
    +
  • throws: Apache_Solr_InvalidArgumentException If invalid option is set
  • +
  • access: public
  • +
+ +
+ void + + setNamedListTreatment + + (string $namedListTreatment) +
+ +
    +
  • + string + $namedListTreatment
  • +
+ + +
+ +
+ +
+ setPath (line 457) +
+ + +

Set the path used. If empty will fallback to constants

+
    +
  • access: public
  • +
+ +
+ void + + setPath + + (string $path) +
+ +
    +
  • + string + $path
  • +
+ + +
+ +
+ +
+ setPort (line 422) +
+ + +

Set the port used. If empty will fallback to constants

+
    +
  • throws: Apache_Solr_InvalidArgumentException If the port parameter is empty
  • +
  • access: public
  • +
+ +
+ void + + setPort + + (integer $port) +
+ +
    +
  • + integer + $port
  • +
+ + +
+ +
+ +
+ setQueryDelimiter (line 603) +
+ + +

Set the string used to separate the path form the query string.

+

Defaulted to '?'

+
    +
  • access: public
  • +
+ +
+ void + + setQueryDelimiter + + (string $queryDelimiter) +
+ +
    +
  • + string + $queryDelimiter
  • +
+ + +
+ +
+ +
+ setQueryStringDelimiter (line 614) +
+ + +

Set the string used to separate the parameters in thequery string Defaulted to '&'

+
    +
  • access: public
  • +
+ +
+ void + + setQueryStringDelimiter + + (string $queryStringDelimiter) +
+ +
    +
  • + string + $queryStringDelimiter
  • +
+ + +
+ +
+ +
+ threads (line 653) +
+ + +

Call the /admin/threads servlet and retrieve information about all threads in the Solr servlet's thread group. Useful for diagnostics.

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + threads + + () +
+ + + +
+ +
+ +
+ _constructUrl (line 258) +
+ + +

Return a valid http URL given this server's host, port and path and a provided servlet name

+
    +
  • access: protected
  • +
+ +
+ string + + _constructUrl + + (string $servlet, [ $params = array()]) +
+ +
    +
  • + string + $servlet
  • +
  • + + $params
  • +
+ + +
+ +
+ +
+ _documentToXmlFragment (line 741) +
+ + +

Create an XML fragment from a Apache_Solr_Document instance appropriate for use inside a Solr add call

+
    +
  • access: protected
  • +
+ +
+ string + + _documentToXmlFragment + + (Apache_Solr_Document $document) +
+ + + + +
+ +
+ +
+ _generateQueryString (line 295) +
+ + +
    +
  • access: protected
  • +
+ +
+ void + + _generateQueryString + + ( $params) +
+ +
    +
  • + + $params
  • +
+ + +
+ +
+ +
+ _initUrls (line 283) +
+ + +

Construct the Full URLs for the three servlets we reference

+
    +
  • access: protected
  • +
+ +
+ void + + _initUrls + + () +
+ + + +
+ +
+ +
+ _sendRawGet (line 329) +
+ + +

Central method for making a get operation against this Solr Server

+
    +
  • throws: Apache_Solr_HttpTransportException If a non 200 response status is returned
  • +
  • access: protected
  • +
+ +
+ Apache_Solr_Response + + _sendRawGet + + (string $url, [float $timeout = FALSE]) +
+ +
    +
  • + string + $url
  • +
  • + float + $timeout: Read timeout in seconds
  • +
+ + +
+ +
+ +
+ _sendRawPost (line 355) +
+ + +

Central method for making a post operation against this Solr Server

+
    +
  • throws: Apache_Solr_HttpTransportException If a non 200 response status is returned
  • +
  • access: protected
  • +
+ +
+ Apache_Solr_Response + + _sendRawPost + + (string $url, string $rawPost, [float $timeout = FALSE], [string $contentType = 'text/xml; charset=UTF-8']) +
+ +
    +
  • + string + $url
  • +
  • + string + $rawPost
  • +
  • + float + $timeout: Read timeout in seconds
  • +
  • + string + $contentType
  • +
+ + +
+ +
+ +
+ _stripCtrlChars (line 803) +
+ + +

Replace control (non-printable) characters from string that are invalid to Solr's XML parser with a space.

+
    +
  • access: protected
  • +
+ +
+ string + + _stripCtrlChars + + (string $string) +
+ +
    +
  • + string + $string
  • +
+ + +
+ +
+
+ + +
+
Class Constants
+ +
+ +
+ +
+ + + EXTRACT_SERVLET + = 'update/extract' + (line 122) + +
+ + + + +
+ +
+ +
+ + + METHOD_GET + = 'GET' + (line 112) + +
+ + +

Search HTTP Methods

+ + +
+ +
+ +
+ + + METHOD_POST + = 'POST' + (line 113) + +
+ + + + +
+ +
+ +
+ + + NAMED_LIST_FLAT + = 'flat' + (line 106) + +
+ + +

NamedList Treatment constants

+ + +
+ +
+ +
+ + + NAMED_LIST_MAP + = 'map' + (line 107) + +
+ + + + +
+ +
+ +
+ + + PING_SERVLET + = 'admin/ping' + (line 118) + +
+ + +

Servlet mappings

+ + +
+ +
+ +
+ + + SEARCH_SERVLET + = 'select' + (line 120) + +
+ + + + +
+ +
+ +
+ + + SOLR_WRITER + = 'json' + (line 101) + +
+ + +

Response writer we'll request - JSON. See http://code.google.com/p/solr-php-client/issues/detail?id=6#c1 for reasoning

+ + +
+ +
+ +
+ + + SVN_ID + = '$Id: Service.php 59 2011-02-08 20:38:59Z donovan.jimenez $' + (line 96) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: 59 $' + (line 91) + +
+ + +

SVN Revision meta data for this class

+ + +
+ +
+ +
+ + + THREADS_SERVLET + = 'admin/threads' + (line 121) + +
+ + + + +
+ +
+ +
+ + + UPDATE_SERVLET + = 'update' + (line 119) + +
+ + + + +
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:19 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service_Balancer.html b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service_Balancer.html new file mode 100644 index 00000000..f74c898c --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service_Balancer.html @@ -0,0 +1,1606 @@ + + + + + + Docs For Class Apache_Solr_Service_Balancer + + + + +
+

Class Apache_Solr_Service_Balancer

+ + +
+
Description
+ +
+ +

Reference Implementation for using multiple Solr services in a distribution. Functionality

+

includes: routing of read / write operations failover (on selection) for multiple read servers

+

+ Located in /Service/Balancer.php (line 51) +

+ + +

+	
+			
+
+ + + +
+
Class Constant Summary
+ +
+
+
+  + SVN_ID = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + +
+
+  + SVN_REVISION = '$Revision: 54 $' + +
+
+
+
+ + +
+
Variable Summary
+ +
+
+
+ mixed + $_backoffEscalation +
+
+ mixed + $_backoffLimit +
+
+ mixed + $_createDocuments +
+
+ mixed + $_currentReadService +
+
+ mixed + $_currentWriteService +
+
+ mixed + $_defaultBackoff +
+
+ mixed + $_readableServices +
+
+ mixed + $_readPingTimeout +
+
+ mixed + $_useBackoff +
+
+ mixed + $_writeableServices +
+
+ mixed + $_writePingTimeout +
+
+
+
+ + +
+
Method Summary
+ +
+
+ +
+ static string + escape + (string $value) +
+ +
+ static string + escapePhrase + (string $value) +
+ +
+ static string + phrase + (string $value) +
+ +
+ Apache_Solr_Service_Balancer + __construct + ([array $readableServices = array()], [array $writeableServices = array()]) +
+ +
+ Apache_Solr_Response + add + (string $rawPost) +
+ +
+ Apache_Solr_Response + addDocument + (Apache_Solr_Document $document, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true]) +
+ +
+ Apache_Solr_Response + addDocuments + (array $documents, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true]) +
+ +
+ void + addReadService + (mixed $service) +
+ +
+ void + addWriteService + (mixed $service) +
+ +
+ Apache_Solr_Response + commit + ([ $optimize = true], [boolean $waitFlush = true], [boolean $waitSearcher = true], [ $timeout = 3600]) +
+ +
+ Apache_Solr_Response + delete + (string $rawPost, [float $timeout = 3600]) +
+ +
+ Apache_Solr_Response + deleteById + (string $id, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
+ Apache_Solr_Response + deleteByMultipleIds + (array $ids, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
+ Apache_Solr_Response + deleteByQuery + (string $rawQuery, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
+ Apache_Solr_Response + extract + (string $file, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
+ Apache_Solr_Response + extractFromString + (string $data, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
+ boolean + getCreateDocuments + () +
+ +
+ Apache_Solr_Response + optimize + ([boolean $waitFlush = true], [boolean $waitSearcher = true], [float $timeout = 3600]) +
+ +
+ void + removeReadService + (mixed $service) +
+ +
+ void + removeWriteService + (mixed $service) +
+ +
+ Apache_Solr_Response + search + (string $query, [int $offset = 0], [int $limit = 10], [array $params = array()], [string $method = Apache_Solr_Service::METHOD_GET]) +
+ +
+ void + setCreateDocuments + (boolean $createDocuments) +
+ +
+ void + setReadPingTimeout + ( $timeout) +
+ +
+ void + setUseBackoff + ( $enable) +
+ +
+ void + setWritePingTimeout + ( $timeout) +
+ +
+ string + _getServiceId + (string $host, integer $port, string $path) +
+ +
+ Apache_Solr_Service + _selectReadService + ([ $forceSelect = false]) +
+ +
+ Apache_Solr_Service + _selectWriteService + ([ $forceSelect = false]) +
+ +
+ Apache_Solr_Service + _selectWriteServiceSafe + ([ $forceSelect = false]) +
+
+
+
+ + +
+
Variables
+ +
+ + +
+ +
+ + mixed + $_backoffEscalation + = 2.0 (line 77) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_backoffLimit + = 600 (line 76) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_createDocuments + = true (line 63) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_currentReadService + = null (line 68) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_currentWriteService + = null (line 69) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_defaultBackoff + = 2.0 (line 78) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_readableServices + = array() (line 65) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_readPingTimeout + = 2 (line 71) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_useBackoff + = false (line 75) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_writeableServices + = array() (line 66) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+ +
+ + mixed + $_writePingTimeout + = 4 (line 72) + +
+ + +
    +
  • access: protected
  • +
+ + + + + +
+ +
+
+ + +
+
Methods
+ +
+ + +
+ +
+ static escape (line 88) +
+ + +

Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.

+

NOTE: inside a phrase fewer characters need escaped, use Apache_Solr_Service::escapePhrase() instead

+
    +
  • access: public
  • +
+ +
+ static string + + escape + + (string $value) +
+ +
    +
  • + string + $value
  • +
+ + +
+ +
+ +
+ static escapePhrase (line 99) +
+ + +

Escape a value meant to be contained in a phrase for special query characters

+
    +
  • access: public
  • +
+ +
+ static string + + escapePhrase + + (string $value) +
+ +
    +
  • + string + $value
  • +
+ + +
+ +
+ +
+ static phrase (line 110) +
+ + +

Convenience function for creating phrase syntax from a value

+
    +
  • access: public
  • +
+ +
+ static string + + phrase + + (string $value) +
+ +
    +
  • + string + $value
  • +
+ + +
+ +
+ +
+ Constructor __construct (line 121) +
+ + +

Constructor. Takes arrays of read and write service instances or descriptions

+
    +
  • access: public
  • +
+ +
+ Apache_Solr_Service_Balancer + + __construct + + ([array $readableServices = array()], [array $writeableServices = array()]) +
+ +
    +
  • + array + $readableServices
  • +
  • + array + $writeableServices
  • +
+ + +
+ +
+ +
+ add (line 491) +
+ + +

Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + add + + (string $rawPost) +
+ +
    +
  • + string + $rawPost
  • +
+ + +
+ +
+ +
+ addDocument (line 526) +
+ + +

Add a Solr Document to the index

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + addDocument + + (Apache_Solr_Document $document, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true]) +
+ +
    +
  • + Apache_Solr_Document + $document
  • +
  • + boolean + $allowDups
  • +
  • + boolean + $overwritePending
  • +
  • + boolean + $overwriteCommitted
  • +
+ + +
+ +
+ +
+ addDocuments (line 561) +
+ + +

Add an array of Solr Documents to the index all at once

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + addDocuments + + (array $documents, [boolean $allowDups = false], [boolean $overwritePending = true], [boolean $overwriteCommitted = true]) +
+ +
    +
  • + array + $documents: Should be an array of Apache_Solr_Document instances
  • +
  • + boolean + $allowDups
  • +
  • + boolean + $overwritePending
  • +
  • + boolean + $overwriteCommitted
  • +
+ + +
+ +
+ +
+ addReadService (line 172) +
+ + +

Adds a service instance or service descriptor (if it is already not added)

+
    +
  • throws: Apache_Solr_InvalidArgumentException If service descriptor is not valid
  • +
  • access: public
  • +
+ +
+ void + + addReadService + + (mixed $service) +
+ +
    +
  • + mixed + $service
  • +
+ + +
+ +
+ +
+ addWriteService (line 240) +
+ + +

Adds a service instance or service descriptor (if it is already not added)

+
    +
  • throws: Apache_Solr_InvalidArgumentException If service descriptor is not valid
  • +
  • access: public
  • +
+ +
+ void + + addWriteService + + (mixed $service) +
+ +
    +
  • + mixed + $service
  • +
+ + +
+ +
+ +
+ commit (line 595) +
+ + +

Send a commit command. Will be synchronous unless both wait parameters are set to false.

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + commit + + ([ $optimize = true], [boolean $waitFlush = true], [boolean $waitSearcher = true], [ $timeout = 3600]) +
+ +
    +
  • + boolean + $waitFlush
  • +
  • + boolean + $waitSearcher
  • +
  • + + $optimize
  • +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ delete (line 629) +
+ + +

Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + delete + + (string $rawPost, [float $timeout = 3600]) +
+ +
    +
  • + string + $rawPost
  • +
  • + float + $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ deleteById (line 664) +
+ + +

Create a delete document based on document ID

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + deleteById + + (string $id, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
    +
  • + string + $id
  • +
  • + boolean + $fromPending
  • +
  • + boolean + $fromCommitted
  • +
  • + float + $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ deleteByMultipleIds (line 699) +
+ + +

Create and post a delete document based on multiple document IDs.

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + deleteByMultipleIds + + (array $ids, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
    +
  • + array + $ids: Expected to be utf-8 encoded strings
  • +
  • + boolean + $fromPending
  • +
  • + boolean + $fromCommitted
  • +
  • + float + $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ deleteByQuery (line 734) +
+ + +

Create a delete document based on a query and submit it

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + deleteByQuery + + (string $rawQuery, [boolean $fromPending = true], [boolean $fromCommitted = true], [float $timeout = 3600]) +
+ +
    +
  • + string + $rawQuery
  • +
  • + boolean + $fromPending
  • +
  • + boolean + $fromCommitted
  • +
  • + float + $timeout: Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ extract (line 776) +
+ + +

Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.

+

NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also pass in a document isntance with an "id" field" - the document's value(s) will take precedence).

+
    +
  • throws: Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + extract + + (string $file, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
    +
  • + string + $file: Path to file to extract data from
  • +
  • + array + $params: optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  • +
  • + Apache_Solr_Document + $document: optional document that will be used to generate post parameters (literal.* and boost.* params)
  • +
  • + string + $mimetype: optional mimetype specification (for the file being extracted)
  • +
+ + +
+ +
+ +
+ extractFromString (line 820) +
+ + +

Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.

+

NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost." as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also pass in a document isntance with an "id" field" - the document's value(s) will take precedence).

+
    +
  • todo: Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
  • +
  • throws: Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + extractFromString + + (string $data, [array $params = array()], [Apache_Solr_Document $document = null], [string $mimetype = 'application/octet-stream']) +
+ +
    +
  • + string + $data: Data that will be passed to Solr Cell
  • +
  • + array + $params: optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  • +
  • + Apache_Solr_Document + $document: optional document that will be used to generate post parameters (literal.* and boost.* params)
  • +
  • + string + $mimetype: optional mimetype specification (for the file being extracted)
  • +
+ + +
+ +
+ +
+ getCreateDocuments (line 477) +
+ + +

Get the current state of teh create documents flag.

+
    +
  • access: public
  • +
+ +
+ boolean + + getCreateDocuments + + () +
+ + + +
+ +
+ +
+ optimize (line 855) +
+ + +

Send an optimize command. Will be synchronous unless both wait parameters are set to false.

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + optimize + + ([boolean $waitFlush = true], [boolean $waitSearcher = true], [float $timeout = 3600]) +
+ +
    +
  • + boolean + $waitFlush
  • +
  • + boolean + $waitSearcher
  • +
  • + float + $timeout: Maximum expected duration of the optimize operation on the server (otherwise, will throw a communication exception)
  • +
+ + +
+ +
+ +
+ removeReadService (line 202) +
+ + +

Removes a service instance or descriptor from the available services

+
    +
  • throws: Apache_Solr_InvalidArgumentException If service descriptor is not valid
  • +
  • access: public
  • +
+ +
+ void + + removeReadService + + (mixed $service) +
+ +
    +
  • + mixed + $service
  • +
+ + +
+ +
+ +
+ removeWriteService (line 270) +
+ + +

Removes a service instance or descriptor from the available services

+
    +
  • throws: Apache_Solr_InvalidArgumentException If service descriptor is not valid
  • +
  • access: public
  • +
+ +
+ void + + removeWriteService + + (mixed $service) +
+ +
    +
  • + mixed + $service
  • +
+ + +
+ +
+ +
+ search (line 891) +
+ + +

Simple Search interface

+
    +
  • throws: Apache_Solr_HttpTransportException If an error occurs during the service call
  • +
  • access: public
  • +
+ +
+ Apache_Solr_Response + + search + + (string $query, [int $offset = 0], [int $limit = 10], [array $params = array()], [string $method = Apache_Solr_Service::METHOD_GET]) +
+ +
    +
  • + string + $query: The raw query string
  • +
  • + int + $offset: The starting offset for result documents
  • +
  • + int + $limit: The maximum number of result documents to return
  • +
  • + array + $params: key / value pairs for query parameters, use arrays for multivalued parameters
  • +
  • + string + $method: The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
  • +
+ + +
+ +
+ +
+ setCreateDocuments (line 460) +
+ + +

Set the create documents flag. This determines whether Apache_Solr_Response objects will parse the response and create Apache_Solr_Document instances in place.

+
    +
  • access: public
  • +
+ +
+ void + + setCreateDocuments + + (boolean $createDocuments) +
+ +
    +
  • + boolean + $createDocuments
  • +
+ + +
+ +
+ +
+ setReadPingTimeout (line 136) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + setReadPingTimeout + + ( $timeout) +
+ +
    +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ setUseBackoff (line 146) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + setUseBackoff + + ( $enable) +
+ +
    +
  • + + $enable
  • +
+ + +
+ +
+ +
+ setWritePingTimeout (line 141) +
+ + +
    +
  • access: public
  • +
+ +
+ void + + setWritePingTimeout + + ( $timeout) +
+ +
    +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ _getServiceId (line 159) +
+ + +

Generates a service ID

+
    +
  • access: protected
  • +
+ +
+ string + + _getServiceId + + (string $host, integer $port, string $path) +
+ +
    +
  • + string + $host
  • +
  • + integer + $port
  • +
  • + string + $path
  • +
+ + +
+ +
+ +
+ _selectReadService (line 308) +
+ + +

Iterate through available read services and select the first with a ping that satisfies configured timeout restrictions (or the default)

+
    +
  • throws: Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
  • +
  • access: protected
  • +
+ +
+ Apache_Solr_Service + + _selectReadService + + ([ $forceSelect = false]) +
+ +
    +
  • + + $forceSelect
  • +
+ + +
+ +
+ +
+ _selectWriteService (line 356) +
+ + +

Iterate through available write services and select the first with a ping that satisfies configured timeout restrictions (or the default)

+
    +
  • throws: Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
  • +
  • access: protected
  • +
+ +
+ Apache_Solr_Service + + _selectWriteService + + ([ $forceSelect = false]) +
+ +
    +
  • + + $forceSelect
  • +
+ + +
+ +
+ +
+ _selectWriteServiceSafe (line 412) +
+ + +

Iterate through available write services and select the first with a ping

+

that satisfies configured timeout restrictions (or the default). The timeout period will increase until a connection is made or the limit is reached. This will allow for increased reliability with heavily loaded server(s).

+
    +
  • throws: Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
  • +
  • access: protected
  • +
+ +
+ Apache_Solr_Service + + _selectWriteServiceSafe + + ([ $forceSelect = false]) +
+ +
    +
  • + + $forceSelect
  • +
+ + +
+ +
+
+ + +
+
Class Constants
+ +
+ +
+ +
+ + + SVN_ID + = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $' + (line 61) + +
+ + +

SVN ID meta data for this class

+ + +
+ +
+ +
+ + + SVN_REVISION + = '$Revision: 54 $' + (line 56) + +
+ + +

SVN Revision meta data for this class

+ + +
+ +
+
+ +

+ Documentation generated on Wed, 04 May 2011 11:01:10 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_Document.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_Document.php.html new file mode 100644 index 00000000..30b56248 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_Document.php.html @@ -0,0 +1,74 @@ + + + + + + Docs for page Document.php + + + + +
+

/Document.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_Document + + Holds Key / Value pairs that represent a Solr Document along with any associated boost values. Field values can be accessed by direct dereferencing such as: +
+
+
+ + + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:13 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_Exception.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_Exception.php.html new file mode 100644 index 00000000..c6cef5e8 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_Exception.php.html @@ -0,0 +1,63 @@ + + + + + + Docs for page Exception.php + + + + +
+

/Exception.php

+ + +
+
Description
+ +
+ + + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_Exception + + Copyright (c) 2007-2011, Servigistics, Inc. +
+
+
+ + + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:13 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Abstract.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Abstract.php.html new file mode 100644 index 00000000..ae504ef7 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Abstract.php.html @@ -0,0 +1,74 @@ + + + + + + Docs for page Abstract.php + + + + +
+

/HttpTransport/Abstract.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_HttpTransport_Abstract + + Convenience class that implements the transport implementation. Can be extended by +
+
+
+ + + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:08 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Curl.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Curl.php.html new file mode 100644 index 00000000..49662ace --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Curl.php.html @@ -0,0 +1,101 @@ + + + + + + Docs for page Curl.php + + + + +
+

/HttpTransport/Curl.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_HttpTransport_Curl + + A Curl based HTTP transport. Uses a single curl session for all requests. +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/Abstract.php') + (line 40) + +
+ + + +
+
+
+ + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:11 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---CurlNoReuse.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---CurlNoReuse.php.html new file mode 100644 index 00000000..1c2eab39 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---CurlNoReuse.php.html @@ -0,0 +1,101 @@ + + + + + + Docs for page CurlNoReuse.php + + + + +
+

/HttpTransport/CurlNoReuse.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_HttpTransport_CurlNoReuse + + An alternative Curl HTTP transport that opens and closes a curl session for every request. This isn't the recommended way to use curl, but some version of PHP have memory issues. +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/Abstract.php') + (line 40) + +
+ + + +
+
+
+ + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:12 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---FileGetContents.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---FileGetContents.php.html new file mode 100644 index 00000000..02984e62 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---FileGetContents.php.html @@ -0,0 +1,101 @@ + + + + + + Docs for page FileGetContents.php + + + + +
+

/HttpTransport/FileGetContents.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_HttpTransport_FileGetContents + + HTTP Transport implemenation that uses the builtin http URL wrappers and file_get_contents +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/Abstract.php') + (line 40) + +
+ + + +
+
+
+ + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:13 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Interface.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Interface.php.html new file mode 100644 index 00000000..a4d9965a --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Interface.php.html @@ -0,0 +1,101 @@ + + + + + + Docs for page Interface.php + + + + +
+

/HttpTransport/Interface.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_HttpTransport_Interface + + Interface that all Transport (HTTP Requester) implementations must implement. These +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/Response.php') + (line 40) + +
+ + + +
+
+
+ + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:14 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Response.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Response.php.html new file mode 100644 index 00000000..f12a5804 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransport---Response.php.html @@ -0,0 +1,74 @@ + + + + + + Docs for page Response.php + + + + +
+

/HttpTransport/Response.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_HttpTransport_Response + + Represents the required pieces of an HTTP response provided by HTTP transport +
+
+
+ + + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransportException.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransportException.php.html new file mode 100644 index 00000000..03f7d50f --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_HttpTransportException.php.html @@ -0,0 +1,63 @@ + + + + + + Docs for page HttpTransportException.php + + + + +
+

/HttpTransportException.php

+ + +
+
Description
+ +
+ + + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_HttpTransportException + + Copyright (c) 2007-2011, Servigistics, Inc. +
+
+
+ + + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:14 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_InvalidArgumentException.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_InvalidArgumentException.php.html new file mode 100644 index 00000000..fdb0c671 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_InvalidArgumentException.php.html @@ -0,0 +1,63 @@ + + + + + + Docs for page InvalidArgumentException.php + + + + +
+

/InvalidArgumentException.php

+ + +
+
Description
+ +
+ + + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_InvalidArgumentException + + Copyright (c) 2007-2011, Servigistics, Inc. +
+
+
+ + + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_NoServiceAvailableException.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_NoServiceAvailableException.php.html new file mode 100644 index 00000000..00d4b4e0 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_NoServiceAvailableException.php.html @@ -0,0 +1,63 @@ + + + + + + Docs for page NoServiceAvailableException.php + + + + +
+

/NoServiceAvailableException.php

+ + +
+
Description
+ +
+ + + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_NoServiceAvailableException + + Copyright (c) 2007-2011, Servigistics, Inc. +
+
+
+ + + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_ParserException.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_ParserException.php.html new file mode 100644 index 00000000..8a69171e --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_ParserException.php.html @@ -0,0 +1,63 @@ + + + + + + Docs for page ParserException.php + + + + +
+

/ParserException.php

+ + +
+
Description
+ +
+ + + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_ParserException + + Copyright (c) 2007-2011, Servigistics, Inc. +
+
+
+ + + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_Response.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_Response.php.html new file mode 100644 index 00000000..3093bbac --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_Response.php.html @@ -0,0 +1,101 @@ + + + + + + Docs for page Response.php + + + + +
+

/Response.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_Response + + Represents a Solr response. Parses the raw response into a set of stdClass objects and associative arrays for easy access. +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/ParserException.php') + (line 39) + +
+ + + +
+
+
+ + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_Service---Balancer.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_Service---Balancer.php.html new file mode 100644 index 00000000..9aaffbfb --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_Service---Balancer.php.html @@ -0,0 +1,115 @@ + + + + + + Docs for page Balancer.php + + + + +
+

/Service/Balancer.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_Service_Balancer + + Reference Implementation for using multiple Solr services in a distribution. Functionality +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+ + require_once + (dirname(dirname(__FILE__)).'/Service.php') + (line 41) + +
+ + + +
+ +
+ +
+ + require_once + (dirname(dirname(__FILE__)).'/NoServiceAvailableException.php') + (line 43) + +
+ + + +
+
+
+ + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:08 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/Apache/Solr/_Service.php.html b/SolrPhpClient/phpdocs/Apache/Solr/_Service.php.html new file mode 100644 index 00000000..39725a04 --- /dev/null +++ b/SolrPhpClient/phpdocs/Apache/Solr/_Service.php.html @@ -0,0 +1,171 @@ + + + + + + Docs for page Service.php + + + + +
+

/Service.php

+ + +
+
Description
+ +
+ +

Copyright (c) 2007-2011, Servigistics, Inc.

+

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution.
  • Neither the name of Servigistics, Inc. nor the names of + its contributors may be used to endorse or promote products derived from + this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+ Apache_Solr_Service + + Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching. +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/HttpTransportException.php') + (line 42) + +
+ + + +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/Exception.php') + (line 41) + +
+ + + +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/InvalidArgumentException.php') + (line 43) + +
+ + + +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/Document.php') + (line 45) + +
+ + + +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/HttpTransport/Interface.php') + (line 48) + +
+ + + +
+ +
+ +
+ + require_once + (dirname(__FILE__).'/Response.php') + (line 46) + +
+ + + +
+
+
+ + + + +

+ Documentation generated on Wed, 04 May 2011 11:01:16 -0400 by phpDocumentor 1.4.3 +

+
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Document.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Document.php.html new file mode 100644 index 00000000..fac94127 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Document.php.html @@ -0,0 +1,387 @@ + + + + + + File Source for Document.php + + + + +

Source for file Document.php

+

Documentation is available at Document.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: Document.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. /**
  78. +
  79.  * Holds Key / Value pairs that represent a Solr Document along with any associated boost
  80. +
  81.  * values. Field values can be accessed by direct dereferencing such as:
  82. +
  83.  * <code>
  84. +
  85.  * ...
  86. +
  87.  * $document->title = 'Something';
  88. +
  89.  * echo $document->title;
  90. +
  91.  * ...
  92. +
  93.  * </code>
  94. +
  95.  *
  96. +
  97.  * Additionally, the field values can be iterated with foreach
  98. +
  99.  *
  100. +
  101.  * <code>
  102. +
  103.  * foreach ($document as $fieldName => $fieldValue)
  104. +
  105.  * {
  106. +
  107.  * ...
  108. +
  109.  * }
  110. +
  111.  * </code>
  112. +
  113.  */
  114. +
  115. class Apache_Solr_Document implements IteratorAggregate
  116. +
  117. {
  118. +
  119.     /**
  120. +
  121.      * SVN Revision meta data for this class
  122. +
  123.      */
  124. +
  125.     const SVN_REVISION '$Revision: 54 $';
  126. +
  127.  
  128. +
  129.     /**
  130. +
  131.      * SVN ID meta data for this class
  132. +
  133.      */
  134. +
  135.     const SVN_ID '$Id: Document.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
  136. +
  137.  
  138. +
  139.     /**
  140. +
  141.      * Document boost value
  142. +
  143.      *
  144. +
  145.      * @var float 
  146. +
  147.      */
  148. +
  149.     protected $_documentBoost = false;
  150. +
  151.  
  152. +
  153.     /**
  154. +
  155.      * Document field values, indexed by name
  156. +
  157.      *
  158. +
  159.      * @var array 
  160. +
  161.      */
  162. +
  163.     protected $_fields = array();
  164. +
  165.  
  166. +
  167.     /**
  168. +
  169.      * Document field boost values, indexed by name
  170. +
  171.      *
  172. +
  173.      * @var array array of floats
  174. +
  175.      */
  176. +
  177.     protected $_fieldBoosts = array();
  178. +
  179.  
  180. +
  181.     /**
  182. +
  183.      * Clear all boosts and fields from this document
  184. +
  185.      */
  186. +
  187.     public function clear()
  188. +
  189.     {
  190. +
  191.         $this->_documentBoost = false;
  192. +
  193.  
  194. +
  195.         $this->_fields = array();
  196. +
  197.         $this->_fieldBoosts = array();
  198. +
  199.     }
  200. +
  201.  
  202. +
  203.     /**
  204. +
  205.      * Get current document boost
  206. +
  207.      *
  208. +
  209.      * @return mixed will be false for default, or else a float
  210. +
  211.      */
  212. +
  213.     public function getBoost()
  214. +
  215.     {
  216. +
  217.         return $this->_documentBoost;
  218. +
  219.     }
  220. +
  221.  
  222. +
  223.     /**
  224. +
  225.      * Set document boost factor
  226. +
  227.      *
  228. +
  229.      * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
  230. +
  231.      */
  232. +
  233.     public function setBoost($boost)
  234. +
  235.     {
  236. +
  237.         $boost = (float) $boost;
  238. +
  239.  
  240. +
  241.         if ($boost 0.0)
  242. +
  243.         {
  244. +
  245.             $this->_documentBoost = $boost;
  246. +
  247.         }
  248. +
  249.         else
  250. +
  251.         {
  252. +
  253.             $this->_documentBoost = false;
  254. +
  255.         }
  256. +
  257.     }
  258. +
  259.  
  260. +
  261.     /**
  262. +
  263.      * Add a value to a multi-valued field
  264. +
  265.      *
  266. +
  267.      * NOTE: the solr XML format allows you to specify boosts
  268. +
  269.      * PER value even though the underlying Lucene implementation
  270. +
  271.      * only allows a boost per field. To remedy this, the final
  272. +
  273.      * field boost value will be the product of all specified boosts
  274. +
  275.      * on field values - this is similar to SolrJ's functionality.
  276. +
  277.      *
  278. +
  279.      * <code>
  280. +
  281.      * $doc = new Apache_Solr_Document();
  282. +
  283.      *
  284. +
  285.      * $doc->addField('foo', 'bar', 2.0);
  286. +
  287.      * $doc->addField('foo', 'baz', 3.0);
  288. +
  289.      *
  290. +
  291.      * // resultant field boost will be 6!
  292. +
  293.      * echo $doc->getFieldBoost('foo');
  294. +
  295.      * </code>
  296. +
  297.      *
  298. +
  299.      * @param string $key 
  300. +
  301.      * @param mixed $value 
  302. +
  303.      * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
  304. +
  305.      */
  306. +
  307.     public function addField($key$value$boost false)
  308. +
  309.     {
  310. +
  311.         if (!isset($this->_fields[$key]))
  312. +
  313.         {
  314. +
  315.             // create holding array if this is the first value
  316. +
  317.             $this->_fields[$keyarray();
  318. +
  319.         }
  320. +
  321.         else if (!is_array($this->_fields[$key]))
  322. +
  323.         {
  324. +
  325.             // move existing value into array if it is not already an array
  326. +
  327.             $this->_fields[$keyarray($this->_fields[$key]);
  328. +
  329.         }
  330. +
  331.  
  332. +
  333.         if ($this->getFieldBoost($key=== false)
  334. +
  335.         {
  336. +
  337.             // boost not already set, set it now
  338. +
  339.             $this->setFieldBoost($key$boost);
  340. +
  341.         }
  342. +
  343.         else if ((float) $boost 0.0)
  344. +
  345.         {
  346. +
  347.             // multiply passed boost with current field boost - similar to SolrJ implementation
  348. +
  349.             $this->_fieldBoosts[$key*= (float) $boost;
  350. +
  351.         }
  352. +
  353.  
  354. +
  355.         // add value to array
  356. +
  357.         $this->_fields[$key][$value;
  358. +
  359.     }
  360. +
  361.  
  362. +
  363.     /**
  364. +
  365.      * Handle the array manipulation for a multi-valued field
  366. +
  367.      *
  368. +
  369.      * @param string $key 
  370. +
  371.      * @param string $value 
  372. +
  373.      * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
  374. +
  375.      *
  376. +
  377.      * @deprecated Use addField(...) instead
  378. +
  379.      */
  380. +
  381.     public function setMultiValue($key$value$boost false)
  382. +
  383.     {
  384. +
  385.         $this->addField($key$value$boost);
  386. +
  387.     }
  388. +
  389.  
  390. +
  391.     /**
  392. +
  393.      * Get field information
  394. +
  395.      *
  396. +
  397.      * @param string $key 
  398. +
  399.      * @return mixed associative array of info if field exists, false otherwise
  400. +
  401.      */
  402. +
  403.     public function getField($key)
  404. +
  405.     {
  406. +
  407.         if (isset($this->_fields[$key]))
  408. +
  409.         {
  410. +
  411.             return array(
  412. +
  413.                 'name' => $key,
  414. +
  415.                 'value' => $this->_fields[$key],
  416. +
  417.                 'boost' => $this->getFieldBoost($key)
  418. +
  419.             );
  420. +
  421.         }
  422. +
  423.  
  424. +
  425.         return false;
  426. +
  427.     }
  428. +
  429.  
  430. +
  431.     /**
  432. +
  433.      * Set a field value. Multi-valued fields should be set as arrays
  434. +
  435.      * or instead use the addField(...) function which will automatically
  436. +
  437.      * make sure the field is an array.
  438. +
  439.      *
  440. +
  441.      * @param string $key 
  442. +
  443.      * @param mixed $value 
  444. +
  445.      * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
  446. +
  447.      */
  448. +
  449.     public function setField($key$value$boost false)
  450. +
  451.     {
  452. +
  453.         $this->_fields[$key$value;
  454. +
  455.         $this->setFieldBoost($key$boost);
  456. +
  457.     }
  458. +
  459.  
  460. +
  461.     /**
  462. +
  463.      * Get the currently set field boost for a document field
  464. +
  465.      *
  466. +
  467.      * @param string $key 
  468. +
  469.      * @return float currently set field boost, false if one is not set
  470. +
  471.      */
  472. +
  473.     public function getFieldBoost($key)
  474. +
  475.     {
  476. +
  477.         return isset($this->_fieldBoosts[$key]$this->_fieldBoosts[$keyfalse;
  478. +
  479.     }
  480. +
  481.  
  482. +
  483.     /**
  484. +
  485.      * Set the field boost for a document field
  486. +
  487.      *
  488. +
  489.      * @param string $key field name for the boost
  490. +
  491.      * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
  492. +
  493.      */
  494. +
  495.     public function setFieldBoost($key$boost)
  496. +
  497.     {
  498. +
  499.         $boost = (float) $boost;
  500. +
  501.  
  502. +
  503.         if ($boost 0.0)
  504. +
  505.         {
  506. +
  507.             $this->_fieldBoosts[$key$boost;
  508. +
  509.         }
  510. +
  511.         else
  512. +
  513.         {
  514. +
  515.             $this->_fieldBoosts[$keyfalse;
  516. +
  517.         }
  518. +
  519.     }
  520. +
  521.  
  522. +
  523.     /**
  524. +
  525.      * Return current field boosts, indexed by field name
  526. +
  527.      *
  528. +
  529.      * @return array 
  530. +
  531.      */
  532. +
  533.     public function getFieldBoosts()
  534. +
  535.     {
  536. +
  537.         return $this->_fieldBoosts;
  538. +
  539.     }
  540. +
  541.  
  542. +
  543.     /**
  544. +
  545.      * Get the names of all fields in this document
  546. +
  547.      *
  548. +
  549.      * @return array 
  550. +
  551.      */
  552. +
  553.     public function getFieldNames()
  554. +
  555.     {
  556. +
  557.         return array_keys($this->_fields);
  558. +
  559.     }
  560. +
  561.  
  562. +
  563.     /**
  564. +
  565.      * Get the values of all fields in this document
  566. +
  567.      *
  568. +
  569.      * @return array 
  570. +
  571.      */
  572. +
  573.     public function getFieldValues()
  574. +
  575.     {
  576. +
  577.         return array_values($this->_fields);
  578. +
  579.     }
  580. +
  581.  
  582. +
  583.     /**
  584. +
  585.      * IteratorAggregate implementation function. Allows usage:
  586. +
  587.      *
  588. +
  589.      * <code>
  590. +
  591.      * foreach ($document as $key => $value)
  592. +
  593.      * {
  594. +
  595.      *     ...
  596. +
  597.      * }
  598. +
  599.      * </code>
  600. +
  601.      */
  602. +
  603.     public function getIterator()
  604. +
  605.     {
  606. +
  607.         $arrayObject new ArrayObject($this->_fields);
  608. +
  609.  
  610. +
  611.         return $arrayObject->getIterator();
  612. +
  613.     }
  614. +
  615.  
  616. +
  617.     /**
  618. +
  619.      * Magic get for field values
  620. +
  621.      *
  622. +
  623.      * @param string $key 
  624. +
  625.      * @return mixed 
  626. +
  627.      */
  628. +
  629.     public function __get($key)
  630. +
  631.     {
  632. +
  633.         if (isset($this->_fields[$key]))
  634. +
  635.         {
  636. +
  637.             return $this->_fields[$key];
  638. +
  639.         }
  640. +
  641.         
  642. +
  643.         return null;
  644. +
  645.     }
  646. +
  647.  
  648. +
  649.     /**
  650. +
  651.      * Magic set for field values. Multi-valued fields should be set as arrays
  652. +
  653.      * or instead use the addField(...) function which will automatically
  654. +
  655.      * make sure the field is an array.
  656. +
  657.      *
  658. +
  659.      * @param string $key 
  660. +
  661.      * @param mixed $value 
  662. +
  663.      */
  664. +
  665.     public function __set($key$value)
  666. +
  667.     {
  668. +
  669.         $this->setField($key$value);
  670. +
  671.     }
  672. +
  673.  
  674. +
  675.     /**
  676. +
  677.      * Magic isset for fields values.  Do not call directly. Allows usage:
  678. +
  679.      *
  680. +
  681.      * <code>
  682. +
  683.      * isset($document->some_field);
  684. +
  685.      * </code>
  686. +
  687.      *
  688. +
  689.      * @param string $key 
  690. +
  691.      * @return boolean 
  692. +
  693.      */
  694. +
  695.     public function __isset($key)
  696. +
  697.     {
  698. +
  699.         return isset($this->_fields[$key]);
  700. +
  701.     }
  702. +
  703.  
  704. +
  705.     /**
  706. +
  707.      * Magic unset for field values. Do not call directly. Allows usage:
  708. +
  709.      *
  710. +
  711.      * <code>
  712. +
  713.      * unset($document->some_field);
  714. +
  715.      * </code>
  716. +
  717.      *
  718. +
  719.      * @param string $key 
  720. +
  721.      */
  722. +
  723.     public function __unset($key)
  724. +
  725.     {
  726. +
  727.         unset($this->_fields[$key]);
  728. +
  729.         unset($this->_fieldBoosts[$key]);
  730. +
  731.     }
  732. +
  733. }
  734. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:13 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Exception.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Exception.php.html new file mode 100644 index 00000000..956888b3 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Exception.php.html @@ -0,0 +1,70 @@ + + + + + + File Source for Exception.php + + + + +

Source for file Exception.php

+

Documentation is available at Exception.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: Exception.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. class Apache_Solr_Exception extends Exception
  78. +
  79. {
  80. +
  81.     /**
  82. +
  83.      * SVN Revision meta data for this class
  84. +
  85.      */
  86. +
  87.     const SVN_REVISION = '$Revision: 54 $';
  88. +
  89.  
  90. +
  91.     /**
  92. +
  93.      * SVN ID meta data for this class
  94. +
  95.      */
  96. +
  97.     const SVN_ID = '$Id: Exception.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
  98. +
  99. }
  100. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:13 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportAbstract.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportAbstract.php.html new file mode 100644 index 00000000..0641914c --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportAbstract.php.html @@ -0,0 +1,109 @@ + + + + + + File Source for Abstract.php + + + + +

Source for file Abstract.php

+

Documentation is available at Abstract.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Timo Schmidt <timo.schmidt@aoemedia.de>, Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. /**
  78. +
  79.  * Convenience class that implements the transport implementation. Can be extended by
  80. +
  81.  * real implementations to do some of the common book keeping
  82. +
  83.  */
  84. +
  85. abstract class Apache_Solr_HttpTransport_Abstract implements Apache_Solr_HttpTransport_Interface
  86. +
  87. {    
  88. +
  89.     /**
  90. +
  91.      * Our default timeout value for requests that don't specify a timeout
  92. +
  93.      *
  94. +
  95.      * @var float 
  96. +
  97.      */
  98. +
  99.     private $_defaultTimeout false;
  100. +
  101.         
  102. +
  103.     /**
  104. +
  105.      * Get the current default timeout setting (initially the default_socket_timeout ini setting)
  106. +
  107.      * in seconds
  108. +
  109.      *
  110. +
  111.      * @return float 
  112. +
  113.      */
  114. +
  115.     public function getDefaultTimeout()
  116. +
  117.     {
  118. +
  119.         // lazy load the default timeout from the ini settings
  120. +
  121.         if ($this->_defaultTimeout === false)
  122. +
  123.         {
  124. +
  125.             $this->_defaultTimeout = (int) ini_get('default_socket_timeout');
  126. +
  127.  
  128. +
  129.             // double check we didn't get 0 for a timeout
  130. +
  131.             if ($this->_defaultTimeout <= 0)
  132. +
  133.             {
  134. +
  135.                 $this->_defaultTimeout 60;
  136. +
  137.             }
  138. +
  139.         }
  140. +
  141.         
  142. +
  143.         return $this->_defaultTimeout;
  144. +
  145.     }
  146. +
  147.     
  148. +
  149.     /**
  150. +
  151.      * Set the current default timeout for all HTTP requests
  152. +
  153.      *
  154. +
  155.      * @param float $timeout 
  156. +
  157.      */
  158. +
  159.     public function setDefaultTimeout($timeout)
  160. +
  161.     {
  162. +
  163.         $timeout = (float) $timeout;
  164. +
  165.         
  166. +
  167.         if ($timeout >= 0)
  168. +
  169.         {
  170. +
  171.             $this->_defaultTimeout $timeout;
  172. +
  173.         }
  174. +
  175.     }    
  176. +
  177. }
  178. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:08 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportCurl.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportCurl.php.html new file mode 100644 index 00000000..c2489794 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportCurl.php.html @@ -0,0 +1,218 @@ + + + + + + File Source for Curl.php + + + + +

Source for file Curl.php

+

Documentation is available at Curl.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Timo Schmidt <timo.schmidt@aoemedia.de>, Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. // Require Apache_Solr_HttpTransport_Abstract
  78. +
  79. require_once(dirname(__FILE__'/Abstract.php');
  80. +
  81.  
  82. +
  83. /**
  84. +
  85.  * A Curl based HTTP transport. Uses a single curl session for all requests.
  86. +
  87.  */
  88. +
  89. +
  90. {
  91. +
  92.     /**
  93. +
  94.      * SVN Revision meta data for this class
  95. +
  96.      */
  97. +
  98.     const SVN_REVISION = '$Revision:$';
  99. +
  100.  
  101. +
  102.     /**
  103. +
  104.      * SVN ID meta data for this class
  105. +
  106.      */
  107. +
  108.     const SVN_ID = '$Id:$';
  109. +
  110.  
  111. +
  112.     /**
  113. +
  114.      * Curl Session Handle
  115. +
  116.      *
  117. +
  118.      * @var resource 
  119. +
  120.      */
  121. +
  122.     private $_curl;
  123. +
  124.  
  125. +
  126.     /**
  127. +
  128.      * Initializes a curl session
  129. +
  130.      */
  131. +
  132.     public function __construct()
  133. +
  134.     {
  135. +
  136.         // initialize a CURL session
  137. +
  138.         $this->_curl curl_init();
  139. +
  140.  
  141. +
  142.         // set common options that will not be changed during the session
  143. +
  144.         curl_setopt_array($this->_curlarray(
  145. +
  146.             // return the response body from curl_exec
  147. +
  148.             CURLOPT_RETURNTRANSFER => true,
  149. +
  150.  
  151. +
  152.             // get the output as binary data
  153. +
  154.             CURLOPT_BINARYTRANSFER => true,
  155. +
  156.  
  157. +
  158.             // we do not need the headers in the output, we get everything we need from curl_getinfo
  159. +
  160.             CURLOPT_HEADER => false
  161. +
  162.         ));
  163. +
  164.     }
  165. +
  166.  
  167. +
  168.     /**
  169. +
  170.      * Closes a curl session
  171. +
  172.      */
  173. +
  174.     function __destruct()
  175. +
  176.     {
  177. +
  178.         // close our curl session
  179. +
  180.         curl_close($this->_curl);
  181. +
  182.     }
  183. +
  184.  
  185. +
  186.     public function performGetRequest($url$timeout false)
  187. +
  188.     {
  189. +
  190.         // check the timeout value
  191. +
  192.         if ($timeout === false || $timeout <= 0.0)
  193. +
  194.         {
  195. +
  196.             // use the default timeout
  197. +
  198.             $timeout $this->getDefaultTimeout();
  199. +
  200.         }
  201. +
  202.  
  203. +
  204.         // set curl GET options
  205. +
  206.         curl_setopt_array($this->_curlarray(
  207. +
  208.             // make sure we're returning the body
  209. +
  210.             CURLOPT_NOBODY => false,
  211. +
  212.  
  213. +
  214.             // make sure we're GET
  215. +
  216.             CURLOPT_HTTPGET => true,
  217. +
  218.  
  219. +
  220.             // set the URL
  221. +
  222.             CURLOPT_URL => $url,
  223. +
  224.  
  225. +
  226.             // set the timeout
  227. +
  228.             CURLOPT_TIMEOUT => $timeout
  229. +
  230.         ));
  231. +
  232.  
  233. +
  234.         // make the request
  235. +
  236.         $responseBody curl_exec($this->_curl);
  237. +
  238.  
  239. +
  240.         // get info from the transfer
  241. +
  242.         $statusCode curl_getinfo($this->_curlCURLINFO_HTTP_CODE);
  243. +
  244.         $contentType curl_getinfo($this->_curlCURLINFO_CONTENT_TYPE);
  245. +
  246.  
  247. +
  248.         return new Apache_Solr_HttpTransport_Response($statusCode$contentType$responseBody);
  249. +
  250.     }
  251. +
  252.  
  253. +
  254.     public function performHeadRequest($url$timeout false)
  255. +
  256.     {
  257. +
  258.         // check the timeout value
  259. +
  260.         if ($timeout === false || $timeout <= 0.0)
  261. +
  262.         {
  263. +
  264.             // use the default timeout
  265. +
  266.             $timeout $this->getDefaultTimeout();
  267. +
  268.         }
  269. +
  270.  
  271. +
  272.         // set curl HEAD options
  273. +
  274.         curl_setopt_array($this->_curlarray(
  275. +
  276.             // this both sets the method to HEAD and says not to return a body
  277. +
  278.             CURLOPT_NOBODY => true,
  279. +
  280.  
  281. +
  282.             // set the URL
  283. +
  284.             CURLOPT_URL => $url,
  285. +
  286.  
  287. +
  288.             // set the timeout
  289. +
  290.             CURLOPT_TIMEOUT => $timeout
  291. +
  292.         ));
  293. +
  294.  
  295. +
  296.         // make the request
  297. +
  298.         $responseBody curl_exec($this->_curl);
  299. +
  300.  
  301. +
  302.         // get info from the transfer
  303. +
  304.         $statusCode curl_getinfo($this->_curlCURLINFO_HTTP_CODE);
  305. +
  306.         $contentType curl_getinfo($this->_curlCURLINFO_CONTENT_TYPE);
  307. +
  308.  
  309. +
  310.         return new Apache_Solr_HttpTransport_Response($statusCode$contentType$responseBody);
  311. +
  312.     }
  313. +
  314.  
  315. +
  316.     public function performPostRequest($url$postData$contentType$timeout false)
  317. +
  318.     {
  319. +
  320.         // check the timeout value
  321. +
  322.         if ($timeout === false || $timeout <= 0.0)
  323. +
  324.         {
  325. +
  326.             // use the default timeout
  327. +
  328.             $timeout $this->getDefaultTimeout();
  329. +
  330.         }
  331. +
  332.  
  333. +
  334.         // set curl POST options
  335. +
  336.         curl_setopt_array($this->_curlarray(
  337. +
  338.             // make sure we're returning the body
  339. +
  340.             CURLOPT_NOBODY => false,
  341. +
  342.  
  343. +
  344.             // make sure we're POST
  345. +
  346.             CURLOPT_POST => true,
  347. +
  348.  
  349. +
  350.             // set the URL
  351. +
  352.             CURLOPT_URL => $url,
  353. +
  354.  
  355. +
  356.             // set the post data
  357. +
  358.             CURLOPT_POSTFIELDS => $postData,
  359. +
  360.  
  361. +
  362.             // set the content type
  363. +
  364.             CURLOPT_HTTPHEADER => array("Content-Type: {$contentType}"),
  365. +
  366.  
  367. +
  368.             // set the timeout
  369. +
  370.             CURLOPT_TIMEOUT => $timeout
  371. +
  372.         ));
  373. +
  374.  
  375. +
  376.         // make the request
  377. +
  378.         $responseBody curl_exec($this->_curl);
  379. +
  380.  
  381. +
  382.         // get info from the transfer
  383. +
  384.         $statusCode curl_getinfo($this->_curlCURLINFO_HTTP_CODE);
  385. +
  386.         $contentType curl_getinfo($this->_curlCURLINFO_CONTENT_TYPE);
  387. +
  388.  
  389. +
  390.         return new Apache_Solr_HttpTransport_Response($statusCode$contentType$responseBody);
  391. +
  392.     }
  393. +
  394. }
  395. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:12 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportCurlNoReuse.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportCurlNoReuse.php.html new file mode 100644 index 00000000..1f772d65 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportCurlNoReuse.php.html @@ -0,0 +1,216 @@ + + + + + + File Source for CurlNoReuse.php + + + + +

Source for file CurlNoReuse.php

+

Documentation is available at CurlNoReuse.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Timo Schmidt <timo.schmidt@aoemedia.de>, Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. // Require Apache_Solr_HttpTransport_Abstract
  78. +
  79. require_once(dirname(__FILE__'/Abstract.php');
  80. +
  81.  
  82. +
  83. /**
  84. +
  85.  * An alternative Curl HTTP transport that opens and closes a curl session for
  86. +
  87.  * every request. This isn't the recommended way to use curl, but some version of
  88. +
  89.  * PHP have memory issues.
  90. +
  91.  */
  92. +
  93. +
  94. {
  95. +
  96.     /**
  97. +
  98.      * SVN Revision meta data for this class
  99. +
  100.      */
  101. +
  102.     const SVN_REVISION = '$Revision:$';
  103. +
  104.  
  105. +
  106.     /**
  107. +
  108.      * SVN ID meta data for this class
  109. +
  110.      */
  111. +
  112.     const SVN_ID = '$Id:$';
  113. +
  114.  
  115. +
  116.     public function performGetRequest($url$timeout false)
  117. +
  118.     {
  119. +
  120.         // check the timeout value
  121. +
  122.         if ($timeout === false || $timeout <= 0.0)
  123. +
  124.         {
  125. +
  126.             // use the default timeout
  127. +
  128.             $timeout $this->getDefaultTimeout();
  129. +
  130.         }
  131. +
  132.         
  133. +
  134.         $curl curl_init();
  135. +
  136.  
  137. +
  138.         // set curl GET options
  139. +
  140.         curl_setopt_array($curlarray(
  141. +
  142.             // return the response body from curl_exec
  143. +
  144.             CURLOPT_RETURNTRANSFER => true,
  145. +
  146.  
  147. +
  148.             // get the output as binary data
  149. +
  150.             CURLOPT_BINARYTRANSFER => true,
  151. +
  152.  
  153. +
  154.             // we do not need the headers in the output, we get everything we need from curl_getinfo
  155. +
  156.             CURLOPT_HEADER => false,
  157. +
  158.             
  159. +
  160.             // set the URL
  161. +
  162.             CURLOPT_URL => $url,
  163. +
  164.  
  165. +
  166.             // set the timeout
  167. +
  168.             CURLOPT_TIMEOUT => $timeout
  169. +
  170.         ));
  171. +
  172.  
  173. +
  174.         // make the request
  175. +
  176.         $responseBody curl_exec($curl);
  177. +
  178.  
  179. +
  180.         // get info from the transfer
  181. +
  182.         $statusCode curl_getinfo($curlCURLINFO_HTTP_CODE);
  183. +
  184.         $contentType curl_getinfo($curlCURLINFO_CONTENT_TYPE);
  185. +
  186.         
  187. +
  188.         // close our curl session - we're done with it
  189. +
  190.         curl_close($curl);
  191. +
  192.  
  193. +
  194.         return new Apache_Solr_HttpTransport_Response($statusCode$contentType$responseBody);
  195. +
  196.     }
  197. +
  198.  
  199. +
  200.     public function performHeadRequest($url$timeout false)
  201. +
  202.     {
  203. +
  204.         // check the timeout value
  205. +
  206.         if ($timeout === false || $timeout <= 0.0)
  207. +
  208.         {
  209. +
  210.             // use the default timeout
  211. +
  212.             $timeout $this->getDefaultTimeout();
  213. +
  214.         }
  215. +
  216.         
  217. +
  218.         $curl curl_init();
  219. +
  220.  
  221. +
  222.         // set curl HEAD options
  223. +
  224.         curl_setopt_array($curlarray(
  225. +
  226.             // return the response body from curl_exec
  227. +
  228.             CURLOPT_RETURNTRANSFER => true,
  229. +
  230.  
  231. +
  232.             // get the output as binary data
  233. +
  234.             CURLOPT_BINARYTRANSFER => true,
  235. +
  236.  
  237. +
  238.             // we do not need the headers in the output, we get everything we need from curl_getinfo
  239. +
  240.             CURLOPT_HEADER => false,
  241. +
  242.             
  243. +
  244.             // this both sets the method to HEAD and says not to return a body
  245. +
  246.             CURLOPT_NOBODY => true,
  247. +
  248.  
  249. +
  250.             // set the URL
  251. +
  252.             CURLOPT_URL => $url,
  253. +
  254.  
  255. +
  256.             // set the timeout
  257. +
  258.             CURLOPT_TIMEOUT => $timeout
  259. +
  260.         ));
  261. +
  262.  
  263. +
  264.         // make the request
  265. +
  266.         $responseBody curl_exec($curl);
  267. +
  268.  
  269. +
  270.         // get info from the transfer
  271. +
  272.         $statusCode curl_getinfo($curlCURLINFO_HTTP_CODE);
  273. +
  274.         $contentType curl_getinfo($curlCURLINFO_CONTENT_TYPE);
  275. +
  276.         
  277. +
  278.         // close our curl session - we're done with it
  279. +
  280.         curl_close($curl);
  281. +
  282.  
  283. +
  284.         return new Apache_Solr_HttpTransport_Response($statusCode$contentType$responseBody);
  285. +
  286.     }
  287. +
  288.  
  289. +
  290.     public function performPostRequest($url$postData$contentType$timeout false)
  291. +
  292.     {
  293. +
  294.         // check the timeout value
  295. +
  296.         if ($timeout === false || $timeout <= 0.0)
  297. +
  298.         {
  299. +
  300.             // use the default timeout
  301. +
  302.             $timeout $this->getDefaultTimeout();
  303. +
  304.         }
  305. +
  306.  
  307. +
  308.         $curl curl_init();
  309. +
  310.         
  311. +
  312.         // set curl POST options
  313. +
  314.         curl_setopt_array($curlarray(
  315. +
  316.             // return the response body from curl_exec
  317. +
  318.             CURLOPT_RETURNTRANSFER => true,
  319. +
  320.  
  321. +
  322.             // get the output as binary data
  323. +
  324.             CURLOPT_BINARYTRANSFER => true,
  325. +
  326.  
  327. +
  328.             // we do not need the headers in the output, we get everything we need from curl_getinfo
  329. +
  330.             CURLOPT_HEADER => false,
  331. +
  332.             
  333. +
  334.             // make sure we're POST
  335. +
  336.             CURLOPT_POST => true,
  337. +
  338.  
  339. +
  340.             // set the URL
  341. +
  342.             CURLOPT_URL => $url,
  343. +
  344.  
  345. +
  346.             // set the post data
  347. +
  348.             CURLOPT_POSTFIELDS => $postData,
  349. +
  350.  
  351. +
  352.             // set the content type
  353. +
  354.             CURLOPT_HTTPHEADER => array("Content-Type: {$contentType}"),
  355. +
  356.  
  357. +
  358.             // set the timeout
  359. +
  360.             CURLOPT_TIMEOUT => $timeout
  361. +
  362.         ));
  363. +
  364.  
  365. +
  366.         // make the request
  367. +
  368.         $responseBody curl_exec($curl);
  369. +
  370.  
  371. +
  372.         // get info from the transfer
  373. +
  374.         $statusCode curl_getinfo($curlCURLINFO_HTTP_CODE);
  375. +
  376.         $contentType curl_getinfo($curlCURLINFO_CONTENT_TYPE);
  377. +
  378.  
  379. +
  380.         // close our curl session - we're done with it
  381. +
  382.         curl_close($curl);
  383. +
  384.  
  385. +
  386.         return new Apache_Solr_HttpTransport_Response($statusCode$contentType$responseBody);
  387. +
  388.     }
  389. +
  390. }
  391. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:13 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportException.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportException.php.html new file mode 100644 index 00000000..b51a64f3 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportException.php.html @@ -0,0 +1,99 @@ + + + + + + File Source for HttpTransportException.php + + + + +

Source for file HttpTransportException.php

+

Documentation is available at HttpTransportException.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: HttpTransportException.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. +
  78. {
  79. +
  80.     /**
  81. +
  82.      * SVN Revision meta data for this class
  83. +
  84.      */
  85. +
  86.     const SVN_REVISION = '$Revision: 54 $';
  87. +
  88.  
  89. +
  90.     /**
  91. +
  92.      * SVN ID meta data for this class
  93. +
  94.      */
  95. +
  96.     const SVN_ID = '$Id: HttpTransportException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
  97. +
  98.  
  99. +
  100.     /**
  101. +
  102.      * Response for which exception was generated
  103. +
  104.      *
  105. +
  106.      * @var Apache_Solr_Response 
  107. +
  108.      */
  109. +
  110.     private $_response;
  111. +
  112.  
  113. +
  114.     /**
  115. +
  116.      * HttpTransportException Constructor
  117. +
  118.      *
  119. +
  120.      * @param Apache_Solr_Response $response 
  121. +
  122.      */
  123. +
  124.     public function __construct(Apache_Solr_Response $response)
  125. +
  126.     {
  127. +
  128.         parent::__construct("'{$response->getHttpStatus()}' Status: {$response->getHttpStatusMessage()}"$response->getHttpStatus());
  129. +
  130.  
  131. +
  132.         $this->_response $response;
  133. +
  134.     }
  135. +
  136.  
  137. +
  138.     /**
  139. +
  140.      * Get the response for which this exception was generated
  141. +
  142.      *
  143. +
  144.      * @return Apache_Solr_Response 
  145. +
  146.      */
  147. +
  148.     public function getResponse()
  149. +
  150.     {
  151. +
  152.         return $this->_response;
  153. +
  154.     }
  155. +
  156. }
  157. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:14 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportFileGetContents.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportFileGetContents.php.html new file mode 100644 index 00000000..1a005cd2 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportFileGetContents.php.html @@ -0,0 +1,236 @@ + + + + + + File Source for FileGetContents.php + + + + +

Source for file FileGetContents.php

+

Documentation is available at FileGetContents.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. // Require Apache_Solr_HttpTransport_Abstract
  78. +
  79. require_once(dirname(__FILE__'/Abstract.php');
  80. +
  81.  
  82. +
  83. /**
  84. +
  85.  * HTTP Transport implemenation that uses the builtin http URL wrappers and file_get_contents
  86. +
  87.  */
  88. +
  89. +
  90. {
  91. +
  92.     /**
  93. +
  94.      * SVN Revision meta data for this class
  95. +
  96.      */
  97. +
  98.     const SVN_REVISION = '$Revision:  $';
  99. +
  100.  
  101. +
  102.     /**
  103. +
  104.      * SVN ID meta data for this class
  105. +
  106.      */
  107. +
  108.     const SVN_ID = '$Id:  $';
  109. +
  110.         
  111. +
  112.     /**
  113. +
  114.      * Reusable stream context resources for GET and POST operations
  115. +
  116.      *
  117. +
  118.      * @var resource 
  119. +
  120.      */
  121. +
  122.     private $_getContext$_headContext$_postContext;
  123. +
  124.     
  125. +
  126.     /**
  127. +
  128.      * Initializes our reuseable get and post stream contexts
  129. +
  130.      */
  131. +
  132.     public function __construct()
  133. +
  134.     {
  135. +
  136.         $this->_getContext stream_context_create();
  137. +
  138.         $this->_headContext stream_context_create();
  139. +
  140.         $this->_postContext stream_context_create();
  141. +
  142.     }
  143. +
  144.  
  145. +
  146.     public function performGetRequest($url$timeout false)
  147. +
  148.     {
  149. +
  150.         // set the timeout if specified
  151. +
  152.         if ($timeout !== FALSE && $timeout 0.0)
  153. +
  154.         {
  155. +
  156.             // timeouts with file_get_contents seem to need
  157. +
  158.             // to be halved to work as expected
  159. +
  160.             $timeout = (float) $timeout 2;
  161. +
  162.  
  163. +
  164.             stream_context_set_option($this->_getContext'http''timeout'$timeout);
  165. +
  166.         }
  167. +
  168.         else
  169. +
  170.         {
  171. +
  172.             // use the default timeout pulled from default_socket_timeout otherwise
  173. +
  174.             stream_context_set_option($this->_getContext'http''timeout'$this->getDefaultTimeout());
  175. +
  176.         }
  177. +
  178.  
  179. +
  180.         // $http_response_headers will be updated by the call to file_get_contents later
  181. +
  182.         // see http://us.php.net/manual/en/wrappers.http.php for documentation
  183. +
  184.         // Unfortunately, it will still create a notice in analyzers if we don't set it here
  185. +
  186.         $http_response_header null;
  187. +
  188.         $responseBody @file_get_contents($urlfalse$this->_getContext);
  189. +
  190.         
  191. +
  192.         return $this->_getResponseFromParts($responseBody$http_response_header);
  193. +
  194.     }
  195. +
  196.  
  197. +
  198.     public function performHeadRequest($url$timeout false)
  199. +
  200.     {
  201. +
  202.         stream_context_set_option($this->_headContextarray(
  203. +
  204.                 'http' => array(
  205. +
  206.                     // set HTTP method
  207. +
  208.                     'method' => 'HEAD',
  209. +
  210.  
  211. +
  212.                     // default timeout
  213. +
  214.                     'timeout' => $this->getDefaultTimeout()
  215. +
  216.                 )
  217. +
  218.             )
  219. +
  220.         );
  221. +
  222.  
  223. +
  224.         // set the timeout if specified
  225. +
  226.         if ($timeout !== FALSE && $timeout 0.0)
  227. +
  228.         {
  229. +
  230.             // timeouts with file_get_contents seem to need
  231. +
  232.             // to be halved to work as expected
  233. +
  234.             $timeout = (float) $timeout 2;
  235. +
  236.  
  237. +
  238.             stream_context_set_option($this->_headContext'http''timeout'$timeout);
  239. +
  240.         }
  241. +
  242.         
  243. +
  244.         // $http_response_headers will be updated by the call to file_get_contents later
  245. +
  246.         // see http://us.php.net/manual/en/wrappers.http.php for documentation
  247. +
  248.         // Unfortunately, it will still create a notice in analyzers if we don't set it here
  249. +
  250.         $http_response_header null;
  251. +
  252.         $responseBody @file_get_contents($urlfalse$this->_headContext);
  253. +
  254.  
  255. +
  256.         return $this->_getResponseFromParts($responseBody$http_response_header);
  257. +
  258.     }
  259. +
  260.     
  261. +
  262.     public function performPostRequest($url$rawPost$contentType$timeout false)
  263. +
  264.     {
  265. +
  266.         stream_context_set_option($this->_postContextarray(
  267. +
  268.                 'http' => array(
  269. +
  270.                     // set HTTP method
  271. +
  272.                     'method' => 'POST',
  273. +
  274.  
  275. +
  276.                     // Add our posted content type
  277. +
  278.                     'header' => "Content-Type: $contentType",
  279. +
  280.  
  281. +
  282.                     // the posted content
  283. +
  284.                     'content' => $rawPost,
  285. +
  286.  
  287. +
  288.                     // default timeout
  289. +
  290.                     'timeout' => $this->getDefaultTimeout()
  291. +
  292.                 )
  293. +
  294.             )
  295. +
  296.         );
  297. +
  298.  
  299. +
  300.         // set the timeout if specified
  301. +
  302.         if ($timeout !== FALSE && $timeout 0.0)
  303. +
  304.         {
  305. +
  306.             // timeouts with file_get_contents seem to need
  307. +
  308.             // to be halved to work as expected
  309. +
  310.             $timeout = (float) $timeout 2;
  311. +
  312.  
  313. +
  314.             stream_context_set_option($this->_postContext'http''timeout'$timeout);
  315. +
  316.         }
  317. +
  318.  
  319. +
  320.         // $http_response_header will be updated by the call to file_get_contents later
  321. +
  322.         // see http://us.php.net/manual/en/wrappers.http.php for documentation
  323. +
  324.         // Unfortunately, it will still create a notice in analyzers if we don't set it here
  325. +
  326.         $http_response_header null;
  327. +
  328.         $responseBody @file_get_contents($urlfalse$this->_postContext);
  329. +
  330.         
  331. +
  332.         // reset content of post context to reclaim memory
  333. +
  334.         stream_context_set_option($this->_postContext'http''content''');
  335. +
  336.         
  337. +
  338.         return $this->_getResponseFromParts($responseBody$http_response_header);
  339. +
  340.     }
  341. +
  342.     
  343. +
  344.     private function _getResponseFromParts($rawResponse$httpHeaders)
  345. +
  346.     {
  347. +
  348.         //Assume 0, false as defaults
  349. +
  350.         $status 0;
  351. +
  352.         $contentType false;
  353. +
  354.  
  355. +
  356.         //iterate through headers for real status, type, and encoding
  357. +
  358.         if (is_array($httpHeaders&& count($httpHeaders0)
  359. +
  360.         {
  361. +
  362.             //look at the first headers for the HTTP status code
  363. +
  364.             //and message (errors are usually returned this way)
  365. +
  366.             //
  367. +
  368.             //HTTP 100 Continue response can also be returned before
  369. +
  370.             //the REAL status header, so we need look until we find
  371. +
  372.             //the last header starting with HTTP
  373. +
  374.             //
  375. +
  376.             //the spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1
  377. +
  378.             //
  379. +
  380.             //Thanks to Daniel Andersson for pointing out this oversight
  381. +
  382.             while (isset($httpHeaders[0]&& substr($httpHeaders[0]04== 'HTTP')
  383. +
  384.             {
  385. +
  386.                 // we can do a intval on status line without the "HTTP/1.X " to get the code
  387. +
  388.                 $status intval(substr($httpHeaders[0]9));
  389. +
  390.  
  391. +
  392.                 // remove this from the headers so we can check for more
  393. +
  394.                 array_shift($httpHeaders);
  395. +
  396.             }
  397. +
  398.  
  399. +
  400.             //Look for the Content-Type response header and determine type
  401. +
  402.             //and encoding from it (if possible - such as 'Content-Type: text/plain; charset=UTF-8')
  403. +
  404.             foreach ($httpHeaders as $header)
  405. +
  406.             {
  407. +
  408.                 // look for the header that starts appropriately
  409. +
  410.                 if (strncasecmp($header'Content-Type:'13== 0)
  411. +
  412.                 {
  413. +
  414.                     $contentType substr($header13);
  415. +
  416.                     break;
  417. +
  418.                 }
  419. +
  420.             }
  421. +
  422.         }
  423. +
  424.         
  425. +
  426.         return new Apache_Solr_HttpTransport_Response($status$contentType$rawResponse);
  427. +
  428.     }
  429. +
  430. }
  431. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:14 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportInterface.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportInterface.php.html new file mode 100644 index 00000000..24be1b05 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportInterface.php.html @@ -0,0 +1,114 @@ + + + + + + File Source for Interface.php + + + + +

Source for file Interface.php

+

Documentation is available at Interface.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Timo Schmidt <timo.schmidt@aoemedia.de>, Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. // require Apache_Solr_HttpTransport_Response
  78. +
  79. require_once(dirname(__FILE__'/Response.php');
  80. +
  81.  
  82. +
  83. /**
  84. +
  85.  * Interface that all Transport (HTTP Requester) implementations must implement. These
  86. +
  87.  * Implementations can then be plugged into the Service instance in order to user their
  88. +
  89.  * the desired method for making HTTP requests
  90. +
  91.  */
  92. +
  93. +
  94. {
  95. +
  96.     /**
  97. +
  98.      * Get the current default timeout for all HTTP requests
  99. +
  100.      *
  101. +
  102.      * @return float 
  103. +
  104.      */
  105. +
  106.     public function getDefaultTimeout();
  107. +
  108.     
  109. +
  110.     /**
  111. +
  112.      * Set the current default timeout for all HTTP requests
  113. +
  114.      *
  115. +
  116.      * @param float $timeout 
  117. +
  118.      */
  119. +
  120.     public function setDefaultTimeout($timeout);
  121. +
  122.         
  123. +
  124.     /**
  125. +
  126.      * Perform a GET HTTP operation with an optional timeout and return the response
  127. +
  128.      * contents, use getLastResponseHeaders to retrieve HTTP headers
  129. +
  130.      *
  131. +
  132.      * @param string $url 
  133. +
  134.      * @param float $timeout 
  135. +
  136.      * @return Apache_Solr_HttpTransport_Response HTTP response
  137. +
  138.      */
  139. +
  140.     public function performGetRequest($url$timeout false);
  141. +
  142.     
  143. +
  144.     /**
  145. +
  146.      * Perform a HEAD HTTP operation with an optional timeout and return the response
  147. +
  148.      * headers - NOTE: head requests have no response body
  149. +
  150.      *
  151. +
  152.      * @param string $url 
  153. +
  154.      * @param float $timeout 
  155. +
  156.      * @return Apache_Solr_HttpTransport_Response HTTP response
  157. +
  158.      */
  159. +
  160.     public function performHeadRequest($url$timeout false);
  161. +
  162.     
  163. +
  164.     /**
  165. +
  166.      * Perform a POST HTTP operation with an optional timeout and return the response
  167. +
  168.      * contents, use getLastResponseHeaders to retrieve HTTP headers
  169. +
  170.      *
  171. +
  172.      * @param string $url 
  173. +
  174.      * @param string $rawPost 
  175. +
  176.      * @param string $contentType 
  177. +
  178.      * @param float $timeout 
  179. +
  180.      * @return Apache_Solr_HttpTransport_Response HTTP response
  181. +
  182.      */
  183. +
  184.     public function performPostRequest($url$rawPost$contentType$timeout false);
  185. +
  186. }
  187. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportResponse.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportResponse.php.html new file mode 100644 index 00000000..4ad92f51 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_HttpTransportResponse.php.html @@ -0,0 +1,275 @@ + + + + + + File Source for Response.php + + + + +

Source for file Response.php

+

Documentation is available at Response.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. /**
  78. +
  79.  * Represents the required pieces of an HTTP response provided by HTTP transport
  80. +
  81.  * implementations and then consumed by the Apache_Solr_Response class which provides
  82. +
  83.  * decoding
  84. +
  85.  */
  86. +
  87. +
  88. {
  89. +
  90.     /**
  91. +
  92.      * Status Messages indexed by Status Code
  93. +
  94.      * Obtained from: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  95. +
  96.      *
  97. +
  98.      * @var array 
  99. +
  100.      */
  101. +
  102.     static private $_defaultStatusMessages array(
  103. +
  104.         // Specific to PHP Solr Client
  105. +
  106.         => "Communication Error",
  107. +
  108.         
  109. +
  110.         // Informational 1XX
  111. +
  112.         100 => "Continue",
  113. +
  114.         101 => "Switching Protocols",
  115. +
  116.         
  117. +
  118.         // Successful 2XX
  119. +
  120.         200 => "OK",
  121. +
  122.         201 => "Created",
  123. +
  124.         202 => "Accepted",
  125. +
  126.         203 => "Non-Authoritative Information",
  127. +
  128.         204 => "No Content",
  129. +
  130.         205 => "Reset Content",
  131. +
  132.         206 => "Partial Content",
  133. +
  134.         
  135. +
  136.         // Redirection 3XX
  137. +
  138.         300 => "Multiple Choices",
  139. +
  140.         301 => "Moved Permanently",
  141. +
  142.         302 => "Found",
  143. +
  144.         303 => "See Other",
  145. +
  146.         304 => "Not Modified",
  147. +
  148.         305 => "Use Proxy",
  149. +
  150.         307 => "Temporary Redirect",
  151. +
  152.         
  153. +
  154.         // Client Error 4XX
  155. +
  156.         400 => "Bad Request",
  157. +
  158.         401 => "Unauthorized",
  159. +
  160.         402 => "Payment Required",
  161. +
  162.         403 => "Forbidden",
  163. +
  164.         404 => "Not Found",
  165. +
  166.         405 => "Method Not Allowed",
  167. +
  168.         406 => "Not Acceptable",
  169. +
  170.         407 => "Proxy Authentication Required",
  171. +
  172.         408 => "Request Timeout",
  173. +
  174.         409 => "Conflict",
  175. +
  176.         410 => "Gone",
  177. +
  178.         411 => "Length Required",
  179. +
  180.         412 => "Precondition Failed",
  181. +
  182.         413 => "Request Entity Too Large",
  183. +
  184.         414 => "Request-URI Too Long",
  185. +
  186.         415 => "Unsupported Media Type",
  187. +
  188.         416 => "Request Range Not Satisfiable",
  189. +
  190.         417 => "Expectation Failed",
  191. +
  192.         
  193. +
  194.         // Server Error 5XX
  195. +
  196.         500 => "Internal Server Error",
  197. +
  198.         501 => "Not Implemented",
  199. +
  200.         502 => "Bad Gateway",
  201. +
  202.         503 => "Service Unavailable",
  203. +
  204.         504 => "Gateway Timeout",
  205. +
  206.         505 => "HTTP Version Not Supported"
  207. +
  208.     );
  209. +
  210.     
  211. +
  212.     /**
  213. +
  214.      * Get the HTTP status message based on status code
  215. +
  216.      *
  217. +
  218.      * @return string 
  219. +
  220.      */
  221. +
  222.     public static function getDefaultStatusMessage($statusCode)
  223. +
  224.     {
  225. +
  226.         $statusCode = (int) $statusCode;
  227. +
  228.         
  229. +
  230.         if (isset(self::$_defaultStatusMessages[$statusCode]))
  231. +
  232.         {
  233. +
  234.             return self::$_defaultStatusMessages[$statusCode];
  235. +
  236.         }
  237. +
  238.         
  239. +
  240.         return "Unknown Status";
  241. +
  242.     }
  243. +
  244.     
  245. +
  246.     /**
  247. +
  248.      * The response's HTTP status code
  249. +
  250.      *
  251. +
  252.      * @var integer 
  253. +
  254.      */
  255. +
  256.     private $_statusCode;
  257. +
  258.     
  259. +
  260.     /**
  261. +
  262.      * The response's HTTP status message
  263. +
  264.      *
  265. +
  266.      * @var string 
  267. +
  268.      */
  269. +
  270.     private $_statusMessage;
  271. +
  272.     
  273. +
  274.     /**
  275. +
  276.      * The response's mime type
  277. +
  278.      *
  279. +
  280.      * @var string 
  281. +
  282.      */
  283. +
  284.     private $_mimeType;
  285. +
  286.     
  287. +
  288.     /**
  289. +
  290.      * The response's character encoding
  291. +
  292.      *
  293. +
  294.      * @var string 
  295. +
  296.      */
  297. +
  298.     private $_encoding;
  299. +
  300.     
  301. +
  302.     /**
  303. +
  304.      * The response's data
  305. +
  306.      *
  307. +
  308.      * @var string 
  309. +
  310.      */
  311. +
  312.     private $_responseBody;
  313. +
  314.     
  315. +
  316.     /**
  317. +
  318.      * Construct a HTTP transport response
  319. +
  320.      * 
  321. +
  322.      * @param integer $statusCode The HTTP status code
  323. +
  324.      * @param string $contentType The VALUE of the Content-Type HTTP header
  325. +
  326.      * @param string $responseBody The body of the HTTP response
  327. +
  328.      */
  329. +
  330.     public function __construct($statusCode$contentType$responseBody)
  331. +
  332.     {
  333. +
  334.         // set the status code, make sure its an integer
  335. +
  336.         $this->_statusCode = (int) $statusCode;
  337. +
  338.         
  339. +
  340.         // lookup up status message based on code
  341. +
  342.         $this->_statusMessage self::getDefaultStatusMessage($this->_statusCode);
  343. +
  344.         
  345. +
  346.         // set the response body, it should always be a string
  347. +
  348.         $this->_responseBody = (string) $responseBody;
  349. +
  350.         
  351. +
  352.         // parse the content type header value for mimetype and encoding
  353. +
  354.         // first set default values that will remain if we can't find
  355. +
  356.         // what we're looking for in the content type
  357. +
  358.         $this->_mimeType "text/plain";
  359. +
  360.         $this->_encoding "UTF-8";
  361. +
  362.         
  363. +
  364.         if ($contentType)
  365. +
  366.         {
  367. +
  368.             // now break apart the header to see if there's character encoding
  369. +
  370.             $contentTypeParts explode(';'$contentType2);
  371. +
  372.  
  373. +
  374.             if (isset($contentTypeParts[0]))
  375. +
  376.             {
  377. +
  378.                 $this->_mimeType trim($contentTypeParts[0]);
  379. +
  380.             }
  381. +
  382.  
  383. +
  384.             if (isset($contentTypeParts[1]))
  385. +
  386.             {
  387. +
  388.                 // we have a second part, split it further
  389. +
  390.                 $contentTypeParts explode('='$contentTypeParts[1]);
  391. +
  392.  
  393. +
  394.                 if (isset($contentTypeParts[1]))
  395. +
  396.                 {
  397. +
  398.                     $this->_encoding trim($contentTypeParts[1]);
  399. +
  400.                 }
  401. +
  402.             }
  403. +
  404.         }
  405. +
  406.     }
  407. +
  408.     
  409. +
  410.     /**
  411. +
  412.      * Get the status code of the response
  413. +
  414.      *
  415. +
  416.      * @return integer 
  417. +
  418.      */
  419. +
  420.     public function getStatusCode()
  421. +
  422.     {
  423. +
  424.         return $this->_statusCode;
  425. +
  426.     }
  427. +
  428.     
  429. +
  430.     /**
  431. +
  432.      * Get the status message of the response
  433. +
  434.      *
  435. +
  436.      * @return string 
  437. +
  438.      */
  439. +
  440.     public function getStatusMessage()
  441. +
  442.     {
  443. +
  444.         return $this->_statusMessage;
  445. +
  446.     }
  447. +
  448.     
  449. +
  450.     /**
  451. +
  452.      * Get the mimetype of the response body
  453. +
  454.      *
  455. +
  456.      * @return string 
  457. +
  458.      */
  459. +
  460.     public function getMimeType()
  461. +
  462.     {
  463. +
  464.         return $this->_mimeType;
  465. +
  466.     }
  467. +
  468.     
  469. +
  470.     /**
  471. +
  472.      * Get the charset encoding of the response body.
  473. +
  474.      *
  475. +
  476.      * @return string 
  477. +
  478.      */
  479. +
  480.     public function getEncoding()
  481. +
  482.     {
  483. +
  484.         return $this->_encoding;
  485. +
  486.     }
  487. +
  488.     
  489. +
  490.     /**
  491. +
  492.      * Get the raw response body
  493. +
  494.      *
  495. +
  496.      * @return string 
  497. +
  498.      */
  499. +
  500.     public function getBody()
  501. +
  502.     {
  503. +
  504.         return $this->_responseBody;
  505. +
  506.     }
  507. +
  508. }
  509. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:16 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_InvalidArgumentException.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_InvalidArgumentException.php.html new file mode 100644 index 00000000..5f7d4e81 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_InvalidArgumentException.php.html @@ -0,0 +1,70 @@ + + + + + + File Source for InvalidArgumentException.php + + + + +

Source for file InvalidArgumentException.php

+

Documentation is available at InvalidArgumentException.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. +
  78. {
  79. +
  80.     /**
  81. +
  82.      * SVN Revision meta data for this class
  83. +
  84.      */
  85. +
  86.     const SVN_REVISION = '$Revision: 54 $';
  87. +
  88.  
  89. +
  90.     /**
  91. +
  92.      * SVN ID meta data for this class
  93. +
  94.      */
  95. +
  96.     const SVN_ID = '$Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
  97. +
  98. }
  99. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_NoServiceAvailableException.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_NoServiceAvailableException.php.html new file mode 100644 index 00000000..00a144e7 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_NoServiceAvailableException.php.html @@ -0,0 +1,70 @@ + + + + + + File Source for NoServiceAvailableException.php + + + + +

Source for file NoServiceAvailableException.php

+

Documentation is available at NoServiceAvailableException.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. +
  78. {
  79. +
  80.     /**
  81. +
  82.      * SVN Revision meta data for this class
  83. +
  84.      */
  85. +
  86.     const SVN_REVISION = '$Revision: 54 $';
  87. +
  88.  
  89. +
  90.     /**
  91. +
  92.      * SVN ID meta data for this class
  93. +
  94.      */
  95. +
  96.     const SVN_ID = '$Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
  97. +
  98. }
  99. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_ParserException.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_ParserException.php.html new file mode 100644 index 00000000..72c0d353 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_ParserException.php.html @@ -0,0 +1,70 @@ + + + + + + File Source for ParserException.php + + + + +

Source for file ParserException.php

+

Documentation is available at ParserException.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. +
  78. {
  79. +
  80.     /**
  81. +
  82.      * SVN Revision meta data for this class
  83. +
  84.      */
  85. +
  86.     const SVN_REVISION = '$Revision: 54 $';
  87. +
  88.  
  89. +
  90.     /**
  91. +
  92.      * SVN ID meta data for this class
  93. +
  94.      */
  95. +
  96.     const SVN_ID = '$Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
  97. +
  98. }
  99. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Response.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Response.php.html new file mode 100644 index 00000000..9ec73786 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Response.php.html @@ -0,0 +1,267 @@ + + + + + + File Source for Response.php + + + + +

Source for file Response.php

+

Documentation is available at Response.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: Response.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. require_once(dirname(__FILE__'/ParserException.php');
  78. +
  79.  
  80. +
  81. /**
  82. +
  83.  * Represents a Solr response.  Parses the raw response into a set of stdClass objects
  84. +
  85.  * and associative arrays for easy access.
  86. +
  87.  *
  88. +
  89.  * Currently requires json_decode which is bundled with PHP >= 5.2.0, Alternatively can be
  90. +
  91.  * installed with PECL.  Zend Framework also includes a purely PHP solution.
  92. +
  93.  */
  94. +
  95. +
  96. {
  97. +
  98.     /**
  99. +
  100.      * SVN Revision meta data for this class
  101. +
  102.      */
  103. +
  104.     const SVN_REVISION '$Revision: 54 $';
  105. +
  106.  
  107. +
  108.     /**
  109. +
  110.      * SVN ID meta data for this class
  111. +
  112.      */
  113. +
  114.     const SVN_ID '$Id: Response.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
  115. +
  116.  
  117. +
  118.     /**
  119. +
  120.      * Holds the raw response used in construction
  121. +
  122.      *
  123. +
  124.      * @var Apache_Solr_HttpTransport_Response HTTP response
  125. +
  126.      */
  127. +
  128.     protected $_response;
  129. +
  130.  
  131. +
  132.     /**
  133. +
  134.      * Whether the raw response has been parsed
  135. +
  136.      *
  137. +
  138.      * @var boolean 
  139. +
  140.      */
  141. +
  142.     protected $_isParsed = false;
  143. +
  144.  
  145. +
  146.     /**
  147. +
  148.      * Parsed representation of the data
  149. +
  150.      *
  151. +
  152.      * @var mixed 
  153. +
  154.      */
  155. +
  156.     protected $_parsedData;
  157. +
  158.  
  159. +
  160.     /**
  161. +
  162.      * Data parsing flags.  Determines what extra processing should be done
  163. +
  164.      * after the data is initially converted to a data structure.
  165. +
  166.      *
  167. +
  168.      * @var boolean 
  169. +
  170.      */
  171. +
  172.     protected $_createDocuments = true,
  173. +
  174.             $_collapseSingleValueArrays = true;
  175. +
  176.  
  177. +
  178.     /**
  179. +
  180.      * Constructor. Takes the raw HTTP response body and the exploded HTTP headers
  181. +
  182.      *
  183. +
  184.      * @return Apache_Solr_HttpTransport_Response HTTP response
  185. +
  186.      * @param boolean $createDocuments Whether to convert the documents json_decoded as stdClass instances to Apache_Solr_Document instances
  187. +
  188.      * @param boolean $collapseSingleValueArrays Whether to make multivalued fields appear as single values
  189. +
  190.      */
  191. +
  192.     public function __construct(Apache_Solr_HttpTransport_Response $response$createDocuments true$collapseSingleValueArrays true)
  193. +
  194.     {
  195. +
  196.         $this->_response = $response;
  197. +
  198.         $this->_createDocuments = (bool) $createDocuments;
  199. +
  200.         $this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
  201. +
  202.     }
  203. +
  204.  
  205. +
  206.     /**
  207. +
  208.      * Get the HTTP status code
  209. +
  210.      *
  211. +
  212.      * @return integer 
  213. +
  214.      */
  215. +
  216.     public function getHttpStatus()
  217. +
  218.     {
  219. +
  220.         return $this->_response->getStatusCode();
  221. +
  222.     }
  223. +
  224.  
  225. +
  226.     /**
  227. +
  228.      * Get the HTTP status message of the response
  229. +
  230.      *
  231. +
  232.      * @return string 
  233. +
  234.      */
  235. +
  236.     public function getHttpStatusMessage()
  237. +
  238.     {
  239. +
  240.         return $this->_response->getStatusMessage();
  241. +
  242.     }
  243. +
  244.  
  245. +
  246.     /**
  247. +
  248.      * Get content type of this Solr response
  249. +
  250.      *
  251. +
  252.      * @return string 
  253. +
  254.      */
  255. +
  256.     public function getType()
  257. +
  258.     {
  259. +
  260.         return $this->_response->getMimeType();
  261. +
  262.     }
  263. +
  264.  
  265. +
  266.     /**
  267. +
  268.      * Get character encoding of this response. Should usually be utf-8, but just in case
  269. +
  270.      *
  271. +
  272.      * @return string 
  273. +
  274.      */
  275. +
  276.     public function getEncoding()
  277. +
  278.     {
  279. +
  280.         return $this->_response->getEncoding();
  281. +
  282.     }
  283. +
  284.  
  285. +
  286.     /**
  287. +
  288.      * Get the raw response as it was given to this object
  289. +
  290.      *
  291. +
  292.      * @return string 
  293. +
  294.      */
  295. +
  296.     public function getRawResponse()
  297. +
  298.     {
  299. +
  300.         return $this->_response->getBody();
  301. +
  302.     }
  303. +
  304.  
  305. +
  306.     /**
  307. +
  308.      * Magic get to expose the parsed data and to lazily load it
  309. +
  310.      *
  311. +
  312.      * @param string $key 
  313. +
  314.      * @return mixed 
  315. +
  316.      */
  317. +
  318.     public function __get($key)
  319. +
  320.     {
  321. +
  322.         if (!$this->_isParsed)
  323. +
  324.         {
  325. +
  326.             $this->_parseData();
  327. +
  328.             $this->_isParsed = true;
  329. +
  330.         }
  331. +
  332.  
  333. +
  334.         if (isset($this->_parsedData->$key))
  335. +
  336.         {
  337. +
  338.             return $this->_parsedData->$key;
  339. +
  340.         }
  341. +
  342.  
  343. +
  344.         return null;
  345. +
  346.     }
  347. +
  348.  
  349. +
  350.     /**
  351. +
  352.      * Magic function for isset function on parsed data
  353. +
  354.      *
  355. +
  356.      * @param string $key 
  357. +
  358.      * @return boolean 
  359. +
  360.      */
  361. +
  362.     public function __isset($key)
  363. +
  364.     {
  365. +
  366.         if (!$this->_isParsed)
  367. +
  368.         {
  369. +
  370.             $this->_parseData();
  371. +
  372.             $this->_isParsed = true;
  373. +
  374.         }
  375. +
  376.  
  377. +
  378.         return isset($this->_parsedData->$key);
  379. +
  380.     }
  381. +
  382.  
  383. +
  384.     /**
  385. +
  386.      * Parse the raw response into the parsed_data array for access
  387. +
  388.      *
  389. +
  390.      * @throws Apache_Solr_ParserException If the data could not be parsed
  391. +
  392.      */
  393. +
  394.     protected function _parseData()
  395. +
  396.     {
  397. +
  398.         //An alternative would be to use Zend_Json::decode(...)
  399. +
  400.         $data json_decode($this->_response->getBody());
  401. +
  402.  
  403. +
  404.         // check that we receive a valid JSON response - we should never receive a null
  405. +
  406.         if ($data === null)
  407. +
  408.         {
  409. +
  410.             throw new Apache_Solr_ParserException('Solr response does not appear to be valid JSON, please examine the raw response with getRawResponse() method');
  411. +
  412.         }
  413. +
  414.  
  415. +
  416.         //if we're configured to collapse single valued arrays or to convert them to Apache_Solr_Document objects
  417. +
  418.         //and we have response documents, then try to collapse the values and / or convert them now
  419. +
  420.         if (($this->_createDocuments || $this->_collapseSingleValueArrays&& isset($data->response&& is_array($data->response->docs))
  421. +
  422.         {
  423. +
  424.             $documents array();
  425. +
  426.  
  427. +
  428.             foreach ($data->response->docs as $originalDocument)
  429. +
  430.             {
  431. +
  432.                 if ($this->_createDocuments)
  433. +
  434.                 {
  435. +
  436.                     $document new Apache_Solr_Document();
  437. +
  438.                 }
  439. +
  440.                 else
  441. +
  442.                 {
  443. +
  444.                     $document $originalDocument;
  445. +
  446.                 }
  447. +
  448.  
  449. +
  450.                 foreach ($originalDocument as $key => $value)
  451. +
  452.                 {
  453. +
  454.                     //If a result is an array with only a single
  455. +
  456.                     //value then its nice to be able to access
  457. +
  458.                     //it as if it were always a single value
  459. +
  460.                     if ($this->_collapseSingleValueArrays && is_array($value&& count($value<= 1)
  461. +
  462.                     {
  463. +
  464.                         $value array_shift($value);
  465. +
  466.                     }
  467. +
  468.  
  469. +
  470.                     $document->$key $value;
  471. +
  472.                 }
  473. +
  474.  
  475. +
  476.                 $documents[$document;
  477. +
  478.             }
  479. +
  480.  
  481. +
  482.             $data->response->docs $documents;
  483. +
  484.         }
  485. +
  486.  
  487. +
  488.         $this->_parsedData = $data;
  489. +
  490.     }
  491. +
  492. }
  493. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:15 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Service.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Service.php.html new file mode 100644 index 00000000..9f1a4388 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_Service.php.html @@ -0,0 +1,1201 @@ + + + + + + File Source for Service.php + + + + +

Source for file Service.php

+

Documentation is available at Service.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: Service.php 59 2011-02-08 20:38:59Z donovan.jimenez $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. // See Issue #1 (http://code.google.com/p/solr-php-client/issues/detail?id=1)
  78. +
  79. // Doesn't follow typical include path conventions, but is more convenient for users
  80. +
  81. require_once(dirname(__FILE__'/Exception.php');
  82. +
  83. require_once(dirname(__FILE__'/HttpTransportException.php');
  84. +
  85. require_once(dirname(__FILE__'/InvalidArgumentException.php');
  86. +
  87.  
  88. +
  89. require_once(dirname(__FILE__'/Document.php');
  90. +
  91. require_once(dirname(__FILE__'/Response.php');
  92. +
  93.  
  94. +
  95. require_once(dirname(__FILE__'/HttpTransport/Interface.php');
  96. +
  97.  
  98. +
  99. /**
  100. +
  101.  * Starting point for the Solr API. Represents a Solr server resource and has
  102. +
  103.  * methods for pinging, adding, deleting, committing, optimizing and searching.
  104. +
  105.  *
  106. +
  107.  * Example Usage:
  108. +
  109.  * <code>
  110. +
  111.  * ...
  112. +
  113.  * $solr = new Apache_Solr_Service(); //or explicitly new Apache_Solr_Service('localhost', 8180, '/solr')
  114. +
  115.  *
  116. +
  117.  * if ($solr->ping())
  118. +
  119.  * {
  120. +
  121.  *         $solr->deleteByQuery('*:*'); //deletes ALL documents - be careful :)
  122. +
  123.  *
  124. +
  125.  *         $document = new Apache_Solr_Document();
  126. +
  127.  *         $document->id = uniqid(); //or something else suitably unique
  128. +
  129.  *
  130. +
  131.  *         $document->title = 'Some Title';
  132. +
  133.  *         $document->content = 'Some content for this wonderful document. Blah blah blah.';
  134. +
  135.  *
  136. +
  137.  *         $solr->addDocument($document);     //if you're going to be adding documents in bulk using addDocuments
  138. +
  139.  *                                         //with an array of documents is faster
  140. +
  141.  *
  142. +
  143.  *         $solr->commit(); //commit to see the deletes and the document
  144. +
  145.  *         $solr->optimize(); //merges multiple segments into one
  146. +
  147.  *
  148. +
  149.  *         //and the one we all care about, search!
  150. +
  151.  *         //any other common or custom parameters to the request handler can go in the
  152. +
  153.  *         //optional 4th array argument.
  154. +
  155.  *         $solr->search('content:blah', 0, 10, array('sort' => 'timestamp desc'));
  156. +
  157.  * }
  158. +
  159.  * ...
  160. +
  161.  * </code>
  162. +
  163.  *
  164. +
  165.  * @todo Investigate using other HTTP clients other than file_get_contents built-in handler. Could provide performance
  166. +
  167.  *  improvements when dealing with multiple requests by using HTTP's keep alive functionality
  168. +
  169.  */
  170. +
  171. +
  172. {
  173. +
  174.     /**
  175. +
  176.      * SVN Revision meta data for this class
  177. +
  178.      */
  179. +
  180.     const SVN_REVISION '$Revision: 59 $';
  181. +
  182.  
  183. +
  184.     /**
  185. +
  186.      * SVN ID meta data for this class
  187. +
  188.      */
  189. +
  190.     const SVN_ID '$Id: Service.php 59 2011-02-08 20:38:59Z donovan.jimenez $';
  191. +
  192.  
  193. +
  194.     /**
  195. +
  196.      * Response writer we'll request - JSON. See http://code.google.com/p/solr-php-client/issues/detail?id=6#c1 for reasoning
  197. +
  198.      */
  199. +
  200.     const SOLR_WRITER 'json';
  201. +
  202.  
  203. +
  204.     /**
  205. +
  206.      * NamedList Treatment constants
  207. +
  208.      */
  209. +
  210.     const NAMED_LIST_FLAT 'flat';
  211. +
  212.     const NAMED_LIST_MAP 'map';
  213. +
  214.  
  215. +
  216.     /**
  217. +
  218.      * Search HTTP Methods
  219. +
  220.      */
  221. +
  222.     const METHOD_GET 'GET';
  223. +
  224.     const METHOD_POST 'POST';
  225. +
  226.  
  227. +
  228.     /**
  229. +
  230.      * Servlet mappings
  231. +
  232.      */
  233. +
  234.     const PING_SERVLET 'admin/ping';
  235. +
  236.     const UPDATE_SERVLET 'update';
  237. +
  238.     const SEARCH_SERVLET 'select';
  239. +
  240.     const THREADS_SERVLET 'admin/threads';
  241. +
  242.     const EXTRACT_SERVLET 'update/extract';
  243. +
  244.  
  245. +
  246.     /**
  247. +
  248.      * Server identification strings
  249. +
  250.      *
  251. +
  252.      * @var string 
  253. +
  254.      */
  255. +
  256.     protected $_host$_port$_path;
  257. +
  258.  
  259. +
  260.     /**
  261. +
  262.      * Whether {@link Apache_Solr_Response} objects should create {@link Apache_Solr_Document}s in
  263. +
  264.      * the returned parsed data
  265. +
  266.      *
  267. +
  268.      * @var boolean 
  269. +
  270.      */
  271. +
  272.     protected $_createDocuments = true;
  273. +
  274.  
  275. +
  276.     /**
  277. +
  278.      * Whether {@link Apache_Solr_Response} objects should have multivalue fields with only a single value
  279. +
  280.      * collapsed to appear as a single value would.
  281. +
  282.      *
  283. +
  284.      * @var boolean 
  285. +
  286.      */
  287. +
  288.     protected $_collapseSingleValueArrays = true;
  289. +
  290.  
  291. +
  292.     /**
  293. +
  294.      * How NamedLists should be formatted in the output.  This specifically effects facet counts. Valid values
  295. +
  296.      * are {@link Apache_Solr_Service::NAMED_LIST_MAP} (default) or {@link Apache_Solr_Service::NAMED_LIST_FLAT}.
  297. +
  298.      *
  299. +
  300.      * @var string 
  301. +
  302.      */
  303. +
  304.     protected $_namedListTreatment = self::NAMED_LIST_MAP;
  305. +
  306.  
  307. +
  308.     /**
  309. +
  310.      * Query delimiters. Someone might want to be able to change
  311. +
  312.      * these (to use &amp; instead of & for example), so I've provided them.
  313. +
  314.      *
  315. +
  316.      * @var string 
  317. +
  318.      */
  319. +
  320.     protected $_queryDelimiter = '?'$_queryStringDelimiter = '&'$_queryBracketsEscaped = true;
  321. +
  322.  
  323. +
  324.     /**
  325. +
  326.      * Constructed servlet full path URLs
  327. +
  328.      *
  329. +
  330.      * @var string 
  331. +
  332.      */
  333. +
  334.     protected $_pingUrl$_updateUrl$_searchUrl$_threadsUrl;
  335. +
  336.  
  337. +
  338.     /**
  339. +
  340.      * Keep track of whether our URLs have been constructed
  341. +
  342.      *
  343. +
  344.      * @var boolean 
  345. +
  346.      */
  347. +
  348.     protected $_urlsInited = false;
  349. +
  350.  
  351. +
  352.     /**
  353. +
  354.      * HTTP Transport implementation (pluggable)
  355. +
  356.      *
  357. +
  358.      * @var Apache_Solr_HttpTransport_Interface 
  359. +
  360.      */
  361. +
  362.     protected $_httpTransport = false;
  363. +
  364.  
  365. +
  366.     /**
  367. +
  368.      * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
  369. +
  370.      *
  371. +
  372.      * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
  373. +
  374.      *
  375. +
  376.      * @param string $value 
  377. +
  378.      * @return string 
  379. +
  380.      */
  381. +
  382.     static public function escape($value)
  383. +
  384.     {
  385. +
  386.         //list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
  387. +
  388.         $pattern '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
  389. +
  390.         $replace '\\\$1';
  391. +
  392.  
  393. +
  394.         return preg_replace($pattern$replace$value);
  395. +
  396.     }
  397. +
  398.  
  399. +
  400.     /**
  401. +
  402.      * Escape a value meant to be contained in a phrase for special query characters
  403. +
  404.      *
  405. +
  406.      * @param string $value 
  407. +
  408.      * @return string 
  409. +
  410.      */
  411. +
  412.     static public function escapePhrase($value)
  413. +
  414.     {
  415. +
  416.         $pattern '/("|\\\)/';
  417. +
  418.         $replace '\\\$1';
  419. +
  420.  
  421. +
  422.         return preg_replace($pattern$replace$value);
  423. +
  424.     }
  425. +
  426.  
  427. +
  428.     /**
  429. +
  430.      * Convenience function for creating phrase syntax from a value
  431. +
  432.      *
  433. +
  434.      * @param string $value 
  435. +
  436.      * @return string 
  437. +
  438.      */
  439. +
  440.     static public function phrase($value)
  441. +
  442.     {
  443. +
  444.         return '"' self::escapePhrase($value'"';
  445. +
  446.     }
  447. +
  448.  
  449. +
  450.     /**
  451. +
  452.      * Constructor. All parameters are optional and will take on default values
  453. +
  454.      * if not specified.
  455. +
  456.      *
  457. +
  458.      * @param string $host 
  459. +
  460.      * @param string $port 
  461. +
  462.      * @param string $path 
  463. +
  464.      * @param Apache_Solr_HttpTransport_Interface $httpTransport 
  465. +
  466.      */
  467. +
  468.     public function __construct($host 'localhost'$port 8180$path '/solr/'$httpTransport false)
  469. +
  470.     {
  471. +
  472.         $this->setHost($host);
  473. +
  474.         $this->setPort($port);
  475. +
  476.         $this->setPath($path);
  477. +
  478.  
  479. +
  480.         $this->_initUrls();
  481. +
  482.  
  483. +
  484.         if ($httpTransport)
  485. +
  486.         {
  487. +
  488.             $this->setHttpTransport($httpTransport);
  489. +
  490.         }
  491. +
  492.  
  493. +
  494.         // check that our php version is >= 5.1.3 so we can correct for http_build_query behavior later
  495. +
  496.         $this->_queryBracketsEscaped = version_compare(phpversion()'5.1.3''>=');
  497. +
  498.     }
  499. +
  500.  
  501. +
  502.     /**
  503. +
  504.      * Return a valid http URL given this server's host, port and path and a provided servlet name
  505. +
  506.      *
  507. +
  508.      * @param string $servlet 
  509. +
  510.      * @return string 
  511. +
  512.      */
  513. +
  514.     protected function _constructUrl($servlet$params array())
  515. +
  516.     {
  517. +
  518.         if (count($params))
  519. +
  520.         {
  521. +
  522.             //escape all parameters appropriately for inclusion in the query string
  523. +
  524.             $escapedParams array();
  525. +
  526.  
  527. +
  528.             foreach ($params as $key => $value)
  529. +
  530.             {
  531. +
  532.                 $escapedParams[urlencode($key'=' urlencode($value);
  533. +
  534.             }
  535. +
  536.  
  537. +
  538.             $queryString $this->_queryDelimiter . implode($this->_queryStringDelimiter$escapedParams);
  539. +
  540.         }
  541. +
  542.         else
  543. +
  544.         {
  545. +
  546.             $queryString '';
  547. +
  548.         }
  549. +
  550.  
  551. +
  552.         return 'http://' $this->_host . ':' $this->_port . $this->_path . $servlet $queryString;
  553. +
  554.     }
  555. +
  556.  
  557. +
  558.     /**
  559. +
  560.      * Construct the Full URLs for the three servlets we reference
  561. +
  562.      */
  563. +
  564.     protected function _initUrls()
  565. +
  566.     {
  567. +
  568.         //Initialize our full servlet URLs now that we have server information
  569. +
  570.         $this->_extractUrl $this->_constructUrl(self::EXTRACT_SERVLET);
  571. +
  572.         $this->_pingUrl = $this->_constructUrl(self::PING_SERVLET);
  573. +
  574.         $this->_searchUrl = $this->_constructUrl(self::SEARCH_SERVLET);
  575. +
  576.         $this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLETarray('wt' => self::SOLR_WRITER ));
  577. +
  578.         $this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLETarray('wt' => self::SOLR_WRITER ));
  579. +
  580.  
  581. +
  582.         $this->_urlsInited = true;
  583. +
  584.     }
  585. +
  586.  
  587. +
  588.     protected function _generateQueryString($params)
  589. +
  590.     {
  591. +
  592.         // use http_build_query to encode our arguments because its faster
  593. +
  594.         // than urlencoding all the parts ourselves in a loop
  595. +
  596.         //
  597. +
  598.         // because http_build_query treats arrays differently than we want to, correct the query
  599. +
  600.         // string by changing foo[#]=bar (# being an actual number) parameter strings to just
  601. +
  602.         // multiple foo=bar strings. This regex should always work since '=' will be urlencoded
  603. +
  604.         // anywhere else the regex isn't expecting it
  605. +
  606.         //
  607. +
  608.         // NOTE: before php 5.1.3 brackets were not url encoded by http_build query - we've checked
  609. +
  610.         // the php version in the constructor and put the results in the instance variable. Also, before
  611. +
  612.         // 5.1.2 the arg_separator parameter was not available, so don't use it
  613. +
  614.         if ($this->_queryBracketsEscaped)
  615. +
  616.         {
  617. +
  618.             $queryString http_build_query($paramsnull$this->_queryStringDelimiter);
  619. +
  620.             return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/''='$queryString);
  621. +
  622.         }
  623. +
  624.         else
  625. +
  626.         {
  627. +
  628.             $queryString http_build_query($params);
  629. +
  630.             return preg_replace('/\\[(?:[0-9]|[1-9][0-9]+)\\]=/''='$queryString);
  631. +
  632.         }
  633. +
  634.     }
  635. +
  636.  
  637. +
  638.     /**
  639. +
  640.      * Central method for making a get operation against this Solr Server
  641. +
  642.      *
  643. +
  644.      * @param string $url 
  645. +
  646.      * @param float $timeout Read timeout in seconds
  647. +
  648.      * @return Apache_Solr_Response 
  649. +
  650.      *
  651. +
  652.      * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
  653. +
  654.      */
  655. +
  656.     protected function _sendRawGet($url$timeout FALSE)
  657. +
  658.     {
  659. +
  660.         $httpTransport $this->getHttpTransport();
  661. +
  662.  
  663. +
  664.         $httpResponse $httpTransport->performGetRequest($url$timeout);
  665. +
  666.         $solrResponse new Apache_Solr_Response($httpResponse$this->_createDocuments$this->_collapseSingleValueArrays);
  667. +
  668.  
  669. +
  670.         if ($solrResponse->getHttpStatus(!= 200)
  671. +
  672.         {
  673. +
  674.             throw new Apache_Solr_HttpTransportException($solrResponse);
  675. +
  676.         }
  677. +
  678.  
  679. +
  680.         return $solrResponse;
  681. +
  682.     }
  683. +
  684.  
  685. +
  686.     /**
  687. +
  688.      * Central method for making a post operation against this Solr Server
  689. +
  690.      *
  691. +
  692.      * @param string $url 
  693. +
  694.      * @param string $rawPost 
  695. +
  696.      * @param float $timeout Read timeout in seconds
  697. +
  698.      * @param string $contentType 
  699. +
  700.      * @return Apache_Solr_Response 
  701. +
  702.      *
  703. +
  704.      * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
  705. +
  706.      */
  707. +
  708.     protected function _sendRawPost($url$rawPost$timeout FALSE$contentType 'text/xml; charset=UTF-8')
  709. +
  710.     {
  711. +
  712.         $httpTransport $this->getHttpTransport();
  713. +
  714.  
  715. +
  716.         $httpResponse $httpTransport->performPostRequest($url$rawPost$contentType$timeout);
  717. +
  718.         $solrResponse new Apache_Solr_Response($httpResponse$this->_createDocuments$this->_collapseSingleValueArrays);
  719. +
  720.  
  721. +
  722.         if ($solrResponse->getHttpStatus(!= 200)
  723. +
  724.         {
  725. +
  726.             throw new Apache_Solr_HttpTransportException($solrResponse);
  727. +
  728.         }
  729. +
  730.  
  731. +
  732.         return $solrResponse;
  733. +
  734.     }
  735. +
  736.  
  737. +
  738.     /**
  739. +
  740.      * Returns the set host
  741. +
  742.      *
  743. +
  744.      * @return string 
  745. +
  746.      */
  747. +
  748.     public function getHost()
  749. +
  750.     {
  751. +
  752.         return $this->_host;
  753. +
  754.     }
  755. +
  756.  
  757. +
  758.     /**
  759. +
  760.      * Set the host used. If empty will fallback to constants
  761. +
  762.      *
  763. +
  764.      * @param string $host 
  765. +
  766.      *
  767. +
  768.      * @throws Apache_Solr_InvalidArgumentException If the host parameter is empty
  769. +
  770.      */
  771. +
  772.     public function setHost($host)
  773. +
  774.     {
  775. +
  776.         //Use the provided host or use the default
  777. +
  778.         if (empty($host))
  779. +
  780.         {
  781. +
  782.             throw new Apache_Solr_InvalidArgumentException('Host parameter is empty');
  783. +
  784.         }
  785. +
  786.         else
  787. +
  788.         {
  789. +
  790.             $this->_host = $host;
  791. +
  792.         }
  793. +
  794.  
  795. +
  796.         if ($this->_urlsInited)
  797. +
  798.         {
  799. +
  800.             $this->_initUrls();
  801. +
  802.         }
  803. +
  804.     }
  805. +
  806.  
  807. +
  808.     /**
  809. +
  810.      * Get the set port
  811. +
  812.      *
  813. +
  814.      * @return integer 
  815. +
  816.      */
  817. +
  818.     public function getPort()
  819. +
  820.     {
  821. +
  822.         return $this->_port;
  823. +
  824.     }
  825. +
  826.  
  827. +
  828.     /**
  829. +
  830.      * Set the port used. If empty will fallback to constants
  831. +
  832.      *
  833. +
  834.      * @param integer $port 
  835. +
  836.      *
  837. +
  838.      * @throws Apache_Solr_InvalidArgumentException If the port parameter is empty
  839. +
  840.      */
  841. +
  842.     public function setPort($port)
  843. +
  844.     {
  845. +
  846.         //Use the provided port or use the default
  847. +
  848.         $port = (int) $port;
  849. +
  850.  
  851. +
  852.         if ($port <= 0)
  853. +
  854.         {
  855. +
  856.             throw new Apache_Solr_InvalidArgumentException('Port is not a valid port number');
  857. +
  858.         }
  859. +
  860.         else
  861. +
  862.         {
  863. +
  864.             $this->_port = $port;
  865. +
  866.         }
  867. +
  868.  
  869. +
  870.         if ($this->_urlsInited)
  871. +
  872.         {
  873. +
  874.             $this->_initUrls();
  875. +
  876.         }
  877. +
  878.     }
  879. +
  880.  
  881. +
  882.     /**
  883. +
  884.      * Get the set path.
  885. +
  886.      *
  887. +
  888.      * @return string 
  889. +
  890.      */
  891. +
  892.     public function getPath()
  893. +
  894.     {
  895. +
  896.         return $this->_path;
  897. +
  898.     }
  899. +
  900.  
  901. +
  902.     /**
  903. +
  904.      * Set the path used. If empty will fallback to constants
  905. +
  906.      *
  907. +
  908.      * @param string $path 
  909. +
  910.      */
  911. +
  912.     public function setPath($path)
  913. +
  914.     {
  915. +
  916.         $path trim($path'/');
  917. +
  918.  
  919. +
  920.         $this->_path = '/' $path '/';
  921. +
  922.  
  923. +
  924.         if ($this->_urlsInited)
  925. +
  926.         {
  927. +
  928.             $this->_initUrls();
  929. +
  930.         }
  931. +
  932.     }
  933. +
  934.  
  935. +
  936.     /**
  937. +
  938.      * Get the current configured HTTP Transport
  939. +
  940.      *
  941. +
  942.      * @return HttpTransportInterface 
  943. +
  944.      */
  945. +
  946.     public function getHttpTransport()
  947. +
  948.     {
  949. +
  950.         // lazy load a default if one has not be set
  951. +
  952.         if ($this->_httpTransport === false)
  953. +
  954.         {
  955. +
  956.             require_once(dirname(__FILE__'/HttpTransport/FileGetContents.php');
  957. +
  958.  
  959. +
  960.             $this->_httpTransport = new Apache_Solr_HttpTransport_FileGetContents();
  961. +
  962.         }
  963. +
  964.  
  965. +
  966.         return $this->_httpTransport;
  967. +
  968.     }
  969. +
  970.  
  971. +
  972.     /**
  973. +
  974.      * Set the HTTP Transport implemenation that will be used for all HTTP requests
  975. +
  976.      *
  977. +
  978.      * @param Apache_Solr_HttpTransport_Interface 
  979. +
  980.      */
  981. +
  982.     public function setHttpTransport(Apache_Solr_HttpTransport_Interface $httpTransport)
  983. +
  984.     {
  985. +
  986.         $this->_httpTransport = $httpTransport;
  987. +
  988.     }
  989. +
  990.  
  991. +
  992.     /**
  993. +
  994.      * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
  995. +
  996.      * parse the response and create {@link Apache_Solr_Document} instances in place.
  997. +
  998.      *
  999. +
  1000.      * @param boolean $createDocuments 
  1001. +
  1002.      */
  1003. +
  1004.     public function setCreateDocuments($createDocuments)
  1005. +
  1006.     {
  1007. +
  1008.         $this->_createDocuments = (bool) $createDocuments;
  1009. +
  1010.     }
  1011. +
  1012.  
  1013. +
  1014.     /**
  1015. +
  1016.      * Get the current state of teh create documents flag.
  1017. +
  1018.      *
  1019. +
  1020.      * @return boolean 
  1021. +
  1022.      */
  1023. +
  1024.     public function getCreateDocuments()
  1025. +
  1026.     {
  1027. +
  1028.         return $this->_createDocuments;
  1029. +
  1030.     }
  1031. +
  1032.  
  1033. +
  1034.     /**
  1035. +
  1036.      * Set the collapse single value arrays flag.
  1037. +
  1038.      *
  1039. +
  1040.      * @param boolean $collapseSingleValueArrays 
  1041. +
  1042.      */
  1043. +
  1044.     public function setCollapseSingleValueArrays($collapseSingleValueArrays)
  1045. +
  1046.     {
  1047. +
  1048.         $this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
  1049. +
  1050.     }
  1051. +
  1052.  
  1053. +
  1054.     /**
  1055. +
  1056.      * Get the current state of the collapse single value arrays flag.
  1057. +
  1058.      *
  1059. +
  1060.      * @return boolean 
  1061. +
  1062.      */
  1063. +
  1064.     public function getCollapseSingleValueArrays()
  1065. +
  1066.     {
  1067. +
  1068.         return $this->_collapseSingleValueArrays;
  1069. +
  1070.     }
  1071. +
  1072.  
  1073. +
  1074.     /**
  1075. +
  1076.      * Get the current default timeout setting (initially the default_socket_timeout ini setting)
  1077. +
  1078.      * in seconds
  1079. +
  1080.      *
  1081. +
  1082.      * @return float 
  1083. +
  1084.      *
  1085. +
  1086.      * @deprecated Use the getDefaultTimeout method on the HTTP transport implementation
  1087. +
  1088.      */
  1089. +
  1090.     public function getDefaultTimeout()
  1091. +
  1092.     {
  1093. +
  1094.         return $this->getHttpTransport()->getDefaultTimeout();
  1095. +
  1096.     }
  1097. +
  1098.  
  1099. +
  1100.     /**
  1101. +
  1102.      * Set the default timeout for all calls that aren't passed a specific timeout
  1103. +
  1104.      *
  1105. +
  1106.      * @param float $timeout Timeout value in seconds
  1107. +
  1108.      *
  1109. +
  1110.      * @deprecated Use the setDefaultTimeout method on the HTTP transport implementation
  1111. +
  1112.      */
  1113. +
  1114.     public function setDefaultTimeout($timeout)
  1115. +
  1116.     {
  1117. +
  1118.         $this->getHttpTransport()->setDefaultTimeout($timeout);
  1119. +
  1120.     }
  1121. +
  1122.  
  1123. +
  1124.     /**
  1125. +
  1126.      * Set how NamedLists should be formatted in the response data. This mainly effects
  1127. +
  1128.      * the facet counts format.
  1129. +
  1130.      *
  1131. +
  1132.      * @param string $namedListTreatment 
  1133. +
  1134.      * @throws Apache_Solr_InvalidArgumentException If invalid option is set
  1135. +
  1136.      */
  1137. +
  1138.     public function setNamedListTreatment($namedListTreatment)
  1139. +
  1140.     {
  1141. +
  1142.         switch ((string) $namedListTreatment)
  1143. +
  1144.         {
  1145. +
  1146.             case Apache_Solr_Service::NAMED_LIST_FLAT:
  1147. +
  1148.                 $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_FLAT;
  1149. +
  1150.                 break;
  1151. +
  1152.  
  1153. +
  1154.             case Apache_Solr_Service::NAMED_LIST_MAP:
  1155. +
  1156.                 $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_MAP;
  1157. +
  1158.                 break;
  1159. +
  1160.  
  1161. +
  1162.             default:
  1163. +
  1164.                 throw new Apache_Solr_InvalidArgumentException('Not a valid named list treatement option');
  1165. +
  1166.         }
  1167. +
  1168.     }
  1169. +
  1170.  
  1171. +
  1172.     /**
  1173. +
  1174.      * Get the current setting for named list treatment.
  1175. +
  1176.      *
  1177. +
  1178.      * @return string 
  1179. +
  1180.      */
  1181. +
  1182.     public function getNamedListTreatment()
  1183. +
  1184.     {
  1185. +
  1186.         return $this->_namedListTreatment;
  1187. +
  1188.     }
  1189. +
  1190.  
  1191. +
  1192.     /**
  1193. +
  1194.      * Set the string used to separate the path form the query string.
  1195. +
  1196.      * Defaulted to '?'
  1197. +
  1198.      *
  1199. +
  1200.      * @param string $queryDelimiter 
  1201. +
  1202.      */
  1203. +
  1204.     public function setQueryDelimiter($queryDelimiter)
  1205. +
  1206.     {
  1207. +
  1208.         $this->_queryDelimiter = $queryDelimiter;
  1209. +
  1210.     }
  1211. +
  1212.  
  1213. +
  1214.     /**
  1215. +
  1216.      * Set the string used to separate the parameters in thequery string
  1217. +
  1218.      * Defaulted to '&'
  1219. +
  1220.      *
  1221. +
  1222.      * @param string $queryStringDelimiter 
  1223. +
  1224.      */
  1225. +
  1226.     public function setQueryStringDelimiter($queryStringDelimiter)
  1227. +
  1228.     {
  1229. +
  1230.         $this->_queryStringDelimiter = $queryStringDelimiter;
  1231. +
  1232.     }
  1233. +
  1234.  
  1235. +
  1236.     /**
  1237. +
  1238.      * Call the /admin/ping servlet, can be used to quickly tell if a connection to the
  1239. +
  1240.      * server is able to be made.
  1241. +
  1242.      *
  1243. +
  1244.      * @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2)
  1245. +
  1246.      * @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs
  1247. +
  1248.      */
  1249. +
  1250.     public function ping($timeout 2)
  1251. +
  1252.     {
  1253. +
  1254.         $start microtime(true);
  1255. +
  1256.         
  1257. +
  1258.         $httpTransport $this->getHttpTransport();
  1259. +
  1260.  
  1261. +
  1262.         $httpResponse $httpTransport->performHeadRequest($this->_pingUrl$timeout);
  1263. +
  1264.         $solrResponse new Apache_Solr_Response($httpResponse$this->_createDocuments$this->_collapseSingleValueArrays);
  1265. +
  1266.  
  1267. +
  1268.         if ($solrResponse->getHttpStatus(== 200)
  1269. +
  1270.         {
  1271. +
  1272.             return microtime(true$start;
  1273. +
  1274.         }
  1275. +
  1276.         else
  1277. +
  1278.         {
  1279. +
  1280.             return false;
  1281. +
  1282.         }
  1283. +
  1284.     }
  1285. +
  1286.  
  1287. +
  1288.     /**
  1289. +
  1290.      * Call the /admin/threads servlet and retrieve information about all threads in the
  1291. +
  1292.      * Solr servlet's thread group. Useful for diagnostics.
  1293. +
  1294.      *
  1295. +
  1296.      * @return Apache_Solr_Response 
  1297. +
  1298.      *
  1299. +
  1300.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1301. +
  1302.      */
  1303. +
  1304.     public function threads()
  1305. +
  1306.     {
  1307. +
  1308.         return $this->_sendRawGet($this->_threadsUrl);
  1309. +
  1310.     }
  1311. +
  1312.  
  1313. +
  1314.     /**
  1315. +
  1316.      * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
  1317. +
  1318.      * should be a complete and well formed "add" xml document.
  1319. +
  1320.      *
  1321. +
  1322.      * @param string $rawPost 
  1323. +
  1324.      * @return Apache_Solr_Response 
  1325. +
  1326.      *
  1327. +
  1328.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1329. +
  1330.      */
  1331. +
  1332.     public function add($rawPost)
  1333. +
  1334.     {
  1335. +
  1336.         return $this->_sendRawPost($this->_updateUrl$rawPost);
  1337. +
  1338.     }
  1339. +
  1340.  
  1341. +
  1342.     /**
  1343. +
  1344.      * Add a Solr Document to the index
  1345. +
  1346.      *
  1347. +
  1348.      * @param Apache_Solr_Document $document 
  1349. +
  1350.      * @param boolean $allowDups 
  1351. +
  1352.      * @param boolean $overwritePending 
  1353. +
  1354.      * @param boolean $overwriteCommitted 
  1355. +
  1356.      * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
  1357. +
  1358.      * @return Apache_Solr_Response 
  1359. +
  1360.      *
  1361. +
  1362.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1363. +
  1364.      */
  1365. +
  1366.     public function addDocument(Apache_Solr_Document $document$allowDups false$overwritePending true$overwriteCommitted true$commitWithin 0)
  1367. +
  1368.     {
  1369. +
  1370.         $dupValue $allowDups 'true' 'false';
  1371. +
  1372.         $pendingValue $overwritePending 'true' 'false';
  1373. +
  1374.         $committedValue $overwriteCommitted 'true' 'false';
  1375. +
  1376.         
  1377. +
  1378.         $commitWithin = (int) $commitWithin;
  1379. +
  1380.         $commitWithinString $commitWithin " commitWithin=\"{$commitWithin}\"'';
  1381. +
  1382.         
  1383. +
  1384.         $rawPost "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
  1385. +
  1386.         $rawPost .= $this->_documentToXmlFragment($document);
  1387. +
  1388.         $rawPost .= '</add>';
  1389. +
  1390.  
  1391. +
  1392.         return $this->add($rawPost);
  1393. +
  1394.     }
  1395. +
  1396.  
  1397. +
  1398.     /**
  1399. +
  1400.      * Add an array of Solr Documents to the index all at once
  1401. +
  1402.      *
  1403. +
  1404.      * @param array $documents Should be an array of Apache_Solr_Document instances
  1405. +
  1406.      * @param boolean $allowDups 
  1407. +
  1408.      * @param boolean $overwritePending 
  1409. +
  1410.      * @param boolean $overwriteCommitted 
  1411. +
  1412.      * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
  1413. +
  1414.      * @return Apache_Solr_Response 
  1415. +
  1416.      *
  1417. +
  1418.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1419. +
  1420.      */
  1421. +
  1422.     public function addDocuments($documents$allowDups false$overwritePending true$overwriteCommitted true$commitWithin 0)
  1423. +
  1424.     {
  1425. +
  1426.         $dupValue $allowDups 'true' 'false';
  1427. +
  1428.         $pendingValue $overwritePending 'true' 'false';
  1429. +
  1430.         $committedValue $overwriteCommitted 'true' 'false';
  1431. +
  1432.  
  1433. +
  1434.         $commitWithin = (int) $commitWithin;
  1435. +
  1436.         $commitWithinString $commitWithin " commitWithin=\"{$commitWithin}\"'';
  1437. +
  1438.  
  1439. +
  1440.         $rawPost "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
  1441. +
  1442.  
  1443. +
  1444.         foreach ($documents as $document)
  1445. +
  1446.         {
  1447. +
  1448.             if ($document instanceof Apache_Solr_Document)
  1449. +
  1450.             {
  1451. +
  1452.                 $rawPost .= $this->_documentToXmlFragment($document);
  1453. +
  1454.             }
  1455. +
  1456.         }
  1457. +
  1458.  
  1459. +
  1460.         $rawPost .= '</add>';
  1461. +
  1462.  
  1463. +
  1464.         return $this->add($rawPost);
  1465. +
  1466.     }
  1467. +
  1468.  
  1469. +
  1470.     /**
  1471. +
  1472.      * Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
  1473. +
  1474.      *
  1475. +
  1476.      * @return string 
  1477. +
  1478.      */
  1479. +
  1480.     protected function _documentToXmlFragment(Apache_Solr_Document $document)
  1481. +
  1482.     {
  1483. +
  1484.         $xml '<doc';
  1485. +
  1486.  
  1487. +
  1488.         if ($document->getBoost(!== false)
  1489. +
  1490.         {
  1491. +
  1492.             $xml .= ' boost="' $document->getBoost('"';
  1493. +
  1494.         }
  1495. +
  1496.  
  1497. +
  1498.         $xml .= '>';
  1499. +
  1500.  
  1501. +
  1502.         foreach ($document as $key => $value)
  1503. +
  1504.         {
  1505. +
  1506.             $key htmlspecialchars($keyENT_QUOTES'UTF-8');
  1507. +
  1508.             $fieldBoost $document->getFieldBoost($key);
  1509. +
  1510.  
  1511. +
  1512.             if (is_array($value))
  1513. +
  1514.             {
  1515. +
  1516.                 foreach ($value as $multivalue)
  1517. +
  1518.                 {
  1519. +
  1520.                     $xml .= '<field name="' $key '"';
  1521. +
  1522.  
  1523. +
  1524.                     if ($fieldBoost !== false)
  1525. +
  1526.                     {
  1527. +
  1528.                         $xml .= ' boost="' $fieldBoost '"';
  1529. +
  1530.  
  1531. +
  1532.                         // only set the boost for the first field in the set
  1533. +
  1534.                         $fieldBoost false;
  1535. +
  1536.                     }
  1537. +
  1538.  
  1539. +
  1540.                     $multivalue htmlspecialchars($multivalueENT_NOQUOTES'UTF-8');
  1541. +
  1542.  
  1543. +
  1544.                     $xml .= '>' $multivalue '</field>';
  1545. +
  1546.                 }
  1547. +
  1548.             }
  1549. +
  1550.             else
  1551. +
  1552.             {
  1553. +
  1554.                 $xml .= '<field name="' $key '"';
  1555. +
  1556.  
  1557. +
  1558.                 if ($fieldBoost !== false)
  1559. +
  1560.                 {
  1561. +
  1562.                     $xml .= ' boost="' $fieldBoost '"';
  1563. +
  1564.                 }
  1565. +
  1566.  
  1567. +
  1568.                 $value htmlspecialchars($valueENT_NOQUOTES'UTF-8');
  1569. +
  1570.  
  1571. +
  1572.                 $xml .= '>' $value '</field>';
  1573. +
  1574.             }
  1575. +
  1576.         }
  1577. +
  1578.  
  1579. +
  1580.         $xml .= '</doc>';
  1581. +
  1582.  
  1583. +
  1584.         // replace any control characters to avoid Solr XML parser exception
  1585. +
  1586.         return $this->_stripCtrlChars($xml);
  1587. +
  1588.     }
  1589. +
  1590.  
  1591. +
  1592.     /**
  1593. +
  1594.      * Replace control (non-printable) characters from string that are invalid to Solr's XML parser with a space.
  1595. +
  1596.      *
  1597. +
  1598.      * @param string $string 
  1599. +
  1600.      * @return string 
  1601. +
  1602.      */
  1603. +
  1604.     protected function _stripCtrlChars($string)
  1605. +
  1606.     {
  1607. +
  1608.         // See:  http://w3.org/International/questions/qa-forms-utf-8.html
  1609. +
  1610.         // Printable utf-8 does not include any of these chars below x7F
  1611. +
  1612.         return preg_replace('@[\x00-\x08\x0B\x0C\x0E-\x1F]@'' '$string);
  1613. +
  1614.     }
  1615. +
  1616.  
  1617. +
  1618.     /**
  1619. +
  1620.      * Send a commit command.  Will be synchronous unless both wait parameters are set to false.
  1621. +
  1622.      *
  1623. +
  1624.      * @param boolean $expungeDeletes Defaults to false, merge segments with deletes away
  1625. +
  1626.      * @param boolean $waitFlush Defaults to true,  block until index changes are flushed to disk
  1627. +
  1628.      * @param boolean $waitSearcher Defaults to true, block until a new searcher is opened and registered as the main query searcher, making the changes visible
  1629. +
  1630.      * @param float $timeout Maximum expected duration (in seconds) of the commit operation on the server (otherwise, will throw a communication exception). Defaults to 1 hour
  1631. +
  1632.      * @return Apache_Solr_Response 
  1633. +
  1634.      *
  1635. +
  1636.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1637. +
  1638.      */
  1639. +
  1640.     public function commit($expungeDeletes false$waitFlush true$waitSearcher true$timeout 3600)
  1641. +
  1642.     {
  1643. +
  1644.         $expungeValue $expungeDeletes 'true' 'false';
  1645. +
  1646.         $flushValue $waitFlush 'true' 'false';
  1647. +
  1648.         $searcherValue $waitSearcher 'true' 'false';
  1649. +
  1650.  
  1651. +
  1652.         $rawPost '<commit expungeDeletes="' $expungeValue '" waitFlush="' $flushValue '" waitSearcher="' $searcherValue '" />';
  1653. +
  1654.  
  1655. +
  1656.         return $this->_sendRawPost($this->_updateUrl$rawPost$timeout);
  1657. +
  1658.     }
  1659. +
  1660.  
  1661. +
  1662.     /**
  1663. +
  1664.      * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
  1665. +
  1666.      * a complete and well formed "delete" xml document
  1667. +
  1668.      *
  1669. +
  1670.      * @param string $rawPost Expected to be utf-8 encoded xml document
  1671. +
  1672.      * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  1673. +
  1674.      * @return Apache_Solr_Response 
  1675. +
  1676.      *
  1677. +
  1678.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1679. +
  1680.      */
  1681. +
  1682.     public function delete($rawPost$timeout 3600)
  1683. +
  1684.     {
  1685. +
  1686.         return $this->_sendRawPost($this->_updateUrl$rawPost$timeout);
  1687. +
  1688.     }
  1689. +
  1690.  
  1691. +
  1692.     /**
  1693. +
  1694.      * Create a delete document based on document ID
  1695. +
  1696.      *
  1697. +
  1698.      * @param string $id Expected to be utf-8 encoded
  1699. +
  1700.      * @param boolean $fromPending 
  1701. +
  1702.      * @param boolean $fromCommitted 
  1703. +
  1704.      * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  1705. +
  1706.      * @return Apache_Solr_Response 
  1707. +
  1708.      *
  1709. +
  1710.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1711. +
  1712.      */
  1713. +
  1714.     public function deleteById($id$fromPending true$fromCommitted true$timeout 3600)
  1715. +
  1716.     {
  1717. +
  1718.         $pendingValue $fromPending 'true' 'false';
  1719. +
  1720.         $committedValue $fromCommitted 'true' 'false';
  1721. +
  1722.  
  1723. +
  1724.         //escape special xml characters
  1725. +
  1726.         $id htmlspecialchars($idENT_NOQUOTES'UTF-8');
  1727. +
  1728.  
  1729. +
  1730.         $rawPost '<delete fromPending="' $pendingValue '" fromCommitted="' $committedValue '"><id>' $id '</id></delete>';
  1731. +
  1732.  
  1733. +
  1734.         return $this->delete($rawPost$timeout);
  1735. +
  1736.     }
  1737. +
  1738.  
  1739. +
  1740.     /**
  1741. +
  1742.      * Create and post a delete document based on multiple document IDs.
  1743. +
  1744.      *
  1745. +
  1746.      * @param array $ids Expected to be utf-8 encoded strings
  1747. +
  1748.      * @param boolean $fromPending 
  1749. +
  1750.      * @param boolean $fromCommitted 
  1751. +
  1752.      * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  1753. +
  1754.      * @return Apache_Solr_Response 
  1755. +
  1756.      *
  1757. +
  1758.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1759. +
  1760.      */
  1761. +
  1762.     public function deleteByMultipleIds($ids$fromPending true$fromCommitted true$timeout 3600)
  1763. +
  1764.     {
  1765. +
  1766.         $pendingValue $fromPending 'true' 'false';
  1767. +
  1768.         $committedValue $fromCommitted 'true' 'false';
  1769. +
  1770.  
  1771. +
  1772.         $rawPost '<delete fromPending="' $pendingValue '" fromCommitted="' $committedValue '">';
  1773. +
  1774.  
  1775. +
  1776.         foreach ($ids as $id)
  1777. +
  1778.         {
  1779. +
  1780.             //escape special xml characters
  1781. +
  1782.             $id htmlspecialchars($idENT_NOQUOTES'UTF-8');
  1783. +
  1784.  
  1785. +
  1786.             $rawPost .= '<id>' $id '</id>';
  1787. +
  1788.         }
  1789. +
  1790.  
  1791. +
  1792.         $rawPost .= '</delete>';
  1793. +
  1794.  
  1795. +
  1796.         return $this->delete($rawPost$timeout);
  1797. +
  1798.     }
  1799. +
  1800.  
  1801. +
  1802.     /**
  1803. +
  1804.      * Create a delete document based on a query and submit it
  1805. +
  1806.      *
  1807. +
  1808.      * @param string $rawQuery Expected to be utf-8 encoded
  1809. +
  1810.      * @param boolean $fromPending 
  1811. +
  1812.      * @param boolean $fromCommitted 
  1813. +
  1814.      * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  1815. +
  1816.      * @return Apache_Solr_Response 
  1817. +
  1818.      *
  1819. +
  1820.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1821. +
  1822.      */
  1823. +
  1824.     public function deleteByQuery($rawQuery$fromPending true$fromCommitted true$timeout 3600)
  1825. +
  1826.     {
  1827. +
  1828.         $pendingValue $fromPending 'true' 'false';
  1829. +
  1830.         $committedValue $fromCommitted 'true' 'false';
  1831. +
  1832.  
  1833. +
  1834.         // escape special xml characters
  1835. +
  1836.         $rawQuery htmlspecialchars($rawQueryENT_NOQUOTES'UTF-8');
  1837. +
  1838.  
  1839. +
  1840.         $rawPost '<delete fromPending="' $pendingValue '" fromCommitted="' $committedValue '"><query>' $rawQuery '</query></delete>';
  1841. +
  1842.  
  1843. +
  1844.         return $this->delete($rawPost$timeout);
  1845. +
  1846.     }
  1847. +
  1848.  
  1849. +
  1850.     /**
  1851. +
  1852.      * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
  1853. +
  1854.      * to use Solr Cell and what parameters are available.
  1855. +
  1856.      *
  1857. +
  1858.      * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
  1859. +
  1860.      * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
  1861. +
  1862.      * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
  1863. +
  1864.      * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
  1865. +
  1866.      *
  1867. +
  1868.      * @param string $file Path to file to extract data from
  1869. +
  1870.      * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  1871. +
  1872.      * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
  1873. +
  1874.      * @param string $mimetype optional mimetype specification (for the file being extracted)
  1875. +
  1876.      *
  1877. +
  1878.      * @return Apache_Solr_Response 
  1879. +
  1880.      *
  1881. +
  1882.      * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  1883. +
  1884.      */
  1885. +
  1886.     public function extract($file$params array()$document null$mimetype 'application/octet-stream')
  1887. +
  1888.     {
  1889. +
  1890.         // check if $params is an array (allow null for default empty array)
  1891. +
  1892.         if (!is_null($params))
  1893. +
  1894.         {
  1895. +
  1896.             if (!is_array($params))
  1897. +
  1898.             {
  1899. +
  1900.                 throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
  1901. +
  1902.             }
  1903. +
  1904.         }
  1905. +
  1906.         else
  1907. +
  1908.         {
  1909. +
  1910.             $params array();
  1911. +
  1912.         }
  1913. +
  1914.         
  1915. +
  1916.         // if $file is an http request, defer to extractFromUrl instead
  1917. +
  1918.         if (substr($file07== 'http://' || substr($file08== 'https://')
  1919. +
  1920.         {
  1921. +
  1922.             return $this->extractFromUrl($file$params$document$mimetype);
  1923. +
  1924.         }
  1925. +
  1926.         
  1927. +
  1928.         // read the contents of the file
  1929. +
  1930.         $contents @file_get_contents($file);
  1931. +
  1932.  
  1933. +
  1934.         if ($contents !== false)
  1935. +
  1936.         {
  1937. +
  1938.             // add the resource.name parameter if not specified
  1939. +
  1940.             if (!isset($params['resource.name']))
  1941. +
  1942.             {
  1943. +
  1944.                 $params['resource.name'basename($file);
  1945. +
  1946.             }
  1947. +
  1948.  
  1949. +
  1950.             // delegate the rest to extractFromString
  1951. +
  1952.             return $this->extractFromString($contents$params$document$mimetype);
  1953. +
  1954.         }
  1955. +
  1956.         else
  1957. +
  1958.         {
  1959. +
  1960.             throw new Apache_Solr_InvalidArgumentException("File '{$file}' is empty or could not be read");
  1961. +
  1962.         }
  1963. +
  1964.     }
  1965. +
  1966.     
  1967. +
  1968.     /**
  1969. +
  1970.      * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
  1971. +
  1972.      * to use Solr Cell and what parameters are available.
  1973. +
  1974.      *
  1975. +
  1976.      * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
  1977. +
  1978.      * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
  1979. +
  1980.      * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
  1981. +
  1982.      * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
  1983. +
  1984.      *
  1985. +
  1986.      * @param string $data Data that will be passed to Solr Cell
  1987. +
  1988.      * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  1989. +
  1990.      * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
  1991. +
  1992.      * @param string $mimetype optional mimetype specification (for the file being extracted)
  1993. +
  1994.      *
  1995. +
  1996.      * @return Apache_Solr_Response 
  1997. +
  1998.      *
  1999. +
  2000.      * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  2001. +
  2002.      *
  2003. +
  2004.      * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
  2005. +
  2006.      */
  2007. +
  2008.     public function extractFromString($data$params array()$document null$mimetype 'application/octet-stream')
  2009. +
  2010.     {
  2011. +
  2012.         // check if $params is an array (allow null for default empty array)
  2013. +
  2014.         if (!is_null($params))
  2015. +
  2016.         {
  2017. +
  2018.             if (!is_array($params))
  2019. +
  2020.             {
  2021. +
  2022.                 throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
  2023. +
  2024.             }
  2025. +
  2026.         }
  2027. +
  2028.         else
  2029. +
  2030.         {
  2031. +
  2032.             $params array();
  2033. +
  2034.         }
  2035. +
  2036.  
  2037. +
  2038.         // make sure we receive our response in JSON and have proper name list treatment
  2039. +
  2040.         $params['wt'self::SOLR_WRITER;
  2041. +
  2042.         $params['json.nl'$this->_namedListTreatment;
  2043. +
  2044.  
  2045. +
  2046.         // check if $document is an Apache_Solr_Document instance
  2047. +
  2048.         if (!is_null($document&& $document instanceof Apache_Solr_Document)
  2049. +
  2050.         {
  2051. +
  2052.             // iterate document, adding literal.* and boost.* fields to $params as appropriate
  2053. +
  2054.             foreach ($document as $field => $fieldValue)
  2055. +
  2056.             {
  2057. +
  2058.                 // check if we need to add a boost.* parameters
  2059. +
  2060.                 $fieldBoost $document->getFieldBoost($field);
  2061. +
  2062.  
  2063. +
  2064.                 if ($fieldBoost !== false)
  2065. +
  2066.                 {
  2067. +
  2068.                     $params["boost.{$field}"$fieldBoost;
  2069. +
  2070.                 }
  2071. +
  2072.  
  2073. +
  2074.                 // add the literal.* parameter
  2075. +
  2076.                 $params["literal.{$field}"$fieldValue;
  2077. +
  2078.             }
  2079. +
  2080.         }
  2081. +
  2082.  
  2083. +
  2084.         // params will be sent to SOLR in the QUERY STRING
  2085. +
  2086.         $queryString $this->_generateQueryString($params);
  2087. +
  2088.  
  2089. +
  2090.         // the file contents will be sent to SOLR as the POST BODY - we use application/octect-stream as default mimetype
  2091. +
  2092.         return $this->_sendRawPost($this->_extractUrl $this->_queryDelimiter . $queryString$datafalse$mimetype);
  2093. +
  2094.     }
  2095. +
  2096.     
  2097. +
  2098.     /**
  2099. +
  2100.      * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
  2101. +
  2102.      * to use Solr Cell and what parameters are available.
  2103. +
  2104.      *
  2105. +
  2106.      * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
  2107. +
  2108.      * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
  2109. +
  2110.      * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
  2111. +
  2112.      * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
  2113. +
  2114.      *
  2115. +
  2116.      * @param string $url URL
  2117. +
  2118.      * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  2119. +
  2120.      * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
  2121. +
  2122.      * @param string $mimetype optional mimetype specification (for the file being extracted)
  2123. +
  2124.      *
  2125. +
  2126.      * @return Apache_Solr_Response 
  2127. +
  2128.      *
  2129. +
  2130.      * @throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid.
  2131. +
  2132.      */
  2133. +
  2134.     public function extractFromUrl($url$params array()$document null$mimetype 'application/octet-stream')
  2135. +
  2136.     {
  2137. +
  2138.         // check if $params is an array (allow null for default empty array)
  2139. +
  2140.         if (!is_null($params))
  2141. +
  2142.         {
  2143. +
  2144.             if (!is_array($params))
  2145. +
  2146.             {
  2147. +
  2148.                 throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
  2149. +
  2150.             }
  2151. +
  2152.         }
  2153. +
  2154.         else
  2155. +
  2156.         {
  2157. +
  2158.             $params array();
  2159. +
  2160.         }
  2161. +
  2162.  
  2163. +
  2164.         $httpTransport $this->getHttpTransport();
  2165. +
  2166.         
  2167. +
  2168.         // read the contents of the URL using our configured Http Transport and default timeout
  2169. +
  2170.         $httpResponse $httpTransport->performGetRequest($url);
  2171. +
  2172.         
  2173. +
  2174.         // check that its a 200 response
  2175. +
  2176.         if ($httpResponse->getStatusCode(== 200)
  2177. +
  2178.         {
  2179. +
  2180.             // add the resource.name parameter if not specified
  2181. +
  2182.             if (!isset($params['resource.name']))
  2183. +
  2184.             {
  2185. +
  2186.                 $params['resource.name'$url;
  2187. +
  2188.             }
  2189. +
  2190.  
  2191. +
  2192.             // delegate the rest to extractFromString
  2193. +
  2194.             return $this->extractFromString($httpResponse->getBody()$params$document$mimetype);
  2195. +
  2196.         }
  2197. +
  2198.         else
  2199. +
  2200.         {
  2201. +
  2202.             throw new Apache_Solr_InvalidArgumentException("URL '{$url}' returned non 200 response code");
  2203. +
  2204.         }
  2205. +
  2206.     }
  2207. +
  2208.  
  2209. +
  2210.     /**
  2211. +
  2212.      * Send an optimize command.  Will be synchronous unless both wait parameters are set
  2213. +
  2214.      * to false.
  2215. +
  2216.      *
  2217. +
  2218.      * @param boolean $waitFlush 
  2219. +
  2220.      * @param boolean $waitSearcher 
  2221. +
  2222.      * @param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
  2223. +
  2224.      * @return Apache_Solr_Response 
  2225. +
  2226.      *
  2227. +
  2228.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  2229. +
  2230.      */
  2231. +
  2232.     public function optimize($waitFlush true$waitSearcher true$timeout 3600)
  2233. +
  2234.     {
  2235. +
  2236.         $flushValue $waitFlush 'true' 'false';
  2237. +
  2238.         $searcherValue $waitSearcher 'true' 'false';
  2239. +
  2240.  
  2241. +
  2242.         $rawPost '<optimize waitFlush="' $flushValue '" waitSearcher="' $searcherValue '" />';
  2243. +
  2244.  
  2245. +
  2246.         return $this->_sendRawPost($this->_updateUrl$rawPost$timeout);
  2247. +
  2248.     }
  2249. +
  2250.  
  2251. +
  2252.     /**
  2253. +
  2254.      * Simple Search interface
  2255. +
  2256.      *
  2257. +
  2258.      * @param string $query The raw query string
  2259. +
  2260.      * @param int $offset The starting offset for result documents
  2261. +
  2262.      * @param int $limit The maximum number of result documents to return
  2263. +
  2264.      * @param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field)
  2265. +
  2266.      * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
  2267. +
  2268.      * @return Apache_Solr_Response 
  2269. +
  2270.      *
  2271. +
  2272.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  2273. +
  2274.      * @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used
  2275. +
  2276.      */
  2277. +
  2278.     public function search($query$offset 0$limit 10$params array()$method self::METHOD_GET)
  2279. +
  2280.     {
  2281. +
  2282.         // ensure params is an array
  2283. +
  2284.         if (!is_null($params))
  2285. +
  2286.         {
  2287. +
  2288.             if (!is_array($params))
  2289. +
  2290.             {
  2291. +
  2292.                 // params was specified but was not an array - invalid
  2293. +
  2294.                 throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
  2295. +
  2296.             }
  2297. +
  2298.         }
  2299. +
  2300.         else
  2301. +
  2302.         {
  2303. +
  2304.             $params array();
  2305. +
  2306.         }
  2307. +
  2308.         
  2309. +
  2310.         // construct our full parameters
  2311. +
  2312.  
  2313. +
  2314.         // common parameters in this interface
  2315. +
  2316.         $params['wt'self::SOLR_WRITER;
  2317. +
  2318.         $params['json.nl'$this->_namedListTreatment;
  2319. +
  2320.  
  2321. +
  2322.         $params['q'$query;
  2323. +
  2324.         $params['start'$offset;
  2325. +
  2326.         $params['rows'$limit;
  2327. +
  2328.  
  2329. +
  2330.         $queryString $this->_generateQueryString($params);
  2331. +
  2332.  
  2333. +
  2334.         if ($method == self::METHOD_GET)
  2335. +
  2336.         {
  2337. +
  2338.             return $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString);
  2339. +
  2340.         }
  2341. +
  2342.         else if ($method == self::METHOD_POST)
  2343. +
  2344.         {
  2345. +
  2346.             return $this->_sendRawPost($this->_searchUrl$queryStringFALSE'application/x-www-form-urlencoded; charset=UTF-8');
  2347. +
  2348.         }
  2349. +
  2350.         else
  2351. +
  2352.         {
  2353. +
  2354.             throw new Apache_Solr_InvalidArgumentException("Unsupported method '$method', please use the Apache_Solr_Service::METHOD_* constants");
  2355. +
  2356.         }
  2357. +
  2358.     }
  2359. +
  2360. }
  2361. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:19 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_ServiceBalancer.php.html b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_ServiceBalancer.php.html new file mode 100644 index 00000000..f7707cd1 --- /dev/null +++ b/SolrPhpClient/phpdocs/__filesource/fsource_Apache_Solr_ServiceBalancer.php.html @@ -0,0 +1,934 @@ + + + + + + File Source for Balancer.php + + + + +

Source for file Balancer.php

+

Documentation is available at Balancer.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.  * Copyright (c) 2007-2011, Servigistics, Inc.
  6. +
  7.  * All rights reserved.
  8. +
  9.  *
  10. +
  11.  * Redistribution and use in source and binary forms, with or without
  12. +
  13.  * modification, are permitted provided that the following conditions are met:
  14. +
  15.  *
  16. +
  17.  *  - Redistributions of source code must retain the above copyright notice,
  18. +
  19.  *    this list of conditions and the following disclaimer.
  20. +
  21.  *  - Redistributions in binary form must reproduce the above copyright
  22. +
  23.  *    notice, this list of conditions and the following disclaimer in the
  24. +
  25.  *    documentation and/or other materials provided with the distribution.
  26. +
  27.  *  - Neither the name of Servigistics, Inc. nor the names of
  28. +
  29.  *    its contributors may be used to endorse or promote products derived from
  30. +
  31.  *    this software without specific prior written permission.
  32. +
  33.  *
  34. +
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36. +
  37.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38. +
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. +
  41.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  42. +
  43.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  44. +
  45.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  46. +
  47.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. +
  49.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. +
  51.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. +
  53.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  54. +
  55.  * POSSIBILITY OF SUCH DAMAGE.
  56. +
  57.  *
  58. +
  59.  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
  60. +
  61.  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
  62. +
  63.  * @version $Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $
  64. +
  65.  *
  66. +
  67.  * @package Apache
  68. +
  69.  * @subpackage Solr
  70. +
  71.  * @author Donovan Jimenez <djimenez@conduit-it.com>, Dan Wolfe
  72. +
  73.  */
  74. +
  75.  
  76. +
  77. // See Issue #1 (http://code.google.com/p/solr-php-client/issues/detail?id=1)
  78. +
  79. // Doesn't follow typical include path conventions, but is more convenient for users
  80. +
  81. require_once(dirname(dirname(__FILE__)) '/Service.php');
  82. +
  83.  
  84. +
  85. require_once(dirname(dirname(__FILE__)) '/NoServiceAvailableException.php');
  86. +
  87.  
  88. +
  89. /**
  90. +
  91.  * Reference Implementation for using multiple Solr services in a distribution. Functionality
  92. +
  93.  * includes:
  94. +
  95.  *     routing of read / write operations
  96. +
  97.  *     failover (on selection) for multiple read servers
  98. +
  99.  */
  100. +
  101. +
  102. {
  103. +
  104.     /**
  105. +
  106.      * SVN Revision meta data for this class
  107. +
  108.      */
  109. +
  110.     const SVN_REVISION '$Revision: 54 $';
  111. +
  112.  
  113. +
  114.     /**
  115. +
  116.      * SVN ID meta data for this class
  117. +
  118.      */
  119. +
  120.     const SVN_ID '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
  121. +
  122.  
  123. +
  124.     protected $_createDocuments = true;
  125. +
  126.  
  127. +
  128.     protected $_readableServices = array();
  129. +
  130.     protected $_writeableServices = array();
  131. +
  132.  
  133. +
  134.     protected $_currentReadService = null;
  135. +
  136.     protected $_currentWriteService = null;
  137. +
  138.  
  139. +
  140.     protected $_readPingTimeout = 2;
  141. +
  142.     protected $_writePingTimeout = 4;
  143. +
  144.  
  145. +
  146.     // Configuration for server selection backoff intervals
  147. +
  148.     protected $_useBackoff = false;        // Set to true to use more resillient write server selection
  149. +
  150.     protected $_backoffLimit = 600;        // 10 minute default maximum
  151. +
  152.     protected $_backoffEscalation = 2.0;     // Rate at which to increase backoff period
  153. +
  154.     protected $_defaultBackoff = 2.0;        // Default backoff interval
  155. +
  156.  
  157. +
  158.     /**
  159. +
  160.      * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
  161. +
  162.      *
  163. +
  164.      * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
  165. +
  166.      *
  167. +
  168.      * @param string $value 
  169. +
  170.      * @return string 
  171. +
  172.      */
  173. +
  174.     static public function escape($value)
  175. +
  176.     {
  177. +
  178.         return Apache_Solr_Service::escape($value);
  179. +
  180.     }
  181. +
  182.  
  183. +
  184.     /**
  185. +
  186.      * Escape a value meant to be contained in a phrase for special query characters
  187. +
  188.      *
  189. +
  190.      * @param string $value 
  191. +
  192.      * @return string 
  193. +
  194.      */
  195. +
  196.     static public function escapePhrase($value)
  197. +
  198.     {
  199. +
  200.         return Apache_Solr_Service::escapePhrase($value);
  201. +
  202.     }
  203. +
  204.  
  205. +
  206.     /**
  207. +
  208.      * Convenience function for creating phrase syntax from a value
  209. +
  210.      *
  211. +
  212.      * @param string $value 
  213. +
  214.      * @return string 
  215. +
  216.      */
  217. +
  218.     static public function phrase($value)
  219. +
  220.     {
  221. +
  222.         return Apache_Solr_Service::phrase($value);
  223. +
  224.     }
  225. +
  226.  
  227. +
  228.     /**
  229. +
  230.      * Constructor. Takes arrays of read and write service instances or descriptions
  231. +
  232.      *
  233. +
  234.      * @param array $readableServices 
  235. +
  236.      * @param array $writeableServices 
  237. +
  238.      */
  239. +
  240.     public function __construct($readableServices array()$writeableServices array())
  241. +
  242.     {
  243. +
  244.         //setup readable services
  245. +
  246.         foreach ($readableServices as $service)
  247. +
  248.         {
  249. +
  250.             $this->addReadService($service);
  251. +
  252.         }
  253. +
  254.  
  255. +
  256.         //setup writeable services
  257. +
  258.         foreach ($writeableServices as $service)
  259. +
  260.         {
  261. +
  262.             $this->addWriteService($service);
  263. +
  264.         }
  265. +
  266.     }
  267. +
  268.  
  269. +
  270.     public function setReadPingTimeout($timeout)
  271. +
  272.     {
  273. +
  274.         $this->_readPingTimeout = $timeout;
  275. +
  276.     }
  277. +
  278.  
  279. +
  280.     public function setWritePingTimeout($timeout)
  281. +
  282.     {
  283. +
  284.         $this->_writePingTimeout = $timeout;
  285. +
  286.     }
  287. +
  288.  
  289. +
  290.     public function setUseBackoff($enable)
  291. +
  292.     {
  293. +
  294.         $this->_useBackoff = $enable;
  295. +
  296.     }
  297. +
  298.  
  299. +
  300.     /**
  301. +
  302.      * Generates a service ID
  303. +
  304.      *
  305. +
  306.      * @param string $host 
  307. +
  308.      * @param integer $port 
  309. +
  310.      * @param string $path 
  311. +
  312.      * @return string 
  313. +
  314.      */
  315. +
  316.     protected function _getServiceId($host$port$path)
  317. +
  318.     {
  319. +
  320.         return $host ':' $port $path;
  321. +
  322.     }
  323. +
  324.  
  325. +
  326.     /**
  327. +
  328.      * Adds a service instance or service descriptor (if it is already
  329. +
  330.      * not added)
  331. +
  332.      *
  333. +
  334.      * @param mixed $service 
  335. +
  336.      *
  337. +
  338.      * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
  339. +
  340.      */
  341. +
  342.     public function addReadService($service)
  343. +
  344.     {
  345. +
  346.         if ($service instanceof Apache_Solr_Service)
  347. +
  348.         {
  349. +
  350.             $id $this->_getServiceId($service->getHost()$service->getPort()$service->getPath());
  351. +
  352.  
  353. +
  354.             $this->_readableServices[$id$service;
  355. +
  356.         }
  357. +
  358.         else if (is_array($service))
  359. +
  360.         {
  361. +
  362.             if (isset($service['host']&& isset($service['port']&& isset($service['path']))
  363. +
  364.             {
  365. +
  366.                 $id $this->_getServiceId((string)$service['host'](int)$service['port'](string)$service['path']);
  367. +
  368.  
  369. +
  370.                 $this->_readableServices[$id$service;
  371. +
  372.             }
  373. +
  374.             else
  375. +
  376.             {
  377. +
  378.                 throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
  379. +
  380.             }
  381. +
  382.         }
  383. +
  384.     }
  385. +
  386.  
  387. +
  388.     /**
  389. +
  390.      * Removes a service instance or descriptor from the available services
  391. +
  392.      *
  393. +
  394.      * @param mixed $service 
  395. +
  396.      *
  397. +
  398.      * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
  399. +
  400.      */
  401. +
  402.     public function removeReadService($service)
  403. +
  404.     {
  405. +
  406.         $id '';
  407. +
  408.  
  409. +
  410.         if ($service instanceof Apache_Solr_Service)
  411. +
  412.         {
  413. +
  414.             $id $this->_getServiceId($service->getHost()$service->getPort()$service->getPath());
  415. +
  416.         }
  417. +
  418.         else if (is_array($service))
  419. +
  420.         {
  421. +
  422.             if (isset($service['host']&& isset($service['port']&& isset($service['path']))
  423. +
  424.             {
  425. +
  426.                 $id $this->_getServiceId((string)$service['host'](int)$service['port'](string)$service['path']);
  427. +
  428.             }
  429. +
  430.             else
  431. +
  432.             {
  433. +
  434.                 throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
  435. +
  436.             }
  437. +
  438.         }
  439. +
  440.         else if (is_string($service))
  441. +
  442.         {
  443. +
  444.             $id $service;
  445. +
  446.         }
  447. +
  448.  
  449. +
  450.         if ($id && isset($this->_readableServices[$id]))
  451. +
  452.         {
  453. +
  454.             unset($this->_readableServices[$id]);
  455. +
  456.         }
  457. +
  458.     }
  459. +
  460.  
  461. +
  462.     /**
  463. +
  464.      * Adds a service instance or service descriptor (if it is already
  465. +
  466.      * not added)
  467. +
  468.      *
  469. +
  470.      * @param mixed $service 
  471. +
  472.      *
  473. +
  474.      * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
  475. +
  476.      */
  477. +
  478.     public function addWriteService($service)
  479. +
  480.     {
  481. +
  482.         if ($service instanceof Apache_Solr_Service)
  483. +
  484.         {
  485. +
  486.             $id $this->_getServiceId($service->getHost()$service->getPort()$service->getPath());
  487. +
  488.  
  489. +
  490.             $this->_writeableServices[$id$service;
  491. +
  492.         }
  493. +
  494.         else if (is_array($service))
  495. +
  496.         {
  497. +
  498.             if (isset($service['host']&& isset($service['port']&& isset($service['path']))
  499. +
  500.             {
  501. +
  502.                 $id $this->_getServiceId((string)$service['host'](int)$service['port'](string)$service['path']);
  503. +
  504.  
  505. +
  506.                 $this->_writeableServices[$id$service;
  507. +
  508.             }
  509. +
  510.             else
  511. +
  512.             {
  513. +
  514.                 throw new Apache_Solr_InvalidArgumentException('A Writeable Service description array does not have all required elements of host, port, and path');
  515. +
  516.             }
  517. +
  518.         }
  519. +
  520.     }
  521. +
  522.  
  523. +
  524.     /**
  525. +
  526.      * Removes a service instance or descriptor from the available services
  527. +
  528.      *
  529. +
  530.      * @param mixed $service 
  531. +
  532.      *
  533. +
  534.      * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
  535. +
  536.      */
  537. +
  538.     public function removeWriteService($service)
  539. +
  540.     {
  541. +
  542.         $id '';
  543. +
  544.  
  545. +
  546.         if ($service instanceof Apache_Solr_Service)
  547. +
  548.         {
  549. +
  550.             $id $this->_getServiceId($service->getHost()$service->getPort()$service->getPath());
  551. +
  552.         }
  553. +
  554.         else if (is_array($service))
  555. +
  556.         {
  557. +
  558.             if (isset($service['host']&& isset($service['port']&& isset($service['path']))
  559. +
  560.             {
  561. +
  562.                 $id $this->_getServiceId((string)$service['host'](int)$service['port'](string)$service['path']);
  563. +
  564.             }
  565. +
  566.             else
  567. +
  568.             {
  569. +
  570.                 throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
  571. +
  572.             }
  573. +
  574.         }
  575. +
  576.         else if (is_string($service))
  577. +
  578.         {
  579. +
  580.             $id $service;
  581. +
  582.         }
  583. +
  584.  
  585. +
  586.         if ($id && isset($this->_writeableServices[$id]))
  587. +
  588.         {
  589. +
  590.             unset($this->_writeableServices[$id]);
  591. +
  592.         }
  593. +
  594.     }
  595. +
  596.  
  597. +
  598.     /**
  599. +
  600.      * Iterate through available read services and select the first with a ping
  601. +
  602.      * that satisfies configured timeout restrictions (or the default)
  603. +
  604.      *
  605. +
  606.      * @return Apache_Solr_Service 
  607. +
  608.      *
  609. +
  610.      * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
  611. +
  612.      */
  613. +
  614.     protected function _selectReadService($forceSelect false)
  615. +
  616.     {
  617. +
  618.         if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]|| $forceSelect)
  619. +
  620.         {
  621. +
  622.             if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]&& $forceSelect)
  623. +
  624.             {
  625. +
  626.                 // we probably had a communication error, ping the current read service, remove it if it times out
  627. +
  628.                 if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout=== false)
  629. +
  630.                 {
  631. +
  632.                     $this->removeReadService($this->_currentReadService);
  633. +
  634.                 }
  635. +
  636.             }
  637. +
  638.  
  639. +
  640.             if (count($this->_readableServices))
  641. +
  642.             {
  643. +
  644.                 // select one of the read services at random
  645. +
  646.                 $ids array_keys($this->_readableServices);
  647. +
  648.  
  649. +
  650.                 $id $ids[rand(0count($ids1)];
  651. +
  652.                 $service $this->_readableServices[$id];
  653. +
  654.  
  655. +
  656.                 if (is_array($service))
  657. +
  658.                 {
  659. +
  660.                     //convert the array definition to a client object
  661. +
  662.                     $service new Apache_Solr_Service($service['host']$service['port']$service['path']);
  663. +
  664.                     $this->_readableServices[$id$service;
  665. +
  666.                 }
  667. +
  668.  
  669. +
  670.                 $service->setCreateDocuments($this->_createDocuments);
  671. +
  672.                 $this->_currentReadService = $id;
  673. +
  674.             }
  675. +
  676.             else
  677. +
  678.             {
  679. +
  680.                 throw new Apache_Solr_NoServiceAvailableException('No read services were available');
  681. +
  682.             }
  683. +
  684.         }
  685. +
  686.  
  687. +
  688.         return $this->_readableServices[$this->_currentReadService];
  689. +
  690.     }
  691. +
  692.  
  693. +
  694.     /**
  695. +
  696.      * Iterate through available write services and select the first with a ping
  697. +
  698.      * that satisfies configured timeout restrictions (or the default)
  699. +
  700.      *
  701. +
  702.      * @return Apache_Solr_Service 
  703. +
  704.      *
  705. +
  706.      * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
  707. +
  708.      */
  709. +
  710.     protected function _selectWriteService($forceSelect false)
  711. +
  712.     {
  713. +
  714.         if($this->_useBackoff)
  715. +
  716.         {
  717. +
  718.             return $this->_selectWriteServiceSafe($forceSelect);
  719. +
  720.         }
  721. +
  722.  
  723. +
  724.         if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]|| $forceSelect)
  725. +
  726.         {
  727. +
  728.             if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]&& $forceSelect)
  729. +
  730.             {
  731. +
  732.                 // we probably had a communication error, ping the current read service, remove it if it times out
  733. +
  734.                 if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout=== false)
  735. +
  736.                 {
  737. +
  738.                     $this->removeWriteService($this->_currentWriteService);
  739. +
  740.                 }
  741. +
  742.             }
  743. +
  744.  
  745. +
  746.             if (count($this->_writeableServices))
  747. +
  748.             {
  749. +
  750.                 // select one of the read services at random
  751. +
  752.                 $ids array_keys($this->_writeableServices);
  753. +
  754.  
  755. +
  756.                 $id $ids[rand(0count($ids1)];
  757. +
  758.                 $service $this->_writeableServices[$id];
  759. +
  760.  
  761. +
  762.                 if (is_array($service))
  763. +
  764.                 {
  765. +
  766.                     //convert the array definition to a client object
  767. +
  768.                     $service new Apache_Solr_Service($service['host']$service['port']$service['path']);
  769. +
  770.                     $this->_writeableServices[$id$service;
  771. +
  772.                 }
  773. +
  774.  
  775. +
  776.                 $this->_currentWriteService = $id;
  777. +
  778.             }
  779. +
  780.             else
  781. +
  782.             {
  783. +
  784.                 throw new Apache_Solr_NoServiceAvailableException('No write services were available');
  785. +
  786.             }
  787. +
  788.         }
  789. +
  790.  
  791. +
  792.         return $this->_writeableServices[$this->_currentWriteService];
  793. +
  794.     }
  795. +
  796.  
  797. +
  798.     /**
  799. +
  800.      * Iterate through available write services and select the first with a ping
  801. +
  802.      * that satisfies configured timeout restrictions (or the default).  The
  803. +
  804.      * timeout period will increase until a connection is made or the limit is
  805. +
  806.      * reached.   This will allow for increased reliability with heavily loaded
  807. +
  808.      * server(s).
  809. +
  810.      *
  811. +
  812.      * @return Apache_Solr_Service 
  813. +
  814.      *
  815. +
  816.      * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
  817. +
  818.      */
  819. +
  820.  
  821. +
  822.     protected function _selectWriteServiceSafe($forceSelect false)
  823. +
  824.     {
  825. +
  826.         if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]|| $forceSelect)
  827. +
  828.         {
  829. +
  830.             if (count($this->_writeableServices))
  831. +
  832.             {
  833. +
  834.                 $backoff $this->_defaultBackoff;
  835. +
  836.  
  837. +
  838.                 do {
  839. +
  840.                     // select one of the read services at random
  841. +
  842.                     $ids array_keys($this->_writeableServices);
  843. +
  844.  
  845. +
  846.                     $id $ids[rand(0count($ids1)];
  847. +
  848.                     $service $this->_writeableServices[$id];
  849. +
  850.  
  851. +
  852.                     if (is_array($service))
  853. +
  854.                     {
  855. +
  856.                         //convert the array definition to a client object
  857. +
  858.                         $service new Apache_Solr_Service($service['host']$service['port']$service['path']);
  859. +
  860.                         $this->_writeableServices[$id$service;
  861. +
  862.                     }
  863. +
  864.  
  865. +
  866.                     $this->_currentWriteService = $id;
  867. +
  868.  
  869. +
  870.                     $backoff *= $this->_backoffEscalation;
  871. +
  872.  
  873. +
  874.                     if($backoff $this->_backoffLimit)
  875. +
  876.                     {
  877. +
  878.                         throw new Apache_Solr_NoServiceAvailableException('No write services were available.  All timeouts exceeded.');
  879. +
  880.                     }
  881. +
  882.  
  883. +
  884.                 while($this->_writeableServices[$this->_currentWriteService]->ping($backoff=== false);
  885. +
  886.             }
  887. +
  888.             else
  889. +
  890.             {
  891. +
  892.                 throw new Apache_Solr_NoServiceAvailableException('No write services were available');
  893. +
  894.             }
  895. +
  896.         }
  897. +
  898.  
  899. +
  900.         return $this->_writeableServices[$this->_currentWriteService];
  901. +
  902.     }
  903. +
  904.  
  905. +
  906.     /**
  907. +
  908.      * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
  909. +
  910.      * parse the response and create {@link Apache_Solr_Document} instances in place.
  911. +
  912.      *
  913. +
  914.      * @param boolean $createDocuments 
  915. +
  916.      */
  917. +
  918.     public function setCreateDocuments($createDocuments)
  919. +
  920.     {
  921. +
  922.         $this->_createDocuments = (bool) $createDocuments;
  923. +
  924.  
  925. +
  926.         // set on current read service
  927. +
  928.         if ($this->_currentReadService)
  929. +
  930.         {
  931. +
  932.             $service $this->_selectReadService();
  933. +
  934.             $service->setCreateDocuments($createDocuments);
  935. +
  936.         }
  937. +
  938.     }
  939. +
  940.  
  941. +
  942.     /**
  943. +
  944.      * Get the current state of teh create documents flag.
  945. +
  946.      *
  947. +
  948.      * @return boolean 
  949. +
  950.      */
  951. +
  952.     public function getCreateDocuments()
  953. +
  954.     {
  955. +
  956.         return $this->_createDocuments;
  957. +
  958.     }
  959. +
  960.     
  961. +
  962.     /**
  963. +
  964.      * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
  965. +
  966.      * should be a complete and well formed "add" xml document.
  967. +
  968.      *
  969. +
  970.      * @param string $rawPost 
  971. +
  972.      * @return Apache_Solr_Response 
  973. +
  974.      *
  975. +
  976.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  977. +
  978.      */
  979. +
  980.     public function add($rawPost)
  981. +
  982.     {
  983. +
  984.         $service $this->_selectWriteService();
  985. +
  986.  
  987. +
  988.         do
  989. +
  990.         {
  991. +
  992.             try
  993. +
  994.             {
  995. +
  996.                 return $service->add($rawPost);
  997. +
  998.             }
  999. +
  1000.             catch (Apache_Solr_HttpTransportException $e)
  1001. +
  1002.             {
  1003. +
  1004.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1005. +
  1006.                 {
  1007. +
  1008.                     throw $e;
  1009. +
  1010.                 }
  1011. +
  1012.             }
  1013. +
  1014.  
  1015. +
  1016.             $service $this->_selectWriteService(true);
  1017. +
  1018.         while ($service);
  1019. +
  1020.  
  1021. +
  1022.         return false;
  1023. +
  1024.     }
  1025. +
  1026.  
  1027. +
  1028.     /**
  1029. +
  1030.      * Add a Solr Document to the index
  1031. +
  1032.      *
  1033. +
  1034.      * @param Apache_Solr_Document $document 
  1035. +
  1036.      * @param boolean $allowDups 
  1037. +
  1038.      * @param boolean $overwritePending 
  1039. +
  1040.      * @param boolean $overwriteCommitted 
  1041. +
  1042.      * @return Apache_Solr_Response 
  1043. +
  1044.      *
  1045. +
  1046.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1047. +
  1048.      */
  1049. +
  1050.     public function addDocument(Apache_Solr_Document $document$allowDups false$overwritePending true$overwriteCommitted true)
  1051. +
  1052.     {
  1053. +
  1054.         $service $this->_selectWriteService();
  1055. +
  1056.  
  1057. +
  1058.         do
  1059. +
  1060.         {
  1061. +
  1062.             try
  1063. +
  1064.             {
  1065. +
  1066.                 return $service->addDocument($document$allowDups$overwritePending$overwriteCommitted);
  1067. +
  1068.             }
  1069. +
  1070.             catch (Apache_Solr_HttpTransportException $e)
  1071. +
  1072.             {
  1073. +
  1074.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1075. +
  1076.                 {
  1077. +
  1078.                     throw $e;
  1079. +
  1080.                 }
  1081. +
  1082.             }
  1083. +
  1084.  
  1085. +
  1086.             $service $this->_selectWriteService(true);
  1087. +
  1088.         while ($service);
  1089. +
  1090.  
  1091. +
  1092.         return false;
  1093. +
  1094.     }
  1095. +
  1096.  
  1097. +
  1098.     /**
  1099. +
  1100.      * Add an array of Solr Documents to the index all at once
  1101. +
  1102.      *
  1103. +
  1104.      * @param array $documents Should be an array of Apache_Solr_Document instances
  1105. +
  1106.      * @param boolean $allowDups 
  1107. +
  1108.      * @param boolean $overwritePending 
  1109. +
  1110.      * @param boolean $overwriteCommitted 
  1111. +
  1112.      * @return Apache_Solr_Response 
  1113. +
  1114.      *
  1115. +
  1116.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1117. +
  1118.      */
  1119. +
  1120.     public function addDocuments($documents$allowDups false$overwritePending true$overwriteCommitted true)
  1121. +
  1122.     {
  1123. +
  1124.         $service $this->_selectWriteService();
  1125. +
  1126.  
  1127. +
  1128.         do
  1129. +
  1130.         {
  1131. +
  1132.             try
  1133. +
  1134.             {
  1135. +
  1136.                 return $service->addDocuments($documents$allowDups$overwritePending$overwriteCommitted);
  1137. +
  1138.             }
  1139. +
  1140.             catch (Apache_Solr_HttpTransportException $e)
  1141. +
  1142.             {
  1143. +
  1144.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1145. +
  1146.                 {
  1147. +
  1148.                     throw $e;
  1149. +
  1150.                 }
  1151. +
  1152.             }
  1153. +
  1154.  
  1155. +
  1156.             $service $this->_selectWriteService(true);
  1157. +
  1158.         while ($service);
  1159. +
  1160.  
  1161. +
  1162.         return false;
  1163. +
  1164.     }
  1165. +
  1166.  
  1167. +
  1168.     /**
  1169. +
  1170.      * Send a commit command.  Will be synchronous unless both wait parameters are set
  1171. +
  1172.      * to false.
  1173. +
  1174.      *
  1175. +
  1176.      * @param boolean $waitFlush 
  1177. +
  1178.      * @param boolean $waitSearcher 
  1179. +
  1180.      * @return Apache_Solr_Response 
  1181. +
  1182.      *
  1183. +
  1184.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1185. +
  1186.      */
  1187. +
  1188.     public function commit($optimize true$waitFlush true$waitSearcher true$timeout 3600)
  1189. +
  1190.     {
  1191. +
  1192.         $service $this->_selectWriteService();
  1193. +
  1194.  
  1195. +
  1196.         do
  1197. +
  1198.         {
  1199. +
  1200.             try
  1201. +
  1202.             {
  1203. +
  1204.                 return $service->commit($optimize$waitFlush$waitSearcher$timeout);
  1205. +
  1206.             }
  1207. +
  1208.             catch (Apache_Solr_HttpTransportException $e)
  1209. +
  1210.             {
  1211. +
  1212.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1213. +
  1214.                 {
  1215. +
  1216.                     throw $e;
  1217. +
  1218.                 }
  1219. +
  1220.             }
  1221. +
  1222.  
  1223. +
  1224.             $service $this->_selectWriteService(true);
  1225. +
  1226.         while ($service);
  1227. +
  1228.  
  1229. +
  1230.         return false;
  1231. +
  1232.     }
  1233. +
  1234.  
  1235. +
  1236.     /**
  1237. +
  1238.      * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
  1239. +
  1240.      * a complete and well formed "delete" xml document
  1241. +
  1242.      *
  1243. +
  1244.      * @param string $rawPost 
  1245. +
  1246.      * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  1247. +
  1248.      * @return Apache_Solr_Response 
  1249. +
  1250.      *
  1251. +
  1252.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1253. +
  1254.      */
  1255. +
  1256.     public function delete($rawPost$timeout 3600)
  1257. +
  1258.     {
  1259. +
  1260.         $service $this->_selectWriteService();
  1261. +
  1262.  
  1263. +
  1264.         do
  1265. +
  1266.         {
  1267. +
  1268.             try
  1269. +
  1270.             {
  1271. +
  1272.                 return $service->delete($rawPost$timeout);
  1273. +
  1274.             }
  1275. +
  1276.             catch (Apache_Solr_HttpTransportException $e)
  1277. +
  1278.             {
  1279. +
  1280.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1281. +
  1282.                 {
  1283. +
  1284.                     throw $e;
  1285. +
  1286.                 }
  1287. +
  1288.             }
  1289. +
  1290.  
  1291. +
  1292.             $service $this->_selectWriteService(true);
  1293. +
  1294.         while ($service);
  1295. +
  1296.  
  1297. +
  1298.         return false;
  1299. +
  1300.     }
  1301. +
  1302.  
  1303. +
  1304.     /**
  1305. +
  1306.      * Create a delete document based on document ID
  1307. +
  1308.      *
  1309. +
  1310.      * @param string $id 
  1311. +
  1312.      * @param boolean $fromPending 
  1313. +
  1314.      * @param boolean $fromCommitted 
  1315. +
  1316.      * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  1317. +
  1318.      * @return Apache_Solr_Response 
  1319. +
  1320.      *
  1321. +
  1322.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1323. +
  1324.      */
  1325. +
  1326.     public function deleteById($id$fromPending true$fromCommitted true$timeout 3600)
  1327. +
  1328.     {
  1329. +
  1330.         $service $this->_selectWriteService();
  1331. +
  1332.  
  1333. +
  1334.         do
  1335. +
  1336.         {
  1337. +
  1338.             try
  1339. +
  1340.             {
  1341. +
  1342.                 return $service->deleteById($id$fromPending$fromCommitted$timeout);
  1343. +
  1344.             }
  1345. +
  1346.             catch (Apache_Solr_HttpTransportException $e)
  1347. +
  1348.             {
  1349. +
  1350.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1351. +
  1352.                 {
  1353. +
  1354.                     throw $e;
  1355. +
  1356.                 }
  1357. +
  1358.             }
  1359. +
  1360.  
  1361. +
  1362.             $service $this->_selectWriteService(true);
  1363. +
  1364.         while ($service);
  1365. +
  1366.  
  1367. +
  1368.         return false;
  1369. +
  1370.     }
  1371. +
  1372.  
  1373. +
  1374.     /**
  1375. +
  1376.      * Create and post a delete document based on multiple document IDs.
  1377. +
  1378.      *
  1379. +
  1380.      * @param array $ids Expected to be utf-8 encoded strings
  1381. +
  1382.      * @param boolean $fromPending 
  1383. +
  1384.      * @param boolean $fromCommitted 
  1385. +
  1386.      * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  1387. +
  1388.      * @return Apache_Solr_Response 
  1389. +
  1390.      *
  1391. +
  1392.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1393. +
  1394.      */
  1395. +
  1396.     public function deleteByMultipleIds($ids$fromPending true$fromCommitted true$timeout 3600)
  1397. +
  1398.     {
  1399. +
  1400.         $service $this->_selectWriteService();
  1401. +
  1402.  
  1403. +
  1404.         do
  1405. +
  1406.         {
  1407. +
  1408.             try
  1409. +
  1410.             {
  1411. +
  1412.                 return $service->deleteByMultipleId($ids$fromPending$fromCommitted$timeout);
  1413. +
  1414.             }
  1415. +
  1416.             catch (Apache_Solr_HttpTransportException $e)
  1417. +
  1418.             {
  1419. +
  1420.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1421. +
  1422.                 {
  1423. +
  1424.                     throw $e;
  1425. +
  1426.                 }
  1427. +
  1428.             }
  1429. +
  1430.  
  1431. +
  1432.             $service $this->_selectWriteService(true);
  1433. +
  1434.         while ($service);
  1435. +
  1436.  
  1437. +
  1438.         return false;
  1439. +
  1440.     }
  1441. +
  1442.  
  1443. +
  1444.     /**
  1445. +
  1446.      * Create a delete document based on a query and submit it
  1447. +
  1448.      *
  1449. +
  1450.      * @param string $rawQuery 
  1451. +
  1452.      * @param boolean $fromPending 
  1453. +
  1454.      * @param boolean $fromCommitted 
  1455. +
  1456.      * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
  1457. +
  1458.      * @return Apache_Solr_Response 
  1459. +
  1460.      *
  1461. +
  1462.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1463. +
  1464.      */
  1465. +
  1466.     public function deleteByQuery($rawQuery$fromPending true$fromCommitted true$timeout 3600)
  1467. +
  1468.     {
  1469. +
  1470.         $service $this->_selectWriteService();
  1471. +
  1472.  
  1473. +
  1474.         do
  1475. +
  1476.         {
  1477. +
  1478.             try
  1479. +
  1480.             {
  1481. +
  1482.                 return $service->deleteByQuery($rawQuery$fromPending$fromCommitted$timeout);
  1483. +
  1484.             }
  1485. +
  1486.             catch (Apache_Solr_HttpTransportException $e)
  1487. +
  1488.             {
  1489. +
  1490.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1491. +
  1492.                 {
  1493. +
  1494.                     throw $e;
  1495. +
  1496.                 }
  1497. +
  1498.             }
  1499. +
  1500.  
  1501. +
  1502.             $service $this->_selectWriteService(true);
  1503. +
  1504.         while ($service);
  1505. +
  1506.  
  1507. +
  1508.         return false;
  1509. +
  1510.     }
  1511. +
  1512.     
  1513. +
  1514.     /**
  1515. +
  1516.      * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
  1517. +
  1518.      * to use Solr Cell and what parameters are available.
  1519. +
  1520.      *
  1521. +
  1522.      * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
  1523. +
  1524.      * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
  1525. +
  1526.      * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
  1527. +
  1528.      * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
  1529. +
  1530.      *
  1531. +
  1532.      * @param string $file Path to file to extract data from
  1533. +
  1534.      * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  1535. +
  1536.      * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
  1537. +
  1538.      * @param string $mimetype optional mimetype specification (for the file being extracted)
  1539. +
  1540.      *
  1541. +
  1542.      * @return Apache_Solr_Response 
  1543. +
  1544.      *
  1545. +
  1546.      * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  1547. +
  1548.      */
  1549. +
  1550.     public function extract($file$params array()$document null$mimetype 'application/octet-stream')
  1551. +
  1552.     {
  1553. +
  1554.         $service $this->_selectWriteService();
  1555. +
  1556.  
  1557. +
  1558.         do
  1559. +
  1560.         {
  1561. +
  1562.             try
  1563. +
  1564.             {
  1565. +
  1566.                 return $service->extract($file$params$document$mimetype);
  1567. +
  1568.             }
  1569. +
  1570.             catch (Apache_Solr_HttpTransportException $e)
  1571. +
  1572.             {
  1573. +
  1574.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1575. +
  1576.                 {
  1577. +
  1578.                     throw $e;
  1579. +
  1580.                 }
  1581. +
  1582.             }
  1583. +
  1584.  
  1585. +
  1586.             $service $this->_selectWriteService(true);
  1587. +
  1588.         while ($service);
  1589. +
  1590.  
  1591. +
  1592.         return false;
  1593. +
  1594.     }
  1595. +
  1596.     
  1597. +
  1598.     /**
  1599. +
  1600.      * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
  1601. +
  1602.      * to use Solr Cell and what parameters are available.
  1603. +
  1604.      *
  1605. +
  1606.      * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
  1607. +
  1608.      * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
  1609. +
  1610.      * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
  1611. +
  1612.      * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
  1613. +
  1614.      *
  1615. +
  1616.      * @param string $data Data that will be passed to Solr Cell
  1617. +
  1618.      * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
  1619. +
  1620.      * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
  1621. +
  1622.      * @param string $mimetype optional mimetype specification (for the file being extracted)
  1623. +
  1624.      *
  1625. +
  1626.      * @return Apache_Solr_Response 
  1627. +
  1628.      *
  1629. +
  1630.      * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
  1631. +
  1632.      *
  1633. +
  1634.      * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
  1635. +
  1636.      */
  1637. +
  1638.     public function extractFromString($data$params array()$document null$mimetype 'application/octet-stream')
  1639. +
  1640.     {
  1641. +
  1642.         $service $this->_selectWriteService();
  1643. +
  1644.  
  1645. +
  1646.         do
  1647. +
  1648.         {
  1649. +
  1650.             try
  1651. +
  1652.             {
  1653. +
  1654.                 return $service->extractFromString($data$params$document$mimetype);
  1655. +
  1656.             }
  1657. +
  1658.             catch (Apache_Solr_HttpTransportException $e)
  1659. +
  1660.             {
  1661. +
  1662.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1663. +
  1664.                 {
  1665. +
  1666.                     throw $e;
  1667. +
  1668.                 }
  1669. +
  1670.             }
  1671. +
  1672.  
  1673. +
  1674.             $service $this->_selectWriteService(true);
  1675. +
  1676.         while ($service);
  1677. +
  1678.  
  1679. +
  1680.         return false;
  1681. +
  1682.     }
  1683. +
  1684.     
  1685. +
  1686.     /**
  1687. +
  1688.      * Send an optimize command.  Will be synchronous unless both wait parameters are set
  1689. +
  1690.      * to false.
  1691. +
  1692.      *
  1693. +
  1694.      * @param boolean $waitFlush 
  1695. +
  1696.      * @param boolean $waitSearcher 
  1697. +
  1698.      * @param float $timeout Maximum expected duration of the optimize operation on the server (otherwise, will throw a communication exception)
  1699. +
  1700.      * @return Apache_Solr_Response 
  1701. +
  1702.      *
  1703. +
  1704.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1705. +
  1706.      */
  1707. +
  1708.     public function optimize($waitFlush true$waitSearcher true$timeout 3600)
  1709. +
  1710.     {
  1711. +
  1712.         $service $this->_selectWriteService();
  1713. +
  1714.  
  1715. +
  1716.         do
  1717. +
  1718.         {
  1719. +
  1720.             try
  1721. +
  1722.             {
  1723. +
  1724.                 return $service->optimize($waitFlush$waitSearcher$timeout);
  1725. +
  1726.             }
  1727. +
  1728.             catch (Apache_Solr_HttpTransportException $e)
  1729. +
  1730.             {
  1731. +
  1732.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1733. +
  1734.                 {
  1735. +
  1736.                     throw $e;
  1737. +
  1738.                 }
  1739. +
  1740.             }
  1741. +
  1742.  
  1743. +
  1744.             $service $this->_selectWriteService(true);
  1745. +
  1746.         while ($service);
  1747. +
  1748.  
  1749. +
  1750.         return false;
  1751. +
  1752.     }
  1753. +
  1754.  
  1755. +
  1756.     /**
  1757. +
  1758.      * Simple Search interface
  1759. +
  1760.      *
  1761. +
  1762.      * @param string $query The raw query string
  1763. +
  1764.      * @param int $offset The starting offset for result documents
  1765. +
  1766.      * @param int $limit The maximum number of result documents to return
  1767. +
  1768.      * @param array $params key / value pairs for query parameters, use arrays for multivalued parameters
  1769. +
  1770.      * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
  1771. +
  1772.      * @return Apache_Solr_Response 
  1773. +
  1774.      *
  1775. +
  1776.      * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
  1777. +
  1778.      */
  1779. +
  1780.     public function search($query$offset 0$limit 10$params array()$method Apache_Solr_Service::METHOD_GET)
  1781. +
  1782.     {
  1783. +
  1784.         $service $this->_selectReadService();
  1785. +
  1786.  
  1787. +
  1788.         do
  1789. +
  1790.         {
  1791. +
  1792.             try
  1793. +
  1794.             {
  1795. +
  1796.                 return $service->search($query$offset$limit$params$method);
  1797. +
  1798.             }
  1799. +
  1800.             catch (Apache_Solr_HttpTransportException $e)
  1801. +
  1802.             {
  1803. +
  1804.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  1805. +
  1806.                 {
  1807. +
  1808.                     throw $e;
  1809. +
  1810.                 }
  1811. +
  1812.             }
  1813. +
  1814.  
  1815. +
  1816.             $service $this->_selectReadService(true);
  1817. +
  1818.         while ($service);
  1819. +
  1820.  
  1821. +
  1822.         return false;
  1823. +
  1824.     }
  1825. +
  1826. }
  1827. +
+
+

+ Documentation generated on Wed, 04 May 2011 11:01:10 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/blank.html b/SolrPhpClient/phpdocs/blank.html new file mode 100644 index 00000000..38517691 --- /dev/null +++ b/SolrPhpClient/phpdocs/blank.html @@ -0,0 +1,13 @@ + + + Generated Documentation + + + + +

Generated Documentation

+Welcome to Apache!
+
+This documentation was generated by phpDocumentor v1.4.3
+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/classtrees_Apache.html b/SolrPhpClient/phpdocs/classtrees_Apache.html new file mode 100644 index 00000000..e82831d9 --- /dev/null +++ b/SolrPhpClient/phpdocs/classtrees_Apache.html @@ -0,0 +1,56 @@ + + + + + + + + + + + + +

+ +

+

Root interface Apache_Solr_HttpTransport_Interface

+ + +

Root class Apache_Solr_Document

+ + +

Root class Apache_Solr_HttpTransport_Abstract

+ + +

Root class Apache_Solr_HttpTransport_Response

+ + +

Root class Apache_Solr_Response

+ + +

Root class Apache_Solr_Service

+ + +

Root class Apache_Solr_Service_Balancer

+ + +

Root class Exception

+ + +

+ Documentation generated on Wed, 04 May 2011 11:01:08 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/elementindex.html b/SolrPhpClient/phpdocs/elementindex.html new file mode 100644 index 00000000..78d0581a --- /dev/null +++ b/SolrPhpClient/phpdocs/elementindex.html @@ -0,0 +1,1726 @@ + + + + + + + + + + + +

Full index

+

Package indexes

+ +
+
+ a + b + c + d + e + f + g + h + i + m + n + o + p + r + s + t + u + _ +
+ + +
+
a
+ +
+
+
+
+ add +
+
+ +
Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.
+
+
+ add +
+
+ +
Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.
+
+
+ addDocument +
+
+ +
Add a Solr Document to the index
+
+
+ addDocument +
+
+ +
Add a Solr Document to the index
+
+
+ addDocuments +
+
+ +
Add an array of Solr Documents to the index all at once
+
+
+ addDocuments +
+
+ +
Add an array of Solr Documents to the index all at once
+
+
+ addField +
+
+ +
Add a value to a multi-valued field
+
+
+ addReadService +
+
+ +
Adds a service instance or service descriptor (if it is already not added)
+
+
+ addWriteService +
+
+ +
Adds a service instance or service descriptor (if it is already not added)
+
+
+ Apache_Solr_Document +
+
+
Apache_Solr_Document in Document.php
+
Holds Key / Value pairs that represent a Solr Document along with any associated boost values. Field values can be accessed by direct dereferencing such as:
+
+
+ Apache_Solr_Exception +
+
+
Apache_Solr_Exception in Exception.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_HttpTransportException +
+
+
Apache_Solr_HttpTransportException in HttpTransportException.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_HttpTransport_Abstract +
+
+ +
Convenience class that implements the transport implementation. Can be extended by
+
+
+ Apache_Solr_HttpTransport_Curl +
+
+ +
A Curl based HTTP transport. Uses a single curl session for all requests.
+
+
+ Apache_Solr_HttpTransport_CurlNoReuse +
+
+ +
An alternative Curl HTTP transport that opens and closes a curl session for every request. This isn't the recommended way to use curl, but some version of PHP have memory issues.
+
+
+ Apache_Solr_HttpTransport_FileGetContents +
+
+ +
HTTP Transport implemenation that uses the builtin http URL wrappers and file_get_contents
+
+
+ Apache_Solr_HttpTransport_Interface +
+
+ +
Interface that all Transport (HTTP Requester) implementations must implement. These
+
+
+ Apache_Solr_HttpTransport_Response +
+
+ +
Represents the required pieces of an HTTP response provided by HTTP transport
+
+
+ Apache_Solr_InvalidArgumentException +
+
+
Apache_Solr_InvalidArgumentException in InvalidArgumentException.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_NoServiceAvailableException +
+
+
Apache_Solr_NoServiceAvailableException in NoServiceAvailableException.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_ParserException +
+
+
Apache_Solr_ParserException in ParserException.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_Response +
+
+
Apache_Solr_Response in Response.php
+
Represents a Solr response. Parses the raw response into a set of stdClass objects and associative arrays for easy access.
+
+
+ Apache_Solr_Service +
+
+
Apache_Solr_Service in Service.php
+
Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.
+
+
+ Apache_Solr_Service_Balancer +
+
+ +
Reference Implementation for using multiple Solr services in a distribution. Functionality
+
+
+ Abstract.php +
+
+
Abstract.php in Abstract.php
+
+
+ +
+
b
+ +
+
+
+
+ Balancer.php +
+
+
Balancer.php in Balancer.php
+
+
+ +
+
c
+ +
+
+
+
+ clear +
+
+ +
Clear all boosts and fields from this document
+
+
+ commit +
+
+ +
Send a commit command. Will be synchronous unless both wait parameters are set to false.
+
+
+ commit +
+
+ +
Send a commit command. Will be synchronous unless both wait parameters are set to false.
+
+
+ Curl.php +
+
+
Curl.php in Curl.php
+
+
+ CurlNoReuse.php +
+
+
CurlNoReuse.php in CurlNoReuse.php
+
+
+ +
+
d
+ +
+
+
+
+ delete +
+
+ +
Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document
+
+
+ delete +
+
+ +
Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document
+
+
+ deleteById +
+
+ +
Create a delete document based on document ID
+
+
+ deleteById +
+
+ +
Create a delete document based on document ID
+
+
+ deleteByMultipleIds +
+
+ +
Create and post a delete document based on multiple document IDs.
+
+
+ deleteByMultipleIds +
+
+ +
Create and post a delete document based on multiple document IDs.
+
+
+ deleteByQuery +
+
+ +
Create a delete document based on a query and submit it
+
+
+ deleteByQuery +
+
+ +
Create a delete document based on a query and submit it
+
+
+ Document.php +
+
+
Document.php in Document.php
+
+
+ +
+
e
+ +
+
+
+
+ escape +
+
+ +
Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
+
+
+ escape +
+
+ +
Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
+
+
+ escapePhrase +
+
+ +
Escape a value meant to be contained in a phrase for special query characters
+
+
+ escapePhrase +
+
+ +
Escape a value meant to be contained in a phrase for special query characters
+
+
+ Exception.php +
+
+
Exception.php in Exception.php
+
+
+ extract +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ extract +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ extractFromString +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ extractFromString +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ extractFromUrl +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ EXTRACT_SERVLET +
+
+ +
+
+ +
+
f
+ +
+
+
+
+ FileGetContents.php +
+
+
FileGetContents.php in FileGetContents.php
+
+
+ +
+
g
+ +
+
+
+
+ getBody +
+
+ +
Get the raw response body
+
+
+ getBoost +
+
+ +
Get current document boost
+
+
+ getCollapseSingleValueArrays +
+
+ +
Get the current state of the collapse single value arrays flag.
+
+
+ getCreateDocuments +
+
+ +
Get the current state of teh create documents flag.
+
+
+ getCreateDocuments +
+
+ +
Get the current state of teh create documents flag.
+
+
+ getDefaultStatusMessage +
+
+ +
Get the HTTP status message based on status code
+
+
+ getDefaultTimeout +
+
+ +
Get the current default timeout setting (initially the default_socket_timeout ini setting) in seconds
+
+
+ getDefaultTimeout +
+
+ +
Get the current default timeout for all HTTP requests
+
+
+ getDefaultTimeout +
+
+ +
Get the current default timeout setting (initially the default_socket_timeout ini setting) in seconds
+
+
+ getEncoding +
+
+ +
Get the charset encoding of the response body.
+
+
+ getEncoding +
+
+ +
Get character encoding of this response. Should usually be utf-8, but just in case
+
+
+ getField +
+
+ +
Get field information
+
+
+ getFieldBoost +
+
+ +
Get the currently set field boost for a document field
+
+
+ getFieldBoosts +
+
+ +
Return current field boosts, indexed by field name
+
+
+ getFieldNames +
+
+ +
Get the names of all fields in this document
+
+
+ getFieldValues +
+
+ +
Get the values of all fields in this document
+
+
+ getHost +
+
+ +
Returns the set host
+
+
+ getHttpStatus +
+
+ +
Get the HTTP status code
+
+
+ getHttpStatusMessage +
+
+ +
Get the HTTP status message of the response
+
+
+ getHttpTransport +
+
+ +
Get the current configured HTTP Transport
+
+
+ getIterator +
+
+ +
IteratorAggregate implementation function. Allows usage:
+
+
+ getMimeType +
+
+ +
Get the mimetype of the response body
+
+
+ getNamedListTreatment +
+
+ +
Get the current setting for named list treatment.
+
+
+ getPath +
+
+ +
Get the set path.
+
+
+ getPort +
+
+ +
Get the set port
+
+
+ getRawResponse +
+
+ +
Get the raw response as it was given to this object
+
+
+ getResponse +
+
+ +
Get the response for which this exception was generated
+
+
+ getStatusCode +
+
+ +
Get the status code of the response
+
+
+ getStatusMessage +
+
+ +
Get the status message of the response
+
+
+ getType +
+
+ +
Get content type of this Solr response
+
+
+ +
+
h
+ +
+
+
+
+ HttpTransportException.php +
+
+
HttpTransportException.php in HttpTransportException.php
+
+
+ +
+
i
+ +
+
+
+
+ Interface.php +
+
+
Interface.php in Interface.php
+
+
+ InvalidArgumentException.php +
+
+
InvalidArgumentException.php in InvalidArgumentException.php
+
+
+ +
+
m
+ +
+
+
+
+ METHOD_GET +
+
+ +
Search HTTP Methods
+
+
+ METHOD_POST +
+
+ +
+
+ +
+
n
+ +
+
+
+
+ NAMED_LIST_FLAT +
+
+ +
NamedList Treatment constants
+
+
+ NAMED_LIST_MAP +
+
+ +
+
+ NoServiceAvailableException.php +
+
+
NoServiceAvailableException.php in NoServiceAvailableException.php
+
+
+ +
+
o
+ +
+
+
+
+ optimize +
+
+ +
Send an optimize command. Will be synchronous unless both wait parameters are set to false.
+
+
+ optimize +
+
+ +
Send an optimize command. Will be synchronous unless both wait parameters are set to false.
+
+
+ +
+
p
+ +
+
+
+
+ ParserException.php +
+
+
ParserException.php in ParserException.php
+
+
+ performGetRequest +
+
+ +
+
+ performGetRequest +
+
+ +
+
+ performGetRequest +
+
+ +
+
+ performGetRequest +
+
+ +
Perform a GET HTTP operation with an optional timeout and return the response contents, use getLastResponseHeaders to retrieve HTTP headers
+
+
+ performHeadRequest +
+
+ +
Perform a HEAD HTTP operation with an optional timeout and return the response headers - NOTE: head requests have no response body
+
+
+ performHeadRequest +
+
+ +
+
+ performHeadRequest +
+
+ +
+
+ performHeadRequest +
+
+ +
+
+ performPostRequest +
+
+ +
+
+ performPostRequest +
+
+ +
Perform a POST HTTP operation with an optional timeout and return the response contents, use getLastResponseHeaders to retrieve HTTP headers
+
+
+ performPostRequest +
+
+ +
+
+ performPostRequest +
+
+ +
+
+ phrase +
+
+ +
Convenience function for creating phrase syntax from a value
+
+
+ phrase +
+
+ +
Convenience function for creating phrase syntax from a value
+
+
+ ping +
+
+ +
Call the /admin/ping servlet, can be used to quickly tell if a connection to the server is able to be made.
+
+
+ PING_SERVLET +
+
+ +
Servlet mappings
+
+
+ +
+
r
+ +
+
+
+
+ Response.php +
+
+
Response.php in Response.php
+
+
+ removeReadService +
+
+ +
Removes a service instance or descriptor from the available services
+
+
+ removeWriteService +
+
+ +
Removes a service instance or descriptor from the available services
+
+
+ Response.php +
+
+
Response.php in Response.php
+
+
+ +
+
s
+ +
+
+
+
+ search +
+
+ +
Simple Search interface
+
+
+ search +
+
+ +
Simple Search interface
+
+
+ SEARCH_SERVLET +
+
+ +
+
+ Service.php +
+
+
Service.php in Service.php
+
+
+ setBoost +
+
+ +
Set document boost factor
+
+
+ setCollapseSingleValueArrays +
+
+ +
Set the collapse single value arrays flag.
+
+
+ setCreateDocuments +
+
+ +
Set the create documents flag. This determines whether Apache_Solr_Response objects will parse the response and create Apache_Solr_Document instances in place.
+
+
+ setCreateDocuments +
+
+ +
Set the create documents flag. This determines whether Apache_Solr_Response objects will parse the response and create Apache_Solr_Document instances in place.
+
+
+ setDefaultTimeout +
+
+ +
Set the current default timeout for all HTTP requests
+
+
+ setDefaultTimeout +
+
+ +
Set the default timeout for all calls that aren't passed a specific timeout
+
+
+ setDefaultTimeout +
+
+ +
Set the current default timeout for all HTTP requests
+
+
+ setField +
+
+ +
Set a field value. Multi-valued fields should be set as arrays or instead use the addField(...) function which will automatically make sure the field is an array.
+
+
+ setFieldBoost +
+
+ +
Set the field boost for a document field
+
+
+ setHost +
+
+ +
Set the host used. If empty will fallback to constants
+
+
+ setHttpTransport +
+
+ +
Set the HTTP Transport implemenation that will be used for all HTTP requests
+
+
+ setMultiValue +
+
+ +
Handle the array manipulation for a multi-valued field
+
+
+ setNamedListTreatment +
+
+ +
Set how NamedLists should be formatted in the response data. This mainly effects the facet counts format.
+
+
+ setPath +
+
+ +
Set the path used. If empty will fallback to constants
+
+
+ setPort +
+
+ +
Set the port used. If empty will fallback to constants
+
+
+ setQueryDelimiter +
+
+ +
Set the string used to separate the path form the query string.
+
+
+ setQueryStringDelimiter +
+
+ +
Set the string used to separate the parameters in thequery string Defaulted to '&'
+
+
+ setReadPingTimeout +
+
+ +
+
+ setUseBackoff +
+
+ +
+
+ setWritePingTimeout +
+
+ +
+
+ SOLR_WRITER +
+
+ +
Response writer we'll request - JSON. See http://code.google.com/p/solr-php-client/issues/detail?id=6#c1 for reasoning
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+
Apache_Solr_InvalidArgumentException::SVN_ID in InvalidArgumentException.php
+
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+
Apache_Solr_HttpTransportException::SVN_ID in HttpTransportException.php
+
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+
Apache_Solr_NoServiceAvailableException::SVN_ID in NoServiceAvailableException.php
+
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ +
+
t
+ +
+
+
+
+ threads +
+
+ +
Call the /admin/threads servlet and retrieve information about all threads in the Solr servlet's thread group. Useful for diagnostics.
+
+
+ THREADS_SERVLET +
+
+ +
+
+ +
+
u
+ +
+
+
+
+ UPDATE_SERVLET +
+
+ +
+
+ +
+
_
+ +
+
+
+
+ $_backoffEscalation +
+
+ +
+
+ $_backoffLimit +
+
+ +
+
+ $_collapseSingleValueArrays +
+
+ +
Whether Apache_Solr_Response objects should have multivalue fields with only a single value collapsed to appear as a single value would.
+
+
+ $_collapseSingleValueArrays +
+
+ +
+
+ $_createDocuments +
+
+ +
Data parsing flags. Determines what extra processing should be done after the data is initially converted to a data structure.
+
+
+ $_createDocuments +
+
+ +
Whether Apache_Solr_Response objects should create Apache_Solr_Documents in the returned parsed data
+
+
+ $_createDocuments +
+
+ +
+
+ $_currentReadService +
+
+ +
+
+ $_currentWriteService +
+
+ +
+
+ $_defaultBackoff +
+
+ +
+
+ $_documentBoost +
+
+ +
Document boost value
+
+
+ $_fieldBoosts +
+
+ +
Document field boost values, indexed by name
+
+
+ $_fields +
+
+ +
Document field values, indexed by name
+
+
+ $_host +
+
+ +
Server identification strings
+
+
+ $_httpTransport +
+
+ +
HTTP Transport implementation (pluggable)
+
+
+ $_isParsed +
+
+ +
Whether the raw response has been parsed
+
+
+ $_namedListTreatment +
+
+ +
How NamedLists should be formatted in the output. This specifically effects facet counts. Valid values are Apache_Solr_Service::NAMED_LIST_MAP (default) or Apache_Solr_Service::NAMED_LIST_FLAT.
+
+
+ $_parsedData +
+
+ +
Parsed representation of the data
+
+
+ $_path +
+
+ +
+
+ $_pingUrl +
+
+ +
Constructed servlet full path URLs
+
+
+ $_port +
+
+ +
+
+ $_queryBracketsEscaped +
+
+ +
+
+ $_queryDelimiter +
+
+ +
Query delimiters. Someone might want to be able to change these (to use &amp; instead of & for example), so I've provided them.
+
+
+ $_queryStringDelimiter +
+
+ +
+
+ $_readableServices +
+
+ +
+
+ $_readPingTimeout +
+
+ +
+
+ $_response +
+
+ +
Holds the raw response used in construction
+
+
+ $_searchUrl +
+
+ +
+
+ $_threadsUrl +
+
+ +
+
+ $_updateUrl +
+
+ +
+
+ $_urlsInited +
+
+ +
Keep track of whether our URLs have been constructed
+
+
+ $_useBackoff +
+
+ +
+
+ $_writeableServices +
+
+ +
+
+ $_writePingTimeout +
+
+ +
+
+ _constructUrl +
+
+ +
Return a valid http URL given this server's host, port and path and a provided servlet name
+
+
+ _documentToXmlFragment +
+
+ +
Create an XML fragment from a Apache_Solr_Document instance appropriate for use inside a Solr add call
+
+
+ _generateQueryString +
+
+ +
+
+ _getServiceId +
+
+ +
Generates a service ID
+
+
+ _initUrls +
+
+ +
Construct the Full URLs for the three servlets we reference
+
+
+ _parseData +
+
+ +
Parse the raw response into the parsed_data array for access
+
+
+ _selectReadService +
+
+ +
Iterate through available read services and select the first with a ping that satisfies configured timeout restrictions (or the default)
+
+
+ _selectWriteService +
+
+ +
Iterate through available write services and select the first with a ping that satisfies configured timeout restrictions (or the default)
+
+
+ _selectWriteServiceSafe +
+
+ +
Iterate through available write services and select the first with a ping
+
+
+ _sendRawGet +
+
+ +
Central method for making a get operation against this Solr Server
+
+
+ _sendRawPost +
+
+ +
Central method for making a post operation against this Solr Server
+
+
+ _stripCtrlChars +
+
+ +
Replace control (non-printable) characters from string that are invalid to Solr's XML parser with a space.
+
+
+ __construct +
+
+ +
Constructor. All parameters are optional and will take on default values if not specified.
+
+
+ __construct +
+
+ +
Construct a HTTP transport response
+
+
+ __construct +
+
+ +
Initializes our reuseable get and post stream contexts
+
+
+ __construct +
+
+ +
Initializes a curl session
+
+
+ __construct +
+
+ +
HttpTransportException Constructor
+
+
+ __construct +
+
+ +
Constructor. Takes the raw HTTP response body and the exploded HTTP headers
+
+
+ __construct +
+
+ +
Constructor. Takes arrays of read and write service instances or descriptions
+
+
+ __destruct +
+
+ +
Closes a curl session
+
+
+ __get +
+
+ +
Magic get to expose the parsed data and to lazily load it
+
+
+ __get +
+
+ +
Magic get for field values
+
+
+ __isset +
+
+ +
Magic isset for fields values. Do not call directly. Allows usage:
+
+
+ __isset +
+
+ +
Magic function for isset function on parsed data
+
+
+ __set +
+
+ +
Magic set for field values. Multi-valued fields should be set as arrays or instead use the addField(...) function which will automatically make sure the field is an array.
+
+
+ __unset +
+
+ +
Magic unset for field values. Do not call directly. Allows usage:
+
+
+ +
+ a + b + c + d + e + f + g + h + i + m + n + o + p + r + s + t + u + _ +
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/elementindex_Apache.html b/SolrPhpClient/phpdocs/elementindex_Apache.html new file mode 100644 index 00000000..ae0fec6f --- /dev/null +++ b/SolrPhpClient/phpdocs/elementindex_Apache.html @@ -0,0 +1,1723 @@ + + + + + + + + + + + +

[Apache] element index

+All elements +
+
+ a + b + c + d + e + f + g + h + i + m + n + o + p + r + s + t + u + _ +
+ + +
+
_
+ +
+
+
+
+ $_backoffEscalation +
+
+ +
+
+ $_backoffLimit +
+
+ +
+
+ $_collapseSingleValueArrays +
+
+ +
Whether Apache_Solr_Response objects should have multivalue fields with only a single value collapsed to appear as a single value would.
+
+
+ $_collapseSingleValueArrays +
+
+ +
+
+ $_createDocuments +
+
+ +
Data parsing flags. Determines what extra processing should be done after the data is initially converted to a data structure.
+
+
+ $_createDocuments +
+
+ +
Whether Apache_Solr_Response objects should create Apache_Solr_Documents in the returned parsed data
+
+
+ $_createDocuments +
+
+ +
+
+ $_currentReadService +
+
+ +
+
+ $_currentWriteService +
+
+ +
+
+ $_defaultBackoff +
+
+ +
+
+ $_documentBoost +
+
+ +
Document boost value
+
+
+ $_fieldBoosts +
+
+ +
Document field boost values, indexed by name
+
+
+ $_fields +
+
+ +
Document field values, indexed by name
+
+
+ $_host +
+
+ +
Server identification strings
+
+
+ $_httpTransport +
+
+ +
HTTP Transport implementation (pluggable)
+
+
+ $_isParsed +
+
+ +
Whether the raw response has been parsed
+
+
+ $_namedListTreatment +
+
+ +
How NamedLists should be formatted in the output. This specifically effects facet counts. Valid values are Apache_Solr_Service::NAMED_LIST_MAP (default) or Apache_Solr_Service::NAMED_LIST_FLAT.
+
+
+ $_parsedData +
+
+ +
Parsed representation of the data
+
+
+ $_path +
+
+ +
+
+ $_pingUrl +
+
+ +
Constructed servlet full path URLs
+
+
+ $_port +
+
+ +
+
+ $_queryBracketsEscaped +
+
+ +
+
+ $_queryDelimiter +
+
+ +
Query delimiters. Someone might want to be able to change these (to use &amp; instead of & for example), so I've provided them.
+
+
+ $_queryStringDelimiter +
+
+ +
+
+ $_readableServices +
+
+ +
+
+ $_readPingTimeout +
+
+ +
+
+ $_response +
+
+ +
Holds the raw response used in construction
+
+
+ $_searchUrl +
+
+ +
+
+ $_threadsUrl +
+
+ +
+
+ $_updateUrl +
+
+ +
+
+ $_urlsInited +
+
+ +
Keep track of whether our URLs have been constructed
+
+
+ $_useBackoff +
+
+ +
+
+ $_writeableServices +
+
+ +
+
+ $_writePingTimeout +
+
+ +
+
+ _constructUrl +
+
+ +
Return a valid http URL given this server's host, port and path and a provided servlet name
+
+
+ _documentToXmlFragment +
+
+ +
Create an XML fragment from a Apache_Solr_Document instance appropriate for use inside a Solr add call
+
+
+ _generateQueryString +
+
+ +
+
+ _getServiceId +
+
+ +
Generates a service ID
+
+
+ _initUrls +
+
+ +
Construct the Full URLs for the three servlets we reference
+
+
+ _parseData +
+
+ +
Parse the raw response into the parsed_data array for access
+
+
+ _selectReadService +
+
+ +
Iterate through available read services and select the first with a ping that satisfies configured timeout restrictions (or the default)
+
+
+ _selectWriteService +
+
+ +
Iterate through available write services and select the first with a ping that satisfies configured timeout restrictions (or the default)
+
+
+ _selectWriteServiceSafe +
+
+ +
Iterate through available write services and select the first with a ping
+
+
+ _sendRawGet +
+
+ +
Central method for making a get operation against this Solr Server
+
+
+ _sendRawPost +
+
+ +
Central method for making a post operation against this Solr Server
+
+
+ _stripCtrlChars +
+
+ +
Replace control (non-printable) characters from string that are invalid to Solr's XML parser with a space.
+
+
+ __construct +
+
+ +
Constructor. All parameters are optional and will take on default values if not specified.
+
+
+ __construct +
+
+ +
Construct a HTTP transport response
+
+
+ __construct +
+
+ +
Initializes our reuseable get and post stream contexts
+
+
+ __construct +
+
+ +
Initializes a curl session
+
+
+ __construct +
+
+ +
HttpTransportException Constructor
+
+
+ __construct +
+
+ +
Constructor. Takes the raw HTTP response body and the exploded HTTP headers
+
+
+ __construct +
+
+ +
Constructor. Takes arrays of read and write service instances or descriptions
+
+
+ __destruct +
+
+ +
Closes a curl session
+
+
+ __get +
+
+ +
Magic get to expose the parsed data and to lazily load it
+
+
+ __get +
+
+ +
Magic get for field values
+
+
+ __isset +
+
+ +
Magic isset for fields values. Do not call directly. Allows usage:
+
+
+ __isset +
+
+ +
Magic function for isset function on parsed data
+
+
+ __set +
+
+ +
Magic set for field values. Multi-valued fields should be set as arrays or instead use the addField(...) function which will automatically make sure the field is an array.
+
+
+ __unset +
+
+ +
Magic unset for field values. Do not call directly. Allows usage:
+
+
+ +
+
a
+ +
+
+
+
+ add +
+
+ +
Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.
+
+
+ add +
+
+ +
Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.
+
+
+ addDocument +
+
+ +
Add a Solr Document to the index
+
+
+ addDocument +
+
+ +
Add a Solr Document to the index
+
+
+ addDocuments +
+
+ +
Add an array of Solr Documents to the index all at once
+
+
+ addDocuments +
+
+ +
Add an array of Solr Documents to the index all at once
+
+
+ addField +
+
+ +
Add a value to a multi-valued field
+
+
+ addReadService +
+
+ +
Adds a service instance or service descriptor (if it is already not added)
+
+
+ addWriteService +
+
+ +
Adds a service instance or service descriptor (if it is already not added)
+
+
+ Apache_Solr_Document +
+
+
Apache_Solr_Document in Document.php
+
Holds Key / Value pairs that represent a Solr Document along with any associated boost values. Field values can be accessed by direct dereferencing such as:
+
+
+ Apache_Solr_Exception +
+
+
Apache_Solr_Exception in Exception.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_HttpTransportException +
+
+
Apache_Solr_HttpTransportException in HttpTransportException.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_HttpTransport_Abstract +
+
+ +
Convenience class that implements the transport implementation. Can be extended by
+
+
+ Apache_Solr_HttpTransport_Curl +
+
+ +
A Curl based HTTP transport. Uses a single curl session for all requests.
+
+
+ Apache_Solr_HttpTransport_CurlNoReuse +
+
+ +
An alternative Curl HTTP transport that opens and closes a curl session for every request. This isn't the recommended way to use curl, but some version of PHP have memory issues.
+
+
+ Apache_Solr_HttpTransport_FileGetContents +
+
+ +
HTTP Transport implemenation that uses the builtin http URL wrappers and file_get_contents
+
+
+ Apache_Solr_HttpTransport_Interface +
+
+ +
Interface that all Transport (HTTP Requester) implementations must implement. These
+
+
+ Apache_Solr_HttpTransport_Response +
+
+ +
Represents the required pieces of an HTTP response provided by HTTP transport
+
+
+ Apache_Solr_InvalidArgumentException +
+
+
Apache_Solr_InvalidArgumentException in InvalidArgumentException.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_NoServiceAvailableException +
+
+
Apache_Solr_NoServiceAvailableException in NoServiceAvailableException.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_ParserException +
+
+
Apache_Solr_ParserException in ParserException.php
+
Copyright (c) 2007-2011, Servigistics, Inc.
+
+
+ Apache_Solr_Response +
+
+
Apache_Solr_Response in Response.php
+
Represents a Solr response. Parses the raw response into a set of stdClass objects and associative arrays for easy access.
+
+
+ Apache_Solr_Service +
+
+
Apache_Solr_Service in Service.php
+
Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.
+
+
+ Apache_Solr_Service_Balancer +
+
+ +
Reference Implementation for using multiple Solr services in a distribution. Functionality
+
+
+ Abstract.php +
+
+
Abstract.php in Abstract.php
+
+
+ +
+
b
+ +
+
+
+
+ Balancer.php +
+
+
Balancer.php in Balancer.php
+
+
+ +
+
c
+ +
+
+
+
+ clear +
+
+ +
Clear all boosts and fields from this document
+
+
+ commit +
+
+ +
Send a commit command. Will be synchronous unless both wait parameters are set to false.
+
+
+ commit +
+
+ +
Send a commit command. Will be synchronous unless both wait parameters are set to false.
+
+
+ Curl.php +
+
+
Curl.php in Curl.php
+
+
+ CurlNoReuse.php +
+
+
CurlNoReuse.php in CurlNoReuse.php
+
+
+ +
+
d
+ +
+
+
+
+ delete +
+
+ +
Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document
+
+
+ delete +
+
+ +
Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document
+
+
+ deleteById +
+
+ +
Create a delete document based on document ID
+
+
+ deleteById +
+
+ +
Create a delete document based on document ID
+
+
+ deleteByMultipleIds +
+
+ +
Create and post a delete document based on multiple document IDs.
+
+
+ deleteByMultipleIds +
+
+ +
Create and post a delete document based on multiple document IDs.
+
+
+ deleteByQuery +
+
+ +
Create a delete document based on a query and submit it
+
+
+ deleteByQuery +
+
+ +
Create a delete document based on a query and submit it
+
+
+ Document.php +
+
+
Document.php in Document.php
+
+
+ +
+
e
+ +
+
+
+
+ escape +
+
+ +
Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
+
+
+ escape +
+
+ +
Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
+
+
+ escapePhrase +
+
+ +
Escape a value meant to be contained in a phrase for special query characters
+
+
+ escapePhrase +
+
+ +
Escape a value meant to be contained in a phrase for special query characters
+
+
+ Exception.php +
+
+
Exception.php in Exception.php
+
+
+ extract +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ extract +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ extractFromString +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ extractFromString +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ extractFromUrl +
+
+ +
Use Solr Cell to extract document contents. See http://wiki.apache.org/solr/ExtractingRequestHandler for information on how to use Solr Cell and what parameters are available.
+
+
+ EXTRACT_SERVLET +
+
+ +
+
+ +
+
f
+ +
+
+
+
+ FileGetContents.php +
+
+
FileGetContents.php in FileGetContents.php
+
+
+ +
+
g
+ +
+
+
+
+ getBody +
+
+ +
Get the raw response body
+
+
+ getBoost +
+
+ +
Get current document boost
+
+
+ getCollapseSingleValueArrays +
+
+ +
Get the current state of the collapse single value arrays flag.
+
+
+ getCreateDocuments +
+
+ +
Get the current state of teh create documents flag.
+
+
+ getCreateDocuments +
+
+ +
Get the current state of teh create documents flag.
+
+
+ getDefaultStatusMessage +
+
+ +
Get the HTTP status message based on status code
+
+
+ getDefaultTimeout +
+
+ +
Get the current default timeout setting (initially the default_socket_timeout ini setting) in seconds
+
+
+ getDefaultTimeout +
+
+ +
Get the current default timeout for all HTTP requests
+
+
+ getDefaultTimeout +
+
+ +
Get the current default timeout setting (initially the default_socket_timeout ini setting) in seconds
+
+
+ getEncoding +
+
+ +
Get the charset encoding of the response body.
+
+
+ getEncoding +
+
+ +
Get character encoding of this response. Should usually be utf-8, but just in case
+
+
+ getField +
+
+ +
Get field information
+
+
+ getFieldBoost +
+
+ +
Get the currently set field boost for a document field
+
+
+ getFieldBoosts +
+
+ +
Return current field boosts, indexed by field name
+
+
+ getFieldNames +
+
+ +
Get the names of all fields in this document
+
+
+ getFieldValues +
+
+ +
Get the values of all fields in this document
+
+
+ getHost +
+
+ +
Returns the set host
+
+
+ getHttpStatus +
+
+ +
Get the HTTP status code
+
+
+ getHttpStatusMessage +
+
+ +
Get the HTTP status message of the response
+
+
+ getHttpTransport +
+
+ +
Get the current configured HTTP Transport
+
+
+ getIterator +
+
+ +
IteratorAggregate implementation function. Allows usage:
+
+
+ getMimeType +
+
+ +
Get the mimetype of the response body
+
+
+ getNamedListTreatment +
+
+ +
Get the current setting for named list treatment.
+
+
+ getPath +
+
+ +
Get the set path.
+
+
+ getPort +
+
+ +
Get the set port
+
+
+ getRawResponse +
+
+ +
Get the raw response as it was given to this object
+
+
+ getResponse +
+
+ +
Get the response for which this exception was generated
+
+
+ getStatusCode +
+
+ +
Get the status code of the response
+
+
+ getStatusMessage +
+
+ +
Get the status message of the response
+
+
+ getType +
+
+ +
Get content type of this Solr response
+
+
+ +
+
h
+ +
+
+
+
+ HttpTransportException.php +
+
+
HttpTransportException.php in HttpTransportException.php
+
+
+ +
+
i
+ +
+
+
+
+ Interface.php +
+
+
Interface.php in Interface.php
+
+
+ InvalidArgumentException.php +
+
+
InvalidArgumentException.php in InvalidArgumentException.php
+
+
+ +
+
m
+ +
+
+
+
+ METHOD_GET +
+
+ +
Search HTTP Methods
+
+
+ METHOD_POST +
+
+ +
+
+ +
+
n
+ +
+
+
+
+ NAMED_LIST_FLAT +
+
+ +
NamedList Treatment constants
+
+
+ NAMED_LIST_MAP +
+
+ +
+
+ NoServiceAvailableException.php +
+
+
NoServiceAvailableException.php in NoServiceAvailableException.php
+
+
+ +
+
o
+ +
+
+
+
+ optimize +
+
+ +
Send an optimize command. Will be synchronous unless both wait parameters are set to false.
+
+
+ optimize +
+
+ +
Send an optimize command. Will be synchronous unless both wait parameters are set to false.
+
+
+ +
+
p
+ +
+
+
+
+ ParserException.php +
+
+
ParserException.php in ParserException.php
+
+
+ performGetRequest +
+
+ +
+
+ performGetRequest +
+
+ +
+
+ performGetRequest +
+
+ +
+
+ performGetRequest +
+
+ +
Perform a GET HTTP operation with an optional timeout and return the response contents, use getLastResponseHeaders to retrieve HTTP headers
+
+
+ performHeadRequest +
+
+ +
Perform a HEAD HTTP operation with an optional timeout and return the response headers - NOTE: head requests have no response body
+
+
+ performHeadRequest +
+
+ +
+
+ performHeadRequest +
+
+ +
+
+ performHeadRequest +
+
+ +
+
+ performPostRequest +
+
+ +
+
+ performPostRequest +
+
+ +
Perform a POST HTTP operation with an optional timeout and return the response contents, use getLastResponseHeaders to retrieve HTTP headers
+
+
+ performPostRequest +
+
+ +
+
+ performPostRequest +
+
+ +
+
+ phrase +
+
+ +
Convenience function for creating phrase syntax from a value
+
+
+ phrase +
+
+ +
Convenience function for creating phrase syntax from a value
+
+
+ ping +
+
+ +
Call the /admin/ping servlet, can be used to quickly tell if a connection to the server is able to be made.
+
+
+ PING_SERVLET +
+
+ +
Servlet mappings
+
+
+ +
+
r
+ +
+
+
+
+ Response.php +
+
+
Response.php in Response.php
+
+
+ removeReadService +
+
+ +
Removes a service instance or descriptor from the available services
+
+
+ removeWriteService +
+
+ +
Removes a service instance or descriptor from the available services
+
+
+ Response.php +
+
+
Response.php in Response.php
+
+
+ +
+
s
+ +
+
+
+
+ search +
+
+ +
Simple Search interface
+
+
+ search +
+
+ +
Simple Search interface
+
+
+ SEARCH_SERVLET +
+
+ +
+
+ Service.php +
+
+
Service.php in Service.php
+
+
+ setBoost +
+
+ +
Set document boost factor
+
+
+ setCollapseSingleValueArrays +
+
+ +
Set the collapse single value arrays flag.
+
+
+ setCreateDocuments +
+
+ +
Set the create documents flag. This determines whether Apache_Solr_Response objects will parse the response and create Apache_Solr_Document instances in place.
+
+
+ setCreateDocuments +
+
+ +
Set the create documents flag. This determines whether Apache_Solr_Response objects will parse the response and create Apache_Solr_Document instances in place.
+
+
+ setDefaultTimeout +
+
+ +
Set the current default timeout for all HTTP requests
+
+
+ setDefaultTimeout +
+
+ +
Set the default timeout for all calls that aren't passed a specific timeout
+
+
+ setDefaultTimeout +
+
+ +
Set the current default timeout for all HTTP requests
+
+
+ setField +
+
+ +
Set a field value. Multi-valued fields should be set as arrays or instead use the addField(...) function which will automatically make sure the field is an array.
+
+
+ setFieldBoost +
+
+ +
Set the field boost for a document field
+
+
+ setHost +
+
+ +
Set the host used. If empty will fallback to constants
+
+
+ setHttpTransport +
+
+ +
Set the HTTP Transport implemenation that will be used for all HTTP requests
+
+
+ setMultiValue +
+
+ +
Handle the array manipulation for a multi-valued field
+
+
+ setNamedListTreatment +
+
+ +
Set how NamedLists should be formatted in the response data. This mainly effects the facet counts format.
+
+
+ setPath +
+
+ +
Set the path used. If empty will fallback to constants
+
+
+ setPort +
+
+ +
Set the port used. If empty will fallback to constants
+
+
+ setQueryDelimiter +
+
+ +
Set the string used to separate the path form the query string.
+
+
+ setQueryStringDelimiter +
+
+ +
Set the string used to separate the parameters in thequery string Defaulted to '&'
+
+
+ setReadPingTimeout +
+
+ +
+
+ setUseBackoff +
+
+ +
+
+ setWritePingTimeout +
+
+ +
+
+ SOLR_WRITER +
+
+ +
Response writer we'll request - JSON. See http://code.google.com/p/solr-php-client/issues/detail?id=6#c1 for reasoning
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+
Apache_Solr_InvalidArgumentException::SVN_ID in InvalidArgumentException.php
+
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+
Apache_Solr_HttpTransportException::SVN_ID in HttpTransportException.php
+
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+
Apache_Solr_NoServiceAvailableException::SVN_ID in NoServiceAvailableException.php
+
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_ID +
+
+ +
SVN ID meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ SVN_REVISION +
+
+ +
SVN Revision meta data for this class
+
+
+ +
+
t
+ +
+
+
+
+ threads +
+
+ +
Call the /admin/threads servlet and retrieve information about all threads in the Solr servlet's thread group. Useful for diagnostics.
+
+
+ THREADS_SERVLET +
+
+ +
+
+ +
+
u
+ +
+
+
+
+ UPDATE_SERVLET +
+
+ +
+
+ +
+ a + b + c + d + e + f + g + h + i + m + n + o + p + r + s + t + u + _ +
+ \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/errors.html b/SolrPhpClient/phpdocs/errors.html new file mode 100644 index 00000000..56c8e288 --- /dev/null +++ b/SolrPhpClient/phpdocs/errors.html @@ -0,0 +1,95 @@ + + + + + + phpDocumentor Parser Errors and Warnings + + + + + Post-parsing
+Balancer.php
+Curl.php
+CurlNoReuse.php
+Document.php
+Exception.php
+FileGetContents.php
+HttpTransportException.php
+Interface.php
+InvalidArgumentException.php
+NoServiceAvailableException.php
+ParserException.php
+Response.php
+Service.php
+ +

Abstract.php

+

Warnings:


+Warning on line 43 - no @package tag was used in a DocBlock for class Apache_Solr_HttpTransport_Abstract
+ +

Balancer.php

+

Warnings:


+Warning on line 40 - Page-level DocBlock precedes "require_once dirname(dirname(__FILE__)).'/Service.php'", use another DocBlock to document the source element
+Warning on line 51 - no @package tag was used in a DocBlock for class Apache_Solr_Service_Balancer
+ +

Curl.php

+

Warnings:


+Warning on line 39 - Page-level DocBlock precedes "require_once dirname(__FILE__).'/Abstract.php'", use another DocBlock to document the source element
+Warning on line 45 - no @package tag was used in a DocBlock for class Apache_Solr_HttpTransport_Curl
+ +

CurlNoReuse.php

+

Warnings:


+Warning on line 39 - Page-level DocBlock precedes "require_once dirname(__FILE__).'/Abstract.php'", use another DocBlock to document the source element
+Warning on line 47 - no @package tag was used in a DocBlock for class Apache_Solr_HttpTransport_CurlNoReuse
+ +

Document.php

+

Warnings:


+Warning on line 58 - no @package tag was used in a DocBlock for class Apache_Solr_Document
+

Errors:


+Error on line 57 - Unclosed code tag in DocBlock, parsing will be incorrect
+ +

Exception.php

+

Warnings:


+Warning on line 39 - DocBlock would be page-level, but precedes class "Apache_Solr_Exception", use another DocBlock to document the file
+ +

FileGetContents.php

+

Warnings:


+Warning on line 39 - Page-level DocBlock precedes "require_once dirname(__FILE__).'/Abstract.php'", use another DocBlock to document the source element
+Warning on line 45 - no @package tag was used in a DocBlock for class Apache_Solr_HttpTransport_FileGetContents
+ +

HttpTransportException.php

+

Warnings:


+Warning on line 39 - DocBlock would be page-level, but precedes class "Apache_Solr_HttpTransportException", use another DocBlock to document the file
+ +

Interface.php

+

Warnings:


+Warning on line 39 - Page-level DocBlock precedes "require_once dirname(__FILE__).'/Response.php'", use another DocBlock to document the source element
+Warning on line 47 - no @package tag was used in a DocBlock for interface Apache_Solr_HttpTransport_Interface
+ +

InvalidArgumentException.php

+

Warnings:


+Warning on line 39 - DocBlock would be page-level, but precedes class "Apache_Solr_InvalidArgumentException", use another DocBlock to document the file
+ +

NoServiceAvailableException.php

+

Warnings:


+Warning on line 39 - DocBlock would be page-level, but precedes class "Apache_Solr_NoServiceAvailableException", use another DocBlock to document the file
+ +

ParserException.php

+

Warnings:


+Warning on line 39 - DocBlock would be page-level, but precedes class "Apache_Solr_ParserException", use another DocBlock to document the file
+ +

Response.php

+

Warnings:


+Warning on line 38 - Page-level DocBlock precedes "require_once dirname(__FILE__).'/ParserException.php'", use another DocBlock to document the source element
+Warning on line 44 - no @package tag was used in a DocBlock for class Apache_Solr_HttpTransport_Response
+Warning on line 48 - no @package tag was used in a DocBlock for class Apache_Solr_Response
+ +

Service.php

+

Warnings:


+Warning on line 40 - Page-level DocBlock precedes "require_once dirname(__FILE__).'/Exception.php'", use another DocBlock to document the source element
+Warning on line 86 - no @package tag was used in a DocBlock for class Apache_Solr_Service
+

+ Documentation generated on Wed, 04 May 2011 11:01:19 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/index.html b/SolrPhpClient/phpdocs/index.html new file mode 100644 index 00000000..dd90e526 --- /dev/null +++ b/SolrPhpClient/phpdocs/index.html @@ -0,0 +1,24 @@ + + + + + + Generated Documentation + + + + + + + + + + + <H2>Frame Alert</H2> + <P>This document is designed to be viewed using the frames feature. + If you see this message, you are using a non-frame-capable web client.</P> + + + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/li_Apache.html b/SolrPhpClient/phpdocs/li_Apache.html new file mode 100644 index 00000000..9b6e2b6e --- /dev/null +++ b/SolrPhpClient/phpdocs/li_Apache.html @@ -0,0 +1,72 @@ + + + + + + + + + + +
Apache
+ +

phpDocumentor v 1.4.3

+ + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/media/banner.css b/SolrPhpClient/phpdocs/media/banner.css new file mode 100644 index 00000000..ba1a7ba5 --- /dev/null +++ b/SolrPhpClient/phpdocs/media/banner.css @@ -0,0 +1,32 @@ +body +{ + background-color: #DDDDDD; + margin: 0px; + padding: 0px; +} + +/* Banner (top bar) classes */ + +.banner { } + +.banner-menu +{ + clear: both; + padding: .5em; + border-top: 2px solid #999999; +} + +.banner-title +{ + text-align: right; + font-size: 20pt; + font-weight: bold; + margin: .2em; +} + +.package-selector +{ + background-color: #CCCCCC; + border: 1px solid black; + color: blue; +} diff --git a/SolrPhpClient/phpdocs/media/stylesheet.css b/SolrPhpClient/phpdocs/media/stylesheet.css new file mode 100644 index 00000000..051586b3 --- /dev/null +++ b/SolrPhpClient/phpdocs/media/stylesheet.css @@ -0,0 +1,142 @@ +a { color: #0000FF; text-decoration: none; } +a:hover { color: #FF0000; text-decoration: underline; } +a:active { color: #FF0000; text-decoration: underline; } + +body { background-color: #EEEEEE; font-family: Verdana, Arial, sans-serif } +body, table { font-size: 10pt } +a img { border: 0px; } +dd { margin-left: 0px; padding-left: 1em; } + +/* Page layout/boxes */ + +.info-box {} +.info-box-title { margin: 1em 0em 0em 0em; padding: .25em; font-weight: normal; font-size: 14pt; border: 2px solid #999999; background-color: #DDDDDD } +.info-box-body { border: 1px solid #999999; padding: .5em; background-color: #F8F8F8; } +.nav-bar { font-size: 8pt; white-space: nowrap; text-align: right; padding: .2em; margin: 0em 0em 1em 0em; } + +.oddrow { background-color: #DDDDDD; border: 1px solid #999999; padding: .5em; margin-bottom: 1em} +.evenrow { background-color: #DDDDDD; border: 1px solid #999999; padding: .5em; margin-bottom: 1em} + +.page-body { max-width: 800px; margin: auto; } +.tree dl { margin: 0px } + +/* Index formatting classes */ + +.index-item-body { margin-top: .5em; margin-bottom: .5em} +.index-item-description { margin-top: .25em } +.index-item-details { font-weight: normal; font-style: italic; font-size: 8pt } +.index-letter-section { background-color: #EEEEEE; border: 1px dotted #999999; padding: .5em; margin-bottom: 1em} +.index-letter-title { font-size: 12pt; font-weight: bold } +.index-letter-menu { text-align: center; margin: 1em } +.index-letter { font-size: 12pt } + +/* Docbook classes */ + +.description {} +.short-description { font-weight: bold; color: #666666; } +.tags { padding-left: 0em; margin-left: 3em; color: #666666; list-style-type: square; } +.parameters { padding-left: 0em; margin-left: 3em; font-style: italic; list-style-type: square; } +.redefinitions { font-size: 8pt; padding-left: 0em; margin-left: 2em; } +.package { } +.package-title { font-weight: bold; font-size: 14pt; border-bottom: 1px solid black } +.package-details { font-size: 85%; } +.sub-package { font-weight: bold; font-size: 120% } +.tutorial { border-width: thin; border-color: #0066ff } +.tutorial-nav-box { width: 100%; border: 2px solid #999999; background-color: #DDDDDD } +.nav-button-disabled { color: #999999; } +.nav-button:active, +.nav-button:focus, +.nav-button:hover { background-color: #AAAAAA; outline: 1px solid #666666; text-decoration: none } +.folder-title { font-style: italic } + +/* Generic formatting */ + +.field { font-weight: bold; } +.detail { font-size: 8pt; } +.notes { font-style: italic; font-size: 8pt; } +.separator { background-color: #999999; height: 2px; } +.warning { color: #FF6600; } +.disabled { font-style: italic; color: #999999; } + +/* Code elements */ + +.line-number { } + +.class-table { width: 100%; } +.class-table-header { border-bottom: 1px dotted #666666; text-align: left} +.class-name { color: #000000; font-weight: bold; } + +.method-summary { padding-left: 1em; font-size: 8pt } +.method-header { } +.method-definition { margin-bottom: .3em } +.method-title { font-weight: bold; } +.method-name { font-weight: bold; } +.method-signature { font-size: 85%; color: #0066BB; margin: .5em 0em } +.method-result { font-style: italic; } + +.var-summary { padding-left: 1em; font-size: 8pt; } +.var-header { } +.var-title { margin-bottom: .3em } +.var-type { color: red; font-weight: bold } +.var-name { font-weight: bold; } +.var-default {} +.var-description { font-weight: normal; color: #000000; } + +.include-title { } +.include-type { font-style: italic; } +.include-name { font-weight: bold; } + +.const-title { } +.const-name { font-weight: bold; } + +/* Syntax highlighting */ + +.src-code { border: 1px solid #336699; padding: 1em; background-color: #EEEEEE; + font-family: 'Courier New', Courier, monospace; font-weight: normal; } +.src-line { font-family: 'Courier New', Courier, monospace; font-weight: normal; } + +.src-comm { color: #666666; } +.src-id { } +.src-inc { color: #0000FF; } +.src-key { color: #0000FF; } +.src-num { color: #CC0000; } +.src-str { color: #66cccc; } +.src-sym { font-weight: bold; } +.src-var { } + +.src-php { font-weight: bold; } + +.src-doc { color: #009999 } +.src-doc-close-template { color: #0000FF } +.src-doc-coretag { color: #0099FF; font-weight: bold } +.src-doc-inlinetag { color: #0099FF } +.src-doc-internal { color: #6699cc } +.src-doc-tag { color: #0080CC } +.src-doc-template { color: #0000FF } +.src-doc-type { font-style: italic } +.src-doc-var { font-style: italic } + +.tute-tag { color: #009999 } +.tute-attribute-name { color: #0000FF } +.tute-attribute-value { color: #0099FF } +.tute-entity { font-weight: bold; } +.tute-comment { font-style: italic } +.tute-inline-tag { color: #636311; font-weight: bold } + +/* tutorial */ + +.authors { } +.author { font-style: italic; font-weight: bold } +.author-blurb { margin: .5em 0em .5em 2em; font-size: 85%; font-weight: normal; font-style: normal } +.example { background-color: #DDDDDD; border: 1px solid #999999; padding: .5em; } +.listing { background-color: #DDDDDD; border: 1px solid #999999; padding: .5em; white-space: nowrap; } +.release-info { font-size: 85%; font-style: italic; margin: 1em 0em } +.ref-title-box { } +.ref-title { } +.ref-purpose { font-style: italic; color: #666666 } +.ref-synopsis { } +.title { font-weight: bold; border-bottom: 1px solid #888888; color: #888888; } +.cmd-synopsis { margin: 1em 0em } +.cmd-title { font-weight: bold } +.toc { margin-left: 2em; padding-left: 0em } + diff --git a/SolrPhpClient/phpdocs/packages.html b/SolrPhpClient/phpdocs/packages.html new file mode 100644 index 00000000..97fe3802 --- /dev/null +++ b/SolrPhpClient/phpdocs/packages.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SolrPhpClient/phpdocs/todolist.html b/SolrPhpClient/phpdocs/todolist.html new file mode 100644 index 00000000..1490bd8d --- /dev/null +++ b/SolrPhpClient/phpdocs/todolist.html @@ -0,0 +1,29 @@ + + + + + + Todo List + + + + +

Todo List

+

Apache

+

Apache_Solr_Service

+
    +
  • Investigate using other HTTP clients other than file_get_contents built-in handler. Could provide performance improvements when dealing with multiple requests by using HTTP's keep alive functionality
  • +
+

Apache_Solr_Service::extractFromString()

+
    +
  • Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
  • +
+

Apache_Solr_Service_Balancer::extractFromString()

+
    +
  • Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
  • +
+

+ Documentation generated on Wed, 04 May 2011 11:01:19 -0400 by phpDocumentor 1.4.3 +

+ + \ No newline at end of file diff --git a/SolrPhpClient/tests/Apache/Solr/DocumentTest.php b/SolrPhpClient/tests/Apache/Solr/DocumentTest.php new file mode 100644 index 00000000..92261c8e --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/DocumentTest.php @@ -0,0 +1,439 @@ + + */ + +/** + * Apache_Solr_Document Unit Test + */ +class Apache_Solr_DocumentTest extends PHPUnit_Framework_TestCase +{ + /** + * Fixture used for testing + * + * @var Apache_Solr_Document + */ + private $_fixture; + + /** + * Setup for the fixture before each unit test - part of test case API + */ + protected function setup() + { + $this->_fixture = new Apache_Solr_Document(); + } + + /** + * Teardown after each unit test - part of test case API + */ + protected function tearDown() + { + unset($this->_fixture); + } + + public function testDefaultStateAfterConstructor() + { + // document boost should be false + $this->assertFalse($this->_fixture->getBoost()); + + // document fields should be empty + $this->assertEquals(0, count($this->_fixture->getFieldNames())); + $this->assertEquals(0, count($this->_fixture->getFieldValues())); + $this->assertEquals(0, count($this->_fixture->getFieldBoosts())); + + // document iterator should be empty + $this->assertEquals(0, iterator_count($this->_fixture)); + } + + public function testSetAndGetField() + { + $field = 'field'; + $value = 'value'; + $boost = 0.5; + + // set the field + $this->_fixture->setField($field, $value, $boost); + + $result = $this->_fixture->getField($field); + + // check the array values + $this->assertTrue(is_array($result)); + $this->assertEquals($field, $result['name']); + $this->assertEquals($value, $result['value']); + $this->assertEquals($boost, $result['boost']); + } + + public function testGetFieldReturnsFalseForNonExistentField() + { + $this->assertFalse($this->_fixture->getField('field')); + } + + public function testMagicGetForFieldValues() + { + $field = 'field'; + $value = 'value'; + + $this->_fixture->setField($field, $value); + + // test the __get value + $this->assertEquals($value, $this->_fixture->{$field}); + } + + /** + * Added for issue #48 (http://code.google.com/p/solr-php-client/issues/detail?id=48) + */ + public function testMagicGetReturnsNullForNonExistentField() + { + $this->assertNull($this->_fixture->nonExistent); + } + + public function testMagicSetForFieldValues() + { + $field = 'field'; + $value = 'value'; + + // set field value with magic __set + $this->_fixture->{$field} = $value; + + $fieldArray = $this->_fixture->getField($field); + + // set values + $this->assertEquals($field, $fieldArray['name']); + $this->assertEquals($value, $fieldArray['value']); + $this->assertTrue($fieldArray['boost'] === false); + } + + public function testMagicIssetForNonExistentField() + { + $this->assertFalse(isset($this->_fixture->field)); + } + + public function testMagicIssetForExistingField() + { + $field = 'field'; + $this->_fixture->{$field} = 'value'; + $this->assertTrue(isset($this->_fixture->{$field})); + } + + public function testMagicUnsetForExistingField() + { + $field = 'field'; + + $this->_fixture->{$field} = 'value'; + + // now unset the field + unset($this->_fixture->{$field}); + + // now test that its unset + $this->assertFalse(isset($this->_fixture->{$field})); + } + + public function testMagicUnsetForNonExistingField() + { + $field = 'field'; + unset($this->_fixture->{$field}); + + // now test that it still does not exist + $this->assertFalse(isset($this->_fixture->{$field})); + } + + public function testSetAndGetFieldBoostWithPositiveNumberSetsBoost() + { + $field = 'field'; + $boost = 0.5; + + $this->_fixture->setFieldBoost($field, $boost); + + // test the field boost + $this->assertEquals($boost, $this->_fixture->getFieldBoost($field)); + } + + public function testSetAndGetFieldBoostWithZeroRemovesBoost() + { + $field = 'field'; + $boost = 0; + + $this->_fixture->setFieldBoost($field, $boost); + + // test the field boost + $this->assertTrue($this->_fixture->getFieldBoost($field) === false); + } + + public function testSetAndGetFieldBoostWithNegativeNumberRemovesBoost() + { + $field = 'field'; + $boost = -1; + + $this->_fixture->setFieldBoost($field, $boost); + + // test the field boost + $this->assertTrue($this->_fixture->getFieldBoost($field) === false); + } + + public function testSetAndGetFieldBoostWithNonNumberRemovesBoost() + { + $field = 'field'; + $boost = "i am not a number"; + + $this->_fixture->setFieldBoost($field, $boost); + + // test the field boost + $this->assertTrue($this->_fixture->getFieldBoost($field) === false); + } + + public function testSetAndGetBoostWithPositiveNumberSetsBoost() + { + $boost = 0.5; + $this->_fixture->setBoost($boost); + + // the boost should now be set + $this->assertEquals($boost, $this->_fixture->getBoost()); + } + + public function testSetAndGetBoostWithZeroRemovesBoost() + { + $this->_fixture->setBoost(0); + + // should be boolean false + $this->assertTrue($this->_fixture->getBoost() === false); + } + + public function testSetAndGetBoostWithNegativeNumberRemovesBoost() + { + $this->_fixture->setBoost(-1); + + // should be boolean false + $this->assertTrue($this->_fixture->getBoost() === false); + } + + public function testSetAndGetBoostWithNonNumberRemovesBoost() + { + $this->_fixture->setBoost("i am not a number"); + + // should be boolean false + $this->assertTrue($this->_fixture->getBoost() === false); + } + + public function testAddFieldCreatesMultiValueWhenFieldDoesNotExist() + { + $field = 'field'; + $value = 'value'; + + $this->_fixture->addField($field, $value); + + // check that value is an array with correct values + $fieldValue = $this->_fixture->{$field}; + + $this->assertTrue(is_array($fieldValue)); + $this->assertEquals(1, count($fieldValue)); + $this->assertEquals($value, $fieldValue[0]); + } + + /** + * setMultiValue has been deprecated and defers to addField + * + * @deprecated + */ + public function testSetMultiValueCreateMultiValueWhenFieldDoesNotExist() + { + $field = 'field'; + $value = 'value'; + + $this->_fixture->setMultiValue($field, $value); + + // check that value is an array with correct values + $fieldValue = $this->_fixture->{$field}; + + $this->assertTrue(is_array($fieldValue)); + $this->assertEquals(1, count($fieldValue)); + $this->assertEquals($value, $fieldValue[0]); + } + + public function testAddFieldCreatesMultiValueWhenFieldDoesExistAsSingleValue() + { + $field = 'field'; + $value1 = 'value1'; + $value2 = 'value2'; + + // set first value as singular value + $this->_fixture->{$field} = $value1; + + // add a second value with addField + $this->_fixture->addField($field, $value2); + + // check that value is an array with correct values + $fieldValue = $this->_fixture->{$field}; + + $this->assertTrue(is_array($fieldValue)); + $this->assertEquals(2, count($fieldValue)); + $this->assertEquals($value1, $fieldValue[0]); + $this->assertEquals($value2, $fieldValue[1]); + } + + /** + * setMultiValue has been deprecated and defers to addField + * + * @deprecated + */ + public function testSetMultiValueCreatesMultiValueWhenFieldDoesExistAsSingleValue() + { + $field = 'field'; + $value1 = 'value1'; + $value2 = 'value2'; + + // set first value as singular value + $this->_fixture->{$field} = $value1; + + // add a second value with addField + $this->_fixture->setMultiValue($field, $value2); + + // check that value is an array with correct values + $fieldValue = $this->_fixture->{$field}; + + $this->assertTrue(is_array($fieldValue)); + $this->assertEquals(2, count($fieldValue)); + $this->assertEquals($value1, $fieldValue[0]); + $this->assertEquals($value2, $fieldValue[1]); + } + + public function testAddFieldWithBoostSetsFieldBoost() + { + $field = 'field'; + $boost = 0.5; + + $this->_fixture->addField($field, 'value', $boost); + + // check the field boost + $this->assertEquals($boost, $this->_fixture->getFieldBoost($field)); + } + + public function testAddFieldWithBoostMultipliesWithAPreexistingBoost() + { + $field = 'field'; + $boost = 0.5; + + // set a field with a boost + $this->_fixture->setField($field, 'value1', $boost); + + // now add another value with the same boost + $this->_fixture->addField($field, 'value2', $boost); + + // new boost should be $boost * $boost + $this->assertEquals($boost * $boost, $this->_fixture->getFieldBoost($field)); + } + + public function testGetFieldNamesIsInitiallyEmpty() + { + $fieldNames = $this->_fixture->getFieldNames(); + + $this->assertTrue(empty($fieldNames)); + } + + public function testGetFieldNamesAfterFieldIsSetIsNotEmpty() + { + $field = 'field'; + + $this->_fixture->{$field} = 'value'; + $fieldNames = $this->_fixture->getFieldNames(); + + $this->assertTrue(!empty($fieldNames)); + $this->assertEquals(1, count($fieldNames)); + $this->assertEquals($field, $fieldNames[0]); + } + + public function testGetFieldValuesIsInitiallyEmpty() + { + $fieldValues = $this->_fixture->getFieldValues(); + + $this->assertTrue(empty($fieldValues)); + } + + public function testGetFieldValuessAfterFieldIsSetIsNotEmpty() + { + $value = 'value'; + + $this->_fixture->field = $value; + $fieldValues = $this->_fixture->getFieldValues(); + + $this->assertTrue(!empty($fieldValues)); + $this->assertEquals(1, count($fieldValues)); + $this->assertEquals($value, $fieldValues[0]); + } + + public function testGetIteratorAfterFieldValueIsSet() + { + $field = 'field'; + $value = 'value'; + + $this->_fixture->{$field} = $value; + + $itemCount = 0; + + foreach ($this->_fixture as $iteratedField => $iteratedValue) + { + ++$itemCount; + + // test field and value + $this->assertEquals($field, $iteratedField); + $this->assertEquals($value, $iteratedValue); + } + + // test number of iterations is 1 + $this->assertEquals(1, $itemCount); + } + + public function testClearReturnsDocumentToDefaultState() + { + // set the document boost + $this->_fixture->setBoost(0.5); + + // set a field + $this->_fixture->someField = "some value"; + + // clear the document to remove boost and fields + $this->_fixture->clear(); + + // document boost should now be false + $this->assertFalse($this->_fixture->getBoost()); + + // document fields should now be empty + $this->assertEquals(0, count($this->_fixture->getFieldNames())); + $this->assertEquals(0, count($this->_fixture->getFieldValues())); + $this->assertEquals(0, count($this->_fixture->getFieldBoosts())); + + // document iterator should now be empty + $this->assertEquals(0, iterator_count($this->_fixture)); + } +} \ No newline at end of file diff --git a/SolrPhpClient/tests/Apache/Solr/HttpTransport/AbstractTest.php b/SolrPhpClient/tests/Apache/Solr/HttpTransport/AbstractTest.php new file mode 100644 index 00000000..a16e8b6d --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/HttpTransport/AbstractTest.php @@ -0,0 +1,208 @@ + + */ + +/** + * Apache_Solr_HttpTransport_Abstract Unit Tests + */ +abstract class Apache_Solr_HttpTransport_AbstractTest extends PHPUnit_Framework_TestCase +{ + const TIMEOUT = 2; + + // request our copyright file from googlecode for GET and HEAD + const GET_URL = "http://solr-php-client.googlecode.com/svn/trunk/COPYING"; + const GET_RESPONSE_MIME_TYPE = 'text/plain'; + const GET_RESPONSE_ENCODING = 'UTF-8'; + const GET_RESPONSE_MATCH = 'Copyright (c) '; + + // post to the issue list page with a search for 'meh' + const POST_URL = "http://code.google.com/p/solr-php-client/issues/list"; + const POST_DATA = "can=2&q=meh&colspec=ID+Type+Status+Priority+Milestone+Owner+Summary&cells=tiles"; + const POST_REQUEST_CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=UTF-8'; + + const POST_RESPONSE_MIME_TYPE = 'text/html'; + const POST_RESPONSE_ENCODING = 'UTF-8'; + //const POST_RESPONSE_MATCH = 'not sure'; + + abstract public function getFixture(); + + public function testGetDefaultTimeoutWithDefaultConstructor() + { + $fixture = $this->getFixture(); + $timeout = $fixture->getDefaultTimeout(); + + $this->assertGreaterThan(0, $timeout); + } + + public function testGetDefaultTimeoutSetToSixtyForBadValues() + { + // first set our default_socket_timeout ini setting + $previousValue = ini_get('default_socket_timeout'); + ini_set('default_socket_timeout', 0); + + $fixture = $this->getFixture(); + $timeout = $fixture->getDefaultTimeout(); + + // reset timeout + ini_set('default_socket_timeout', $previousValue); + + $this->assertEquals(60, $timeout); + } + + public function testSetDefaultTimeout() + { + $newTimeout = 1234; + + $fixture = $this->getFixture(); + $fixture->setDefaultTimeout($newTimeout); + $timeout = $fixture->getDefaultTimeout(); + + $this->assertEquals($newTimeout, $timeout); + } + + public function testPerformGetRequest() + { + $fixture = $this->getFixture(); + $fixture->setDefaultTimeout(self::TIMEOUT); + + $response = $fixture->performGetRequest(self::GET_URL); + + $this->assertType('Apache_Solr_HttpTransport_Response', $response); + + $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200'); + $this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct'); + $this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct'); + $this->assertStringStartsWith(self::GET_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text'); + } + + public function testPerformGetRequestWithTimeout() + { + $fixture = $this->getFixture(); + $response = $fixture->performGetRequest(self::GET_URL, self::TIMEOUT); + + $this->assertType('Apache_Solr_HttpTransport_Response', $response); + + $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200'); + $this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct'); + $this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct'); + $this->assertStringStartsWith(self::GET_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text'); + } + + public function testPerformHeadRequest() + { + $fixture = $this->getFixture(); + $fixture->setDefaultTimeout(self::TIMEOUT); + + $response = $fixture->performHeadRequest(self::GET_URL); + + // we should get everything the same as a get, except the body + $this->assertType('Apache_Solr_HttpTransport_Response', $response); + + $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200'); + $this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct'); + $this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct'); + $this->assertEquals("", $response->getBody(), 'body was not empty'); + } + + public function testPerformHeadRequestWithTimeout() + { + $fixture = $this->getFixture(); + $response = $fixture->performHeadRequest(self::GET_URL, self::TIMEOUT); + + // we should get everything the same as a get, except the body + $this->assertType('Apache_Solr_HttpTransport_Response', $response); + + $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200'); + $this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct'); + $this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct'); + $this->assertEquals("", $response->getBody(), 'body was not empty'); + } + + public function testPerformPostRequest() + { + $fixture = $this->getFixture(); + $fixture->setDefaultTimeout(self::TIMEOUT); + + $response = $fixture->performPostRequest(self::POST_URL, self::POST_DATA, self::POST_REQUEST_CONTENT_TYPE); + + $this->assertType('Apache_Solr_HttpTransport_Response', $response); + + $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200'); + $this->assertEquals(self::POST_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct'); + $this->assertEquals(self::POST_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct'); + //$this->assertStringStartsWith(self::POST_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text'); + } + + public function testPerformPostRequestWithTimeout() + { + $fixture = $this->getFixture(); + $response = $fixture->performPostRequest(self::POST_URL, self::POST_DATA, self::POST_REQUEST_CONTENT_TYPE, self::TIMEOUT); + + $this->assertType('Apache_Solr_HttpTransport_Response', $response); + + $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200'); + $this->assertEquals(self::POST_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct'); + $this->assertEquals(self::POST_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct'); + //$this->assertStringStartsWith(self::POST_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text'); + } + + /** + * Test one session doing multiple requests in multiple orders + */ + public function testMultipleRequests() + { + // initial get request + $this->testPerformGetRequest(); + + // head following get + $this->testPerformHeadRequest(); + + // post following head + $this->testPerformPostRequest(); + + // get following post + $this->testPerformGetRequest(); + + // post following get + $this->testPerformPostRequest(); + + // head following post + $this->testPerformHeadRequest(); + + // get following post + $this->testPerformGetRequest(); + } +} \ No newline at end of file diff --git a/SolrPhpClient/tests/Apache/Solr/HttpTransport/CurlNoReuseTest.php b/SolrPhpClient/tests/Apache/Solr/HttpTransport/CurlNoReuseTest.php new file mode 100644 index 00000000..0484dd4d --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/HttpTransport/CurlNoReuseTest.php @@ -0,0 +1,53 @@ + + */ + +/** + * Apache_Solr_HttpTransport_CurlNoReuse Unit Tests + */ +class Apache_Solr_HttpTransport_CurlNoReuseTest extends Apache_Solr_HttpTransport_AbstractTest +{ + public function getFixture() + { + // ensure curl is enabled + if (!extension_loaded('curl')) + { + $this->markTestSkipped("curl module is not enabled"); + } + + return new Apache_Solr_HttpTransport_CurlNoReuse(); + } +} diff --git a/SolrPhpClient/tests/Apache/Solr/HttpTransport/CurlTest.php b/SolrPhpClient/tests/Apache/Solr/HttpTransport/CurlTest.php new file mode 100644 index 00000000..070c164f --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/HttpTransport/CurlTest.php @@ -0,0 +1,53 @@ + + */ + +/** + * Apache_Solr_HttpTransport_Curl Unit Tests + */ +class Apache_Solr_HttpTransport_CurlTest extends Apache_Solr_HttpTransport_AbstractTest +{ + public function getFixture() + { + // ensure curl is enabled + if (!extension_loaded('curl')) + { + $this->markTestSkipped("curl module is not enabled"); + } + + return new Apache_Solr_HttpTransport_Curl(); + } +} diff --git a/SolrPhpClient/tests/Apache/Solr/HttpTransport/FileGetContentsTest.php b/SolrPhpClient/tests/Apache/Solr/HttpTransport/FileGetContentsTest.php new file mode 100644 index 00000000..2e4f8e90 --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/HttpTransport/FileGetContentsTest.php @@ -0,0 +1,53 @@ + + */ + +/** + * Apache_Solr_HttpTransport_FileGetContents Unit Tests + */ +class Apache_Solr_HttpTransport_FileGetContentsTest extends Apache_Solr_HttpTransport_AbstractTest +{ + public function getFixture() + { + // make sure allow_url_fopen is on + if (!ini_get("allow_url_fopen")) + { + $this->markTestSkipped("allow_url_fopen is not enabled"); + } + + return new Apache_Solr_HttpTransport_FileGetContents(); + } +} \ No newline at end of file diff --git a/SolrPhpClient/tests/Apache/Solr/HttpTransport/ResponseTest.php b/SolrPhpClient/tests/Apache/Solr/HttpTransport/ResponseTest.php new file mode 100644 index 00000000..f3c11273 --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/HttpTransport/ResponseTest.php @@ -0,0 +1,164 @@ + + */ + +/** + * Apache_Solr_HttpTransport_Response Unit Tests + */ +class Apache_Solr_HttpTransport_ResponseTest extends PHPUnit_Framework_TestCase +{ + // generated with the following query string: select?q=solr&wt=json + const STATUS_CODE_200 = 200; + const STATUS_MESSAGE_200 = "OK"; + const BODY_200 = '{"responseHeader":{"status":0,"QTime":0,"params":{"q":"solr","wt":"json"}},"response":{"numFound":0,"start":0,"docs":[]}}'; + const BODY_200_WITH_DOCUMENTS = '{"responseHeader":{"status":0,"QTime":0,"params":{"q":"*:*","wt":"json"}},"response":{"numFound":1,"start":0,"docs":[{"guid":"dev/2/products/45410/1236981","cit_domain":"products","cit_client":"2","cit_instance":"dev","cit_timestamp":"2010-10-06T18:16:51.573Z","product_code_t":["235784"],"product_id":[1236981],"dealer_id":[45410],"category_id":[1030],"manufacturer_id":[0],"vendor_id":[472],"catalog_id":[202]}]}}'; + const CONTENT_TYPE_200 = "text/plain; charset=utf-8"; + const MIME_TYPE_200 = "text/plain"; + const ENCODING_200 = "utf-8"; + + // generated with the following query string: select?qt=standad&q=solr&wt=json + // NOTE: the intentional mispelling of the standard in the qt parameter + const STATUS_CODE_400 = 400; + const STATUS_MESSAGE_400 = "Bad Request"; + const BODY_400 = 'Apache Tomcat/6.0.24 - Error report

HTTP Status 400 - unknown handler: standad


type Status report

message unknown handler: standad

description The request sent by the client was syntactically incorrect (unknown handler: standad).


Apache Tomcat/6.0.24

'; + const CONTENT_TYPE_400 = "text/html; charset=utf-8"; + const MIME_TYPE_400 = "text/html"; + const ENCODING_400 = "utf-8"; + + // generated with the following query string: select?q=solr&wt=json on a core that does not exist + const STATUS_CODE_404 = 404; + const STATUS_MESSAGE_404 = "Not Found"; + const BODY_404 = 'Apache Tomcat/6.0.24 - Error report

HTTP Status 404 - /solr/doesnotexist/select


type Status report

message /solr/doesnotexist/select

description The requested resource (/solr/doesnotexist/select) is not available.


Apache Tomcat/6.0.24

'; + const CONTENT_TYPE_404 = "text/html; charset=utf-8"; + const MIME_TYPE_404 = "text/html"; + const ENCODING_404 = "utf-8"; + + public static function get0Response() + { + return new Apache_Solr_HttpTransport_Response(null, null, null); + } + + public static function get200Response() + { + return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_200, self::CONTENT_TYPE_200, self::BODY_200); + } + + public static function get200ResponseWithDocuments() + { + return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_200, self::CONTENT_TYPE_200, self::BODY_200_WITH_DOCUMENTS); + } + + public static function get400Response() + { + return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_400, self::CONTENT_TYPE_400, self::BODY_400); + } + + public static function get404Response() + { + return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_404, self::CONTENT_TYPE_404, self::BODY_404); + } + + public function testGetStatusCode() + { + $fixture = self::get200Response(); + + $statusCode = $fixture->getStatusCode(); + + $this->assertEquals(self::STATUS_CODE_200, $statusCode); + } + + public function testGetStatusMessage() + { + $fixture = self::get200Response(); + + $statusMessage = $fixture->getStatusMessage(); + + $this->assertEquals(self::STATUS_MESSAGE_200, $statusMessage); + } + + public function testGetStatusMessageWithUnknownCode() + { + $fixture = new Apache_Solr_HttpTransport_Response(499, null, null); + + $statusMessage = $fixture->getStatusMessage(); + $this->assertEquals("Unknown Status", $statusMessage); + } + + public function testGetBody() + { + $fixture = self::get200Response(); + + $body = $fixture->getBody(); + + $this->assertEquals(self::BODY_200, $body); + } + + public function testGetMimeType() + { + $fixture = self::get200Response(); + + $mimeType = $fixture->getMimeType(); + + $this->assertEquals(self::MIME_TYPE_200, $mimeType); + } + + public function testGetEncoding() + { + $fixture = self::get200Response(); + + $encoding = $fixture->getEncoding(); + + $this->assertEquals(self::ENCODING_200, $encoding); + } + + public function testGetStatusMessageWhenNotProvided() + { + // test 4 of the most common status code responses, probably don't need + // to test all the codes we have + + $fixture = new Apache_Solr_HttpTransport_Response(null, null, null, null, null); + $this->assertEquals("Communication Error", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 0'); + + $fixture = new Apache_Solr_HttpTransport_Response(200, null, null, null, null); + $this->assertEquals("OK", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 200'); + + $fixture = new Apache_Solr_HttpTransport_Response(400, null, null, null, null); + $this->assertEquals("Bad Request", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 400'); + + $fixture = new Apache_Solr_HttpTransport_Response(404, null, null, null, null); + $this->assertEquals("Not Found", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 404'); + } +} diff --git a/SolrPhpClient/tests/Apache/Solr/HttpTransportExceptionTest.php b/SolrPhpClient/tests/Apache/Solr/HttpTransportExceptionTest.php new file mode 100644 index 00000000..a0958753 --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/HttpTransportExceptionTest.php @@ -0,0 +1,58 @@ + + */ + +/** + * Apache_Solr_HttpTransportException Unit Tests + */ +class Apache_Solr_HttpTransportExceptionTest extends PHPUnit_Framework_TestCase +{ + /** + * @expectedException PHPUnit_Framework_Error + */ + public function testConstructorRequiresResponse() + { + $fixture = new Apache_Solr_HttpTransportException(); + } + + public function testGetResponse() + { + $response = Apache_Solr_ResponseTest::get0Response(); + $fixture = new Apache_Solr_HttpTransportException($response); + + $this->assertEquals($response, $fixture->getResponse()); + } +} diff --git a/SolrPhpClient/tests/Apache/Solr/ResponseTest.php b/SolrPhpClient/tests/Apache/Solr/ResponseTest.php new file mode 100644 index 00000000..6ba4fe99 --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/ResponseTest.php @@ -0,0 +1,194 @@ + + */ + +/** + * Apache_Solr_Response Unit Test + */ +class Apache_Solr_ResponseTest extends PHPUnit_Framework_TestCase +{ + static public function get0Response($createDocuments = true, $collapseSingleValueArrays = true) + { + return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get0Response(), $createDocuments, $collapseSingleValueArrays); + } + + static public function get200Response($createDocuments = true, $collapseSingleValueArrays = true) + { + return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get200Response(), $createDocuments, $collapseSingleValueArrays); + } + + static public function get200ResponseWithDocuments($createDocuments = true, $collapseSingleValueArrays = true) + { + return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get200ResponseWithDocuments(), $createDocuments, $collapseSingleValueArrays); + } + + static public function get400Response($createDocuments = true, $collapseSingleValueArrays = true) + { + return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get400Response(), $createDocuments, $collapseSingleValueArrays); + } + + static public function get404Response($createDocuments = true, $collapseSingleValueArrays = true) + { + return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get404Response(), $createDocuments, $collapseSingleValueArrays); + } + + public function testConstuctorWithValidBodyAndHeaders() + { + $fixture = self::get200Response(); + + // check that we parsed the HTTP status correctly + $this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::STATUS_CODE_200, $fixture->getHttpStatus()); + + // check that we received the body correctly + $this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::BODY_200, $fixture->getRawResponse()); + + // check that our defaults are correct + $this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::ENCODING_200, $fixture->getEncoding()); + $this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::MIME_TYPE_200, $fixture->getType()); + } + + public function testConstructorWithBadBodyAndHeaders() + { + $fixture = self::get0Response(); + + // check that our defaults are correct + $this->assertEquals(0, $fixture->getHttpStatus()); + $this->assertEquals("UTF-8", $fixture->getEncoding()); + $this->assertEquals("text/plain", $fixture->getType()); + } + + public function testMagicGetWithValidBodyAndHeaders() + { + $fixture = self::get200Response(); + + // test top level gets + $this->assertType('stdClass', $fixture->responseHeader); + $this->assertEquals(0, $fixture->responseHeader->status); + $this->assertEquals(0, $fixture->responseHeader->QTime); + + $this->assertType('stdClass', $fixture->response); + $this->assertEquals(0, $fixture->response->numFound); + + $this->assertTrue(is_array($fixture->response->docs)); + $this->assertEquals(0, count($fixture->response->docs)); + } + + /** + * @expectedException Apache_Solr_ParserException + */ + public function testMagicGetWith0Response() + { + $fixture = self::get0Response(); + + // attempting to magic get a part of the response + // should throw a ParserException + $fixture->responseHeader; + + $this->fail("Expected Apache_Solr_ParserException was not raised"); + } + + /** + * @expectedException Apache_Solr_ParserException + */ + public function testMagicGetWith400Response() + { + $fixture = self::get400Response(); + + // attempting to magic get a part of the response + // should throw a ParserException + $fixture->responseHeader; + + $this->fail("Expected Apache_Solr_ParserException was not raised"); + } + + /** + * @expectedException Apache_Solr_ParserException + */ + public function testMagicGetWith404Response() + { + $fixture = self::get404Response(); + + // attempting to magic get a part of the response + // should throw a ParserException + $fixture->responseHeader; + + $this->fail("Expected Apache_Solr_ParserException was not raised"); + } + + public function testCreateDocuments() + { + $fixture = self::get200ResponseWithDocuments(); + + $this->assertTrue(count($fixture->response->docs) > 0, 'There are not 1 or more documents, cannot test'); + $this->assertType('Apache_Solr_Document', $fixture->response->docs[0], 'The first document is not of type Apache_Solr_Document'); + } + + public function testDontCreateDocuments() + { + $fixture = self::get200ResponseWithDocuments(false); + + $this->assertTrue(count($fixture->response->docs) > 0, 'There are not 1 or more documents, cannot test'); + $this->assertType('stdClass', $fixture->response->docs[0], 'The first document is not of type stdClass'); + } + + public function testGetHttpStatusMessage() + { + $fixture = self::get200Response(); + + $this->assertEquals("OK", $fixture->getHttpStatusMessage()); + } + + public function testMagicGetReturnsNullForUndefinedData() + { + $fixture = self::get200Response(); + + $this->assertNull($fixture->doesnotexist); + } + + public function testMagicIssetForDefinedProperty() + { + $fixture = self::get200Response(); + + $this->assertTrue(isset($fixture->responseHeader)); + } + + public function testMagicIssetForUndefinedProperty() + { + $fixture = self::get200Response(); + + $this->assertFalse(isset($fixture->doesnotexist)); + } +} diff --git a/SolrPhpClient/tests/Apache/Solr/Service/BalancerTest.php b/SolrPhpClient/tests/Apache/Solr/Service/BalancerTest.php new file mode 100644 index 00000000..df398749 --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/Service/BalancerTest.php @@ -0,0 +1,47 @@ + + */ + +/** + * Apache_Solr_Service_Balancer Unit Tests + */ +class Apache_Solr_Service_BalancerTest extends Apache_Solr_ServiceAbstractTest +{ + public function getFixture() + { + return new Apache_Solr_Service_Balancer(); + } +} \ No newline at end of file diff --git a/SolrPhpClient/tests/Apache/Solr/ServiceAbstractTest.php b/SolrPhpClient/tests/Apache/Solr/ServiceAbstractTest.php new file mode 100644 index 00000000..0e8fdf52 --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/ServiceAbstractTest.php @@ -0,0 +1,139 @@ + + */ + +/** + * Provides base funcationality test for both Apache_Solr_Service and the + * Apache_Solr_Service_Balancer classes. + */ +abstract class Apache_Solr_ServiceAbstractTest extends PHPUnit_Framework_TestCase +{ + /** + * Method that gets the appropriate instance for testing + */ + abstract public function getFixture(); + + /** + * @dataProvider testEscapeDataProvider + */ + public function testEscape($input, $expectedOutput) + { + $fixture = $this->getFixture(); + + $this->assertEquals($expectedOutput, $fixture->escape($input)); + } + + public function testEscapeDataProvider() + { + return array( + array( + "I should look the same", + "I should look the same" + ), + + array( + "(There) are: ^lots \\ && of spec!al charaters", + "\\(There\\) are\\: \\^lots \\\\ \\&& of spec\\!al charaters" + ) + ); + } + + /** + * @dataProvider testEscapePhraseDataProvider + */ + public function testEscapePhrase($input, $expectedOutput) + { + $fixture = $this->getFixture(); + + $this->assertEquals($expectedOutput, $fixture->escapePhrase($input)); + } + + public function testEscapePhraseDataProvider() + { + return array( + array( + "I'm a simple phrase", + "I'm a simple phrase" + ), + + array( + "I have \"phrase\" characters", + 'I have \\"phrase\\" characters' + ) + ); + } + + /** + * @dataProvider testPhraseDataProvider + */ + public function testPhrase($input, $expectedOutput) + { + $fixture = $this->getFixture(); + + $this->assertEquals($expectedOutput, $fixture->phrase($input)); + } + + public function testPhraseDataProvider() + { + return array( + array( + "I'm a simple phrase", + '"I\'m a simple phrase"' + ), + + array( + "I have \"phrase\" characters", + '"I have \\"phrase\\" characters"' + ) + ); + } + + public function testGetCreateDocumentWithDefaultConstructor() + { + $fixture = $this->getFixture(); + + $this->assertTrue($fixture->getCreateDocuments()); + } + + public function testSetCreateDocuments() + { + $fixture = $this->getFixture(); + + $fixture->setCreateDocuments(false); + + $this->assertFalse($fixture->getCreateDocuments()); + } +} \ No newline at end of file diff --git a/SolrPhpClient/tests/Apache/Solr/ServiceTest.php b/SolrPhpClient/tests/Apache/Solr/ServiceTest.php new file mode 100644 index 00000000..4f0284e0 --- /dev/null +++ b/SolrPhpClient/tests/Apache/Solr/ServiceTest.php @@ -0,0 +1,1119 @@ + + */ + +/** + * Apache_Solr_Service Unit Test + */ +class Apache_Solr_ServiceTest extends Apache_Solr_ServiceAbstractTest +{ + public function getFixture() + { + return new Apache_Solr_Service(); + } + + public function getMockHttpTransportInterface() + { + return $this->getMock( + 'Apache_Solr_HttpTransport_Interface', + array( + 'getDefaultTimeout', + 'setDefaultTimeout', + 'performGetRequest', + 'performHeadRequest', + 'performPostRequest', + ) + ); + } + + //================================================================// + // ATTEMPT TO MOVE THESE TO ServiceAbstractTest AT SOME POINT // + // Apache_Solr_Service_Balancer will need functions added // + //================================================================// + public function testGetHttpTransportWithDefaultConstructor() + { + $fixture = new Apache_Solr_Service(); + + $httpTransport = $fixture->getHttpTransport(); + + $this->assertInstanceOf('Apache_Solr_HttpTransport_Interface', $httpTransport, 'Default http transport does not implement interface'); + $this->assertInstanceOf('Apache_Solr_HttpTransport_FileGetContents', $httpTransport, 'Default http transport is not URL Wrapper implementation'); + } + + + public function testSetHttpTransport() + { + $newTransport = new Apache_Solr_HttpTransport_Curl(); + $fixture = new Apache_Solr_Service(); + + $fixture->setHttpTransport($newTransport); + $httpTransport = $fixture->getHttpTransport(); + + $this->assertInstanceOf('Apache_Solr_HttpTransport_Interface', $httpTransport); + $this->assertInstanceOf('Apache_Solr_HttpTransport_Curl', $httpTransport); + $this->assertEquals($newTransport, $httpTransport); + + } + + public function testSetHttpTransportWithConstructor() + { + $newTransport = new Apache_Solr_HttpTransport_Curl(); + + $fixture = new Apache_Solr_Service('localhost', 8180, '/solr/', $newTransport); + + $fixture->setHttpTransport($newTransport); + $httpTransport = $fixture->getHttpTransport(); + + $this->assertInstanceOf('Apache_Solr_HttpTransport_Interface', $httpTransport); + $this->assertInstanceOf('Apache_Solr_HttpTransport_Curl', $httpTransport); + $this->assertEquals($newTransport, $httpTransport); + } + + public function testGetCollapseSingleValueArraysWithDefaultConstructor() + { + $fixture = $this->getFixture(); + + $this->assertTrue($fixture->getCollapseSingleValueArrays()); + } + + public function testSetCollapseSingleValueArrays() + { + $fixture = $this->getFixture(); + + $fixture->setCollapseSingleValueArrays(false); + $this->assertFalse($fixture->getCollapseSingleValueArrays()); + } + + public function testGetNamedListTreatmetnWithDefaultConstructor() + { + $fixture = $this->getFixture(); + + $this->assertEquals(Apache_Solr_Service::NAMED_LIST_MAP, $fixture->getNamedListTreatment()); + } + + public function testSetNamedListTreatment() + { + $fixture = $this->getFixture(); + + $fixture->setNamedListTreatment(Apache_Solr_Service::NAMED_LIST_FLAT); + $this->assertEquals(Apache_Solr_Service::NAMED_LIST_FLAT, $fixture->getNamedListTreatment()); + + $fixture->setNamedListTreatment(Apache_Solr_Service::NAMED_LIST_MAP); + $this->assertEquals(Apache_Solr_Service::NAMED_LIST_MAP, $fixture->getNamedListTreatment()); + } + + /** + * @expectedException Apache_Solr_InvalidArgumentException + */ + public function testSetNamedListTreatmentInvalidArgumentException() + { + $fixture = $this->getFixture(); + + $fixture->setNamedListTreatment("broken"); + } + + //================================================================// + // END SECTION OF CODE THAT SHOULD BE MOVED // + // Apache_Solr_Service_Balancer will need functions added // + //================================================================// + + + public function testConstructorDefaultArguments() + { + $fixture = new Apache_Solr_Service(); + + $this->assertInstanceOf('Apache_Solr_Service', $fixture); + } + + public function testGetHostWithDefaultConstructor() + { + $fixture = new Apache_Solr_Service(); + $host = $fixture->getHost(); + + $this->assertEquals("localhost", $host); + } + + public function testSetHost() + { + $newHost = "example.com"; + + $fixture = new Apache_Solr_Service(); + $fixture->setHost($newHost); + $host = $fixture->getHost(); + + $this->assertEquals($newHost, $host); + } + + /** + * @expectedException Apache_Solr_InvalidArgumentException + */ + public function testSetEmptyHost() + { + $fixture = new Apache_Solr_Service(); + + // should throw an invalid argument exception + $fixture->setHost(""); + } + + public function testSetHostWithConstructor() + { + $newHost = "example.com"; + + $fixture = new Apache_Solr_Service($newHost); + $host = $fixture->getHost(); + + $this->assertEquals($newHost, $host); + } + + public function testGetPortWithDefaultConstructor() + { + $fixture = new Apache_Solr_Service(); + $port = $fixture->getPort(); + + $this->assertEquals(8180, $port); + } + + public function testSetPort() + { + $newPort = 12345; + + $fixture = new Apache_Solr_Service(); + $fixture->setPort($newPort); + $port = $fixture->getPort(); + + $this->assertEquals($newPort, $port); + } + + /** + * @expectedException Apache_Solr_InvalidArgumentException + */ + public function testSetPortWithInvalidArgument() + { + $fixture = new Apache_Solr_Service(); + + $fixture->setPort("broken"); + } + + public function testSetPortWithConstructor() + { + $newPort = 12345; + + $fixture = new Apache_Solr_Service('locahost', $newPort); + $port = $fixture->getPort(); + + $this->assertEquals($newPort, $port); + } + + public function testGetPathWithDefaultConstructor() + { + $fixture = new Apache_Solr_Service(); + $path = $fixture->getPath(); + + $this->assertEquals("/solr/", $path); + } + + public function testSetPath() + { + $newPath = "/new/path/"; + + $fixture = new Apache_Solr_Service(); + $fixture->setPath($newPath); + $path = $fixture->getPath(); + + $this->assertEquals($path, $newPath); + } + + public function testSetPathWillAddContainingSlashes() + { + $newPath = "new/path"; + $containedPath = "/{$newPath}/"; + + $fixture = new Apache_Solr_Service(); + $fixture->setPath($newPath); + $path = $fixture->getPath(); + + $this->assertEquals($containedPath, $path, 'setPath did not ensure propertly wrapped with slashes'); + } + + public function testSetPathWithConstructor() + { + $newPath = "/new/path/"; + + $fixture = new Apache_Solr_Service('localhost', 8180, $newPath); + $path = $fixture->getPath(); + + $this->assertEquals($newPath, $path); + } + + + public function testGetDefaultTimeoutCallsThroughToTransport() + { + $fixture = new Apache_Solr_Service(); + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call + $mockTransport->expects($this->once())->method('getDefaultTimeout'); + + $fixture->setHttpTransport($mockTransport); + + $fixture->getDefaultTimeout(); + } + + public function testSetDefaultTimeoutCallsThroughToTransport() + { + $timeout = 12345; + $fixture = new Apache_Solr_Service(); + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call + $mockTransport->expects($this->once())->method('setDefaultTimeout')->with($this->equalTo($timeout)); + + $fixture->setHttpTransport($mockTransport); + $fixture->setDefaultTimeout($timeout); + } + + public function testPing() + { + $expectedUrl = "http://localhost:8180/solr/admin/ping"; + $expectedTimeout = 2; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performHeadRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + // call ping + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + $time = $fixture->ping(); + + $this->assertGreaterThan(0, $time); + } + + public function testPingReturnsFalse() + { + $expectedUrl = "http://localhost:8180/solr/admin/ping"; + $expectedTimeout = 2; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performHeadRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get0Response())); + + // call ping + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $this->assertFalse($fixture->ping()); + } + + public function testThreads() + { + $expectedUrl = "http://localhost:8180/solr/admin/threads?wt=json"; + $expectedTimeout = false; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performGetRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + // call threads + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + $fixture->threads(); + } + + /** + * @expectedException Apache_Solr_HttpTransportException + */ + public function testThreads404() + { + $expectedUrl = "http://localhost:8180/solr/admin/threads?wt=json"; + $expectedTimeout = false; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performGetRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get404Response())); + + // call threads + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + $fixture->threads(); + } + + public function testAdd() + { + $postData = "does not have to be valid"; + + $expectedUrl = "http://localhost:8180/solr/update?wt=json"; + $expectedTimeout = false; + $expectedPostData = $postData; + $expectedContentType = "text/xml; charset=UTF-8"; // default for _sendRawPost + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($postData), $this->equalTo($expectedContentType), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + // call add + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + $fixture->add($postData); + } + + /** + * @expectedException Apache_Solr_HttpTransportException + */ + public function testAdd400() + { + $postData = "does not have to be valid"; + + $expectedUrl = "http://localhost:8180/solr/update?wt=json"; + $expectedTimeout = false; + $expectedPostData = $postData; + $expectedContentType = "text/xml; charset=UTF-8"; // default for _sendRawPost + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($postData), $this->equalTo($expectedContentType), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get400Response())); + + // call add + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + $fixture->add($postData); + } + + public function testAddDocument() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + // url + $this->equalTo('http://localhost:8180/solr/update?wt=json'), + + // raw post + $this->equalTo(''), + + // content type + $this->equalTo('text/xml; charset=UTF-8'), + + // timeout + $this->equalTo(false) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $document = new Apache_Solr_Document(); + + $fixture->addDocument($document); + } + + public function testAddDocumentWithNonDefaultParameters() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + // url + $this->equalTo('http://localhost:8180/solr/update?wt=json'), + + // raw post + $this->equalTo(''), + + // content type + $this->equalTo('text/xml; charset=UTF-8'), + + // timeout + $this->equalTo(false) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $document = new Apache_Solr_Document(); + + $fixture->addDocument($document, true, false, false, 3600); + } + + public function testAddDocumentWithFields() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + // url + $this->equalTo('http://localhost:8180/solr/update?wt=json'), + + // raw post + $this->equalTo('global unique idvaluevalue 1value 2'), + + // content type + $this->equalTo('text/xml; charset=UTF-8'), + + // timeout + $this->equalTo(false) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $document = new Apache_Solr_Document(); + + $document->guid = "global unique id"; + $document->field = "value"; + $document->multivalue = array("value 1", "value 2"); + + $fixture->addDocument($document); + } + + public function testAddDocumentWithFieldBoost() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + // url + $this->equalTo('http://localhost:8180/solr/update?wt=json'), + + // raw post + $this->equalTo('global unique idvaluevalue 1value 2'), + + // content type + $this->equalTo('text/xml; charset=UTF-8'), + + // timeout + $this->equalTo(false) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $document = new Apache_Solr_Document(); + + $document->guid = "global unique id"; + + $document->field = "value"; + $document->setFieldBoost('field', 2); + + $document->multivalue = array("value 1", "value 2"); + $document->setFieldBoost('multivalue', 3); + + $fixture->addDocument($document); + } + + public function testAddDocumentWithDocumentBoost() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + // url + $this->equalTo('http://localhost:8180/solr/update?wt=json'), + + // raw post + $this->equalTo('global unique idvalue'), + + // content type + $this->equalTo('text/xml; charset=UTF-8'), + + // timeout + $this->equalTo(false) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $document = new Apache_Solr_Document(); + $document->setBoost(2); + + $document->guid = "global unique id"; + $document->field = "value"; + + $fixture->addDocument($document); + } + + public function testAddDocuments() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + // url + $this->equalTo('http://localhost:8180/solr/update?wt=json'), + + // raw post + $this->equalTo(''), + + // content type + $this->equalTo('text/xml; charset=UTF-8'), + + // timeout + $this->equalTo(false) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $documents = array( + new Apache_Solr_Document(), + new Apache_Solr_Document() + ); + + $fixture->addDocuments($documents); + } + + public function testAddDocumentsWithNonDefaultParameters() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + // url + $this->equalTo('http://localhost:8180/solr/update?wt=json'), + + // raw post + $this->equalTo(''), + + // content type + $this->equalTo('text/xml; charset=UTF-8'), + + // timeout + $this->equalTo(false) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $documents = array( + new Apache_Solr_Document(), + new Apache_Solr_Document() + ); + + $fixture->addDocuments($documents, true, false, false, 3600); + } + + public function testCommit() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + // url + $this->equalTo('http://localhost:8180/solr/update?wt=json'), + + // raw post + $this->equalTo(''), + + // content type + $this->equalTo('text/xml; charset=UTF-8'), + + // timeout + $this->equalTo(3600) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->commit(); + } + + public function testCommitWithNonDefaultParameters() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + // url + $this->equalTo('http://localhost:8180/solr/update?wt=json'), + + // raw post + $this->equalTo(''), + + // content type + $this->equalTo('text/xml; charset=UTF-8'), + + // timeout + $this->equalTo(7200) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->commit(true, false, false, 7200); + } + + public function testDelete() + { + $postData = "does not have to be valid"; + + $expectedUrl = "http://localhost:8180/solr/update?wt=json"; + $expectedTimeout = 3600; // default for delete + $expectedPostData = $postData; + $expectedContentType = "text/xml; charset=UTF-8"; // default for _sendRawPost + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($postData), $this->equalTo($expectedContentType), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + // call add + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + $fixture->delete($postData); + } + + public function testDeleteById() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->deleteById("does not exist"); + } + + public function testDeleteByMultipleIds() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->deleteByMultipleIds(array(1, 2, 3)); + } + + public function testDeleteByQuery() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->deleteByQuery("*:*"); + } + + public function testExtracts() + { + $extractFile = __FILE__; + + $expectedUrl = "http://localhost:8180/solr/update/extract?resource.name=ServiceTest.php&wt=json&json.nl=map"; + $expectedPostData = file_get_contents($extractFile); + $expectedContentType = 'application/octet-stream'; // default for extract + $expectedTimeout = false; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($expectedPostData), $this->equalTo($expectedContentType), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->extract($extractFile); + } + + /** + * @expectedException Apache_Solr_InvalidArgumentException + */ + public function testExtractWithInvalidParams() + { + $extractFile = __FILE__; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->extract($extractFile, "invalid"); + } + + /** + * @expectedException Apache_Solr_InvalidArgumentException + */ + public function testExtractFromStringWithInvalidParams() + { + $extractFileData = "does not matter what it is"; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->extractFromString($extractFileData, "invalid"); + } + + public function testExtractsWithNullParams() + { + $extractFile = __FILE__; + + $expectedUrl = "http://localhost:8180/solr/update/extract?resource.name=ServiceTest.php&wt=json&json.nl=map"; + $expectedPostData = file_get_contents($extractFile); + $expectedContentType = 'application/octet-stream'; // default for extract + $expectedTimeout = false; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($expectedPostData), $this->equalTo($expectedContentType), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->extract($extractFile, null); + } + + /** + * @expectedException Apache_Solr_InvalidArgumentException + */ + public function testExtractWithEmptyFile() + { + $extractFile = "iDontExist.txt"; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->extract($extractFile); + } + + public function testExtractsWithDocument() + { + $extractFile = __FILE__; + + $expectedUrl = "http://localhost:8180/solr/update/extract?resource.name=ServiceTest.php&wt=json&json.nl=map&boost.field=2&literal.field=literal+value"; + $expectedPostData = file_get_contents($extractFile); + $expectedContentType = 'application/octet-stream'; // default for extract + $expectedTimeout = false; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with($this->equalTo($expectedUrl), $this->equalTo($expectedPostData), $this->equalTo($expectedContentType), $this->equalTo($expectedTimeout)) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $literals = new Apache_Solr_Document(); + $literals->field = "literal value"; + $literals->setFieldBoost('field', 2); + + $fixture->extract($extractFile, null, $literals); + } + + public function testExtractWithUrlDefers() + { + $extractUrl = "http://example.com"; + + $expectedUrl = "http://localhost:8180/solr/update/extract?resource.name=http%3A%2F%2Fexample.com&wt=json&json.nl=map"; + $expectedPostData = Apache_Solr_HttpTransport_ResponseTest::BODY_200; + $expectedContentType = 'application/octet-stream'; // default for extract + $expectedTimeout = false; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performGetRequest') + ->with( + $this->equalTo($extractUrl) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + $this->equalTo($expectedUrl), + $this->equalTo($expectedPostData), + $this->equalTo($expectedContentType), + $this->equalTo($expectedTimeout) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->extract($extractUrl); + } + + public function testExtractFromUrl() + { + $extractUrl = "http://example.com"; + + $expectedUrl = "http://localhost:8180/solr/update/extract?resource.name=http%3A%2F%2Fexample.com&wt=json&json.nl=map"; + $expectedPostData = Apache_Solr_HttpTransport_ResponseTest::BODY_200; + $expectedContentType = 'application/octet-stream'; // default for extract + $expectedTimeout = false; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performGetRequest') + ->with( + $this->equalTo($extractUrl) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->with( + $this->equalTo($expectedUrl), + $this->equalTo($expectedPostData), + $this->equalTo($expectedContentType), + $this->equalTo($expectedTimeout) + ) + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->extractFromUrl($extractUrl); + } + + /** + * @expectedException Apache_Solr_InvalidArgumentException + */ + public function testExtractFromUrlWithInvalidParams() + { + $extractUrl = "http://example.com"; + + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->extractFromUrl($extractUrl, "invalid"); + } + + public function testOptimize() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_Service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->optimize(); + } + + public function testSearch() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performGetRequest') + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->search("solr"); + } + + /** + * @expectedException Apache_Solr_InvalidArgumentException + */ + public function testSearchWithInvalidParams() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->search("solr", 0, 10, "invalid"); + + $this->fail("Should have through InvalidArgumentException"); + } + + public function testSearchWithEmptyParams() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performGetRequest') + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->search("solr", 0, 10, null); + } + + public function testSearchWithPostMethod() + { + // set a mock transport + $mockTransport = $this->getMockHttpTransportInterface(); + + // setup expected call and response + $mockTransport->expects($this->once()) + ->method('performPostRequest') + ->will($this->returnValue(Apache_Solr_HttpTransport_ResponseTest::get200Response())); + + $fixture = new Apache_Solr_service(); + $fixture->setHttpTransport($mockTransport); + + $fixture->search("solr", 0, 10, array(), Apache_Solr_Service::METHOD_POST); + } + + /** + * @expectedException Apache_Solr_InvalidArgumentException + */ + public function testSearchWithInvalidMethod() + { + $fixture = new Apache_Solr_service(); + + $fixture->search("solr", 0, 10, array(), "INVALID METHOD"); + } +} \ No newline at end of file diff --git a/SolrPhpClient/tests/README b/SolrPhpClient/tests/README new file mode 100644 index 00000000..39ede2e9 --- /dev/null +++ b/SolrPhpClient/tests/README @@ -0,0 +1,20 @@ +Use the run.php script included in this directory to run all unit tests for the +Solr PHP Client library. Your system will require phpunit PEAR package - which +you can get install instructions for at: + +http://www.phpunit.de/ + +To generate the code coverage report, you will also need the XDebug pecl package +installed, typically this can be done with a simple: + +pecl install xdebug + +If you need more information on installation, then please see the official website: + +http://www.xdebug.org + +The scripts, configuration, and test files in this directory have been confirmed to +work with the following versions: + +phpunit: 3.3.16 +xdebug: 2.0.4 \ No newline at end of file diff --git a/SolrPhpClient/tests/phpunit.bootstrap.inc b/SolrPhpClient/tests/phpunit.bootstrap.inc new file mode 100644 index 00000000..237a0ec1 --- /dev/null +++ b/SolrPhpClient/tests/phpunit.bootstrap.inc @@ -0,0 +1,28 @@ + + + + + + + + + ../Apache + + ./run.php + + + + diff --git a/SolrPhpClient/tests/run.php b/SolrPhpClient/tests/run.php new file mode 100644 index 00000000..b7445481 --- /dev/null +++ b/SolrPhpClient/tests/run.php @@ -0,0 +1,42 @@ +#! /usr/bin/php +http_auth = $http_auth; + } + + /** + * Perform a GET HTTP operation with an optional timeout and return the response + * contents, use getLastResponseHeaders to retrieve HTTP headers + * + * @param string $url + * @param float $timeout + * @return Apache_Solr_HttpTransport_Response HTTP response + */ + public function performGetRequest($url, $timeout = false) { + return $this->performHttpRequest('GET', $url, $timeout); + } + + /** + * Perform a HEAD HTTP operation with an optional timeout and return the response + * headers - NOTE: head requests have no response body + * + * @param string $url + * @param float $timeout + * @return Apache_Solr_HttpTransport_Response HTTP response + */ + public function performHeadRequest($url, $timeout = false) { + return $this->performHttpRequest('HEAD', $url, $timeout); + } + + /** + * Perform a POST HTTP operation with an optional timeout and return the response + * contents, use getLastResponseHeaders to retrieve HTTP headers + * + * @param string $url + * @param string $rawPost + * @param string $contentType + * @param float $timeout + * @return Apache_Solr_HttpTransport_Response HTTP response + */ + public function performPostRequest($url, $rawPost, $contentType, $timeout = false) { + return $this->performHttpRequest('POST', $url, $timeout, $rawPost, $contentType); + } + + /** + * Helper method for making an HTTP request. + */ + protected function performHttpRequest($method, $url, $timeout, $rawPost = NULL, $contentType = NULL) { + $options = array( + 'method' => $method, + 'timeout' => $timeout && $timeout > 0 ? $timeout : $this->getDefaultTimeout(), + 'headers' => array(), + ); + + if ($this->http_auth) { + $options['headers']['Authorization'] = $this->http_auth; + } + if ($timeout) { + $options['timeout'] = $timeout; + } + if ($rawPost) { + $options['data'] = $rawPost; + } + if ($contentType) { + $options['headers']['Content-Type'] = $contentType; + } + + $response = drupal_http_request($url, $options); + + $type = isset($response->headers['content-type']) ? $response->headers['content-type'] : 'text/xml'; + $body = isset($response->data) ? $response->data : NULL; + return new Apache_Solr_HttpTransport_Response($response->code, $type, $body); + } + +} diff --git a/includes/spellcheck.inc b/includes/spellcheck.inc new file mode 100644 index 00000000..3e89ce00 --- /dev/null +++ b/includes/spellcheck.inc @@ -0,0 +1,33 @@ +spellcheck->suggestions)) { + $suggestions = $response->spellcheck->suggestions; + foreach ($suggestions as $word => $data) { + foreach ($data->suggestion as $suggestion) { + $this->addSuggestion(new SearchApiSpellcheckSuggestion($word, $suggestion)); + } + } + } + } + +} diff --git a/search_api_solr.api.php b/search_api_solr.api.php new file mode 100644 index 00000000..f4074071 --- /dev/null +++ b/search_api_solr.api.php @@ -0,0 +1,89 @@ +getOption('foobar')) { + $call_args['params']['foo'] = 'bar'; + } +} + +/** + * Change the way the index's field names are mapped to Solr field names. + * + * @param $index + * The index whose field mappings are altered. + * @param array $fields + * An associative array containing the index field names mapped to their Solr + * counterparts. The special fields 'search_api_id' and 'search_api_relevance' + * are also included. + */ +function hook_search_api_solr_field_mapping_alter(SearchApiIndex $index, array &$fields) { + if ($index->entity_type == 'node' && isset($fields['body:value'])) { + $fields['body:value'] = 'text'; + } +} + +/** + * Lets modules alter the search results returned from a Solr search, based on + * the original Solr response. + * + * @param array $results + * The results array that will be returned for the search. + * @param SearchApiQueryInterface $query + * The SearchApiQueryInterface object representing the executed search query. + * @param Apache_Solr_Response $response + * The response object returned by Solr. + */ +function hook_search_api_solr_search_results_alter(array &$results, SearchApiQueryInterface $query, Apache_Solr_Response $response) { + if (isset($response->facet_counts->facet_fields->custom_field)) { + // Do something with $results. + } +} + +/** + * Lets modules alter a Solr search request for a multi-index search before + * sending it. + * + * Apache_Solr_Service::search() is called afterwards with these parameters. + * Please see this method for details on what should be altered where and what + * is set afterwards. + * + * @param array $call_args + * An associative array containing all four arguments to the + * Apache_Solr_Service::search() call ("query", "offset", "limit" and + * "params") as references. + * @param SearchApiMultiQueryInterface $query + * The object representing the executed search query. + */ +function hook_search_api_solr_multi_query_alter(array &$call_args, SearchApiMultiQueryInterface $query) { + if ($query->getOption('foobar')) { + $call_args['params']['foo'] = 'bar'; + } +} + +/** + * @} End of "addtogroup hooks". + */ diff --git a/search_api_solr.info b/search_api_solr.info new file mode 100644 index 00000000..4659486c --- /dev/null +++ b/search_api_solr.info @@ -0,0 +1,18 @@ +name = Solr search +description = Offers an implementation of the Search API that uses an Apache Solr server for indexing content. +dependencies[] = search_api +core = 7.x +package = Search + +files[] = service.inc +files[] = solr_connection.inc +files[] = solr_field.inc +files[] = includes/solr_httptransport.inc +files[] = includes/spellcheck.inc + +; Information added by drupal.org packaging script on 2013-01-07 +version = "7.x-1.0-rc3" +core = "7.x" +project = "search_api_solr" +datestamp = "1357517056" + diff --git a/search_api_solr.install b/search_api_solr.install new file mode 100644 index 00000000..60270c57 --- /dev/null +++ b/search_api_solr.install @@ -0,0 +1,154 @@ + array( + 'title' => $t('Solr PHP library'), + 'value' => $t('The library is correctly installed, but out of date'), + 'description' => $t('It is suggested to install the newest version (@version).', array('@version' => 'r60')), + 'severity' => REQUIREMENT_WARNING, + ), + ); + } + return array( + 'search_api_solr' => array( + 'title' => $t('Solr PHP library'), + 'value' => $t('The library was correctly installed'), + 'severity' => REQUIREMENT_OK, + ), + ); + } + else { + return array( + 'search_api_solr' => array( + 'title' => $t('Solr PHP library'), + 'value' => $t('The library was not correctly installed. Please see INSTALL.txt for instructions.'), + 'severity' => REQUIREMENT_ERROR, + ), + ); + } + } + elseif ($phase == 'runtime') { + $servers = search_api_server_load_multiple(FALSE, array('class' => 'search_api_solr_service', 'enabled' => TRUE)); + $count = 0; + $unavailable = 0; + $last = NULL; + foreach ($servers as $server) { + if (!$server->ping()) { + ++$unavailable; + $last = $server; + } + ++$count; + } + if (!$count) { + return array(); + } + $ret['search_api_solr'] = array( + 'title' => t('Solr servers'), + 'value' => format_plural($count, '1 server', '@count servers'), + ); + if ($unavailable) { + if ($unavailable == 1) { + $ret['search_api_solr']['description'] = t('The Solr server of %name could not be reached.', + array('!url' => url('admin/config/search/search_api/server/' . $last->machine_name), '%name' => $last->name)); + } + else { + $ret['search_api_solr']['description'] = t('@count Solr servers could not be reached.', array('@count' => $unavailable)); + } + $ret['search_api_solr']['severity'] = REQUIREMENT_ERROR; + } + else { + $ret['search_api_solr']['description'] = format_plural($count, 'The Solr server could be reached.', 'All @count Solr servers could be reached.'); + $ret['search_api_solr']['severity'] = REQUIREMENT_OK; + } + + // Check version of the SolrPhpClient library. + $version = trim(Apache_Solr_Service::SVN_REVISION, '$ :A..Za..z'); + if ($version < 59) { + $ret['search_api_solr_client'] = array( + 'title' => t('Solr PHP library'), + 'value' => t('Version @version', array('@version' => "r$version")), + 'description' => t('The library is correctly installed, but out of date. ' . + 'It is suggested to install the newest version (@version).', + array('@url' => 'http://code.google.com/p/solr-php-client/downloads/list', '@version' => 'r60')), + 'severity' => REQUIREMENT_WARNING, + ); + } + return $ret; + } +} + +/** + * Implements hook_install(). + * + * We register our autoloader here because our hook_init() won't get called + * until the next bootstrap (it registers the autoloader too.) + */ +function search_api_solr_install() { + spl_autoload_register('_search_api_solr_autoload'); +} + +/** + * Implements hook_uninstall(). + */ +function search_api_solr_uninstall() { + if (module_exists('search_api')) { + db_delete('search_api_server') + ->condition('class', 'search_api_solr_service') + ->execute(); + } + variable_del('search_api_solr_last_optimize'); + variable_del('search_api_solr_autocomplete_max_occurrences'); +} + +/** + * Implements hook_update_dependencies(). + */ +function search_api_solr_update_dependencies() { + // This update should run after primary IDs have been changed to machine names in the framework. + $dependencies['search_api_solr'][7101] = array( + 'search_api' => 7102, + ); + return $dependencies; +} + +/** + * Implements hook_update_N(). + * + * Implements transition from using the index IDs to using machine names. + */ +function search_api_solr_update_7101() { + foreach (search_api_server_load_multiple(FALSE, array('class' => 'search_api_solr_service')) as $server) { + if ($server->enabled) { + $server->deleteItems('all'); + } + else { + $tasks = variable_get('search_api_tasks', array()); + $tasks[$server->machine_name][''] = array('clear all'); + variable_set('search_api_tasks', $tasks); + } + $query = db_select('search_api_index', 'i') + ->fields('i', array('machine_name')) + ->condition('server', $server->machine_name); + db_update('search_api_item') + ->fields(array( + 'changed' => REQUEST_TIME, + )) + ->condition('index_id', $query, 'IN') + ->execute(); + } + + return t('The Solr search module was updated. ' . + 'Please stop your Solr servers, replace their schema.xml with the new version and then start them again. ' . + 'All data indexed on Solr servers will have to be reindexed.'); +} diff --git a/search_api_solr.module b/search_api_solr.module new file mode 100644 index 00000000..9e30397e --- /dev/null +++ b/search_api_solr.module @@ -0,0 +1,145 @@ + t('Solr service'), + 'description' => t('

Index items using an Apache Solr search server.

' . + '
    ' . '
  • All field types are supported and indexed in a special way, with URI/String and Integer/Duration being equivalent.
  • ' . + '
  • See the Solr wiki for information about the "direct" parse mode.
  • ' . + '
  • Supports the search_api_facets and search_api_multi features.
  • ' . + '
  • Will use internal Solr preprocessors, so Search API preprocessors should for the most part be deactivated.
  • ' . + '
  • See the README.txt file provided with this module for details.
  • ' . '
', + array('@url' => url('http://wiki.apache.org/solr/SolrQuerySyntax'))), + 'class' => 'SearchApiSolrService', + ); + return $services; +} + +/** + * Implements hook_help(). + */ +function search_api_solr_help($path, array $arg = array()) { + if ($path == 'admin/config/search/search_api') { + // Included because we need the REQUIREMENT_* constants. + include_once(DRUPAL_ROOT . '/includes/install.inc'); + module_load_include('install', 'search_api_solr'); + $reqs = search_api_solr_requirements('runtime'); + foreach ($reqs as $req) { + if (isset($req['description'])) { + $type = $req['severity'] == REQUIREMENT_ERROR ? 'error' : ($req['severity'] == REQUIREMENT_WARNING ? 'warning' : 'status'); + drupal_set_message($req['description'], $type); + } + } + } + elseif ($path == 'admin/config/search/search_api/server/%' && !empty($arg[5])) { + $server = search_api_server_load($arg[5]); + if ($server && $server->enabled && $server->class == 'search_api_solr_service') { + $ping = $server->ping(); + $type = $ping ? 'status' : 'error'; + if ($ping) { + $msg = t('The Solr server could be reached (latency: @millisecs ms).', array('@millisecs' => $ping * 1000)); + } + else { + $msg = t('The Solr server could not be reached.'); + } + drupal_set_message($msg, $type); + } + } +} + +/** + * Implements hook_cron(). + * + * Used to execute an optimization operation on all enabled Solr servers once a + * day. + */ +function search_api_solr_cron() { + if (REQUEST_TIME - variable_get('search_api_solr_last_optimize', 0) > 86400) { + variable_set('search_api_solr_last_optimize', REQUEST_TIME); + $conditions = array('class' => 'search_api_solr_service', 'enabled' => TRUE); + foreach (search_api_server_load_multiple(FALSE, $conditions) as $server) { + try { + $server->getSolrConnection()->optimize(FALSE, FALSE); + } + catch(Exception $e) { + watchdog_exception('search_api_solr', $e, '%type while optimizing Solr server @server: !message in %function (line %line of %file).', array('@server' => $server->name)); + } + } + } +} diff --git a/service.inc b/service.inc new file mode 100644 index 00000000..9047b083 --- /dev/null +++ b/service.inc @@ -0,0 +1,1655 @@ + 'tm', + 'tokens' => 'tm', + 'string' => 's', + 'integer' => 'i', + 'decimal' => 'f', + 'date' => 'd', + 'duration' => 'i', + 'boolean' => 'b', + 'uri' => 's', + 'location' => 'loc', + 'geohash' => 'geohash', + ); + + /** + * @var array + */ + protected $fieldNames = array(); + + /** + * Metadata describing fields on the Solr/Lucene index. + * + * @see SearchApiSolrService::getFields(). + * + * @var array + */ + protected $fields; + + /** + * Saves whether a commit operation was already scheduled for this server. + * + * @var boolean + */ + protected $commitScheduled = FALSE; + + /** + * Request handler to use for this search query. + * + * @var string + */ + protected $request_handler = NULL; + + public function __construct(SearchApiServer $server) { + parent::__construct($server); + } + + public function configurationForm(array $form, array &$form_state) { + if ($this->options) { + // Editing this server + $url = 'http://' . $this->options['host'] . ':' . $this->options['port'] . $this->options['path']; + $form['server_description'] = array( + '#type' => 'item', + '#title' => t('Solr server URI'), + '#description' => l($url, $url), + ); + } + + $options = $this->options + array( + 'host' => 'localhost', + 'port' => '8983', + 'path' => '/solr', + 'http_user' => '', + 'http_pass' => '', + 'excerpt' => FALSE, + 'retrieve_data' => FALSE, + 'highlight_data' => FALSE, + 'http_method' => Apache_Solr_Service::METHOD_POST, + 'autocorrect_spell' => TRUE, + 'autocorrect_suggest_words' => TRUE, + ); + + $form['host'] = array( + '#type' => 'textfield', + '#title' => t('Solr host'), + '#description' => t('The host name or IP of your Solr server, e.g. localhost or www.example.com.'), + '#default_value' => $options['host'], + '#required' => TRUE, + ); + $form['port'] = array( + '#type' => 'textfield', + '#title' => t('Solr port'), + '#description' => t('The Jetty example server is at port 8983, while Tomcat uses 8080 by default.'), + '#default_value' => $options['port'], + '#required' => TRUE, + ); + $form['path'] = array( + '#type' => 'textfield', + '#title' => t('Solr path'), + '#description' => t('The path that identifies the Solr instance to use on the server.'), + '#default_value' => $options['path'], + ); + + $form['http'] = array( + '#type' => 'fieldset', + '#title' => t('Basic HTTP authentication'), + '#description' => t('If your Solr server is protected by basic HTTP authentication, enter the login data here.'), + '#collapsible' => TRUE, + '#collapsed' => empty($options['http_user']), + ); + $form['http']['http_user'] = array( + '#type' => 'textfield', + '#title' => t('Username'), + '#default_value' => $options['http_user'], + ); + $form['http']['http_pass'] = array( + '#type' => 'password', + '#title' => t('Password'), + '#default_value' => $options['http_pass'], + ); + + $form['advanced'] = array( + '#type' => 'fieldset', + '#title' => t('Advanced'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['advanced']['excerpt'] = array( + '#type' => 'checkbox', + '#title' => t('Return an excerpt for all results'), + '#description' => t("If search keywords are given, use Solr's capabilities to create a highlighted search excerpt for each result. " . + 'Whether the excerpts will actually be displayed depends on the settings of the search, though.'), + '#default_value' => $options['excerpt'], + ); + $form['advanced']['retrieve_data'] = array( + '#type' => 'checkbox', + '#title' => t('Retrieve result data from Solr'), + '#description' => t('When checked, result data will be retrieved directly from the Solr server. ' . + 'This might make item loads unnecessary. Only indexed fields can be retrieved. ' . + 'Note also that the returned field data might not always be correct, due to preprocessing and caching issues.'), + '#default_value' => $options['retrieve_data'], + ); + $form['advanced']['highlight_data'] = array( + '#type' => 'checkbox', + '#title' => t('Highlight retrieved data'), + '#description' => t('When retrieving result data from the Solr server, try to highlight the search terms in the returned fulltext fields.'), + '#default_value' => $options['highlight_data'], + ); + // Highlighting retrieved data only makes sense when we retrieve data. + // (Actually, internally it doesn't really matter. However, from a user's + // perspective, having to check both probably makes sense.) + $form['advanced']['highlight_data']['#states']['invisible'] + [':input[name="options[form][advanced][retrieve_data]"]']['checked'] = FALSE; + + $form['advanced']['http_method'] = array( + '#type' => 'select', + '#title' => t('HTTP method'), + '#description' => t('The HTTP method to use for sending queries. Usually, POST will work fine in all cases.'), + '#default_value' => $options['http_method'], + '#options' => array( + Apache_Solr_Service::METHOD_POST => 'POST', + Apache_Solr_Service::METHOD_GET => 'GET', + ), + ); + + if (module_exists('search_api_autocomplete')) { + $form['advanced']['autocomplete'] = array( + '#type' => 'fieldset', + '#title' => t('Autocomplete'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['advanced']['autocomplete']['autocorrect_spell'] = array( + '#type' => 'checkbox', + '#title' => t('Use spellcheck for autocomplete suggestions'), + '#description' => t('If activated, spellcheck suggestions ("Did you mean") will be included in the autocomplete suggestions. Since the used dictionary contains words from all indexes, this might lead to leaking of sensitive data, depending on your setup.'), + '#default_value' => $options['autocorrect_spell'], + ); + $form['advanced']['autocomplete']['autocorrect_suggest_words'] = array( + '#type' => 'checkbox', + '#title' => t('Suggest additional words'), + '#description' => t('If activated and the user enters a complete word, Solr will suggest additional words the user wants to search, which are often found (not searched!) together. This has been known to lead to strange results in some configurations – if you see inappropriate additional-word suggestions, you might want to deactivate this option.'), + '#default_value' => $options['autocorrect_suggest_words'], + ); + } + + return $form; + } + + public function configurationFormValidate(array $form, array &$values, array &$form_state) { + if (isset($values['port']) && (!is_numeric($values['port']) || $values['port'] < 0 || $values['port'] > 65535)) { + form_error($form['port'], t('The port has to be an integer between 0 and 65535.')); + } + } + + public function configurationFormSubmit(array $form, array &$values, array &$form_state) { + // Since the form is nested into another, we can't simply use #parents for + // doing this array restructuring magic. (At least not without creating an + // unnecessary dependency on internal implementation.) + $values += $values['http']; + $values += $values['advanced']; + $values += !empty($values['autocomplete']) ? $values['autocomplete'] : array(); + unset($values['http'], $values['advanced'], $values['autocomplete']); + // Highlighting retrieved data only makes sense when we retrieve data. + $values['highlight_data'] &= $values['retrieve_data']; + + parent::configurationFormSubmit($form, $values, $form_state); + } + + public function supportsFeature($feature) { + $supported = drupal_map_assoc(array( + 'search_api_autocomplete', + 'search_api_facets', + 'search_api_facets_operator_or', + 'search_api_mlt', + 'search_api_multi', + 'search_api_spellcheck', + 'search_api_data_type_location', + 'search_api_data_type_geohash', + )); + return isset($supported[$feature]); + } + + /** + * View this server's settings. + */ + public function viewSettings() { + $output = ''; + $options = $this->options; + + $url = 'http://' . $options['host'] . ':' . $options['port'] . $options['path']; + $output .= "
\n
"; + $output .= t('Solr server URI'); + $output .= "
\n
"; + $output .= l($url, $url); + $output .= '
'; + if ($options['http_user']) { + $output .= "\n
"; + $output .= t('Basic HTTP authentication'); + $output .= "
\n
"; + $output .= t('Username: @user', array('@user' => $options['http_user'])); + $output .= "
\n
"; + $output .= t('Password: @pass', array('@pass' => str_repeat('*', strlen($options['http_pass'])))); + $output .= '
'; + } + $output .= "\n
"; + + return $output; + } + + /** + * Create a connection to the Solr server as configured in $this->options. + */ + protected function connect() { + if (!$this->solr) { + if (!class_exists('Apache_Solr_Service')) { + throw new Exception(t('SolrPhpClient library not found! Please follow the instructions in search_api_solr/INSTALL.txt for installing the Solr search module.')); + } + $this->solr = new SearchApiSolrConnection($this->options); + } + } + + public function addIndex(SearchApiIndex $index) { + if (module_exists('search_api_multi') && module_exists('search_api_views')) { + views_invalidate_cache(); + } + } + + public function fieldsUpdated(SearchApiIndex $index) { + if (module_exists('search_api_multi') && module_exists('search_api_views')) { + views_invalidate_cache(); + } + return TRUE; + } + + public function removeIndex($index) { + if (module_exists('search_api_multi') && module_exists('search_api_views')) { + views_invalidate_cache(); + } + $id = is_object($index) ? $index->machine_name : $index; + // Only delete the index's data if the index isn't read-only. + if (!is_object($index) || empty($index->read_only)) { + try { + $this->connect(); + $this->solr->deleteByQuery("index_id:" . $id); + } + catch (Exception $e) { + watchdog_exception('search_api_solr', $e, "%type while deleting an index's data: !message in %function (line %line of %file)."); + } + } + } + + public function indexItems(SearchApiIndex $index, array $items) { + $documents = array(); + $ret = array(); + $index_id = $index->machine_name; + $fields = $this->getFieldNames($index); + + foreach ($items as $id => $item) { + try { + $doc = new Apache_Solr_Document(); + $doc->setField('id', $this->createId($index_id, $id)); + $doc->setField('index_id', $index_id); + $doc->setField('item_id', $id); + + foreach ($item as $key => $field) { + if (!isset($fields[$key])) { + throw new SearchApiException(t('Unknown field @field.', array('@field' => $key))); + } + $this->addIndexField($doc, $fields[$key], $field['value'], $field['type']); + } + + $documents[] = $doc; + $ret[] = $id; + } + catch (Exception $e) { + watchdog_exception('search_api_solr', $e, "%type while indexing @type with ID @id: !message in %function (line %line of %file).", array('@type' => $index->item_type, '@id' => $id), WATCHDOG_WARNING); + } + } + + if (!$documents) { + return array(); + } + try { + $this->connect(); + $response = $this->solr->addDocuments($documents); + if ($response->getHttpStatus() == 200) { + if (!empty($index->options['index_directly'])) { + $this->scheduleCommit(); + } + return $ret; + } + throw new SearchApiException(t('HTTP status @status: @msg.', + array('@status' => $response->getHttpStatus(), '@msg' => $response->getHttpStatusMessage()))); + } + catch (Exception $e) { + watchdog_exception('search_api_solr', $e, "%type while indexing: !message in %function (line %line of %file)."); + } + return array(); + } + + /** + * Creates an ID used as the unique identifier at the Solr server. This has to + * consist of both index and item ID. + */ + protected function createId($index_id, $item_id) { + return "$index_id-$item_id"; + } + + /** + * Create a list of all indexed field names mapped to their Solr field names. + * + * The special fields "search_api_id", "search_api_relevance", and "id" are + * also included. Any Solr fields that exist on search results are mapped back + * to their local field names in the final result set. + * + * @see SearchApiSolrService::search() + */ + public function getFieldNames(SearchApiIndex $index, $reset = FALSE) { + if (!isset($this->fieldNames[$index->machine_name]) || $reset) { + // This array maps "local property name" => "solr doc property name". + $ret = array( + 'search_api_id' => 'ss_search_api_id', + 'search_api_relevance' => 'score', + 'search_api_item_id' => 'item_id', + ); + + // Add the names of any fields configured on the index. + $fields = (isset($index->options['fields']) ? $index->options['fields'] : array()); + foreach ($fields as $key => $field) { + // Generate a field name; this corresponds with naming conventions in + // our schema.xml + $type = $field['type']; + + // Use the real type of the field if the server supports this type. + if (isset($field['real_type'])) { + $custom_type = search_api_extract_inner_type($field['real_type']); + if ($this->supportsFeature('search_api_data_type_' . $custom_type)) { + $type = $field['real_type']; + } + } + + $inner_type = search_api_extract_inner_type($type); + $pref = isset(self::$type_prefixes[$inner_type]) ? self::$type_prefixes[$inner_type] : ''; + if ($pref != 'tm') { + $pref .= $type == $inner_type ? 's' : 'm'; + } + $name = $pref . '_' . $key; + + $ret[$key] = $name; + } + + // Let modules adjust the field mappings. + drupal_alter('search_api_solr_field_mapping', $index, $ret); + + $this->fieldNames[$index->machine_name] = $ret; + } + + return $this->fieldNames[$index->machine_name]; + } + + /** + * Helper method for indexing. + * Add $field with field name $key to the document $doc. The format of $field + * is the same as specified in SearchApiServiceInterface::indexItems(). + */ + protected function addIndexField(Apache_Solr_Document $doc, $key, $value, $type, $multi_valued = FALSE) { + // Don't index empty values (i.e., when field is missing) + if (!isset($value)) { + return; + } + if (search_api_is_list_type($type)) { + $type = substr($type, 5, -1); + foreach ($value as $v) { + $this->addIndexField($doc, $key, $v, $type, TRUE); + } + return; + } + switch ($type) { + case 'tokens': + foreach ($value as $v) { + $doc->addField($key, $v['value']); + } + return; + case 'boolean': + $value = $value ? 'true' : 'false'; + break; + case 'date': + $value = is_numeric($value) ? (int) $value : strtotime($value); + if ($value === FALSE) { + return; + } + $value = format_date($value, 'custom', self::SOLR_DATE_FORMAT, 'UTC'); + break; + case 'integer': + $value = (int) $value; + break; + case 'decimal': + $value = (float) $value; + break; + } + if ($multi_valued) { + $doc->addField($key, $value); + } + else { + $doc->setField($key, $value); + } + } + + /** + * Delete items from an index on this server. + * + * This method has a custom, Solr-specific extension: + * If $ids is a string other than "all", it is treated as a Solr query. All + * items matching that Solr query are then deleted. If $index is additionally + * specified, then only those items also lying on that index will be deleted. + * It is up to the caller to ensure $ids is a valid query when the method is + * called in this fashion. + */ + public function deleteItems($ids = 'all', SearchApiIndex $index = NULL) { + try { + $this->connect(); + if ($index) { + $index_id = $index->machine_name; + if (is_array($ids)) { + $solr_ids = array(); + foreach ($ids as $id) { + $solr_ids[] = $this->createId($index_id, $id); + } + $this->solr->deleteByMultipleIds($solr_ids); + } + elseif ($ids == 'all') { + $this->solr->deleteByQuery("index_id:" . $index_id); + } + else { + $this->solr->deleteByQuery("index_id:" . $index_id . ' (' . $ids . ')'); + } + } + else { + $q = $ids == 'all' ? '*:*' : $ids; + $this->solr->deleteByQuery($q); + } + $this->scheduleCommit(); + } + catch(Exception $e) { + watchdog_exception('search_api_solr', $e, '%type while deleting items from server @server: !message in %function (line %line of %file).', array('@server' => $this->server->name)); + } + } + + public function search(SearchApiQueryInterface $query) { + $time_method_called = microtime(TRUE); + // Reset request handler + $this->request_handler = NULL; + // Get field information + $index = $query->getIndex(); + $fields = $this->getFieldNames($index); + + // Extract keys + $keys = $query->getKeys(); + if (is_array($keys)) { + $keys = $this->flattenKeys($keys); + } + + // Set searched fields + $options = $query->getOptions(); + $search_fields = $query->getFields(); + // Get the index fields to be able to retrieve boosts. + $index_fields = $index->getFields(); + $qf = array(); + foreach ($search_fields as $f) { + $boost = ''; + $boost = isset($index_fields[$f]['boost']) ? '^' . $index_fields[$f]['boost'] : ''; + $qf[] = $fields[$f] . $boost; + } + + // Extract filters + $filter = $query->getFilter(); + $fq = $this->createFilterQueries($filter, $fields, $index->options['fields']); + $fq[] = 'index_id:' . $index->machine_name; + + // Extract sort + $sort = array(); + foreach ($query->getSort() as $f => $order) { + $f = $fields[$f]; + if (substr($f, 0, 3) == 'ss_') { + $f = 'sort_' . substr($f, 3); + } + $order = strtolower($order); + $sort[] = "$f $order"; + } + + // Get facet fields + $facets = $query->getOption('search_api_facets', array()); + $facet_params = $this->getFacetParams($facets, $fields, $fq); + + // Handle highlighting + $highlight_params = $this->getHighlightParams($query); + + // Handle More Like This query + $mlt = $query->getOption('search_api_mlt'); + if ($mlt) { + $mlt_params['qt'] = 'mlt'; + // The fields to look for similarities in. + $mlt_fl = array(); + foreach($mlt['fields'] as $f) { + $mlt_fl[] = $fields[$f]; + // For non-text fields, set minimum word length to 0. + if (isset($index->options['fields'][$f]['type']) && !search_api_is_text_type($index->options['fields'][$f]['type'])) { + $mlt_params['f.' . $fields[$f] . '.mlt.minwl'] = 0; + } + } + $mlt_params['mlt.fl'] = implode(',', $mlt_fl); + $keys = 'id:' . SearchApiSolrConnection::phrase($this->createId($index->machine_name, $mlt['id'])); + } + + // Set defaults + if (!$keys) { + $keys = NULL; + } + $offset = isset($options['offset']) ? $options['offset'] : 0; + $limit = isset($options['limit']) ? $options['limit'] : 1000000; + + // Collect parameters + $params = array( + 'fl' => 'item_id,score', + 'qf' => $qf, + 'fq' => $fq, + ); + if ($sort) { + $params['sort'] = implode(', ', $sort); + } + if (!empty($facet_params['facet.field'])) { + $params += $facet_params; + } + if (!empty($highlight_params)) { + $params += $highlight_params; + } + if (!empty($options['search_api_spellcheck'])) { + $params['spellcheck'] = 'true'; + } + if (!empty($mlt_params['mlt.fl'])) { + $params += $mlt_params; + } + if (!empty($this->options['retrieve_data'])) { + $params['fl'] = '*,score'; + } + $call_args = array( + 'query' => &$keys, + 'offset' => &$offset, + 'limit' => &$limit, + 'params' => &$params, + ); + if ($this->request_handler) { + $this->setRequestHandler($this->request_handler, $call_args); + } + + try { + // Send search request + $time_processing_done = microtime(TRUE); + $this->connect(); + drupal_alter('search_api_solr_query', $call_args, $query); + $this->preQuery($call_args, $query); + + // Retrieve http method from server options. + $http_method = !empty($this->options['http_method']) ? $this->options['http_method'] : Apache_Solr_Service::METHOD_POST; + $response = $this->solr->search($keys, $offset, $limit, $params, $http_method); + $time_query_done = microtime(TRUE); + + if ($response->getHttpStatus() != 200) { + throw new SearchApiException(t('The Solr server responded with status code @status: @msg.', + array('@status' => $response->getHttpStatus(), '@msg' => $response->getHttpStatusMessage()))); + } + + // Extract results + $results = $this->extractResults($query, $response); + + // Extract facets + if ($facets = $this->extractFacets($query, $response)) { + $results['search_api_facets'] = $facets; + } + + drupal_alter('search_api_solr_search_results', $results, $query, $response); + $this->postQuery($results, $query, $response); + + // Compute performance + $time_end = microtime(TRUE); + $results['performance'] = array( + 'complete' => $time_end - $time_method_called, + 'preprocessing' => $time_processing_done - $time_method_called, + 'execution' => $time_query_done - $time_processing_done, + 'postprocessing' => $time_end - $time_query_done, + ); + + return $results; + } + catch (Exception $e) { + throw new SearchApiException(t('An error occurred while trying to search with Solr: @msg.', array('@msg' => $e->getMessage()))); + } + } + + /** + * Extract results from a Solr response. + * + * @param Apache_Solr_Response $response + * A response object from SolrPhpClient. + * + * @return array + * An array with two keys: + * - result count: The number of total results. + * - results: An array of search results, as specified by + * SearchApiQueryInterface::execute(). + */ + protected function extractResults(SearchApiQueryInterface $query, Apache_Solr_Response $response) { + $index = $query->getIndex(); + $fields = $this->getFieldNames($index); + $field_options = $index->options['fields']; + + // Set up the results array. + $results = array(); + $results['results'] = array(); + // In some rare cases (e.g., MLT query with nonexistent ID) the response + // will be NULL. + if (!isset($response->response)) { + $results['result count'] = 0; + return $results; + } + $results['result count'] = $response->response->numFound; + + // Add each search result to the results array. + foreach ($response->response->docs as $doc) { + // Blank result array. + $result = array( + 'id' => NULL, + 'score' => NULL, + 'fields' => array(), + ); + + // Extract properties from the Solr document, translating from Solr to + // Search API property names. This reverses the mapping in + // SearchApiSolrService::getFieldNames(). + foreach ($fields as $search_api_property => $solr_property) { + if (isset($doc->{$solr_property})) { + $result['fields'][$search_api_property] = $doc->{$solr_property}; + // Date fields need some special treatment to become valid date values + // (i.e., timestamps) again. + if (isset($field_options[$search_api_property]['type']) + && $field_options[$search_api_property]['type'] == 'date' + && preg_match('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/', $result['fields'][$search_api_property])) { + $result['fields'][$search_api_property] = strtotime($result['fields'][$search_api_property]); + } + } + } + + // We can find the item id and score in the special 'search_api_*' + // properties. Mappings are provided for these properties in + // SearchApiSolrService::getFieldNames(). + $result['id'] = $result['fields']['search_api_item_id']; + $result['score'] = $result['fields']['search_api_relevance']; + + $solr_id = $this->createId($index->machine_name, $result['id']); + $excerpt = $this->getExcerpt($response, $solr_id, $result['fields'], $fields); + if ($excerpt) { + $result['excerpt'] = $excerpt; + } + + // Use the result's id as the array key. By default, 'id' is mapped to + // 'item_id' in SearchApiSolrService::getFieldNames(). + if ($result['id']) { + $results['results'][$result['id']] = $result; + } + } + + // Check for spellcheck suggestions. + if (module_exists('search_api_spellcheck') && $query->getOption('search_api_spellcheck')) { + $results['search_api_spellcheck'] = new SearchApiSpellcheckSolr($response); + } + + return $results; + } + + /** + * Extract and format highlighting information for a specific item from a Solr response. + * + * Will also use highlighted fields to replace retrieved field data, if the + * corresponding option is set. + */ + protected function getExcerpt(Apache_Solr_Response $response, $id, array &$fields, array $field_mapping) { + if (!isset($response->highlighting->$id)) { + return FALSE; + } + $output = ''; + + if (!empty($this->options['excerpt']) && !empty($response->highlighting->$id->spell)) { + foreach ($response->highlighting->$id->spell as $snippet) { + $snippet = strip_tags($snippet); + $snippet = preg_replace('/^.*>|<.*$/', '', $snippet); + $snippet = $this->formatHighlighting($snippet); + // The created fragments sometimes have leading or trailing punctuation. + // We remove that here for all common cases, but take care not to remove + // < or > (so HTML tags stay valid). + $snippet = trim($snippet, "\00..\x2F:;=\x3F..\x40\x5B..\x60"); + $output .= $snippet . ' … '; + } + } + if (!empty($this->options['highlight_data'])) { + foreach ($field_mapping as $search_api_property => $solr_property) { + if (substr($solr_property, 0, 2) == 't_' && !empty($response->highlighting->$id->$solr_property)) { + // Contrary to above, we here want to preserve HTML, so we just + // replace the [HIGHLIGHT] tags with the appropriate format here. + $fields[$search_api_property] = $this->formatHighlighting($response->highlighting->$id->$solr_property); + } + } + } + + return $output; + } + + + protected function formatHighlighting($snippet) { + return preg_replace('#\[(/?)HIGHLIGHT\]#', '<$1strong>', $snippet); + } + + /** + * Extract facets from a Solr response. + * + * @param Apache_Solr_Response $response + * A response object from SolrPhpClient. + * + * @return array + * An array describing facets that apply to the current results. + */ + protected function extractFacets(SearchApiQueryInterface $query, Apache_Solr_Response $response) { + if (isset($response->facet_counts->facet_fields)) { + $index = $query->getIndex(); + $fields = $this->getFieldNames($index); + + $facets = array(); + $facet_fields = $response->facet_counts->facet_fields; + + $extract_facets = $query->getOption('search_api_facets'); + $extract_facets = ($extract_facets ? $extract_facets : array()); + + foreach ($extract_facets as $delta => $info) { + $field = $fields[$info['field']]; + if (!empty($facet_fields->$field)) { + $min_count = $info['min_count']; + $terms = $facet_fields->$field; + if ($info['missing']) { + // We have to correctly incorporate the "_empty_" term. + // This will ensure that the term with the least results is dropped, if the limit would be exceeded. + if (isset($terms->_empty_) && $terms->_empty_ < $min_count) { + unset($terms->_empty_); + } + else { + $terms = (array) $terms; + arsort($terms); + if (count($terms) > $info['limit']) { + array_pop($terms); + } + } + } + elseif (isset($terms->_empty_)) { + $terms = clone $terms; + unset($terms->_empty_); + } + $type = isset($index->options['fields'][$info['field']]['type']) ? $index->options['fields'][$info['field']]['type'] : 'string'; + foreach ($terms as $term => $count) { + if ($count >= $min_count) { + if ($type == 'boolean') { + if ($term == 'true') { + $term = 1; + } + elseif ($term == 'false') { + $term = 0; + } + } + elseif ($type == 'date') { + $term = isset($term) ? strtotime($term) : NULL; + } + $term = $term === '_empty_' ? '!' : '"' . $term . '"'; + $facets[$delta][] = array( + 'filter' => $term, + 'count' => $count, + ); + } + } + if (empty($facets[$delta])) { + unset($facets[$delta]); + } + } + } + + return $facets; + } + } + + /** + * Flatten a keys array into a single search string. + * + * @param array $keys + * The keys array to flatten, formatted as specified by + * SearchApiQueryInterface::getKeys(). + * + * @return string + * A Solr query string representing the same keys. + */ + protected function flattenKeys(array $keys) { + $k = array(); + $or = $keys['#conjunction'] == 'OR'; + $neg = !empty($keys['#negation']); + foreach (element_children($keys) as $i) { + $key = $keys[$i]; + if (!$key) { + continue; + } + if (is_array($key)) { + $subkeys = $this->flattenKeys($key); + if ($subkeys) { + $nested_expressions = TRUE; + // If this is a negated OR expression, we can't just use nested keys + // as-is, but have to put them into parantheses. + if ($or && $neg) { + $subkeys = "($subkeys)"; + } + $k[] = $subkeys; + } + } + else { + $key = trim($key); + $key = SearchApiSolrConnection::phrase($key); + $k[] = $key; + } + } + if (!$k) { + return ''; + } + + // Formatting the keys into a Solr query can be a bit complex. The following + // code will produce that look like this: + // + // #conjunction | #negation | return value + // ---------------------------------------------------------------- + // AND | FALSE | A B C + // AND | TRUE | -(A B C) + // OR | FALSE | ((A) OR (B) OR (C)) + // OR | TRUE | -A -B -C + + // If there was just a single, unnested key, we can ignore all this. + if (count($k) == 1 && empty($nested_expressions)) { + $k = reset($k); + return $neg ? "-$k" : $k; + } + + if ($or) { + if ($neg) { + return '-' . implode(' -', $k); + } + return '((' . implode(') OR (', $k) . '))'; + } + $k = implode(' ', $k); + return $neg ? "-($k)" : $k; + } + + /** + * Transforms a query filter into a flat array of Solr filter queries, using + * the field names in $fields. + */ + protected function createFilterQueries(SearchApiQueryFilterInterface $filter, array $solr_fields, array $fields) { + $or = $filter->getConjunction() == 'OR'; + $fq = array(); + foreach ($filter->getFilters() as $f) { + if (is_array($f)) { + if (!isset($fields[$f[0]])) { + throw new SearchApiException(t('Filter term on unknown or unindexed field @field.', array('@field' => $f[0]))); + } + if ($f[1] !== '') { + $fq[] = $this->createFilterQuery($solr_fields[$f[0]], $f[1], $f[2], $fields[$f[0]]); + } + } + else { + $q = $this->createFilterQueries($f, $solr_fields, $fields); + if ($filter->getConjunction() != $f->getConjunction()) { + // $or == TRUE means the nested filter has conjunction AND, and vice versa + $sep = $or ? ' ' : ' OR '; + $fq[] = count($q) == 1 ? reset($q) : '((' . implode(')' . $sep . '(', $q) . '))'; + } + else { + $fq = array_merge($fq, $q); + } + } + } + return ($or && count($fq) > 1) ? array('((' . implode(') OR (', $fq) . '))') : $fq; + } + + /** + * Create a single search query string according to the given field, value + * and operator. + */ + protected function createFilterQuery($field, $value, $operator, $field_info) { + $field = SearchApiSolrConnection::escapeFieldName($field); + if ($value === NULL) { + return ($operator == '=' ? '-' : '') . "$field:[* TO *]"; + } + $value = trim($value); + $value = $this->formatFilterValue($value, search_api_extract_inner_type($field_info['type'])); + switch ($operator) { + case '<>': + return "-($field:$value)"; + case '<': + return "$field:{* TO $value}"; + case '<=': + return "$field:[* TO $value]"; + case '>=': + return "$field:[$value TO *]"; + case '>': + return "$field:{{$value} TO *}"; + + default: + return "$field:$value"; + } + } + + /** + * Format a value for filtering on a field of a specific type. + */ + protected function formatFilterValue($value, $type) { + switch ($type) { + case 'boolean': + $value = $value ? 'true' : 'false'; + break; + case 'date': + $value = is_numeric($value) ? (int) $value : strtotime($value); + if ($value === FALSE) { + return 0; + } + $value = format_date($value, 'custom', self::SOLR_DATE_FORMAT, 'UTC'); + break; + } + return SearchApiSolrConnection::phrase($value); + } + + /** + * Helper method for creating the facet field parameters. + */ + protected function getFacetParams(array $facets, array $fields, array &$fq = array()) { + if (!$facets) { + return array(); + } + $facet_params['facet'] = 'true'; + $facet_params['facet.sort'] = 'count'; + $facet_params['facet.limit'] = 10; + $facet_params['facet.mincount'] = 1; + $facet_params['facet.missing'] = 'false'; + $taggedFields = array(); + foreach ($facets as $info) { + if (empty($fields[$info['field']])) { + continue; + } + // String fields have their own corresponding facet fields. + $field = $fields[$info['field']]; + // Check for the "or" operator. + if (isset($info['operator']) && $info['operator'] === 'or') { + // Remember that filters for this field should be tagged. + $escaped = SearchApiSolrConnection::escapeFieldName($fields[$info['field']]); + $taggedFields[$escaped] = "{!tag=$escaped}"; + // Add the facet field. + $facet_params['facet.field'][] = "{!ex=$escaped}$field"; + } + else { + // Add the facet field. + $facet_params['facet.field'][] = $field; + } + // Set limit, unless it's the default. + if ($info['limit'] != 10) { + $facet_params["f.$field.facet.limit"] = $info['limit'] ? $info['limit'] : -1; + } + // Set mincount, unless it's the default. + if ($info['min_count'] != 1) { + $facet_params["f.$field.facet.mincount"] = $info['min_count']; + } + // Set missing, if specified. + if ($info['missing']) { + $facet_params["f.$field.facet.missing"] = 'true'; + } + } + // Tag filters of fields with "OR" facets. + foreach ($taggedFields as $field => $tag) { + $regex = '#(? $filter) { + // Solr can't handle two tags on the same filter, so we don't add two. + // Another option here would even be to remove the other tag, too, + // since we can be pretty sure that this filter does not originate from + // a facet – however, wrong results would still be possible, and this is + // definitely an edge case, so don't bother. + if (preg_match($regex, $filter) && substr($filter, 0, 6) != '{!tag=') { + $fq[$i] = $tag . $filter; + } + } + } + + return $facet_params; + } + + /** + * Helper method for creating the highlighting parameters. + * + * (The $query parameter currently isn't used and only here for the potential + * sake of subclasses.) + */ + protected function getHighlightParams(SearchApiQueryInterface $query) { + $highlight_params = array(); + + if (!empty($this->options['excerpt']) || !empty($this->options['highlight_data'])) { + $highlight_params['hl'] = 'true'; + $highlight_params['hl.fl'] = 'spell'; + $highlight_params['hl.simple.pre'] = '[HIGHLIGHT]'; + $highlight_params['hl.simple.post'] = '[/HIGHLIGHT]'; + $highlight_params['hl.snippets'] = 3; + $highlight_params['hl.fragsize'] = 70; + $highlight_params['hl.mergeContiguous'] = 'true'; + } + + if (!empty($this->options['highlight_data'])) { + $highlight_params['hl.fl'] = 't_*'; + $highlight_params['hl.snippets'] = 1; + $highlight_params['hl.fragsize'] = 0; + if (!empty($this->options['excerpt'])) { + // If we also generate a "normal" excerpt, set the settings for the + // "spell" field (which we use to generate the excerpt) back to the + // above values. + $highlight_params['f.spell.hl.snippets'] = 3; + $highlight_params['f.spell.hl.fragsize'] = 70; + // It regrettably doesn't seem to be possible to set hl.fl to several + // values, if one contains wild cards (i.e., "t_*,spell" wouldn't work). + $highlight_params['hl.fl'] = '*'; + } + } + + return $highlight_params; + } + + /** + * Helper method for setting the request handler, and making necessary + * adjustments to the request parameters. + * + * @param $handler + * Name of the handler to set. + * @param array $call_args + * An associative array containing all four arguments to the + * Apache_Solr_Service::search() call ("query", "offset", "limit" and + * "params") as references. + * + * @return boolean + * TRUE iff this method invocation handled the given handler. This allows + * subclasses to recognize whether the request handler was already set by + * this method. + */ + protected function setRequestHandler($handler, array &$call_args) { + if ($handler == 'pinkPony') { + $call_args['params']['qt'] = $handler; + return TRUE; + } + return FALSE; + } + + /** + * Empty method to allow subclasses to apply custom changes before the query + * is sent to Solr. Works exactly like hook_search_api_solr_query_alter(). + * + * @param array $call_args + * An associative array containing all four arguments to the + * Apache_Solr_Service::search() call ("query", "offset", "limit" and + * "params") as references. + * @param SearchApiQueryInterface $query + * The SearchApiQueryInterface object representing the executed search query. + */ + protected function preQuery(array &$call_args, SearchApiQueryInterface $query) { + } + + /** + * Empty method to allow subclasses to apply custom changes before search results are returned. + * + * Works exactly like hook_search_api_solr_search_results_alter(). + * + * @param array $results + * The results array that will be returned for the search. + * @param SearchApiQueryInterface $query + * The SearchApiQueryInterface object representing the executed search query. + * @param Apache_Solr_Response $response + * The response object returned by Solr. + */ + protected function postQuery(array &$results, SearchApiQueryInterface $query, Apache_Solr_Response $response) { + } + + // + // Autocompletion feature + // + + /** + * Get autocompletion suggestions for some user input. + * + * @param SearchApiQueryInterface $query + * A query representing the completed user input so far. + * @param SearchApiAutocompleteSearch $search + * An object containing details about the search the user is on, and + * settings for the autocompletion. + * @param string $incomplete_key + * The start of another fulltext keyword for the search, which should be + * completed. + * @param string $user_input + * The complete user input for the fulltext search keywords so far. + * + * @return array + * An array of suggestion. Each suggestion is either a simple string + * containing the whole suggested keywords, or an array containing the + * following keys: + * - prefix: For special suggestions, some kind of prefix describing them. + * - suggestion_prefix: A suggested prefix for the entered input. + * - user_input: The input entered by the user. Defaults to $user_input. + * - suggestion_suffix: A suggested suffix for the entered input. + * - results: If available, the estimated number of results for these keys. + */ + // Largely copied from the apachesolr_autocomplete module. + public function getAutocompleteSuggestions(SearchApiQueryInterface $query, SearchApiAutocompleteSearch $search, $incomplete_key, $user_input) { + $suggestions = array(); + // Reset request handler + $this->request_handler = NULL; + // Turn inputs to lower case, otherwise we get case sensivity problems. + $incomp = drupal_strtolower($incomplete_key); + + $index = $query->getIndex(); + $fields = $this->getFieldNames($index); + $complete = $query->getOriginalKeys(); + + // Extract keys + $keys = $query->getKeys(); + if (is_array($keys)) { + $keys_array = array(); + while ($keys) { + reset($keys); + if (!element_child(key($keys))) { + array_shift($keys); + continue; + } + $key = array_shift($keys); + if (is_array($key)) { + $keys = array_merge($keys, $key); + } + else { + $keys_array[$key] = $key; + } + } + $keys = $this->flattenKeys($query->getKeys()); + } + else { + $keys_array = drupal_map_assoc(preg_split('/[-\s():{}\[\]\\\\"]+/', $keys, -1, PREG_SPLIT_NO_EMPTY)); + } + if (!$keys) { + $keys = NULL; + } + + // Set searched fields + $options = $query->getOptions(); + $search_fields = $query->getFields(); + $qf = array(); + foreach ($search_fields as $f) { + $qf[] = $fields[$f]; + } + + // Extract filters + $fq = $this->createFilterQueries($query->getFilter(), $fields, $index->options['fields']); + $fq[] = 'index_id:' . $index->machine_name; + + // Autocomplete magic + $facet_fields = array(); + foreach ($search_fields as $f) { + $facet_fields[] = $fields[$f]; + } + + $limit = $query->getOption('limit', 10); + + $params = array( + 'qf' => $qf, + 'fq' => $fq, + 'facet' => 'true', + 'facet.field' => $facet_fields, + 'facet.prefix' => $incomp, + 'facet.limit' => $limit * 5, + 'facet.mincount' => 1, + 'spellcheck' => (!isset($this->options['autocorrect_spell']) || $this->options['autocorrect_spell']) ? 'true' : 'false', + 'spellcheck.count' => 1, + ); + $call_args = array( + 'query' => &$keys, + 'offset' => 0, + 'limit' => 0, + 'params' => &$params, + ); + if ($this->request_handler) { + $this->setRequestHandler($this->request_handler, $call_args); + } + $second_pass = !isset($this->options['autocorrect_suggest_words']) || $this->options['autocorrect_suggest_words']; + for ($i = 0; $i < ($second_pass ? 2 : 1); ++$i) { + try { + // Send search request + $this->connect(); + drupal_alter('search_api_solr_query', $call_args, $query); + $this->preQuery($call_args, $query); + $response = $this->solr->search($keys, 0, 0, $params); + + if ($response->getHttpStatus() != 200) { + watchdog('search_api_solr', 'The Solr server responded with status code @status: @msg.', array('@status' => $response->getHttpStatus(), '@msg' => $response->getHttpStatusMessage()), WATCHDOG_WARNING, 'admin/config/search/search_api/server/' . $this->server->machine_name); + return array(); + } + + if (!empty($response->spellcheck->suggestions)) { + $replace = array(); + foreach ($response->spellcheck->suggestions as $word => $data) { + $replace[$word] = $data->suggestion[0]; + } + $corrected = str_ireplace(array_keys($replace), array_values($replace), $user_input); + if ($corrected != $user_input) { + array_unshift($suggestions, array( + 'prefix' => t('Did you mean') . ':', + 'user_input' => $corrected, + )); + } + } + + $matches = array(); + if (isset($response->facet_counts->facet_fields)) { + foreach ($response->facet_counts->facet_fields as $terms) { + foreach ($terms as $term => $count) { + if (isset($matches[$term])) { + // If we just add the result counts, we can easily get over the + // total number of results if terms appear in multiple fields. + // Therefore, we just take the highest value from any field. + $matches[$term] = max($matches[$term], $count); + } + else { + $matches[$term] = $count; + } + } + } + + if ($matches) { + // Eliminate suggestions that are too short or already in the query. + foreach ($matches as $term => $count) { + if (strlen($term) < 3 || isset($keys_array[$term])) { + unset($matches[$term]); + } + } + + // Don't suggest terms that are too frequent (by default in more + // than 90% of results). + $result_count = $response->response->numFound; + $max_occurrences = $result_count * variable_get('search_api_solr_autocomplete_max_occurrences', 0.9); + if (($max_occurrences >= 1 || $i > 0) && $max_occurrences < $result_count) { + foreach ($matches as $match => $count) { + if ($count > $max_occurrences) { + unset($matches[$match]); + } + } + } + + // The $count in this array is actually a score. We want the + // highest ones first. + arsort($matches); + + // Shorten the array to the right ones. + $additional_matches = array_slice($matches, $limit - count($suggestions), NULL, TRUE); + $matches = array_slice($matches, 0, $limit, TRUE); + + // Build suggestions using returned facets + $incomp_length = strlen($incomp); + foreach ($matches as $term => $count) { + if (drupal_strtolower(substr($term, 0, $incomp_length)) == $incomp) { + $suggestions[] = array( + 'suggestion_suffix' => substr($term, $incomp_length), + 'results' => $count, + ); + } + else { + $suggestions[] = array( + 'suggestion_suffix' => ' ' . $term, + 'results' => $count, + ); + } + } + } + } + } + catch (Exception $e) { + watchdog_exception('search_api_solr', $e, "%type during autocomplete Solr query: !message in %function (line %line of %file).", array(), WATCHDOG_WARNING); + } + + if (count($suggestions) >= $limit) { + break; + } + // Change parameters for second query. + unset($params['facet.prefix']); + $keys = trim ($keys . ' ' . $incomplete_key); + } + + return $suggestions; + } + + // + // SearchApiMultiServiceInterface methods + // + + /** + * Create a query object for searching on this server. + * + * @param $options + * Associative array of options configuring this query. See + * SearchApiMultiQueryInterface::__construct(). + * + * @throws SearchApiException + * If the server is currently disabled. + * + * @return SearchApiMultiQueryInterface + * An object for searching this server. + */ + public function queryMultiple(array $options = array()) { + return new SearchApiMultiQuery($this->server, $options); + } + + /** + * Executes a search on the server represented by this object. + * + * @param SearchApiMultiQueryInterface $query + * The search query to execute. + * + * @throws SearchApiException + * If an error prevented the search from completing. + * + * @return array + * An associative array containing the search results, as required by + * SearchApiMultiQueryInterface::execute(). + */ + public function searchMultiple(SearchApiMultiQueryInterface $query) { + $time_method_called = microtime(TRUE); + // Get field information + $solr_fields = array( + 'search_api_id' => 'ss_search_api_id', + 'search_api_relevance' => 'score', + 'search_api_multi_index' => 'index_id', + ); + $fields = array( + 'search_api_multi_index' => array( + 'type' => 'string', + ), + ); + foreach ($query->getIndexes() as $index_id => $index) { + if (empty($index->options['fields'])) { + continue; + } + $prefix = $index_id . ':'; + foreach ($this->getFieldNames($index) as $field => $key) { + if (!isset($solr_fields[$field])) { + $solr_fields[$prefix . $field] = $key; + } + } + foreach ($index->options['fields'] as $field => $info) { + $fields[$prefix . $field] = $info; + } + } + + // Extract keys + $keys = $query->getKeys(); + if (is_array($keys)) { + $keys = $this->flattenKeys($keys); + } + + // Set searched fields + $search_fields = $query->getFields(); + $qf = array(); + foreach ($search_fields as $f) { + $qf[] = $solr_fields[$f]; + } + + // Extract filters + $filter = $query->getFilter(); + $fq = $this->createFilterQueries($filter, $solr_fields, $fields); + + // Restrict search to searched indexes. + $index_filter = array(); + foreach ($query->getIndexes() as $index_id => $index) { + $index_filter[] = 'index_id:' . SearchApiSolrConnection::phrase($index_id); + } + $fq[] = implode(' OR ', $index_filter); + + // Extract sort + $sort = array(); + foreach ($query->getSort() as $f => $order) { + $f = $solr_fields[$f]; + if (substr($f, 0, 3) == 'ss_') { + $f = 'sort_' . substr($f, 3); + } + $order = strtolower($order); + $sort[] = "$f $order"; + } + + // Get facet fields + $facets = $query->getOption('search_api_facets') ? $query->getOption('search_api_facets') : array(); + $facet_params = $this->getFacetParams($facets, $solr_fields); + + // Set defaults + if (!$keys) { + $keys = NULL; + } + $options = $query->getOptions(); + $offset = isset($options['offset']) ? $options['offset'] : 0; + $limit = isset($options['limit']) ? $options['limit'] : 1000000; + + // Collect parameters + $params = array( + 'qf' => $qf, + 'fl' => 'item_id,index_id,score', + 'fq' => $fq, + ); + if ($sort) { + $params['sort'] = implode(', ', $sort); + } + if (!empty($facet_params['facet.field'])) { + $params += $facet_params; + } + try { + // Send search request + $time_processing_done = microtime(TRUE); + $this->connect(); + $call_args = array( + 'query' => &$keys, + 'offset' => &$offset, + 'limit' => &$limit, + 'params' => &$params, + ); + drupal_alter('search_api_solr_multi_query', $call_args, $query); + + // Retrieve http method from server options. + $http_method = !empty($this->options['http_method']) ? $this->options['http_method'] : Apache_Solr_Service::METHOD_POST; + $response = $this->solr->search($keys, $offset, $limit, $params, $http_method); + $time_query_done = microtime(TRUE); + + if ($response->getHttpStatus() != 200) { + throw new SearchApiException(t('The Solr server responded with status code @status: @msg.', + array('@status' => $response->getHttpStatus(), '@msg' => $response->getHttpStatusMessage()))); + } + + // Extract results + $results = array(); + $results['result count'] = $response->response->numFound; + $results['results'] = array(); + $tmp = array(); + foreach ($response->response->docs as $id => $doc) { + $result = array( + 'id' => $doc->item_id, + 'index_id' => $doc->index_id, + 'score' => $doc->score, + ); + $excerpt = $this->getExcerpt($response, $id, $tmp, array()); + if ($excerpt) { + $result['excerpt'] = $excerpt; + } + $results['results'][$id] = $result; + } + + // Extract facets + if (isset($response->facet_counts->facet_fields)) { + $results['search_api_facets'] = array(); + $facet_fields = $response->facet_counts->facet_fields; + foreach ($facets as $delta => $info) { + $field = $this->getFacetField($solr_fields[$info['field']]); + if (!empty($facet_fields->$field)) { + $min_count = $info['min_count']; + $terms = $facet_fields->$field; + if ($info['missing']) { + // We have to correctly incorporate the "_empty_" term. + // This will ensure that the term with the least results is dropped, if the limit would be exceeded. + $terms = (array) $terms; + arsort($terms); + if (count($terms) > $info['limit']) { + array_pop($terms); + } + } + foreach ($terms as $term => $count) { + if ($count >= $min_count) { + $term = $term == '_empty_' ? '!' : '"' . $term . '"'; + $results['search_api_facets'][$delta][] = array( + 'filter' => $term, + 'count' => $count, + ); + } + } + if (empty($results['search_api_facets'][$delta]) || count($results['search_api_facets'][$delta]) <= 1) { + unset($results['search_api_facets'][$delta]); + } + } + } + } + + // Compute performance + $time_end = microtime(TRUE); + $results['performance'] = array( + 'complete' => $time_end - $time_method_called, + 'preprocessing' => $time_processing_done - $time_method_called, + 'execution' => $time_query_done - $time_processing_done, + 'postprocessing' => $time_end - $time_query_done, + ); + + return $results; + } + catch (Exception $e) { + throw new SearchApiException($e->getMessage()); + } + } + + // + // Additional methods that might be used when knowing the service class. + // + + /** + * Ping the Solr server to tell whether it can be accessed. + * + * Uses the admin/ping request handler. + */ + public function ping() { + $this->connect(); + return $this->solr->ping(); + } + + /** + * Sends a commit command to the Solr server. + */ + public function commit() { + try { + $this->connect(); + return $this->solr->commit(FALSE, FALSE, FALSE); + } + catch (Exception $e) { + watchdog('search_api_solr', 'A commit operation for server @name failed: @msg.', + array('@name' => $this->server->machine_name, '@msg' => $e->getMessage()), WATCHDOG_WARNING); + } + } + + /** + * Schedules a commit operation for this server. + * + * The commit will be sent at the end of the current page request. Multiple + * calls to this method will still only result in one commit operation. + */ + public function scheduleCommit() { + if (!$this->commitScheduled) { + $this->commitScheduled = TRUE; + drupal_register_shutdown_function(array($this, 'commit')); + } + } + + /** + * @return SearchApiSolrConnection + * The solr connection object used by this server. + */ + public function getSolrConnection() { + $this->connect(); + return $this->solr; + } + + /** + * Get metadata about fields in the Solr/Lucene index. + * + * @param boolean $reset + * Reload the cached data? + */ + public function getFields($reset = FALSE) { + $cid = 'search_api_solr:fields:' . $this->server->machine_name; + + // If the data hasn't been retrieved before and we aren't refreshing it, try + // to get data from the cache. + if (!isset($this->fields) && !$reset) { + $cache = cache_get($cid); + if (isset($cache->data) && !$reset) { + $this->fields = $cache->data; + } + } + + // If there was no data in the cache, or if we're refreshing the data, + // connect to the Solr server, retrieve schema information, and cache it. + if (!isset($this->fields) || $reset) { + $this->connect(); + $this->fields = array(); + foreach ($this->solr->getFields() as $name => $info) { + $this->fields[$name] = new SearchApiSolrField($info); + } + cache_set($cid, $this->fields); + } + + return $this->fields; + } + +} diff --git a/solr-conf/1.4/protwords.txt b/solr-conf/1.4/protwords.txt new file mode 100644 index 00000000..cda85814 --- /dev/null +++ b/solr-conf/1.4/protwords.txt @@ -0,0 +1,7 @@ +#----------------------------------------------------------------------- +# This file blocks words from being operated on by the stemmer and word delimiter. +& +< +> +' +" diff --git a/solr-conf/1.4/schema.xml b/solr-conf/1.4/schema.xml new file mode 100644 index 00000000..543d2766 --- /dev/null +++ b/solr-conf/1.4/schema.xml @@ -0,0 +1,535 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + + + content + + + + + diff --git a/solr-conf/1.4/solrconfig.xml b/solr-conf/1.4/solrconfig.xml new file mode 100644 index 00000000..246be0e0 --- /dev/null +++ b/solr-conf/1.4/solrconfig.xml @@ -0,0 +1,1637 @@ + + + + + + + + + ${solr.abortOnConfigurationError:true} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + 4 + + 32 + + + + 2147483647 + 100000 + 1000 + + + + + + + + + single + + + + + + + + + false + 32 + 10 + + + false + + + true + + + + + 1 + + 0 + + + + + + false + + + + + + + + + + + + + + + + 10000 + 120000 + + + + + + + + + + + + + + + + + 1024 + + + + + + + + + + + + + + + + + + + + + + true + + + + + + 20 + + + 200 + + + + + + + + + + + + solr rocks010 + + + + + + false + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dismax + explicit + true + 0.01 + + ${pinkPony.timeAllowed:-1} + *:* + + + false + + true + false + + 1 + + + spellcheck + + + + + + + 1 + 1 + 3 + 15 + 20 + false + + ${mlt.timeAllowed:2000} + + + + + + + + + + + + + + + + + + + + + + text + true + ignored_ + + + true + links + ignored_ + + + + + + + + + + + + + + + + + + + + + + + + pinkPony + solrpingquery + + + all + + + + + + + explicit + true + + + + + + + ${enable.master:false} + commit + startup + ${confFiles} + + + ${enable.slave:false} + ${masterCoreUrl}/replication + ${pollTime:00:00:60} + + + + + + + + + textSpell + + + + + + default + name + spellchecker + + + + + + + + + + + + + + + + + false + false + 1 + + + spellcheck + + + + + + + + + + true + + + tvComponent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + terms + + + + + + + + string + elevate.xml + + + + + + explicit + + + elevator + + + + + + + + + + + 100 + + + + + + + + 70 + + 0.5 + + [-\w ,/\n\"']{20,200} + + + + + + + ]]> + ]]> + + + + + + + + + + + + + + + + + + + + + ,, + ,, + ,, + ,, + ,]]> + ]]> + + + + + + 10 + .,!? + + + + + + + WORD + + + en + US + + + + + + + + + + + + + + + + + + + text/plain; charset=UTF-8 + + + + + + + + + + 5 + + + + + + + + + + + + + *:* + + + + + + diff --git a/solr-conf/1.4/solrcore.properties b/solr-conf/1.4/solrcore.properties new file mode 100644 index 00000000..476f8ddb --- /dev/null +++ b/solr-conf/1.4/solrcore.properties @@ -0,0 +1,8 @@ +#solrcore.properties for this specific core +enable.master=false +enable.slave=false +pollTime=00:00:60 +masterCoreUrl=http://localhost:8983/solr +confFiles=schema.xml,mapping-ISOLatin1Accent.txt,protwords.txt,stopwords.txt,synonyms.txt,elevate.xml +mlt.timeAllowed=2000 +pinkPony.timeAllowed=-1 diff --git a/solr-conf/3.x/protwords.txt b/solr-conf/3.x/protwords.txt new file mode 100644 index 00000000..cda85814 --- /dev/null +++ b/solr-conf/3.x/protwords.txt @@ -0,0 +1,7 @@ +#----------------------------------------------------------------------- +# This file blocks words from being operated on by the stemmer and word delimiter. +& +< +> +' +" diff --git a/solr-conf/3.x/schema.xml b/solr-conf/3.x/schema.xml new file mode 100644 index 00000000..dff885d1 --- /dev/null +++ b/solr-conf/3.x/schema.xml @@ -0,0 +1,548 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + + + content + + + + + diff --git a/solr-conf/3.x/solrconfig.xml b/solr-conf/3.x/solrconfig.xml new file mode 100644 index 00000000..841963d6 --- /dev/null +++ b/solr-conf/3.x/solrconfig.xml @@ -0,0 +1,1645 @@ + + + + + + + + + ${solr.abortOnConfigurationError:true} + + + ${luceneVersion:LUCENE_35} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + 4 + + 32 + + + + 2147483647 + 100000 + 1000 + + + + + + + + + single + + + + + + + + + false + 32 + 10 + + + false + + + true + + + + + 1 + + 0 + + + + + + false + + + + + + + + + + + + + + + + 10000 + 120000 + + + + + + + + + + + + + + + + + 1024 + + + + + + + + + + + + + + + + + + + + + + true + + + + + + 20 + + + 200 + + + + + + + + + + + + solr rocks010 + + + + + + false + + + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + edismax + explicit + true + 0.01 + + ${pinkPony.timeAllowed:-1} + *:* + + + false + + true + false + + 1 + + + spellcheck + + + + + + + 1 + 1 + 3 + 15 + 20 + false + + ${mlt.timeAllowed:2000} + + + + + + + + + + + + + + + + + + + + + + text + true + ignored_ + + + true + links + ignored_ + + + + + + + + + + + + + + + + + + + + + + + + pinkPony + solrpingquery + + + all + + + + + + + explicit + true + + + + + + + ${enable.master:false} + commit + startup + ${confFiles} + + + ${enable.slave:false} + ${masterCoreUrl}/replication + ${pollTime:00:00:60} + + + + + + + + + textSpell + + + + + + default + name + spellchecker + + + + + + + + + + + + + + + + + false + false + 1 + + + spellcheck + + + + + + + + + + true + + + tvComponent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + terms + + + + + + + + string + elevate.xml + + + + + + explicit + + + elevator + + + + + + + + + + + 100 + + + + + + + + 70 + + 0.5 + + [-\w ,/\n\"']{20,200} + + + + + + + ]]> + ]]> + + + + + + + + + + + + + + + + + + + + + ,, + ,, + ,, + ,, + ,]]> + ]]> + + + + + + 10 + .,!? + + + + + + + WORD + + + en + US + + + + + + + + + + + + + + + + + + + text/plain; charset=UTF-8 + + + + + + + + + + 5 + + + + + + + + + + + + + *:* + + + + + + diff --git a/solr-conf/3.x/solrcore.properties b/solr-conf/3.x/solrcore.properties new file mode 100644 index 00000000..0f3933d2 --- /dev/null +++ b/solr-conf/3.x/solrcore.properties @@ -0,0 +1,10 @@ +#solrcore.properties for this specific core +enable.master=false +enable.slave=false +pollTime=00:00:60 +masterCoreUrl=http://localhost:8983/solr +confFiles=schema.xml,mapping-ISOLatin1Accent.txt,protwords.txt,stopwords.txt,synonyms.txt,elevate.xml +mlt.timeAllowed=2000 +# You should not set your luceneVersion to anything lower then your Solr Version +luceneVersion=LUCENE_35 +pinkPony.timeAllowed=-1 diff --git a/solr_connection.inc b/solr_connection.inc new file mode 100644 index 00000000..770a7b6e --- /dev/null +++ b/solr_connection.inc @@ -0,0 +1,259 @@ + 'localhost', + 'port' => 8983, + 'path' => '', + 'http_user' => NULL, + 'http_pass' => NULL, + 'default_field'=>'id', + ); + parent::__construct($options['host'], $options['port'], $options['path']); + if ($options['http_user'] && $options['http_pass']) { + $this->http_auth = 'Basic ' . base64_encode($options['http_user'] . ':' . $options['http_pass']); + } + // Since /ping otherwise complains about missing default field. + $this->_pingUrl .= '?q=' . $options['default_field'] . ':1'; + + // As of July 2011, the newest release is r60, with Service.php having + // revision 59. Revision 40 is just anything between 22 (old) and that. + $this->newClient = trim(parent::SVN_REVISION, '$ :A..Za..z') > 40; + if ($this->newClient) { + $this->_httpTransport = new SearchApiSolrHttpTransport($this->http_auth); + } + } + + /** + * Central method for making a get operation against this Solr Server. + * + * @see Apache_Solr_Service::_sendRawGet() + */ + protected function _sendRawGet($url, $timeout = FALSE) { + // Little "hack" to allow filter-only queries + // Since "*:*" doesn't work with the dismax query handler, we mustn't set + // "q", to let "q.alt" kick in. However, Apache_Solr_Service::search() will + // always add "q", even if it is empty. Therefore, we delete empty "q" + // parameters here. + $url = preg_replace('/([?&])q=(&|$)/', '$1', $url); + + if ($this->newClient) { + return parent::_sendRawGet($url, $timeout); + } + + list($data, $headers) = $this->_makeHttpRequest($url, 'GET', array(), '', $timeout); + $response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays); + $code = (int) $response->getHttpStatus(); + if ($code != 200) { + $message = $response->getHttpStatusMessage(); + if ($code >= 400 && $code != 403 && $code != 404) { + // Add details, like Solr's exception message. + $message .= $response->getRawResponse(); + } + throw new Exception('"' . $code . '" Status: ' . $message); + } + return $response; + } + + /** + * Central method for making a post operation against this Solr Server. + * + * @see Apache_Solr_Service::_sendRawPost() + */ + protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { + if ($this->newClient) { + return parent::_sendRawPost($url, $rawPost, $timeout, $contentType); + } + + $request_headers = array('Content-Type' => $contentType); + list($data, $headers) = $this->_makeHttpRequest($url, 'POST', $request_headers, $rawPost, $timeout); + $response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays); + $code = (int) $response->getHttpStatus(); + if ($code != 200) { + $message = $response->getHttpStatusMessage(); + if ($code >= 400 && $code != 403 && $code != 404) { + // Add details, like Solr's exception message. + $message .= $response->getRawResponse(); + } + throw new Exception('"' . $code . '" Status: ' . $message); + } + return $response; + } + + + /** + * Call the /admin/ping servlet, to test the connection to the server. + * + * @param $timeout + * maximum time to wait for ping in seconds, -1 for unlimited (default 2). + * @return + * (float) seconds taken to ping the server, FALSE if timeout occurs. + */ + public function ping($timeout = 2) { + if ($this->newClient) { + return parent::ping($timeout); + } + $start = microtime(TRUE); + + if ($timeout <= 0.0) { + $timeout = -1; + } + // Attempt a HEAD request to the solr ping url. + list($data, $headers) = $this->_makeHttpRequest($this->_pingUrl, 'HEAD', array(), NULL, $timeout); + $response = new Apache_Solr_Response($data, $headers); + + if ($response->getHttpStatus() == 200) { + // Add 0.1 ms to the ping time so we never return 0.0. + return microtime(TRUE) - $start + 0.0001; + } + else { + return FALSE; + } + } + + /** + * Helper method for making an HTTP request, without using stupid stuff like + * file_get_contents(). + */ + protected function _makeHttpRequest($url, $method = 'GET', $headers = array(), $content = '', $timeout = FALSE) { + $options = array( + 'headers' => $headers, + 'method' => $method, + 'data' => $content, + ); + + if ($this->http_auth) { + $options['headers']['Authorization'] = $this->http_auth; + } + if ($timeout) { + $options['timeout'] = $timeout; + } + + $result = drupal_http_request($url, $options); + + if (!isset($result->code) || $result->code < 0) { + $result->code = 0; + $result->status_message = 'Request failed'; + $result->protocol = 'HTTP/1.0'; + } + // Additional information may be in the error property. + if (isset($result->error)) { + $result->status_message .= ': ' . check_plain($result->error); + } + + if (!isset($result->data)) { + $result->data = ''; + } + // The headers have to be reformatted for the response class. + $headers[] = "{$result->protocol} {$result->code} {$result->status_message}"; + if (isset($result->headers)) { + foreach ($result->headers as $name => $value) { + $headers[] = "$name: $value"; + } + } + return array($result->data, $headers); + } + + /** + * Convenience function for escaping a field name. + * + * Since field names can only contain one special character, ":", there is no + * need to use the complete escape() method. + * + * @param string $value + * The field name to escape. + * + * @return string + * An escaped string suitable for passing to Solr. + */ + static public function escapeFieldName($value) { + $value = str_replace(':', '\:', $value); + return $value; + } + + /** + * Convenience function for creating phrase syntax from a value. + * + * @param string $value + * The string to convert into a Solr phrase value. + * + * @return string + * A quoted string suitable for passing to Solr. + */ + static public function phrase($value) { + $value = str_replace("\\", "\\\\", $value); + $value = str_replace('"', '\"', $value); + return '"' . $value . '"'; + } + + /** + * Get metadata about the Lucene index. + * + * @param int $num_terms + * Number of 'top terms' to return. + * + * @return Apache_Solr_Response + * A response object containing schema information. + */ + public function getLuke($num_terms = 0) { + if (!isset($this->luke[$num_terms])) { + $url = $this->_constructUrl(self::LUKE_SERVLET, array('numTerms' => "$num_terms", 'wt' => self::SOLR_WRITER)); + $this->luke[$num_terms] = $this->_sendRawGet($url); + } + return $this->luke[$num_terms]; + } + + /** + * Get metadata about fields in the Lucene index. + * + * @return array + * An array of objects, keyed by field name, describing fields on the index. + * + * @see SearchApiSolrConnection::getLuke() + * @see http://wiki.apache.org/solr/LukeRequestHandler + */ + public function getFields() { + return (array) $this->getLuke()->fields; + } + +} diff --git a/solr_field.inc b/solr_field.inc new file mode 100644 index 00000000..6eea13dd --- /dev/null +++ b/solr_field.inc @@ -0,0 +1,185 @@ + 'Indexed', + 'T' => 'Tokenized', + 'S' => 'Stored', + 'M' => 'Multivalued', + 'V' => 'TermVector Stored', + 'o' => 'Store Offset With TermVector', + 'p' => 'Store Position With TermVector', + 'O' => 'Omit Norms', + 'L' => 'Lazy', + 'B' => 'Binary', + 'C' => 'Compressed', + 'f' => 'Sort Missing First', + 'l' => 'Sort Missing Last', + ); + + /** + * @var stdclass + * The original field object. + */ + protected $field; + + /** + * @var array + * An array of schema properties for this field. This will be a subset of + * the SearchApiSolrField::schemaLabels array. + */ + protected $schema; + + /** + * Constructor. + * + * @param stdClass $field + * A field object from Solr's "Luke" servlet. + */ + public function __construct($field) { + $this->field = $field; + } + + /** + * Get the type of the Solr field, according to the Solr schema. + * + * Note that field types like "text", "boolean", and "date" are conventions, + * but their presence and behavior are entirely determined by the particular + * schema.xml file used by a Solr core. + * + * @return string + * The type of the Solr field. + */ + public function getType() { + return $this->field->type; + } + + /** + * Get an array of field properties. + * + * @return array + * An array of properties describing the solr schema. The array keys are + * single-character codes, and the values are human-readable labels. This + * will be a subset of the SearchApiSolrField::schemaLabels array. + */ + public function getSchema() { + if (!isset($this->schema)) { + foreach (str_split(str_replace('-', '', $this->field->schema)) as $key) { + $this->schema[$key] = isset(self::$schemaLabels[$key]) ? self::$schemaLabels[$key] : $key; + } + } + return $this->schema; + } + + /** + * Get the "dynamic base" of this field. + * + * This typically looks like 'ss_*, and is used to aggregate fields based on + * "hungarian" naming conventions. + * + * @return string + * The mask describing the solr aggregate field, if there is one. + */ + public function getDynamicBase() { + return isset($this->field->dynamicBase) ? $this->field->dynamicBase : NULL; + } + + /** + * Determine whether this field may be suitable for use as a key field. + * + * Unfortunately, it seems like the best way to find an actual uniqueKey field + * according to Solr is to examine the Solr core's schema.xml. + * + * @return boolean + * Whether the field is suitable for use as a key. + */ + public function isPossibleKey() { + return !$this->getDynamicBase() + && !in_array($this->getType(), array('boolean', 'date', 'text')) + && $this->isStored() + && !$this->isMultivalued(); + } + + /** + * Determine whether a field is suitable for sorting. + * + * In order for a field to yield useful sorted results in Solr, it must be + * indexed, not multivalued, and not tokenized. It's ok if a field is + * tokenized and yields only one token, but there's no general way to check + * for that. + * + * @return boolean + * Whether the field is suitable for sorting. + */ + public function isSortable() { + return $this->isIndexed() + && !$this->isMultivalued() + && !$this->isTokenized(); + } + + /** + * The following functions return information about specific properties of this field. + * + * @return boolean + */ + public function isIndexed() { + $this->getSchema(); + return isset($this->schema['I']); + } + public function isTokenized() { + $this->getSchema(); + return isset($this->schema['T']); + } + public function isStored() { + $this->getSchema(); + return isset($this->schema['S']); + } + public function isMultivalued() { + $this->getSchema(); + return isset($this->schema['M']); + } + public function isTermVectorStored() { + $this->getSchema(); + return isset($this->schema['V']); + } + public function isStoreOffsetWithTermVector() { + $this->getSchema(); + return isset($this->schema['o']); + } + public function isStorePositionWithTermVector() { + $this->getSchema(); + return isset($this->schema['p']); + } + public function isOmitNorms() { + $this->getSchema(); + return isset($this->schema['O']); + } + public function isLazy() { + $this->getSchema(); + return isset($this->schema['L']); + } + public function isBinary() { + $this->getSchema(); + return isset($this->schema['B']); + } + public function isCompressed() { + $this->getSchema(); + return isset($this->schema['C']); + } + public function isSortMissingFirst() { + $this->getSchema(); + return isset($this->schema['f']); + } + public function isSortMissingLast() { + $this->getSchema(); + return isset($this->schema['l']); + } +}