├── .docker └── entrypoint.sh ├── .github └── workflows │ ├── linux-tests.yml │ └── windows-tests.yml ├── .gitignore ├── .travis.yml ├── CREDITS ├── Dockerfile ├── LICENSE ├── NEWS ├── README.ABOUT_SOLR_EXTENSION ├── README.CONTRIBUTORS ├── README.INSTALLATION ├── README.MEMORY_ALLOCATION ├── README.MIGRATION-2.0-TO-2.1.md ├── README.RELEASE_CHECKLIST ├── README.SUBMITTING_CONTRIBUTIONS ├── README.md ├── TODO ├── config.m4 ├── config.w32 ├── docker-compose.yml ├── docs └── documentation.php ├── examples ├── bootstrap.php ├── facet_001.php ├── facet_002.php ├── files │ ├── document.1.xml │ ├── document.2.xml │ └── response_xml.1.xml ├── solrclient_001_adddocument_01.php ├── solrclient_002_adddocument_02.php ├── solrclient_002_adddocument_03_child_docs.php ├── solrclient_003_adddocuments_01.php ├── solrclient_004_adddocuments_02.php ├── solrclient_005_optimize.php ├── solrclient_006_commit.php ├── solrclient_007_query.php ├── solrclient_008_query_lucene.php ├── solrclient_009_query_parsemode.php ├── solrclient_010_getbyid.php ├── solrclient_011_getbyids.php ├── solrclient_012_system.php ├── solrdismaxquery_001.php ├── solrdocument_001.php ├── solrdocument_002.php ├── solrdocument_003.php ├── solrdocument_004.php ├── solrinputdocument_update_partial.php ├── solrobject_001.php ├── solrobject_002.php ├── solrobject_003.php ├── solrobject_004.php ├── solrobject_005.php ├── solrquery_001.php ├── solrquery_002_facet.php ├── solrquery_003_date_facet.php ├── solrquery_004_highlight.php ├── solrquery_005_stats.php ├── solrquery_006_mlt.php ├── solrquery_007_terms.php ├── solrquery_008_facetquery.php ├── solrquery_009_grouping.php ├── solrquery_010_collapse.php ├── solrquery_011_expand.php ├── solrutils_001_digestxmlresponse.php ├── solrutils_002_escapequerychars.php ├── terms_001.php ├── terms_002.php ├── terms_003.php ├── test.config.php ├── update_stream_file.php └── update_stream_payload.php ├── package.xml ├── pecl-compat ├── README.md ├── compat.h └── src │ ├── common.h │ ├── misc.h │ ├── zend_hash.h │ └── zend_string.h ├── scripts ├── gen_travis_yml.php └── test-coverage.sh ├── solr.dsp ├── src ├── php_solr.c ├── php_solr.h ├── php_solr_api.h ├── php_solr_client.c ├── php_solr_collapse_function.c ├── php_solr_dismax_query.c ├── php_solr_dismax_query.h ├── php_solr_document.c ├── php_solr_exception.c ├── php_solr_extract.c ├── php_solr_input_document.c ├── php_solr_object.c ├── php_solr_params.c ├── php_solr_query.c ├── php_solr_response.c ├── php_solr_utils.c ├── php_solr_version.h ├── solr_constants.h ├── solr_functions_client.c ├── solr_functions_debug.c ├── solr_functions_document.c ├── solr_functions_helpers.c ├── solr_functions_params.c ├── solr_functions_response.c ├── solr_macros.h ├── solr_string.c ├── solr_string.h └── solr_types.h ├── tests ├── 000.solr_int_arg.phpt ├── 000.solr_int_arg_strict.phpt ├── 000.solr_server_compat.phpt ├── 000.solrclient_ping.phpt ├── 001.solrclient_addDocument.phpt ├── 001.solrclient_addDocument_partial.phpt ├── 002.solrclient_addDocuments.phpt ├── 003.solrclient_addDocument_no_overwrite.phpt ├── 003.solrclient_addDocuments_commitwithin.phpt ├── 003.solrclient_options.phpt ├── 004.solrclient_query_response.phpt ├── 004.solrclient_query_terms.phpt ├── 005.solrclient_query_error.phpt ├── 006.solrclient_system.phpt ├── 007.solrclient_deleteById.phpt ├── 007.solrclient_deleteByIds.phpt ├── 008.solrclient_commit.phpt ├── 008.solrclient_rollback.phpt ├── 009.solrclient_optimize.phpt ├── 010.solrclient_getOptions.phpt ├── 011.solrclient_phps_response.phpt ├── 012.solrclient_getById.phpt ├── 013.solrclient_getByIds.phpt ├── 014.solrclient_addDocument_nested_document.phpt ├── 015.solrclient_addDocuments_nested_document.phpt ├── 016.solrclient_request.phpt ├── 016.solrclient_sendUpdateStream_bin.phpt ├── 016.solrclient_sendUpdateStream_file.phpt ├── 017.solrclient_deletebyqueries.phpt ├── 017.solrclient_deletebyquery.phpt ├── 017.solrclient_threads.phpt ├── 018.solrclient_setservlet.phpt ├── 019.solrclient_clone.phpt ├── 019.solrclient_getdebug.phpt ├── 019.solrclient_serialize.phpt ├── 020.solrdocument_adding_fields.phpt ├── 020.solrdocument_update_field.phpt ├── 021.solrdocument_iterator.phpt ├── 022.solrdocument_getInputDocument.phpt ├── 023.solrdocument_merge.phpt ├── 023.solrdocument_merge_no_overwrite.phpt ├── 024.solrdocument_child_fetch.phpt ├── 025.solrdocument_haschilddocuments.phpt ├── 026.solrdocument_getchilddocscount.phpt ├── 027.solrdocument_getinputdocument_children.phpt ├── 028.solrdocument_clone.phpt ├── 029.solrdocument_serialize.phpt ├── 029.solrdocument_serialize_php81.phpt ├── 030.solrdocument_magic.phpt ├── 031.solrdocument_clear.phpt ├── 032.solrdocument_fieldexists.phpt ├── 033.solrdocument_sort.phpt ├── 034.solrdocument_deletefield.phpt ├── 035.solrdocument_getfieldnames.phpt ├── 036.solrdocument_array_access.phpt ├── 037.solrdocument_getfield.phpt ├── 040.solrobject_xmlresponse.phpt ├── 041.solrobject_illegal_operation.phpt ├── 042.solrobject_magic_property.phpt ├── 043.solrobject_magic_properties.phpt ├── 044.solrobject_dimension_access_properties.phpt ├── 045.solrobject_array_access.phpt ├── 046.solrobject_getpropertynames.phpt ├── 047.solrobject_offsetExists.phpt ├── 050.solrinputdocument_addchilddocument_01.phpt ├── 050.solrinputdocument_addchilddocument_02_error.phpt ├── 051.solrinputdocument_getchilddocuments.phpt ├── 052.solrinputdocument_haschilddocuments.phpt ├── 053.solrinputdocument_getchilddocumentscount.phpt ├── 054.solrinputdocument_addchilddocuments.phpt ├── 055.solrinputdocument_serialization.phpt ├── 056.solrinputdocument_toArray.phpt ├── 057.solrinputdocument_clone.phpt ├── 058.solrinputdocument_deletefield.phpt ├── 059.solrinputdocument_clear.phpt ├── 059.solrinputdocument_fieldexists.phpt ├── 059.solrinputdocument_getboost.phpt ├── 059.solrinputdocument_getfield.phpt ├── 059.solrinputdocument_getfieldcount.phpt ├── 059.solrinputdocument_getfieldnames.phpt ├── 059.solrinputdocument_merge.phpt ├── 059.solrinputdocument_set_getfieldboost.phpt ├── 059.solrinputdocument_setversion.phpt ├── 059.solrinputdocument_sort.phpt ├── 060.solrquery_comon_query_params.phpt ├── 061.solrquery_simpleFacetParameters.phpt ├── 062.solrquery_date_facet_parameters.phpt ├── 063.solrquery_HighlightingParameters.phpt ├── 064.solrquery_StatsComponent.phpt ├── 065.solrquery_MoreLikeThis.phpt ├── 066.solrquery_TermsComponent.phpt ├── 067.solrquery__construct.phpt ├── 068.solrquery_parameters_error.phpt ├── 069.solrquery_GroupParameters.phpt ├── 070.solrquery_collapse.phpt ├── 071.solrquery_collapse_exception.phpt ├── 072.solrquery_expand.phpt ├── 080.solrutils_escapequerychars.phpt ├── 081.solrutils_digest_json_response.phpt ├── 082.solrutils_getsolrversion.phpt ├── 083.solrutils_getsolrstats.phpt ├── 084.solrutils_queryphrase.phpt ├── 090.solrserverexception_xml.phpt ├── 091.solrserverexception_json.phpt ├── 092.solrserverexception_php.phpt ├── 100.solrresponse_json.phpt ├── 101.solrresponse_parseMode.phpt ├── 102.solrresponse_phps.phpt ├── 103.solrresponse_get_array_response.phpt ├── 104.solrresponse_get_response_maxscore.phpt ├── 105.solrresponse_child_doc_response.phpt ├── 106.solrresponse_child_doc_response_solrdoc.phpt ├── 107.solrresponse_getrawresponseheaders.phpt ├── 108.solrresponse_getdigestedresponse.phpt ├── 109.solrresponse_gethttpstatus.phpt ├── 109.solrresponse_getrequesturl.phpt ├── 109.solrresponse_success.phpt ├── 110.solrdismaxquery.phpt ├── 111.solrdismaxquery_boostquery.phpt ├── 112.solrdismaxquery_query_parser.phpt ├── 113.solrdismaxquery_bigramfields.phpt ├── 114.solrdismaxquery_trigramfields.phpt ├── 115.solrdismaxquery_userfields.phpt ├── 116.solrdismaxquery_boostfunction.phpt ├── 130.parameters_simple_list_separator.phpt ├── 150.solrcollapsefunction.phpt ├── 151.solrcollapsefunction_illegal_operations.phpt ├── 160.solr_update_document_block.phpt ├── 180.solrdocumentfield_construct.phpt ├── 181.solrdocumentfield_write_property.phpt ├── 182.solrdocumentfield_unset_property.phpt ├── 190.solrparams_setparam.phpt ├── 191.solrparams_addparam.phpt ├── 192.solrparams_getparam.phpt ├── 193.solrparams_getparams.phpt ├── 194.solrparams_getpreparedparams.phpt ├── 195.solrparams_tostring.phpt ├── 196.solrparams_serialize.phpt ├── 196.solrparams_serialize_php81.phpt ├── 197.solrparams_unserialize.phpt ├── 198.solrparams_clone.phpt ├── 200.solrextractrequest_clone.phpt ├── 201.solrextractrequest_serialize.phpt ├── 202.solrdocument_new_serialize.phpt ├── 203.solrquery_strict_types.phpt ├── 204.solrutils_empty_escapequerychars.phpt ├── bootstrap.inc ├── bug_59511_error.phpt ├── bug_61836_error.phpt ├── bug_67394.phpt ├── bug_68179.phpt ├── bug_68181.phpt ├── bug_69156.phpt ├── bug_70482.phpt ├── bug_70495.phpt ├── bug_70496.phpt ├── bug_72033.phpt ├── bug_72740.phpt ├── bug_unknown.phpt ├── docker │ ├── Dockerfile │ └── collections │ │ ├── collection1.json │ │ └── metal_store.json ├── files │ ├── bug67394.json │ ├── bug67394.xml │ ├── extract_file.1.pdf │ ├── response_xml.1.xml │ ├── response_xml.2.xml │ ├── response_xml.3.xml │ ├── response_xml.4.xml │ ├── sample.html │ ├── sample_1.xlsx │ └── solr-word.pdf ├── skip.if.server_not_configured.inc └── test.config.inc └── travis └── pecl ├── LICENSE ├── Makefile ├── README.md ├── check-packagexml.php ├── cppcheck.suppressions ├── fetch-master.sh ├── gen-matrix.php ├── php-version-url-dist.php ├── php-version-url-qa.php └── php-version.php /.docker/entrypoint.sh: -------------------------------------------------------------------------------- 1 | pecl package package.xml 2 | pecl install ./solr-2.8.1.tgz 3 | echo "extension=solr.so" > /usr/local/etc/php/conf.d/solr.ini 4 | php -m | grep solr 5 | bash 6 | -------------------------------------------------------------------------------- /.github/workflows/linux-tests.yml: -------------------------------------------------------------------------------- 1 | name: Linux (tests) 2 | on: 3 | pull_request: 4 | branches: 5 | - "master" 6 | push: 7 | tags: 8 | - "*" 9 | branches: 10 | - "master" 11 | 12 | jobs: 13 | test: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v3 22 | - name: Install dependencies 23 | run: | 24 | sudo apt-get update 25 | sudo apt-get install -y libcurl4-openssl-dev 26 | - name: Install PHP ${{ matrix.php }} 27 | uses: shivammathur/setup-php@v2 28 | with: 29 | php-version: ${{ matrix.php }} 30 | extensions: curl, json 31 | # For PHP 7.x we need to specify a full path to json.so, for PHP 8.x the JSON module is compiled into the core binary 32 | - name: Set TEST_PHP_ARGS 33 | if: ${{ startsWith(matrix.php, '7.') }} 34 | run: echo "TEST_PHP_ARGS=-d extension=$(php -i | grep extension_dir | cut -d " " -f 5 | head -n 1)/json.so" >> $GITHUB_ENV 35 | - name: Build PHP extension 36 | run: | 37 | phpize 38 | ./configure 39 | make 40 | # Run tests (we add the -q flag to skip the "send report?" question at the end) 41 | - name: Run tests 42 | env: 43 | SOLR_SERVER_CONFIGURED: 1 44 | run: TEST_PHP_ARGS="$TEST_PHP_ARGS -q" make test 45 | 46 | services: 47 | solr: 48 | image: omars44/pecl-solr-test:latest 49 | ports: 50 | - 8983:8983 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # General Ignores 2 | *~ 3 | .#* 4 | *. 5 | *.slo 6 | *.mk 7 | *.mem 8 | *.gcda 9 | *.gcno 10 | *.la 11 | *.lo 12 | *.loT 13 | *.o 14 | *.a 15 | *.ncb 16 | *.opt 17 | *.plg 18 | *swp 19 | *.patch 20 | *.tgz 21 | *.tar.gz 22 | *.tar.bz2 23 | .FBCIndex 24 | .FBCLockFolder 25 | .deps 26 | .libs 27 | *.dep 28 | phpt.* 29 | core 30 | dynlib.m4 31 | Debug 32 | Debug_TS 33 | Makefile 34 | Makefile.fragments 35 | Makefile.objects 36 | Makefile.global 37 | Release 38 | Release_TS 39 | Release_TSDbg 40 | Release_TS_inline 41 | Release_inline 42 | _libs 43 | acconfig.h 44 | aclocal.m4 45 | acinclude.m4 46 | autom4te.cache 47 | bsd_converted 48 | buildconf.stamp 49 | buildmk.stamp 50 | confdefs.h 51 | config.h 52 | config.guess 53 | config.cache 54 | config.h.in 55 | config.log 56 | config.nice 57 | config.nice.bat 58 | config.status 59 | config.sub 60 | config_vars.mk 61 | configuration-parser.c 62 | configuration-parser.h 63 | configuration-parser.output 64 | configuration-scanner.c 65 | configure 66 | configure.bat 67 | configure.js 68 | configure.n 69 | configure.ac 70 | conftest 71 | conftest.c 72 | debug.log 73 | diff 74 | generated_lists 75 | include 76 | install-sh 77 | internal_functions.c 78 | lcov_data 79 | lcov_html 80 | libs 81 | libtool 82 | meta_cc 83 | meta_ccld 84 | missing 85 | mkinstalldirs 86 | modules 87 | shlibtool 88 | .cproject 89 | .project 90 | .settings 91 | 92 | # Test specific Ignores 93 | tests/*.diff 94 | tests/*.out 95 | tests/*.php 96 | tests/*.exp 97 | tests/*.log 98 | tests/*.sh 99 | run-tests.php 100 | run-tests.sh 101 | tmp-php.ini 102 | 103 | # Extension specifc ignores 104 | configure.in 105 | ltmain.sh 106 | ltmain.sh.backup 107 | libs.mk 108 | build 109 | scan_makefile_in.awk 110 | Makefile.global 111 | acinclude.m4 112 | config.sub 113 | 114 | # Debug Specific Ignores 115 | debug/ 116 | .autotools 117 | 118 | # coverage 119 | report/ 120 | coverage.info 121 | 122 | .idea 123 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | solr 2 | Israel Koko Ekpo 3 | Omar Shaban 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.4-cli 2 | 3 | RUN apt update && apt install libxml2-dev libcurl4-gnutls-dev --yes 4 | 5 | RUN apt install vim --yes 6 | 7 | COPY .docker/entrypoint.sh /opt/ 8 | 9 | RUN mkdir /opt/solr2 10 | 11 | COPY ./ /opt/solr2 12 | 13 | WORKDIR /opt/solr2 14 | 15 | ENTRYPOINT ["sh","/opt/entrypoint.sh"] 16 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php/pecl-search_engine-solr/9a8452d7ddc06f18f97752b34198d9b36499d29d/NEWS -------------------------------------------------------------------------------- /README.MIGRATION-2.0-TO-2.1.md: -------------------------------------------------------------------------------- 1 | Migrating from PECL Solr 2.0 to PECL Solr 2.1 2 | ============================================= 3 | 4 | If you are using json Response Writer: 5 | Version 2.0 and 1.* 6 | ```php 7 | $result = $client->query($query); 8 | $result->getResponse(); 9 | // ^ SolrResponse::getResponse() returns an array 10 | ``` 11 | 12 | Version 2.1: 13 | ```php 14 | SolrResponse::getResponse() returns a SolrObject 15 | ``` 16 | 17 | You can still get an array from the SolrResponse object but by using SolrResponse::getArrayResponse() 18 | -------------------------------------------------------------------------------- /README.RELEASE_CHECKLIST: -------------------------------------------------------------------------------- 1 | Release Checklist 2 | ================================================================== 3 | 0. Make sure version information is updated in php_solr_version.h and package.xml 4 | 5 | 1. Checkout release candidate source code from SVN, then compile and install. 6 | 7 | svn co http://svn.php.net/repository/pecl/solr/trunk pecl-solr 8 | 9 | cd pecl-solr 10 | 11 | phpize 12 | 13 | ./configure 14 | 15 | make 16 | 17 | make install 18 | 19 | Adjust the php.ini files as needed 20 | 21 | 2. Make sure to compile and run make test for both debug and ZTS/non-ZTS modes in target php versions. 22 | 23 | 3. If successful, document all the changes in the package.xml file and also in the php documentation and then create an svn tag 24 | 25 | svn copy http://svn.php.net/repository/pecl/solr/trunk http://svn.php.net/repository/pecl/solr/tags/release_A_B_C 26 | 27 | 4. Create the release tarball 28 | 29 | pear package 30 | 31 | 5. Upload the tarball to PECL 32 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2014-02-17 2 | 3 | ================================================================================ 4 | Features and things to do in the library 5 | ================================================================================ 6 | 7 | - Set up php.ini entries for default servlet values. 8 | 9 | This will allow developers to set custom values for the servlets. 10 | 11 | - Ability to send custom requests to Solr (custom url, custom request contents) 12 | 13 | - Ability to add files (pdf, office documents, etc) 14 | 15 | - Ensure the SolrQuery::getFields(), SolrQuery::getFacets() et all returns an array consistently. 16 | 17 | - More frequent compilations of releases for PHP 5.3 on Windows 18 | 19 | - Support JSON Writer 20 | 21 | - Support Solr Spatial Features Natively 22 | 23 | - Introduce SolrServerException to parse and return Solr Server error messages instead of dumping xml docs 24 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2.1' 2 | 3 | services: 4 | solr: 5 | build: tests/docker/ 6 | ports: 7 | - "8983:8983" 8 | -------------------------------------------------------------------------------- /examples/bootstrap.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $query = new SolrQuery('*:*'); 17 | 18 | $query->setFacet(true); 19 | 20 | $query->addFacetField('cat')->addFacetField('name')->setFacetMinCount(2); 21 | 22 | $updateResponse = $client->query($query); 23 | 24 | $response_array = $updateResponse->getResponse(); 25 | 26 | $facet_data = $response_array->facet_counts->facet_fields; 27 | 28 | print_r($facet_data); 29 | -------------------------------------------------------------------------------- /examples/facet_002.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $query = new SolrQuery('*:*'); 17 | 18 | $query->setFacet(true); 19 | 20 | $query->addFacetField('cat')->addFacetField('name')->setFacetMinCount(2); 21 | 22 | $query->setFacetMinCount(4, 'name'); 23 | 24 | $updateResponse = $client->query($query); 25 | 26 | $response_array = $updateResponse->getResponse(); 27 | 28 | $facet_data = $response_array->facet_counts->facet_fields; 29 | 30 | print_r($facet_data); 31 | -------------------------------------------------------------------------------- /examples/files/document.1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 0 6 | 7 | on 8 | id:1 AND type:collection 9 | xml 10 | 2.2 11 | 12 | 13 | 14 | 15 | 16 | _LBL_COLLECTION 17 | collection 18 | 19 | 1 20 | Accueil 21 | 1collectionAccueil 22 | Accueil 23 | collection 24 | collection_1 25 | /accueil 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/files/document.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 0 6 | 7 | on 8 | id:1 AND type:collection 9 | xml 10 | 2.2 11 | 12 | 13 | 14 | 1 15 | 2 16 | 17 | on 18 | id:1 AND type:collection 19 | xml 20 | 2.2 21 | 22 | 23 | 24 | 25 | 26 | _LBL_COLLECTION 27 | collection 28 | 29 | 1 30 | Accueil 31 | 1collectionAccueil 32 | Accueil 33 | collection 34 | collection_1 35 | /accueil 36 | /accueil 37 | /accueil 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /examples/solrclient_001_adddocument_01.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $doc = new SolrInputDocument(); 17 | 18 | $doc->addField('id', 334455); 19 | $doc->addField('cat', 'Software'); 20 | $doc->addField('cat', 'Lucene'); 21 | 22 | $updateResponse = $client->addDocument($doc); 23 | 24 | print_r($updateResponse->getResponse()); 25 | 26 | /* you will have to commit changes to be written if you didn't use $commitWithin */ 27 | $client->commit(); 28 | -------------------------------------------------------------------------------- /examples/solrclient_002_adddocument_02.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $doc = new SolrInputDocument(); 17 | 18 | $doc->addField('id', 334455); 19 | $doc->addField('cat', 'Software'); 20 | $doc->addField('cat', 'Lucene'); 21 | 22 | // No need to call commit() because $commitWithin is passed, so Solr Server will auto commit within 10 seconds 23 | $updateResponse = $client->addDocument($doc, false, 10000); 24 | 25 | print_r($updateResponse->getResponse()); 26 | -------------------------------------------------------------------------------- /examples/solrclient_002_adddocument_03_child_docs.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_STORE_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $product = new SolrInputDocument(); 17 | 18 | $product->addField('id', 'black'); 19 | $product->addField('cat', 'tshirt'); 20 | $product->addField('cat', 'polo'); 21 | $product->addField('content_type', 'product'); 22 | 23 | $small = new SolrInputDocument(); 24 | $small->addField('id', 'TS-BLK-S'); 25 | $small->addField('content_type', 'sku'); 26 | $small->addField('size', 'S'); 27 | $small->addField('inventory', 100); 28 | 29 | $medium = new SolrInputDocument(); 30 | $medium->addField('id', 'TS-BLK-M'); 31 | $medium->addField('content_type', 'sku'); 32 | $medium->addField('size', 'M'); 33 | $medium->addField('inventory', 200); 34 | 35 | $large = new SolrInputDocument(); 36 | $large->addField('id', 'TS-BLK-L'); 37 | $large->addField('content_type', 'sku'); 38 | $large->addField('size', 'L'); 39 | $large->addField('inventory', 300); 40 | 41 | // add child documents 42 | $product->addChildDocument($small); 43 | $product->addChildDocument($medium); 44 | $product->addChildDocument($large); 45 | // or 46 | // $skus = [$small, $medium, $large]; 47 | // $product->addChildDocuments($skus); 48 | 49 | // add product document to the index 50 | $updateResponse = $client->addDocument( 51 | $product, 52 | true, // overwrite if the document exists 53 | 10000 // commit within 10 seconds 54 | ); 55 | 56 | print_r($updateResponse->getResponse()); 57 | 58 | /* OUTPUT SIMILAR TO: 59 | SolrObject Object 60 | ( 61 | [responseHeader] => SolrObject Object 62 | ( 63 | [status] => 0 64 | [QTime] => 5 65 | ) 66 | ) 67 | */ 68 | -------------------------------------------------------------------------------- /examples/solrclient_003_adddocuments_01.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $doc = new SolrInputDocument(); 17 | 18 | $doc->addField('id', 334455); 19 | $doc->addField('cat', 'Software'); 20 | $doc->addField('cat', 'Lucene'); 21 | 22 | $doc2 = clone $doc; 23 | 24 | $doc2->deleteField('id'); 25 | $doc2->addField('id', 334456); 26 | 27 | $docs = array($doc, $doc2); 28 | 29 | $updateResponse = $client->addDocuments($docs); 30 | 31 | /* you will have to commit changes to be written if you didn't use $commitWithin */ 32 | $client->commit(); 33 | 34 | print_r($updateResponse->getResponse()); 35 | -------------------------------------------------------------------------------- /examples/solrclient_004_adddocuments_02.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $doc = new SolrInputDocument(); 17 | 18 | $doc->addField('id', 334455); 19 | $doc->addField('cat', 'Software'); 20 | $doc->addField('cat', 'Lucene'); 21 | 22 | $doc2 = clone $doc; 23 | 24 | $doc2->deleteField('id'); 25 | $doc2->addField('id', 334456); 26 | 27 | $docs = array($doc, $doc2); 28 | 29 | $updateResponse = $client->addDocuments($docs, true, 1024); 30 | 31 | print $updateResponse->getRawRequest(); 32 | -------------------------------------------------------------------------------- /examples/solrclient_005_optimize.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $update_response = $client->optimize(4, false, false); 17 | 18 | $response = $update_response->getRawRequest(); 19 | 20 | print_r($response); 21 | -------------------------------------------------------------------------------- /examples/solrclient_006_commit.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $update_response = $client->commit(true, false, false); 17 | 18 | $response = $update_response->getRawRequest(); 19 | 20 | print_r($response); 21 | -------------------------------------------------------------------------------- /examples/solrclient_007_query.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $query = new SolrQuery(); 17 | 18 | $query->setQuery('lucene'); 19 | 20 | $query->setStart(0); 21 | 22 | $query->setRows(50); 23 | 24 | $query->addField('cat')->addField('features')->addField('id')->addField('timestamp'); 25 | 26 | $query_response = $client->query($query); 27 | 28 | $response = $query_response->getResponse(); 29 | 30 | print_r($response); 31 | -------------------------------------------------------------------------------- /examples/solrclient_008_query_lucene.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $query = new SolrQuery(); 17 | 18 | $query->setQuery('manu:"Apple Computer Inc." OR text:apple'); 19 | 20 | $query->setStart(0); 21 | 22 | $query->setRows(50); 23 | 24 | $query->addField('cat')->addField('features')->addField('id')->addField('timestamp'); 25 | 26 | $query_response = $client->query($query); 27 | 28 | $response = $query_response->getResponse(); 29 | 30 | print_r($response); 31 | -------------------------------------------------------------------------------- /examples/solrclient_009_query_parsemode.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $query = new SolrQuery(); 17 | 18 | $query->setQuery('lucene'); 19 | 20 | $query->setStart(0); 21 | 22 | $query->setRows(50); 23 | 24 | $query->addField('cat')->addField('features')->addField('id')->addField('timestamp'); 25 | 26 | $query_response = $client->query($query); 27 | 28 | $query_response->setParseMode(SolrQueryResponse::PARSE_SOLR_DOC); 29 | 30 | $response = $query_response->getResponse(); 31 | 32 | print_r($response); 33 | -------------------------------------------------------------------------------- /examples/solrclient_010_getbyid.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | $response = $client->getById('GB18030TEST'); 16 | print_r($response->getResponse()); 17 | -------------------------------------------------------------------------------- /examples/solrclient_011_getbyids.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | $response = $client->getByIds(['GB18030TEST', '6H500F0']); 16 | 17 | print_r($response->getResponse()); 18 | -------------------------------------------------------------------------------- /examples/solrclient_012_system.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH, 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $query_response = $client->system(); 17 | 18 | $response = $query_response->getResponse(); 19 | 20 | print_r($response); 21 | -------------------------------------------------------------------------------- /examples/solrdismaxquery_001.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 7 | 'login' => SOLR_SERVER_USERNAME, 8 | 'password' => SOLR_SERVER_PASSWORD, 9 | 'port' => SOLR_SERVER_PORT, 10 | 'path' => SOLR_SERVER_PATH, 11 | ); 12 | 13 | $client = new SolrClient($options); 14 | 15 | $disMaxQuery = new SolrDisMaxQuery(); 16 | 17 | $disMaxQuery->setStart(0)->setQuery('solr')->setTimeAllowed(500)->setRows(17); 18 | 19 | $disMaxQuery->addSortField('price', 0); 20 | 21 | $disMaxQuery 22 | ->setQueryAlt('*:*')->addQueryField('text', 1.5) 23 | ->addQueryField('title', 5) 24 | ->addBoostQuery('cat', 'electronics', 2) 25 | ->setQueryPhraseSlop(1) 26 | ->setBigramPhraseSlop(3) 27 | ->addBigramPhraseField('text', 2.5) 28 | ->addBigramPhraseField('type', 3, 4) 29 | ->setTrigramPhraseFields('content^0.5 anchor~4^1.5 title^1.2 site^1.5') 30 | ; 31 | 32 | $queryResponse = $client->query($disMaxQuery); 33 | 34 | $response = $queryResponse->getResponse(); 35 | 36 | if($response->response->numFound > 0) { 37 | $docs = $response->response->docs; 38 | print_r($docs); 39 | } else { 40 | echo "No Documents Found".PHP_EOL; 41 | } 42 | -------------------------------------------------------------------------------- /examples/solrdocument_001.php: -------------------------------------------------------------------------------- 1 | addField('id', 1123); 8 | 9 | $doc->features = "PHP Client Side"; 10 | $doc->features = "Fast development cycles"; 11 | 12 | $doc['cat'] = 'Software'; 13 | $doc['cat'] = 'Custom Search'; 14 | $doc->cat = 'Information Technology'; 15 | 16 | print_r($doc->toArray()); 17 | 18 | ?> 19 | -------------------------------------------------------------------------------- /examples/solrdocument_002.php: -------------------------------------------------------------------------------- 1 | addField('id', 1123); 8 | 9 | $doc->features = "PHP Client Side"; 10 | $doc->features = "Fast development cycles"; 11 | 12 | $doc['cat'] = 'Software'; 13 | $doc['cat'] = 'Custom Search'; 14 | $doc->cat = 'Information Technology'; 15 | 16 | foreach ($doc as $fieldname => $fieldvalues) 17 | { 18 | print "$fieldname\n"; 19 | 20 | print_r($fieldvalues); 21 | } 22 | 23 | ?> 24 | -------------------------------------------------------------------------------- /examples/solrdocument_003.php: -------------------------------------------------------------------------------- 1 | addField('id', 1123); 8 | 9 | $doc->features = "PHP Client Side"; 10 | $doc->features = "Fast development cycles"; 11 | 12 | $doc['cat'] = 'Software'; 13 | $doc['cat'] = 'Custom Search'; 14 | $doc->cat = 'Information Technology'; 15 | 16 | 17 | $input_doc = $doc->getInputDocument(); 18 | 19 | var_dump(get_class($input_doc)); 20 | 21 | ?> 22 | -------------------------------------------------------------------------------- /examples/solrdocument_004.php: -------------------------------------------------------------------------------- 1 | addField('id', 1123); 10 | 11 | $doc->features = "PHP Client Side"; 12 | $doc->features = "Fast development cycles"; 13 | 14 | $doc['cat'] = 'Software'; 15 | $doc['cat'] = 'Custom Search'; 16 | $doc->cat = 'Information Technology'; 17 | 18 | $second_doc->addField('cat', 'Lucene Search'); 19 | 20 | $second_doc->merge($doc, true); 21 | 22 | print_r($second_doc->toArray()); 23 | 24 | 25 | ?> 26 | -------------------------------------------------------------------------------- /examples/solrinputdocument_update_partial.php: -------------------------------------------------------------------------------- 1 | addField('id', 'my_long_doc_id'); 5 | $doc->updateField('field1', SolrInputDocument::UPDATE_MODIFIER_ADD, 'newly added value'); 6 | $doc->updateField('field1', SolrInputDocument::UPDATE_MODIFIER_REMOVE, 'remove me please'); 7 | $doc->updateField('field3_i', SolrInputDocument::UPDATE_MODIFIER_INC, 5); 8 | $doc->updateField('field2_s', SolrInputDocument::UPDATE_MODIFIER_SET, 'updated string'); 9 | $doc->updateField('field1', SolrInputDocument::UPDATE_MODIFIER_REMOVEREGEX, '[\d]{2}/[\d]{2}/[\d]{4}'); 10 | 11 | 12 | 13 | $response = $client->addDocument($doc); 14 | $client->commit(); -------------------------------------------------------------------------------- /examples/solrobject_001.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /examples/solrobject_002.php: -------------------------------------------------------------------------------- 1 | email = "iekpo@php.net"; 8 | 9 | } catch (Exception $e) { 10 | 11 | var_dump($e->getCode()); 12 | 13 | var_dump($e->getMessage()); 14 | } 15 | 16 | var_dump($solrObject->getPropertyNames()); 17 | ?> 18 | -------------------------------------------------------------------------------- /examples/solrobject_003.php: -------------------------------------------------------------------------------- 1 | system->threadDump->thread->stackTrace); 10 | 11 | ?> 12 | -------------------------------------------------------------------------------- /examples/solrobject_004.php: -------------------------------------------------------------------------------- 1 | responseHeader); 10 | 11 | $system = $solrObject->system; 12 | 13 | print_r($header); 14 | 15 | print_r($system); 16 | 17 | ?> 18 | -------------------------------------------------------------------------------- /examples/solrobject_005.php: -------------------------------------------------------------------------------- 1 | 18 | -------------------------------------------------------------------------------- /examples/solrquery_001.php: -------------------------------------------------------------------------------- 1 | setParam('a', 1); 6 | $query->setParam('b', 2); 7 | $query->setParam('c', 3); 8 | 9 | $query->setStart(4)->setQuery('solr')->setTimeAllowed(500)->setRows(17); 10 | 11 | $query->addField('israel')->addField('joshua')->addField('june'); 12 | 13 | $query->addSortField('cat', 0); 14 | 15 | $query->addFilterQuery('solr')->addFilterQuery('solr1')->addFilterQuery('solr2'); 16 | 17 | 18 | echo $query; 19 | echo "\n"; 20 | -------------------------------------------------------------------------------- /examples/solrquery_002_facet.php: -------------------------------------------------------------------------------- 1 | setFacet(0); 6 | 7 | $query->addFacetField('israel')->addFacetField('israel2'); 8 | 9 | $query->addFacetQuery('silk')->addFacetQuery('name:june'); 10 | 11 | $query->setFacetPrefix('A')->setFacetPrefix('C', 'june'); 12 | 13 | $query->setFacetSort(1)->setFacetSort(0, 'june'); 14 | 15 | // 16 | $query->setFacetLimit(98)->setFacetLimit(44, 'june'); 17 | 18 | $query->setFacetOffset(110)->setFacetOffset(12, 'june'); 19 | 20 | $query->setFacetMinCount(4)->setFacetMinCount(30, 'june'); 21 | 22 | $query->setFacetMissing(1)->setFacetMissing(0, 'june'); 23 | 24 | $query->setFacetMethod('enum')->setFacetMethod('fc', 'june'); 25 | 26 | echo $query; 27 | echo "\n"; 28 | -------------------------------------------------------------------------------- /examples/solrquery_003_date_facet.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 7 | 'login' => SOLR_SERVER_USERNAME, 8 | 'password' => SOLR_SERVER_PASSWORD, 9 | 'port' => SOLR_SERVER_PORT, 10 | 'path' => SOLR_SERVER_PATH, 11 | ); 12 | 13 | $client = new SolrClient($options); 14 | 15 | $query = new SolrQuery('*:*'); 16 | 17 | $query->setFacet(true); 18 | 19 | $query->addFacetDateField('manufacturedate_dt'); 20 | 21 | $query->setFacetDateStart('2006-02-13T00:00:00Z'); 22 | 23 | $query->setFacetDateEnd('2012-02-13T00:00:00Z'); 24 | 25 | $query->setFacetDateGap('+1YEAR'); 26 | 27 | $query->setFacetDateHardEnd(1); 28 | 29 | $query->addFacetDateOther('before'); 30 | 31 | $updateResponse = $client->query($query); 32 | 33 | $response_array = $updateResponse->getResponse(); 34 | 35 | $facet_data = $response_array->facet_counts->facet_dates; 36 | 37 | print_r($facet_data); 38 | -------------------------------------------------------------------------------- /examples/solrquery_004_highlight.php: -------------------------------------------------------------------------------- 1 | setHighlight(true); 6 | 7 | $query->setHighlightQuery('title:PHP OR description:Solr'); 8 | 9 | $query->addHighlightField('a')->addHighlightField('a')->addHighlightField('a'); 10 | 11 | $query->removeHighlightField('a')->removeHighlightField('a')->removeHighlightField('a'); 12 | 13 | $query->setHighlightSnippets(4)->setHighlightSnippets(5, 'june'); 14 | 15 | $query->setHighlightFragsize(41)->setHighlightFragsize(52, 'june'); 16 | 17 | $query->setHighlightMergeContiguous(true)->setHighlightMergeContiguous(false, 'june'); 18 | 19 | $query->setHighlightRequireFieldMatch(true); 20 | 21 | $query->setHighlightMaxAnalyzedChars(44)->setHighlightMaxAnalyzedChars(53); 22 | 23 | $query->setHighlightAlternateField('pizza')->setHighlightAlternateField('bread', 'june'); 24 | 25 | $query->setHighlightAlternateField('blue')->setHighlightAlternateField('red','june'); 26 | 27 | $query->setHighlightAlternateField('a')->setHighlightAlternateField('b','june'); 28 | 29 | $query->setHighlightMaxAlternateFieldLength(300)->setHighlightMaxAlternateFieldLength(335, 'june'); 30 | 31 | $query->setHighlightFormatter('F')->setHighlightFormatter('G', 'june'); 32 | 33 | $query->setHighlightSimplePre('OO')->setHighlightSimplePre('PP', 'june'); 34 | 35 | $query->setHighlightSimplePost('ZZ')->setHighlightSimplePost('YY', 'june'); 36 | 37 | $query->setHighlightFragmenter('gap')->setHighlightFragmenter('space', 'june'); 38 | 39 | $query->setHighlightUsePhraseHighlighter(false); 40 | 41 | $query->setHighlightHighlightMultiTerm(1); 42 | 43 | $query->setHighlightRegexSlop(0.0025); 44 | 45 | $query->setHighlightRegexPattern("israel")->setHighlightRegexPattern("ekpo"); 46 | 47 | $query->setHighlightRegexMaxAnalyzedChars(444)->setHighlightRegexMaxAnalyzedChars(5.0); 48 | 49 | echo $query; 50 | echo "\n"; 51 | -------------------------------------------------------------------------------- /examples/solrquery_005_stats.php: -------------------------------------------------------------------------------- 1 | setStats(0); 6 | 7 | $query->addStatsField('hello')->addStatsField('june')->removeStatsField('hello'); 8 | 9 | $query->addStatsFacet('world')->addStatsFacet('pear')->removeStatsFacet('world'); 10 | 11 | echo $query; 12 | echo "\n"; 13 | -------------------------------------------------------------------------------- /examples/solrquery_006_mlt.php: -------------------------------------------------------------------------------- 1 | setMlt(1); 6 | 7 | $query->setMltCount(55)->setMltCount(90); 8 | 9 | $query->addMltField('june')->addMltField('joshua')->addMltField('mom')->removeMltField('joshua'); 10 | 11 | $query->addMltQueryField('june', 0.0)->addMltQueryField('israel', 9.558); 12 | 13 | $query->setMltMinTermFrequency(9); 14 | 15 | $query->setMltMinDocFrequency(5); 16 | 17 | $query->setMltMinWordLength(8); 18 | 19 | $query->setMltMaxWordLength(99); 20 | 21 | $query->setMltMaxNumTokens(6); 22 | 23 | $query->setMltMaxNumQueryTerms(2); 24 | 25 | $query->setMltBoost(true); 26 | 27 | echo $query; 28 | echo "\n"; 29 | -------------------------------------------------------------------------------- /examples/solrquery_007_terms.php: -------------------------------------------------------------------------------- 1 | setTerms(true); 6 | 7 | $query->setTermsField('israel'); 8 | 9 | $query->setTermsLowerBound('june'); 10 | 11 | $query->setTermsUpperBound('joshua'); 12 | 13 | $query->setTermsIncludeLowerBound(false); 14 | 15 | $query->setTermsIncludeUpperBound(0); 16 | 17 | $query->setTermsMinCount(50); 18 | 19 | $query->setTermsMaxCount(200); 20 | 21 | $query->setTermsPrefix('A'); 22 | 23 | $query->setTermsLimit(45); 24 | 25 | $query->setTermsReturnRaw(false); 26 | 27 | $query->setTermsSort(0); 28 | 29 | echo $query; 30 | echo "\n"; 31 | -------------------------------------------------------------------------------- /examples/solrquery_008_facetquery.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 7 | 'login' => SOLR_SERVER_USERNAME, 8 | 'password' => SOLR_SERVER_PASSWORD, 9 | 'port' => SOLR_SERVER_PORT, 10 | 'path' => SOLR_SERVER_PATH, 11 | ); 12 | 13 | $client = new SolrClient($options); 14 | 15 | $query = new SolrQuery('*:*'); 16 | 17 | $query->setFacet(true); 18 | 19 | $query->addFacetQuery('price:[* TO 500]')->addFacetQuery('price:[500 TO *]'); 20 | 21 | $query_response = $client->query($query); 22 | 23 | $response = $query_response->getResponse(); 24 | 25 | print_r($response->facet_counts->facet_queries); 26 | -------------------------------------------------------------------------------- /examples/solrquery_009_grouping.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $query = new SolrDismaxQuery('*:*'); 17 | 18 | $query->setRows(4); 19 | 20 | $query->setGroup(true); 21 | 22 | $query->addGroupField('manu_s_id'); 23 | 24 | $query->setGroupLimit(2); 25 | 26 | $query->addGroupSortField('price', SolrQuery::ORDER_ASC); 27 | 28 | $query->setGroupNGroups(true); 29 | 30 | $query_response = $client->query($query); 31 | 32 | $response = $query_response->getResponse(); 33 | 34 | print_r($response); 35 | -------------------------------------------------------------------------------- /examples/solrquery_010_collapse.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $query = new SolrQuery('*:*'); 17 | 18 | $collapseFunction = new SolrCollapseFunction('manu_id_s'); 19 | 20 | $collapseFunction 21 | ->setSize(2) 22 | ->setNullPolicy(SolrCollapseFunction::NULLPOLICY_IGNORE); 23 | 24 | // $collapseFunction->setMax('sum(cscore(),field(A))'); 25 | 26 | $query 27 | ->collapse($collapseFunction) 28 | ->setRows(4); 29 | 30 | $queryResponse = $client->query($query); 31 | 32 | $response = $queryResponse->getResponse(); 33 | 34 | print_r($response); 35 | -------------------------------------------------------------------------------- /examples/solrquery_011_expand.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | 'path' => SOLR_SERVER_PATH 12 | ); 13 | 14 | $client = new SolrClient($options); 15 | 16 | $query = new SolrQuery('*:*'); 17 | 18 | $func = new SolrCollapseFunction('manu_id_s'); 19 | 20 | $query->collapse($func); 21 | 22 | $query->setExpand(true); 23 | $query->setExpandRows(10); 24 | $query->setExpandQuery('manu_id_s:corsair'); 25 | $query->addExpandFilterQuery('inStock:true'); 26 | $query->addExpandSortField('score', SolrQuery::ORDER_DESC); 27 | 28 | $queryResponse = $client->query($query); 29 | 30 | $response = $queryResponse->getResponse(); 31 | 32 | print_r($response); 33 | -------------------------------------------------------------------------------- /examples/solrutils_001_digestxmlresponse.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 8 | 'login' => SOLR_SERVER_USERNAME, 9 | 'password' => SOLR_SERVER_PASSWORD, 10 | 'port' => SOLR_SERVER_PORT, 11 | ); 12 | 13 | $client = new SolrClient($options); 14 | 15 | $query = new SolrQuery(); 16 | 17 | $userInput = 'USB/2'; 18 | 19 | $escapedUserInput = SolrUtils::escapeQueryChars($userInput); 20 | 21 | $query->setQuery('text:'.$escapedUserInput); 22 | 23 | echo $query.PHP_EOL; 24 | -------------------------------------------------------------------------------- /examples/terms_001.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 7 | 'login' => SOLR_SERVER_USERNAME, 8 | 'password' => SOLR_SERVER_PASSWORD, 9 | 'port' => SOLR_SERVER_PORT, 10 | 'path' => SOLR_SERVER_PATH, 11 | ); 12 | 13 | $client = new SolrClient($options); 14 | 15 | $query = new SolrQuery(); 16 | 17 | $query->setTerms(true); 18 | 19 | $query->setTermsField('cat'); 20 | 21 | $updateResponse = $client->query($query); 22 | 23 | print_r($updateResponse->getResponse()); 24 | -------------------------------------------------------------------------------- /examples/terms_002.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 7 | 'login' => SOLR_SERVER_USERNAME, 8 | 'password' => SOLR_SERVER_PASSWORD, 9 | 'port' => SOLR_SERVER_PORT, 10 | 'path' => SOLR_SERVER_PATH, 11 | ); 12 | 13 | $client = new SolrClient($options); 14 | 15 | $query = new SolrQuery(); 16 | 17 | $query->setTerms(true); 18 | 19 | /* Return only terms starting with $prefix */ 20 | $prefix = 'c'; 21 | 22 | $query->setTermsField('cat')->setTermsPrefix($prefix); 23 | 24 | $updateResponse = $client->query($query); 25 | 26 | print_r($updateResponse->getResponse()); 27 | -------------------------------------------------------------------------------- /examples/terms_003.php: -------------------------------------------------------------------------------- 1 | SOLR_SERVER_HOSTNAME, 7 | 'login' => SOLR_SERVER_USERNAME, 8 | 'password' => SOLR_SERVER_PASSWORD, 9 | 'port' => SOLR_SERVER_PORT, 10 | 'path' => SOLR_SERVER_PATH, 11 | ); 12 | 13 | $client = new SolrClient($options); 14 | 15 | $query = new SolrQuery(); 16 | 17 | $query->setTerms(true); 18 | 19 | /* Return only terms starting with $prefix */ 20 | $prefix = 'c'; 21 | 22 | /* Return only terms with a frequency of 2 or greater */ 23 | $min_frequency = 2; 24 | 25 | $query->setTermsField('cat')->setTermsPrefix($prefix)->setTermsMinCount($min_frequency); 26 | 27 | $updateResponse = $client->query($query); 28 | 29 | print_r($updateResponse->getResponse()); 30 | -------------------------------------------------------------------------------- /examples/test.config.php: -------------------------------------------------------------------------------- 1 | 55 | -------------------------------------------------------------------------------- /examples/update_stream_file.php: -------------------------------------------------------------------------------- 1 | set(SolrExtractRequest::LITERALS_PREFIX . 'id', 'doc1') 7 | 8 | // capture what is inside paragraph tags 9 | ->set(SolrExtractRequest::CAPTURE_ELEMENTS, 'p') 10 | 11 | // Indexes attributes of the Tika XHTML elements into separate fields 12 | ->set(SolrExtractRequest::CAPTURE_ATTRIBUTES, 'true') 13 | 14 | // map p content to solr field 15 | ->set( 16 | SolrExtractRequest::FIELD_MAPPING_PREFIX . 'p', 17 | 'an_indexed_field_name_that_holds_paragraphs' 18 | ) 19 | 20 | // capture unmapped content here 21 | ->set(SolrExtractRequest::DEFAULT_FIELD, '__text__') 22 | 23 | // restrict capturing to matching xpath expression 24 | ->set( 25 | SolrExtractRequest::XPATH_EXPRESSION, 26 | '/xhtml:html/xhtml:body/xhtml:div//node()' 27 | ) 28 | ; 29 | 30 | // please reference docs/documentation.php for the rest of the parameters 31 | 32 | $extractRequest = SolrExtractRequest::createFromFile('path/to/file.html', $extractParams); 33 | $response = $client->sendUpdateStream($extractRequest); 34 | 35 | -------------------------------------------------------------------------------- /examples/update_stream_payload.php: -------------------------------------------------------------------------------- 1 | set(SolrExtractRequest::LITERALS_PREFIX . 'id', 'doc1') 7 | 8 | // capture what is inside paragraph tags 9 | ->set(SolrExtractRequest::CAPTURE_ELEMENTS, 'p') 10 | 11 | // Indexes attributes of the Tika XHTML elements into separate fields 12 | ->set(SolrExtractRequest::CAPTURE_ATTRIBUTES, 'true') 13 | 14 | // map p content to solr field 15 | ->set( 16 | SolrExtractRequest::FIELD_MAPPING_PREFIX . 'p', 17 | 'an_indexed_field_name_that_holds_paragraphs' 18 | ) 19 | 20 | // capture unmapped content here 21 | ->set(SolrExtractRequest::DEFAULT_FIELD, '__text__') 22 | 23 | // restrict capturing to matching xpath expression 24 | ->set( 25 | SolrExtractRequest::XPATH_EXPRESSION, 26 | '/xhtml:html/xhtml:body/xhtml:div//node()' 27 | ) 28 | ; 29 | 30 | $binContent = file_get_contents('somefile.pdf'); 31 | // please reference docs/documentation.php for the rest of the parameters 32 | 33 | $extractRequest = SolrExtractRequest::createFromStream($binContent, 'application/pdf', $extractParams); 34 | $response = $client->sendUpdateStream($extractRequest); 35 | 36 | -------------------------------------------------------------------------------- /pecl-compat/src/common.h: -------------------------------------------------------------------------------- 1 | #ifndef PHP_7 2 | 3 | PHPAPI extern zend_string *compat_php_base64_decode(const unsigned char * str, int length) 4 | { 5 | int ret_length = 0L; 6 | unsigned char * return_str = php_base64_decode(str, length, &ret_length); 7 | return zend_string_init(return_str, ret_length, 1); 8 | } 9 | 10 | PHPAPI extern int compat_php_var_unserialize(zval *rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC) 11 | { 12 | return php_var_unserialize(&rval, p, max, var_hash TSRMLS_CC); 13 | } 14 | 15 | #else 16 | #define compat_php_base64_decode php_base64_decode 17 | #define compat_php_var_unserialize php_var_unserialize 18 | #endif 19 | -------------------------------------------------------------------------------- /scripts/gen_travis_yml.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | # file generated by gen_travis_yml.php, do not edit! 3 | 4 | # use the container infrastructure 5 | sudo: required 6 | 7 | services: 8 | - docker 9 | 10 | language: c 11 | 12 | # use the system's PHP to run this script 13 | addons: 14 | apt: 15 | packages: 16 | - php5-cli 17 | - php-pear 18 | - libxml2-dev 19 | - libcurl4-gnutls-dev 20 | - lcov 21 | 22 | install: 23 | - gem install lcoveralls 24 | 25 | # now we'll specify the build matrix environment 26 | env: 27 | ["5.4","5.5","5.6","7.0"], 36 | # test debug and non-debug builds 37 | "enable_debug", 38 | # test threadsafe and non-threadsafe builds 39 | "enable_maintainer_zts", 40 | # test with ext/json enabled an disabled 41 | "enable_libxml" => ["yes"], 42 | "enable_json" => ["yes"], 43 | ]); 44 | 45 | # output the build matrix 46 | foreach ($env as $e) { 47 | printf(" - %s\n", $e); 48 | } 49 | 50 | ?> 51 | 52 | before_script: 53 | # build the matrix' PHP version 54 | - make -f travis/pecl/Makefile php 55 | # build the extension, the PECL variable expects the extension name 56 | # and optionally the soname and a specific version of the extension 57 | # separeated by double colon, e.g. PECL=myext:ext:1.7.5 58 | - make -f travis/pecl/Makefile ext PECL=solr 59 | - docker pull omars/solr53 60 | - docker run -d --name solr53 -p 127.0.0.1:8983:8983 -t omars/solr53 61 | - sleep 5 62 | - lcov --directory . -f --zerocounters && lcov --directory . -f --capture --initial --no-external --output-file coverage.info 63 | 64 | script: 65 | # run the PHPT test suite 66 | - make -f travis/pecl/Makefile test 67 | 68 | after_script: 69 | - lcov --no-checksum --directory . -f --capture --output-file coverage.info && lcov -f --remove coverage.info "/usr/*" -o coverage.info 70 | - lcoveralls -r . 71 | 72 | notifications: 73 | email: 74 | - omars@php.net 75 | -------------------------------------------------------------------------------- /scripts/test-coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # build and test against a phpenv managed php version 3 | 4 | set -e 5 | 6 | SCRIPT_DIR=$(dirname $0) 7 | 8 | make distclean &>/dev/null || true 9 | phpize && 10 | ./configure --enable-coverage 11 | make -j4 && 12 | lcov --directory . --zerocounters && 13 | lcov --directory . --capture --initial --output-file coverage.info 14 | 15 | USE_PHP=${TEST_PHP_EXECUTABLE:-$(which php)} 16 | 17 | TEST_PHP_EXECUTABLE=${USE_PHP} \ 18 | REPORT_EXIT_STATUS=0 \ 19 | ${USE_PHP} \ 20 | -n -d open_basedir= -d output_buffering=0 -d memory_limit=-1 \ 21 | run-tests.php -q -n -d extension=json.so -d extension=$PWD/modules/solr.so tests 22 | 23 | lcov --no-checksum --directory . --capture --output-file coverage.info 24 | lcov --remove coverage.info "/usr/*" -o coverage.info 25 | genhtml --highlight --legend --output-directory report coverage.info 26 | -------------------------------------------------------------------------------- /src/php_solr_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Author: Israel Ekpo | 14 | +----------------------------------------------------------------------+ 15 | */ 16 | 17 | /** 18 | * Declaring Macro for function attributes 19 | * 20 | * This is for functions on GNU systems and Win32 systems 21 | * 22 | * On Win32 systems __declspec(dllexport) adds the export directive to the 23 | * object file so you do not need to use a .def file 24 | * 25 | * Using __declspec(dllexport) in addition to using a .def file should 26 | * not cause build errors. 27 | */ 28 | #ifndef PHP_SOLR_API_H 29 | #define PHP_SOLR_API_H 30 | #ifdef PHP_WIN32 31 | #define PHP_SOLR_API __declspec(dllexport) 32 | #elif defined(__GNUC__) && __GNUC__ >= 4 33 | #define PHP_SOLR_API __attribute__ ((visibility("default"))) 34 | #else 35 | #define PHP_SOLR_API 36 | #endif 37 | #endif /* PHP_SOLR_API_H */ 38 | 39 | /* 40 | * Local variables: 41 | * tab-width: 4 42 | * c-basic-offset: 4 43 | * indent-tabs-mode: t 44 | * End: 45 | * vim600: fdm=marker 46 | * vim: noet sw=4 ts=4 47 | */ 48 | -------------------------------------------------------------------------------- /tests/000.solr_int_arg.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr - Accept int (non-strict mode 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 14 | 'login' => SOLR_SERVER_USERNAME, 15 | 'password' => SOLR_SERVER_PASSWORD, 16 | 'port' => SOLR_SERVER_PORT, 17 | 'path' => SOLR_SERVER_PATH 18 | ); 19 | 20 | case_title(1, 'No arguments passed'); 21 | $client = new SolrClient($options); 22 | $updateResponse = $client->optimize(); 23 | print $updateResponse->getRawRequest(); 24 | 25 | case_title(2, 'int argument passed'); 26 | $updateResponse = $client->optimize(4, true, false); 27 | print $updateResponse->getRawRequest(); 28 | 29 | case_title(3, 'string argument passed'); 30 | $updateResponse = $client->optimize('5', true, false); 31 | print $updateResponse->getRawRequest(); 32 | 33 | case_title(4, 'object argument passed'); 34 | try { 35 | $updateResponse = $client->optimize(new StdClass()); 36 | } catch (SolrIllegalArgumentException $e) { 37 | echo $e->getMessage() . PHP_EOL; 38 | } 39 | --EXPECTF-- 40 | 41 | case #1: No arguments passed 42 | 43 | 44 | 45 | case #2: int argument passed 46 | 47 | 48 | 49 | case #3: string argument passed 50 | 51 | 52 | 53 | case #4: object argument passed 54 | maxSegments must be of type int. -------------------------------------------------------------------------------- /tests/000.solr_int_arg_strict.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr - Accept int (strict mode) 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | $client = new SolrClient($options); 21 | 22 | case_title(1, 'No arguments passed'); 23 | $updateResponse = $client->optimize(); 24 | print $updateResponse->getRawRequest(); 25 | 26 | case_title(2, 'int argument passed'); 27 | $updateResponse = $client->optimize(4, true, false); 28 | print $updateResponse->getRawRequest(); 29 | 30 | case_title(3, 'string argument passed'); 31 | try { 32 | $updateResponse = $client->optimize('5', true, false); 33 | } catch (SolrIllegalArgumentException $e) { 34 | echo $e->getMessage() . PHP_EOL; 35 | } 36 | 37 | case_title(4, 'object argument passed'); 38 | try { 39 | $updateResponse = $client->optimize(new StdClass()); 40 | } catch (SolrIllegalArgumentException $e) { 41 | echo $e->getMessage() . PHP_EOL; 42 | } 43 | ?> 44 | --EXPECTF-- 45 | 46 | case #1: No arguments passed 47 | 48 | 49 | 50 | case #2: int argument passed 51 | 52 | 53 | 54 | case #3: string argument passed 55 | 56 | case #4: object argument passed 57 | maxSegments must be of type int. -------------------------------------------------------------------------------- /tests/000.solr_server_compat.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Server 4+ Compatibility Test 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $query_response = $client->system(); 22 | $solrVersion = $query_response->getResponse()->lucene['solr-spec-version']; 23 | 24 | $match = preg_match('#([0-9]+)\.[0-9]+\.[0-9]+#', $solrVersion, $matches); 25 | 26 | var_dump($matches[1] >=4 ); 27 | ?> 28 | --EXPECTF-- 29 | bool(true) -------------------------------------------------------------------------------- /tests/000.solrclient_ping.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::ping() - Ping Solr Server 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $pingResponse = $client->ping(); 22 | 23 | echo $pingResponse->getRawResponse(); 24 | ?> 25 | --EXPECT-- 26 | HTTP/1.1 200 OK 27 | Content-Type: application/xml; charset=UTF-8 28 | Content-Length: 0 -------------------------------------------------------------------------------- /tests/001.solrclient_addDocument.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::addDocument() - sending document to the Solr server 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | 23 | $doc = new SolrInputDocument(); 24 | 25 | $doc->addField('id', 334455); 26 | $doc->addField('cat', 'Software'); 27 | $doc->addField('cat', 'Lucene'); 28 | 29 | $doc2 = new SolrInputDocument(); 30 | 31 | $doc2->addField('id', 12345); 32 | $doc->addField('cat', 'Category1'); 33 | $doc->addField('cat', 'Category2'); 34 | 35 | $updateResponse = $client->addDocument($doc, true, 500); 36 | $updateResponse = $client->addDocument($doc2, true, 500); 37 | 38 | print_r($updateResponse->getResponse()); 39 | 40 | ?> 41 | --EXPECTF-- 42 | SolrObject Object 43 | ( 44 | [responseHeader] => SolrObject Object 45 | ( 46 | [status] => 0 47 | [QTime] => %d 48 | ) 49 | 50 | ) 51 | -------------------------------------------------------------------------------- /tests/002.solrclient_addDocuments.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::addDocuments() - sending multiple documents to the Solr server 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | 23 | $doc = new SolrInputDocument(); 24 | 25 | $doc->addField('id', 334455); 26 | $doc->addField('cat', 'Software'); 27 | $doc->addField('cat', 'Lucene'); 28 | 29 | $doc2 = new SolrInputDocument(); 30 | 31 | $doc2->addField('id', 12345); 32 | $doc->addField('cat', 'Category1'); 33 | $doc->addField('cat', 'Category2'); 34 | 35 | $docs = array($doc, $doc2); 36 | 37 | $updateResponse = $client->addDocuments($docs); 38 | $client->commit(); 39 | print_r($updateResponse->getResponse()); 40 | 41 | ?> 42 | --EXPECTF-- 43 | SolrObject Object 44 | ( 45 | [responseHeader] => SolrObject Object 46 | ( 47 | [status] => 0 48 | [QTime] => %d 49 | ) 50 | 51 | ) 52 | -------------------------------------------------------------------------------- /tests/003.solrclient_addDocument_no_overwrite.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::addDocument() - Overwrite an existing document 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | 23 | $doc = new SolrInputDocument(); 24 | 25 | $doc->addField('id', 334455); 26 | $doc->addField('cat', 'Software'); 27 | $doc->addField('cat', 'Solr'); 28 | 29 | $updateResponse = $client->addDocument($doc, false); 30 | $client->commit(); 31 | print $updateResponse->getRawRequest(); 32 | ?> 33 | --EXPECT-- 34 | 35 | 36 | 37 | 334455 38 | Software 39 | Solr 40 | 41 | 42 | -------------------------------------------------------------------------------- /tests/003.solrclient_addDocuments_commitwithin.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::addDocuments() - sending multiple documents to the Solr server 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | 23 | $doc = new SolrInputDocument(); 24 | 25 | $doc->addField('id', 334455); 26 | $doc->addField('cat', 'Software'); 27 | $doc->addField('cat', 'Lucene'); 28 | 29 | $doc2 = new SolrInputDocument(); 30 | 31 | $doc2->addField('id', 12345); 32 | $doc->addField('cat', 'Category1'); 33 | $doc->addField('cat', 'Category2'); 34 | 35 | $docs = array($doc, $doc2); 36 | 37 | $updateResponse = $client->addDocuments($docs, true, 500); 38 | print_r($updateResponse->getResponse()); 39 | 40 | ?> 41 | --EXPECTF-- 42 | SolrObject Object 43 | ( 44 | [responseHeader] => SolrObject Object 45 | ( 46 | [status] => 0 47 | [QTime] => %d 48 | ) 49 | 50 | ) 51 | -------------------------------------------------------------------------------- /tests/004.solrclient_query_response.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::query() - Sending a chained query request 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | 22 | $client = new SolrClient($options); 23 | 24 | $query = new SolrQuery(); 25 | 26 | $query->setQuery('lucene'); 27 | 28 | $query->setStart(0); 29 | 30 | $query->setRows(50); 31 | 32 | $query->addField('cat')->addField('features')->addField('id')->addField('timestamp'); 33 | 34 | $query_response = $client->query($query); 35 | 36 | $response = $query_response->getResponse(); 37 | 38 | var_dump(get_class($response->responseHeader->params) == 'SolrObject'); 39 | var_dump(property_exists($response->responseHeader->params, 'q')); 40 | var_dump(property_exists($response->responseHeader->params, 'wt')); 41 | var_dump(property_exists($response->responseHeader->params, 'version')); 42 | ?> 43 | --EXPECTF-- 44 | bool(true) 45 | bool(true) 46 | bool(true) 47 | bool(true) -------------------------------------------------------------------------------- /tests/004.solrclient_query_terms.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::query() - Terms component 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | 22 | $client = new SolrClient($options); 23 | 24 | $query = new SolrQuery('*:*'); 25 | 26 | $query->setTerms(true); 27 | 28 | $query->setTermsField('name'); 29 | 30 | $query->setTermsLowerBound('a'); 31 | 32 | $query->setTermsSort(SolrQuery::TERMS_SORT_INDEX); 33 | 34 | $query_response = $client->query($query); 35 | 36 | echo $query_response->getRequestUrl() .PHP_EOL; 37 | 38 | print_r($query_response->getResponse()); 39 | 40 | ?> 41 | --EXPECTF-- 42 | http://%s/solr/collection1/terms/?version=2.2&indent=on&wt=xml 43 | SolrObject Object 44 | ( 45 | [responseHeader] => SolrObject Object 46 | ( 47 | [status] => %d 48 | [QTime] => %d 49 | ) 50 | 51 | [terms] => SolrObject Object 52 | ( 53 | [name] => SolrObject Object 54 | ( 55 | [iPod & iPod Mini USB 2.0 Cable] => %d 56 | ) 57 | 58 | ) 59 | 60 | ) 61 | -------------------------------------------------------------------------------- /tests/005.solrclient_query_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::query() - throw SolrClientException on Solr Server exception 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | $query = new SolrQuery("lucene\\"); 21 | 22 | try { 23 | $query_response = $client->query($query); 24 | } catch (SolrServerException $e) { 25 | echo $e->getMessage(); 26 | } 27 | 28 | ?> 29 | --EXPECTF-- 30 | %s: Cannot parse 'lucene\': Lexical error at line 1, column 8. Encountered: after : "" -------------------------------------------------------------------------------- /tests/006.solrclient_system.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::system() - Retrieve Solr Server/System Info 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | 23 | $genericResponse = $client->system(); 24 | var_dump(get_class($genericResponse->getResponse())) . PHP_EOL; 25 | var_dump(get_class($genericResponse->getResponse()->system)); 26 | ?> 27 | --EXPECTF-- 28 | string(10) "SolrObject" 29 | string(10) "SolrObject" 30 | -------------------------------------------------------------------------------- /tests/007.solrclient_deleteById.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::deleteById() - Testing deleting a document by ID 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | $response = $client->deleteById('334457'); 23 | $client->commit(); 24 | print_r($response->getResponse()); 25 | ?> 26 | --EXPECTF-- 27 | SolrObject Object 28 | ( 29 | [responseHeader] => SolrObject Object 30 | ( 31 | [status] => %d 32 | [QTime] => %d 33 | ) 34 | 35 | ) 36 | -------------------------------------------------------------------------------- /tests/007.solrclient_deleteByIds.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::deleteByIds() - Test deleting documents by an array of IDS 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | $response = $client->deleteByIds(array('334455','334456')); 23 | $client->commit(); 24 | print_r($response->getResponse()); 25 | 26 | try { 27 | $client->deleteByIds(array(0)); 28 | } catch (SolrIllegalArgumentException $e) { 29 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()). PHP_EOL; 30 | } 31 | 32 | try { 33 | $client->deleteByIds(array('334455', '')); 34 | } catch (SolrIllegalArgumentException $e) { 35 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()). PHP_EOL; 36 | } 37 | 38 | ?> 39 | --EXPECTF-- 40 | SolrObject Object 41 | ( 42 | [responseHeader] => SolrObject Object 43 | ( 44 | [status] => %d 45 | [QTime] => %d 46 | ) 47 | 48 | ) 49 | Exception 4000: Id number 1 is not a valid string 50 | Exception 4000: Id number 2 is not a valid string -------------------------------------------------------------------------------- /tests/008.solrclient_commit.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::commit() - Testing commit 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | $updateResponse = $client->commit(); 23 | print $updateResponse->getRawRequest(); 24 | $updateResponse = $client->commit(true,false,true); 25 | print $updateResponse->getRawRequest(); 26 | 27 | $updateResponse = $client->commit(true,false,true); 28 | ?> 29 | --EXPECTF-- 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /tests/008.solrclient_rollback.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::rollback() - Testing rollback 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | $updateResponse = $client->rollback(); 23 | print $updateResponse->getRawRequest(); 24 | ?> 25 | --EXPECTF-- 26 | 27 | -------------------------------------------------------------------------------- /tests/009.solrclient_optimize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::optimize() - Testing optimize 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 14 | 'login' => SOLR_SERVER_USERNAME, 15 | 'password' => SOLR_SERVER_PASSWORD, 16 | 'port' => SOLR_SERVER_PORT, 17 | 'path' => SOLR_SERVER_PATH 18 | ); 19 | 20 | $client = new SolrClient($options); 21 | $updateResponse = $client->optimize(); 22 | print $updateResponse->getRawRequest(); 23 | $updateResponse = $client->optimize(4,true,false); 24 | print $updateResponse->getRawRequest(); 25 | $updateResponse = $client->optimize('5',true,false); 26 | print $updateResponse->getRawRequest(); 27 | ?> 28 | --EXPECTF-- 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/010.solrclient_getOptions.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::getOptions - Returning all the default options 3 | --FILE-- 4 | false); 7 | 8 | $client = new SolrClient($options); 9 | 10 | var_dump($client->getOptions()); 11 | 12 | ?> 13 | --EXPECTF-- 14 | array(17) { 15 | ["timeout"]=> 16 | int(30) 17 | ["secure"]=> 18 | bool(false) 19 | ["hostname"]=> 20 | string(9) "localhost" 21 | ["wt"]=> 22 | string(3) "xml" 23 | ["port"]=> 24 | int(8983) 25 | ["proxy_host"]=> 26 | string(0) "" 27 | ["proxy_port"]=> 28 | int(0) 29 | ["path"]=> 30 | string(4) "solr" 31 | ["http_auth"]=> 32 | string(0) "" 33 | ["proxy_auth"]=> 34 | string(0) "" 35 | ["ssl_verify_peer"]=> 36 | bool(false) 37 | ["ssl_verify_host"]=> 38 | int(2) 39 | ["ssl_cert"]=> 40 | string(0) "" 41 | ["ssl_key"]=> 42 | string(0) "" 43 | ["ssl_keypassword"]=> 44 | string(0) "" 45 | ["ssl_cainfo"]=> 46 | string(0) "" 47 | ["ssl_capath"]=> 48 | string(0) "" 49 | } 50 | -------------------------------------------------------------------------------- /tests/011.solrclient_phps_response.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient - PHPS response writer support 3 | --FILE-- 4 | SOLR_SERVER_HOSTNAME, 9 | 'login' => SOLR_SERVER_USERNAME, 10 | 'password' => SOLR_SERVER_PASSWORD, 11 | 'port' => SOLR_SERVER_PORT, 12 | 'path' => SOLR_SERVER_PATH, 13 | ); 14 | 15 | $client = new SolrClient ( $options ); 16 | $client->setResponseWriter('phps'); 17 | $options = $client->getOptions(); 18 | var_dump($options['wt'] == 'phps'); 19 | ?> 20 | --EXPECTF-- 21 | bool(true) -------------------------------------------------------------------------------- /tests/012.solrclient_getById.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::getById() - Testing Real Time Get by id 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | $response = $client->getById('GB18030TEST'); 23 | var_dump(isset($response->getArrayResponse()['doc'])).PHP_EOL; 24 | var_dump($response->getResponse()->doc->id) . PHP_EOL; 25 | ?> 26 | --EXPECTF-- 27 | bool(true) 28 | string(11) "GB18030TEST" -------------------------------------------------------------------------------- /tests/013.solrclient_getByIds.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::getByIds() - Testing Real Time Get by ids 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | $response = $client->getByIds(['GB18030TEST', '6H500F0']); 23 | var_dump(isset($response->getArrayResponse()['response']['docs'])) . PHP_EOL; 24 | var_dump($response->getResponse()->response->start) . PHP_EOL; 25 | try { 26 | $response = $client->getByIds(['GB18030TEST', '']); 27 | } catch (Exception $e) { 28 | printf("Exception %d: %s", $e->getCode(), $e->getMessage()); 29 | } 30 | echo PHP_EOL.PHP_EOL; 31 | // make sure request was reset 32 | $response = $client->getByIds(['GB18030TEST']); 33 | $headers = explode(PHP_EOL, trim($response->getRawRequestHeaders())); 34 | 35 | $headers = array_filter($headers, function($header) { 36 | return strstr($header, 'collection1') !== false; 37 | }); 38 | 39 | print_r(implode(PHP_EOL, $headers).PHP_EOL); 40 | 41 | echo PHP_EOL; 42 | try { 43 | $response = $client->getByIds([]); 44 | } catch (Exception $e) { 45 | printf("Exception %d: %s", $e->getCode(), $e->getMessage()); 46 | } 47 | ?> 48 | --EXPECTF-- 49 | bool(true) 50 | int(0) 51 | Exception 4000: Invalid id at position 1 52 | 53 | GET /solr/collection1/get/?version=2.2&indent=on&wt=xml&ids=GB18030TEST HTTP/1.1 54 | 55 | Exception 4000: Invalid parameter: at least 1 ID is required. Passed an empty array. 56 | -------------------------------------------------------------------------------- /tests/016.solrclient_request.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::Request() - Sending custom update request 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $rawAtomicUpdateRequest = << 23 | 24 | 25 | IW-02 26 | 1 27 | New Atomic Update Feature 28 | true 29 | 30 | 31 | REQ; 32 | 33 | $response = $client->request($rawAtomicUpdateRequest)->getResponse(); 34 | $client->commit(); 35 | 36 | print_r($response); 37 | ?> 38 | --EXPECTF-- 39 | 40 | SolrObject Object 41 | ( 42 | [responseHeader] => SolrObject Object 43 | ( 44 | [status] => %d 45 | [QTime] => %d 46 | ) 47 | 48 | ) -------------------------------------------------------------------------------- /tests/016.solrclient_sendUpdateStream_bin.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::sendUpdateStream - send SolrExtractRequest (bin) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 12 | 'login' => SOLR_SERVER_USERNAME, 13 | 'password' => SOLR_SERVER_PASSWORD, 14 | 'port' => SOLR_SERVER_PORT, 15 | 'path' => SOLR_SERVER_FILES_PATH, 16 | ); 17 | 18 | $client = new SolrClient($options); 19 | 20 | $extractParams = new SolrModifiableParams(); 21 | 22 | $extractParams 23 | ->set(SolrExtractRequest::LITERALS_PREFIX . 'id', 'doc1') 24 | ->set(SolrExtractRequest::CAPTURE_ELEMENTS, 'p') 25 | ->set(SolrExtractRequest::FIELD_MAPPING_PREFIX . 'p', 'text') 26 | ; 27 | 28 | $binContent = file_get_contents(EXTRACT_FILE_1); 29 | 30 | $extractRequest = SolrExtractRequest::createFromStream($binContent, 'application/pdf', $extractParams); 31 | 32 | $response = $client->sendUpdateStream($extractRequest); 33 | 34 | $client->rollback(); 35 | 36 | echo $response->getHttpStatus() . PHP_EOL; 37 | echo $response->getRequestUrl() . PHP_EOL; 38 | ?> 39 | --EXPECTF-- 40 | 200 41 | http://%s/update/extract/?version=2.2&indent=on&wt=xml&literal.id=doc1&capture=p&fmap.p=text 42 | -------------------------------------------------------------------------------- /tests/016.solrclient_sendUpdateStream_file.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::sendUpdateStream - send SolrExtractRequest (file) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 12 | 'login' => SOLR_SERVER_USERNAME, 13 | 'password' => SOLR_SERVER_PASSWORD, 14 | 'port' => SOLR_SERVER_PORT, 15 | 'path' => SOLR_SERVER_FILES_PATH, 16 | ); 17 | 18 | $client = new SolrClient($options); 19 | 20 | $extractParams = new SolrModifiableParams(); 21 | 22 | $extractParams 23 | ->set(SolrExtractRequest::LITERALS_PREFIX . 'id', 'doc1') 24 | ->set(SolrExtractRequest::CAPTURE_ELEMENTS, 'p') 25 | ->set(SolrExtractRequest::FIELD_MAPPING_PREFIX . 'p', 'text') 26 | ; 27 | 28 | $extractRequest = SolrExtractRequest::createFromFile(EXTRACT_FILE_1, $extractParams); 29 | 30 | $response = $client->sendUpdateStream($extractRequest); 31 | 32 | $client->rollback(); 33 | 34 | echo $response->getHttpStatus() . PHP_EOL; 35 | echo $response->getRequestUrl() . PHP_EOL; 36 | ?> 37 | --EXPECTF-- 38 | 200 39 | http://%s/update/extract/?version=2.2&indent=on&wt=xml&literal.id=doc1&capture=p&fmap.p=text 40 | -------------------------------------------------------------------------------- /tests/017.solrclient_deletebyqueries.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::deleteByQueries() - delete by multiple queries 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $serverOutput = $client->deleteByQueries([ 22 | 'id:3675', 23 | 'id:2548' 24 | ]); 25 | 26 | $response = $serverOutput->getResponse(); 27 | 28 | print_r($serverOutput->getRawRequest()); 29 | print_r($response); 30 | 31 | try { 32 | $client->deleteByQueries(array(0,'')); 33 | } catch (SolrIllegalArgumentException $e) { 34 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()); 35 | } 36 | ?> 37 | --EXPECTF-- 38 | 39 | 40 | id:3675 41 | id:2548 42 | 43 | SolrObject Object 44 | ( 45 | [responseHeader] => SolrObject Object 46 | ( 47 | [status] => %d 48 | [QTime] => %d 49 | ) 50 | 51 | ) 52 | Exception 4000: Query number 1 is not a valid query string 53 | 54 | -------------------------------------------------------------------------------- /tests/017.solrclient_deletebyquery.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::deleteByQuery() - delete by query 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $serverOutput = $client->deleteByQuery('id:3675'); 22 | 23 | $response = $serverOutput->getResponse(); 24 | 25 | print_r($serverOutput->getRawRequest()); 26 | print_r($response); 27 | ?> 28 | --EXPECTF-- 29 | 30 | 31 | id:3675 32 | 33 | SolrObject Object 34 | ( 35 | [responseHeader] => SolrObject Object 36 | ( 37 | [status] => %d 38 | [QTime] => %d 39 | ) 40 | 41 | ) 42 | -------------------------------------------------------------------------------- /tests/017.solrclient_threads.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::threads() - Solr Threads Info 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $response = $client->threads()->getResponse(); 22 | 23 | print_r($response->system->threadCount); 24 | ?> 25 | --EXPECTF-- 26 | SolrObject Object 27 | ( 28 | [current] => %d 29 | [peak] => %d 30 | [daemon] => %d 31 | ) 32 | -------------------------------------------------------------------------------- /tests/018.solrclient_setservlet.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::setServlet() - set different servlet for a certain request type 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $response = $client->ping(); 22 | echo $response->getRequestUrl().PHP_EOL; 23 | 24 | $client->setServlet(SolrClient::PING_SERVLET_TYPE, 'select'); 25 | $response = $client->ping(); 26 | echo $response->getRequestUrl().PHP_EOL; 27 | 28 | ?> 29 | --EXPECTF-- 30 | http://%s/solr/collection1/admin/ping/?version=2.2&indent=on&wt=xml 31 | http://%s/solr/collection1/select/?version=2.2&indent=on&wt=xml 32 | -------------------------------------------------------------------------------- /tests/019.solrclient_clone.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::__clone() - expect exception on clone 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | try { 22 | $failing = clone $client; 23 | } catch (SolrIllegalOperationException $e) { 24 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()) . PHP_EOL; 25 | } 26 | 27 | ?> 28 | --EXPECTF-- 29 | Exception 4001: Cloning of SolrClient objects is currently not supported -------------------------------------------------------------------------------- /tests/019.solrclient_getdebug.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::getDebug() - Get request debug logs for the last request 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $response = $client->ping(); 22 | 23 | $debug = $client->getDebug(); 24 | 25 | $lines = explode("\n",$debug); 26 | $print = false; 27 | sort($lines); 28 | foreach ( $lines as $line) { 29 | if ($line == '' || 30 | FALSE !== strpos($line, 'Trying') || 31 | 0 === strpos($line, 'Mark bundle') || 32 | 0 === strpos($line, 'Server') || 33 | 0 === strpos($line, 'Hostname') || 34 | 0 === strpos($line, 'TCP_NODELAY') || 35 | 0 === strpos($line, 'Accept-Encoding') || 36 | 0 === strpos($line, 'Curl_http_done') || 37 | 0 === strpos($line, 'processing:') 38 | ) { 39 | $print = false; 40 | } else { 41 | $print = true; 42 | } 43 | 44 | if ($print) { 45 | echo $line . "\n"; 46 | } 47 | } 48 | ?> 49 | --EXPECTF-- 50 | Accept-Charset: utf-8 51 | Accept: */* 52 | Authorization: Basic %s 53 | Connected to %s 54 | Connection #0 to host %s left intact 55 | Connection: keep-alive 56 | Content-Length: 0 57 | Content-Type: application/xml; charset=UTF-8 58 | HEAD /solr/collection1/admin/ping/?version=2.2&indent=on&wt=xml HTTP/1.1 59 | HTTP/1.1 200 OK 60 | Host: %s:%s 61 | Keep-Alive: 300 62 | User-Agent: %s 63 | -------------------------------------------------------------------------------- /tests/019.solrclient_serialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient - serialization 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | try { 22 | serialize($client); 23 | } catch (SolrIllegalOperationException $e) { 24 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()) . PHP_EOL; 25 | } 26 | 27 | try { 28 | $serializedString = 'O:10:"SolrClient":0:{}'; 29 | unserialize($serializedString); 30 | } catch (SolrIllegalOperationException $e) { 31 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()) . PHP_EOL; 32 | } 33 | 34 | ?> 35 | --EXPECTF-- 36 | Exception 1001: SolrClient objects cannot be serialized or unserialized 37 | Exception 1001: SolrClient objects cannot be serialized or unserialized 38 | -------------------------------------------------------------------------------- /tests/020.solrdocument_adding_fields.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument - checking dimension and magic property sets. 3 | --FILE-- 4 | addField('id', 1123); 11 | 12 | $doc->features = "PHP Client Side"; 13 | $doc->features = "Fast development cycles"; 14 | 15 | $doc['cat'] = 'Software'; 16 | $doc['cat'] = 'Custom Search'; 17 | $doc->cat = 'Information Technology'; 18 | 19 | print_r($doc->toArray()); 20 | 21 | ?> 22 | --EXPECT-- 23 | Array 24 | ( 25 | [document_boost] => 0 26 | [field_count] => 3 27 | [fields] => Array 28 | ( 29 | [0] => SolrDocumentField Object 30 | ( 31 | [name] => id 32 | [boost] => 0 33 | [values] => Array 34 | ( 35 | [0] => 1123 36 | ) 37 | 38 | ) 39 | 40 | [1] => SolrDocumentField Object 41 | ( 42 | [name] => features 43 | [boost] => 0 44 | [values] => Array 45 | ( 46 | [0] => PHP Client Side 47 | [1] => Fast development cycles 48 | ) 49 | 50 | ) 51 | 52 | [2] => SolrDocumentField Object 53 | ( 54 | [name] => cat 55 | [boost] => 0 56 | [values] => Array 57 | ( 58 | [0] => Software 59 | [1] => Custom Search 60 | [2] => Information Technology 61 | ) 62 | 63 | ) 64 | 65 | ) 66 | 67 | ) 68 | -------------------------------------------------------------------------------- /tests/021.solrdocument_iterator.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument - checking Iterator interface implementation 3 | --FILE-- 4 | addField('id', 1123); 11 | 12 | $doc->features = "PHP Client Side"; 13 | $doc->features = "Fast development cycles"; 14 | 15 | $doc['cat'] = 'Software'; 16 | $doc['cat'] = 'Custom Search'; 17 | $doc->cat = 'Information Technology'; 18 | 19 | foreach ($doc as $fieldname => $fieldvalues) 20 | { 21 | print "$fieldname\n"; 22 | 23 | print_r($fieldvalues); 24 | } 25 | 26 | ?> 27 | --EXPECT-- 28 | id 29 | SolrDocumentField Object 30 | ( 31 | [name] => id 32 | [boost] => 0 33 | [values] => Array 34 | ( 35 | [0] => 1123 36 | ) 37 | 38 | ) 39 | features 40 | SolrDocumentField Object 41 | ( 42 | [name] => features 43 | [boost] => 0 44 | [values] => Array 45 | ( 46 | [0] => PHP Client Side 47 | [1] => Fast development cycles 48 | ) 49 | 50 | ) 51 | cat 52 | SolrDocumentField Object 53 | ( 54 | [name] => cat 55 | [boost] => 0 56 | [values] => Array 57 | ( 58 | [0] => Software 59 | [1] => Custom Search 60 | [2] => Information Technology 61 | ) 62 | 63 | ) 64 | -------------------------------------------------------------------------------- /tests/022.solrdocument_getInputDocument.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::getInputDocument() - creating SolrInputDocument from SolrDocument 3 | --FILE-- 4 | addField('id', 1123); 11 | 12 | $doc->features = "PHP Client Side"; 13 | $doc->features = "Fast development cycles"; 14 | 15 | $doc['cat'] = 'Software'; 16 | $doc['cat'] = 'Custom Search'; 17 | $doc->cat = 'Information Technology'; 18 | 19 | 20 | $input_doc = $doc->getInputDocument(); 21 | 22 | var_dump(get_class($input_doc)); 23 | 24 | ?> 25 | --EXPECT-- 26 | string(17) "SolrInputDocument" 27 | -------------------------------------------------------------------------------- /tests/023.solrdocument_merge.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::merge() - merging source document into current document 3 | --FILE-- 4 | addField('id', 1123); 13 | 14 | $doc->features = "PHP Client Side"; 15 | $doc->features = "Fast development cycles"; 16 | 17 | $doc['cat'] = 'Software'; 18 | $doc['cat'] = 'Custom Search'; 19 | $doc->cat = 'Information Technology'; 20 | 21 | $second_doc->addField('cat', 'Lucene Search'); 22 | 23 | $second_doc->merge($doc, true); 24 | 25 | print_r($second_doc->toArray()); 26 | 27 | 28 | ?> 29 | --EXPECT-- 30 | Array 31 | ( 32 | [document_boost] => 0 33 | [field_count] => 3 34 | [fields] => Array 35 | ( 36 | [0] => SolrDocumentField Object 37 | ( 38 | [name] => cat 39 | [boost] => 0 40 | [values] => Array 41 | ( 42 | [0] => Software 43 | [1] => Custom Search 44 | [2] => Information Technology 45 | ) 46 | 47 | ) 48 | 49 | [1] => SolrDocumentField Object 50 | ( 51 | [name] => id 52 | [boost] => 0 53 | [values] => Array 54 | ( 55 | [0] => 1123 56 | ) 57 | 58 | ) 59 | 60 | [2] => SolrDocumentField Object 61 | ( 62 | [name] => features 63 | [boost] => 0 64 | [values] => Array 65 | ( 66 | [0] => PHP Client Side 67 | [1] => Fast development cycles 68 | ) 69 | 70 | ) 71 | 72 | ) 73 | 74 | ) 75 | -------------------------------------------------------------------------------- /tests/023.solrdocument_merge_no_overwrite.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::merge() - merging source document into current document without overwrite 3 | --FILE-- 4 | addField('id', 1123); 13 | 14 | $doc->features = "PHP Client Side"; 15 | $doc->features = "Fast development cycles"; 16 | 17 | $doc['cat'] = 'Software'; 18 | $doc['cat'] = 'Custom Search'; 19 | $doc->cat = 'Information Technology'; 20 | 21 | $second_doc->addField('cat', 'Lucene Search'); 22 | 23 | $second_doc->merge($doc, false); 24 | 25 | print_r($second_doc->toArray()); 26 | 27 | 28 | ?> 29 | --EXPECT-- 30 | Array 31 | ( 32 | [document_boost] => 0 33 | [field_count] => 3 34 | [fields] => Array 35 | ( 36 | [0] => SolrDocumentField Object 37 | ( 38 | [name] => cat 39 | [boost] => 0 40 | [values] => Array 41 | ( 42 | [0] => Lucene Search 43 | ) 44 | 45 | ) 46 | 47 | [1] => SolrDocumentField Object 48 | ( 49 | [name] => id 50 | [boost] => 0 51 | [values] => Array 52 | ( 53 | [0] => 1123 54 | ) 55 | 56 | ) 57 | 58 | [2] => SolrDocumentField Object 59 | ( 60 | [name] => features 61 | [boost] => 0 62 | [values] => Array 63 | ( 64 | [0] => PHP Client Side 65 | [1] => Fast development cycles 66 | ) 67 | 68 | ) 69 | 70 | ) 71 | 72 | ) 73 | -------------------------------------------------------------------------------- /tests/024.solrdocument_child_fetch.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrClient::query() - Query child documents SolrObject (Integ) 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 14 | 'login' => SOLR_SERVER_USERNAME, 15 | 'password' => SOLR_SERVER_PASSWORD, 16 | 'port' => SOLR_SERVER_PORT, 17 | 'path' => SOLR_SERVER_STORE_PATH, 18 | 'wt' => 'xml' 19 | ); 20 | 21 | $client = new SolrClient ( $options ); 22 | 23 | $query = new SolrQuery (); 24 | 25 | $query->setQuery ( 'id:1 AND {!parent which=$parentFilter}' ); 26 | $query->setParam ( 'parentFilter', 'content_type_s:product' ); 27 | $query->addFilterQuery('{!parent which=$parentFilter}'); 28 | 29 | $query->addField ( '*' ); 30 | $query->addField ( '[child parentFilter=$parentFilter]' ); 31 | 32 | $query->setStart ( 0 ); 33 | 34 | $query->setRows ( 50 ); 35 | $queryResponse = $client->query ( $query ); 36 | 37 | $response = $queryResponse->getResponse (); 38 | echo "----XML----" . PHP_EOL; 39 | var_dump($response->response->docs[0]->_childDocuments_[0]->id); 40 | 41 | echo "----JSON----" . PHP_EOL; 42 | $options['wt'] = 'json'; 43 | $client = new SolrClient ( $options ); 44 | $queryResponse = $client->query($query); 45 | $response = $queryResponse->getResponse (); 46 | var_dump($response->response->docs[0]->_childDocuments_[0]->id); 47 | ?> 48 | --EXPECT-- 49 | ----XML---- 50 | string(9) "IMM-HOW-S" 51 | ----JSON---- 52 | string(9) "IMM-HOW-S" -------------------------------------------------------------------------------- /tests/025.solrdocument_haschilddocuments.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::hasChildDocuments() - Method test 3 | --FILE-- 4 | response->docs[0]->hasChildDocuments()); 12 | ?> 13 | --EXPECT-- 14 | bool(true) -------------------------------------------------------------------------------- /tests/026.solrdocument_getchilddocscount.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::getChildDocumentsCount() - Method test 3 | --FILE-- 4 | response->docs[0]->getChildDocumentsCount()); 12 | ?> 13 | --EXPECT-- 14 | int(1) -------------------------------------------------------------------------------- /tests/027.solrdocument_getinputdocument_children.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::getInputDocument() - Where document has child docs 3 | --FILE-- 4 | response->docs as $doc) 13 | { 14 | $childrenOfTheInput = $doc->getInputDocument()->getChildDocuments(); 15 | 16 | if ($childrenOfTheInput) 17 | { 18 | $firstChild = $childrenOfTheInput[0]; 19 | var_dump(get_class($firstChild)); 20 | var_dump(current($childrenOfTheInput)->toArray()); 21 | } 22 | } 23 | 24 | ?> 25 | --EXPECT-- 26 | string(17) "SolrInputDocument" 27 | array(3) { 28 | ["document_boost"]=> 29 | float(0) 30 | ["field_count"]=> 31 | int(1) 32 | ["fields"]=> 33 | array(1) { 34 | [0]=> 35 | object(SolrDocumentField)#9 (3) { 36 | ["name"]=> 37 | string(2) "id" 38 | ["boost"]=> 39 | float(0) 40 | ["values"]=> 41 | array(1) { 42 | [0]=> 43 | string(9) "CHILD_1_1" 44 | } 45 | } 46 | } 47 | } 48 | string(17) "SolrInputDocument" 49 | array(3) { 50 | ["document_boost"]=> 51 | float(0) 52 | ["field_count"]=> 53 | int(1) 54 | ["fields"]=> 55 | array(1) { 56 | [0]=> 57 | object(SolrDocumentField)#10 (3) { 58 | ["name"]=> 59 | string(2) "id" 60 | ["boost"]=> 61 | float(0) 62 | ["values"]=> 63 | array(1) { 64 | [0]=> 65 | string(9) "CHILD_2_1" 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/028.solrdocument_clone.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument - clone 3 | --FILE-- 4 | response->docs as $doc) 13 | { 14 | $clone = clone $doc; 15 | $childrenOfTheInput = $clone->getInputDocument()->getChildDocuments(); 16 | 17 | if ($childrenOfTheInput) 18 | { 19 | $firstChild = $childrenOfTheInput[0]; 20 | var_dump(get_class($firstChild)); 21 | var_dump(current($childrenOfTheInput)->toArray()); 22 | } 23 | } 24 | 25 | ?> 26 | --EXPECTF-- 27 | string(17) "SolrInputDocument" 28 | array(3) { 29 | ["document_boost"]=> 30 | float(0) 31 | ["field_count"]=> 32 | int(1) 33 | ["fields"]=> 34 | array(1) { 35 | [0]=> 36 | object(SolrDocumentField)#%d (3) { 37 | ["name"]=> 38 | string(2) "id" 39 | ["boost"]=> 40 | float(0) 41 | ["values"]=> 42 | array(1) { 43 | [0]=> 44 | string(9) "CHILD_1_1" 45 | } 46 | } 47 | } 48 | } 49 | string(17) "SolrInputDocument" 50 | array(3) { 51 | ["document_boost"]=> 52 | float(0) 53 | ["field_count"]=> 54 | int(1) 55 | ["fields"]=> 56 | array(1) { 57 | [0]=> 58 | object(SolrDocumentField)#%d (3) { 59 | ["name"]=> 60 | string(2) "id" 61 | ["boost"]=> 62 | float(0) 63 | ["values"]=> 64 | array(1) { 65 | [0]=> 66 | string(9) "CHILD_2_1" 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/029.solrdocument_serialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument - clone 3 | --SKIPIF-- 4 | = 80100) die("skip PHP < 8.1 only"); ?> 5 | --FILE-- 6 | response->docs[1]; 15 | 16 | $serializedString = serialize($doc); 17 | print_r($serializedString); 18 | echo PHP_EOL; 19 | print_r(unserialize($serializedString)->toArray()); 20 | ?> 21 | --EXPECT-- 22 | C:12:"SolrDocument":172:{ 23 | 24 | 25 | 26 | parent_2 27 | 28 | 29 | 30 | } 31 | Array 32 | ( 33 | [document_boost] => 0 34 | [field_count] => 1 35 | [fields] => Array 36 | ( 37 | [0] => SolrDocumentField Object 38 | ( 39 | [name] => id 40 | [boost] => 0 41 | [values] => Array 42 | ( 43 | [0] => parent_2 44 | ) 45 | 46 | ) 47 | 48 | ) 49 | 50 | ) 51 | -------------------------------------------------------------------------------- /tests/029.solrdocument_serialize_php81.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument - clone 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | response->docs[1]; 15 | 16 | $serializedString = serialize($doc); 17 | print_r($serializedString); 18 | echo PHP_EOL; 19 | print_r(unserialize($serializedString)->toArray()); 20 | ?> 21 | --EXPECT-- 22 | O:12:"SolrDocument":1:{s:3:"xml";s:172:" 23 | 24 | 25 | 26 | parent_2 27 | 28 | 29 | 30 | ";} 31 | Array 32 | ( 33 | [document_boost] => 0 34 | [field_count] => 1 35 | [fields] => Array 36 | ( 37 | [0] => SolrDocumentField Object 38 | ( 39 | [name] => id 40 | [boost] => 0 41 | [values] => Array 42 | ( 43 | [0] => parent_2 44 | ) 45 | 46 | ) 47 | 48 | ) 49 | 50 | ) 51 | -------------------------------------------------------------------------------- /tests/030.solrdocument_magic.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument - magic __isset/__unset/__get/__set 3 | --FILE-- 4 | check = 1; 11 | $doc->deleteMe = 1; 12 | 13 | var_dump(isset($doc->check)); 14 | var_dump(isset($doc->doesNotExist)); 15 | 16 | 17 | var_dump(isset($doc->deleteMe)); 18 | unset($doc->deleteMe); 19 | var_dump(isset($doc->deleteMe)); 20 | 21 | $doc->addField('id', 1); 22 | 23 | var_dump($doc->id instanceof SolrDocumentField); 24 | ?> 25 | --EXPECTF-- 26 | bool(true) 27 | bool(false) 28 | bool(true) 29 | bool(false) 30 | bool(true) -------------------------------------------------------------------------------- /tests/031.solrdocument_clear.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::clear - Remove all fields from the document 3 | --FILE-- 4 | check = 1; 16 | 17 | var_dump($doc->getFieldCount()); 18 | $doc->clear(); 19 | var_dump($doc->getFieldCount()); 20 | ?> 21 | --EXPECTF-- 22 | int(1) 23 | int(0) -------------------------------------------------------------------------------- /tests/032.solrdocument_fieldexists.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::fieldExists 3 | --FILE-- 4 | check = 1; 16 | 17 | var_dump($doc->fieldExists('check')); 18 | var_dump($doc->fieldExists('nonExistingField')); 19 | ?> 20 | --EXPECT-- 21 | bool(true) 22 | bool(false) -------------------------------------------------------------------------------- /tests/033.solrdocument_sort.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::sort - Sort Document fields 3 | --FILE-- 4 | addField('z1', 'z1val'); 11 | $doc->addField('z1', 'z1val2'); 12 | $doc->addField('z1', 'z1val3'); 13 | 14 | $doc->addField('id', 334455); 15 | $doc->addField('cat', 'Software'); 16 | $doc->addField('cat', 'Lucene'); 17 | 18 | separator('unsorted'); 19 | print_r($doc->getFieldNames()); 20 | 21 | separator('field ASC'); 22 | $doc->sort(SolrDocument::SORT_FIELD_NAME, SolrDocument::SORT_ASC); 23 | print_r($doc->getFieldNames()); 24 | separator('field DESC'); 25 | $doc->sort(SolrDocument::SORT_FIELD_NAME, SolrDocument::SORT_DESC); 26 | print_r($doc->getFieldNames()); 27 | 28 | separator('value ASC'); 29 | $doc->sort(SolrDocument::SORT_FIELD_VALUE_COUNT, SolrDocument::SORT_ASC); 30 | print_r($doc->getFieldNames()); 31 | separator('value DESC'); 32 | $doc->sort(SolrDocument::SORT_FIELD_VALUE_COUNT, SolrDocument::SORT_DESC); 33 | print_r($doc->getFieldNames()); 34 | ?> 35 | --EXPECT-- 36 | =================================== unsorted =================================== 37 | Array 38 | ( 39 | [0] => z1 40 | [1] => id 41 | [2] => cat 42 | ) 43 | ================================== field ASC =================================== 44 | Array 45 | ( 46 | [0] => cat 47 | [1] => id 48 | [2] => z1 49 | ) 50 | ================================== field DESC ================================== 51 | Array 52 | ( 53 | [0] => z1 54 | [1] => id 55 | [2] => cat 56 | ) 57 | ================================== value ASC =================================== 58 | Array 59 | ( 60 | [0] => id 61 | [1] => cat 62 | [2] => z1 63 | ) 64 | ================================== value DESC ================================== 65 | Array 66 | ( 67 | [0] => z1 68 | [1] => cat 69 | [2] => id 70 | ) 71 | -------------------------------------------------------------------------------- /tests/034.solrdocument_deletefield.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::deleteField 3 | --FILE-- 4 | check = 1; 11 | 12 | var_dump($doc->getFieldCount()); 13 | $doc->deleteField('check'); 14 | var_dump($doc->getFieldCount()); 15 | ?> 16 | --EXPECTF-- 17 | int(1) 18 | int(0) -------------------------------------------------------------------------------- /tests/035.solrdocument_getfieldnames.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::getFieldNames 3 | --FILE-- 4 | addField('id', 334455); 10 | $doc->addField('manu_id_s', 'apache'); 11 | $doc->addField('cat', 'Software'); 12 | 13 | print_r($doc->getFieldNames()); 14 | ?> 15 | --EXPECT-- 16 | Array 17 | ( 18 | [0] => id 19 | [1] => manu_id_s 20 | [2] => cat 21 | ) 22 | -------------------------------------------------------------------------------- /tests/036.solrdocument_array_access.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument - Array Access 3 | --FILE-- 4 | addField('id', 334455); 10 | $doc->addField('manu_id_s', 'apache'); 11 | // set 12 | $doc['cat'] = 'Software'; 13 | 14 | // get 15 | var_dump($doc['cat']->values[0]); 16 | 17 | // exists 18 | var_dump(isset($doc['cat'])); 19 | 20 | // unset 21 | unset($doc['cat']); 22 | print_r($doc->toArray()); 23 | ?> 24 | --EXPECT-- 25 | string(8) "Software" 26 | bool(true) 27 | Array 28 | ( 29 | [document_boost] => 0 30 | [field_count] => 2 31 | [fields] => Array 32 | ( 33 | [0] => SolrDocumentField Object 34 | ( 35 | [name] => id 36 | [boost] => 0 37 | [values] => Array 38 | ( 39 | [0] => 334455 40 | ) 41 | 42 | ) 43 | 44 | [1] => SolrDocumentField Object 45 | ( 46 | [name] => manu_id_s 47 | [boost] => 0 48 | [values] => Array 49 | ( 50 | [0] => apache 51 | ) 52 | 53 | ) 54 | 55 | ) 56 | 57 | ) 58 | -------------------------------------------------------------------------------- /tests/037.solrdocument_getfield.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument::getField 3 | --FILE-- 4 | check = 1; 16 | 17 | var_dump($doc->getField('check') instanceof SolrDocumentField); 18 | ?> 19 | --EXPECT-- 20 | bool(true) -------------------------------------------------------------------------------- /tests/041.solrobject_illegal_operation.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrObject - checking illegal operation of modifying object 3 | --FILE-- 4 | email = "iekpo@php.net"; 11 | } catch (Exception $e) { 12 | var_dump($e->getCode()); 13 | var_dump($e->getMessage()); 14 | } 15 | 16 | try { 17 | $solrObject['usingOffset'] = 'test'; 18 | } catch (SolrIllegalOperationException $e) { 19 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()) . PHP_EOL; 20 | } 21 | 22 | try { 23 | $solrObject['newprop2_dimension_access'] = 'test'; 24 | } catch (SolrIllegalOperationException $e) { 25 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()) . PHP_EOL; 26 | } 27 | 28 | // unset 29 | try { 30 | unset($solrObject->responseHeader); 31 | } catch (SolrIllegalOperationException $e) { 32 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()) . PHP_EOL; 33 | } 34 | 35 | try { 36 | unset($solrObject['responseHeader']); 37 | } catch (SolrIllegalOperationException $e) { 38 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()) . PHP_EOL; 39 | } 40 | 41 | ?> 42 | --EXPECTF-- 43 | int(1006) 44 | string(83) "SolrObject instances are read-only. Properties cannot be added, updated or removed." 45 | 46 | Warning: main(): Attempting to set value for [usingOffset] property in a SolrObject instance in %s on line %d 47 | Exception 1006: SolrObject instances are read-only. Properties cannot be added, updated or removed. 48 | 49 | Warning: main(): Attempting to set value for [newprop2_dimension_access] property in a SolrObject instance in %s on line %d 50 | Exception 1006: SolrObject instances are read-only. Properties cannot be added, updated or removed. 51 | Exception 1006: SolrObject instances are read-only. Properties cannot be added, updated or removed. 52 | 53 | Warning: main(): Attempting to remove [responseHeader] property in a SolrObject instance in %s on line %d 54 | Exception 1006: SolrObject instances are read-only. Properties cannot be added, updated or removed. 55 | -------------------------------------------------------------------------------- /tests/042.solrobject_magic_property.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrObject - testing the magic property access 3 | --FILE-- 4 | system->threadDump->thread->stackTrace); 13 | 14 | ?> 15 | --EXPECT-- 16 | Array 17 | ( 18 | [0] => java.net.PlainSocketImpl.socketAccept(Native Method) 19 | [1] => java.net.PlainSocketImpl.accept(PlainSocketImpl.java:384) 20 | [2] => java.net.ServerSocket.implAccept(ServerSocket.java:450) 21 | [3] => java.net.ServerSocket.accept(ServerSocket.java:421) 22 | [4] => org.apache.catalina.core.StandardServer.await(StandardServer.java:389) 23 | [5] => org.apache.catalina.startup.Catalina.await(Catalina.java:642) 24 | [6] => org.apache.catalina.startup.Catalina.start(Catalina.java:602) 25 | [7] => sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 26 | [8] => sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 27 | [9] => sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 28 | [10] => java.lang.reflect.Method.invoke(Method.java:585) 29 | [11] => org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) 30 | [12] => org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) 31 | ) 32 | -------------------------------------------------------------------------------- /tests/043.solrobject_magic_properties.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrObject - test property access 3 | --FILE-- 4 | responseHeader; 13 | 14 | $system = $solrObject->system; 15 | 16 | var_dump(isset($solrObject['system'])); 17 | var_dump(property_exists($solrObject, 'system')); 18 | ?> 19 | --EXPECT-- 20 | bool(true) 21 | bool(true) -------------------------------------------------------------------------------- /tests/046.solrobject_getpropertynames.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrObject - SolrObject::getPropertyNames() 3 | --FILE-- 4 | getPropertyNames()); 9 | 10 | require_once "bootstrap.inc"; 11 | 12 | $xml_reponse = file_get_contents(EXAMPLE_RESPONSE_XML_1); 13 | 14 | $solrObject = SolrUtils::digestXMLResponse($xml_reponse); 15 | 16 | var_dump($solrObject->getPropertyNames()); 17 | ?> 18 | --EXPECT-- 19 | array(0) { 20 | } 21 | array(2) { 22 | [0]=> 23 | string(14) "responseHeader" 24 | [1]=> 25 | string(6) "system" 26 | } 27 | -------------------------------------------------------------------------------- /tests/047.solrobject_offsetExists.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrObject::offsetExists 3 | --FILE-- 4 | 18 | --EXPECT-- 19 | bool(false) 20 | bool(true) 21 | bool(false) -------------------------------------------------------------------------------- /tests/050.solrinputdocument_addchilddocument_01.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::addChildDocument() - add child document 3 | --FILE-- 4 | addField('id', 1123); 13 | $doc->addField('features', "PHP Client Side"); 14 | $doc->addField('features', "Fast development cycles"); 15 | $doc->cat = 'Information Technology'; 16 | 17 | $secondDoc->addField('cat', 'Lucene Search'); 18 | $secondDoc->cat = 'Custom Search'; 19 | 20 | $doc->addChildDocument($secondDoc); 21 | 22 | var_dump($doc->hasChildDocuments(), $secondDoc->hasChildDocuments()); 23 | 24 | $childs = $doc->getChildDocuments(); 25 | print_r($childs[0]->getField('cat')); 26 | 27 | ?> 28 | --EXPECT-- 29 | bool(true) 30 | bool(false) 31 | SolrDocumentField Object 32 | ( 33 | [name] => cat 34 | [boost] => 0 35 | [values] => Array 36 | ( 37 | [0] => Lucene Search 38 | ) 39 | 40 | ) 41 | -------------------------------------------------------------------------------- /tests/050.solrinputdocument_addchilddocument_02_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::addChildDocument()/SolrInputDocument::addChildDocuments() - Expected SolrIllegalArgumentException 3 | --FILE-- 4 | addField('id', 1123); 14 | $doc->addField('features', "PHP Client Side"); 15 | $doc->addField('features', "Fast development cycles"); 16 | $doc->cat = 'Information Technology'; 17 | try { 18 | $doc->addChildDocument($child1); 19 | } catch (SolrIllegalArgumentException $e) { 20 | echo $e->getMessage(). PHP_EOL; 21 | } 22 | 23 | $children = array($child1, $child2); 24 | try { 25 | $doc->addChildDocuments($children); 26 | } catch (SolrIllegalArgumentException $e) { 27 | echo $e->getMessage(). PHP_EOL; 28 | } 29 | ?> 30 | --EXPECT-- 31 | Child document has no fields 32 | SolrInputDocument number 1 has no fields -------------------------------------------------------------------------------- /tests/051.solrinputdocument_getchilddocuments.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::getChildDocuments() - test 3 | --FILE-- 4 | addField('id', 1123); 13 | $doc->addField('features', "PHP Client Side"); 14 | $doc->addField('features', "Fast development cycles"); 15 | $doc->cat = 'Information Technology'; 16 | 17 | $secondDoc->addField('cat', 'Lucene Search'); 18 | $secondDoc->cat = 'Custom Search'; 19 | 20 | $doc->addChildDocument($secondDoc); 21 | 22 | $childs = $doc->getChildDocuments(); 23 | print_r($childs[0]->getField('cat')); 24 | 25 | ?> 26 | --EXPECT-- 27 | SolrDocumentField Object 28 | ( 29 | [name] => cat 30 | [boost] => 0 31 | [values] => Array 32 | ( 33 | [0] => Lucene Search 34 | ) 35 | 36 | ) -------------------------------------------------------------------------------- /tests/052.solrinputdocument_haschilddocuments.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::hasChildDocuments() - test 3 | --FILE-- 4 | addField('id', 1123); 13 | $doc->addField('features', "PHP Client Side"); 14 | $doc->addField('features', "Fast development cycles"); 15 | $doc->cat = 'Information Technology'; 16 | 17 | $secondDoc->addField('cat', 'Lucene Search'); 18 | $secondDoc->cat = 'Custom Search'; 19 | 20 | $doc->addChildDocument($secondDoc); 21 | 22 | var_dump($doc->hasChildDocuments()); 23 | var_dump($secondDoc->hasChildDocuments()); 24 | ?> 25 | --EXPECT-- 26 | bool(true) 27 | bool(false) -------------------------------------------------------------------------------- /tests/053.solrinputdocument_getchilddocumentscount.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::getChildDocumentsCount() - test 3 | --FILE-- 4 | addField('id', 1123); 13 | $doc->addField('features', "PHP Client Side"); 14 | $doc->addField('features', "Fast development cycles"); 15 | $doc->cat = 'Information Technology'; 16 | 17 | $secondDoc->addField('cat', 'Lucene Search'); 18 | $secondDoc->cat = 'Custom Search'; 19 | 20 | $doc->addChildDocument($secondDoc); 21 | 22 | var_dump($doc->getChildDocumentsCount()); 23 | var_dump($secondDoc->getChildDocumentsCount()); 24 | ?> 25 | --EXPECT-- 26 | int(1) 27 | int(0) -------------------------------------------------------------------------------- /tests/054.solrinputdocument_addchilddocuments.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::addChildDocuments() - add child documents 3 | --FILE-- 4 | addField('id', 1123); 14 | $doc->addField('features', "PHP Client Side"); 15 | $doc->addField('features', "Fast development cycles"); 16 | $doc->cat = 'Information Technology'; 17 | 18 | $doc2->addField('cat', 'Lucene Search'); 19 | $doc2->cat = 'Custom Search'; 20 | 21 | $doc2->addField('cat', 'Lucene Search'); 22 | $doc2->cat = 'Custom Search'; 23 | 24 | $doc3->addField('cat', 'Lucene Search'); 25 | $doc3->cat = 'Custom Search'; 26 | $docs = array($doc2, $doc3); 27 | $doc->addChildDocuments($docs); 28 | 29 | var_dump($doc->getChildDocumentsCount()); 30 | ?> 31 | --EXPECT-- 32 | int(2) -------------------------------------------------------------------------------- /tests/055.solrinputdocument_serialization.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument - serialize/unserialize Exception 3 | --FILE-- 4 | getMessage().PHP_EOL; 14 | } 15 | ?> 16 | --EXPECT-- 17 | SolrInputDocument objects cannot be serialized or unserialized -------------------------------------------------------------------------------- /tests/056.solrinputdocument_toArray.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::toArray - Array conversion 3 | --FILE-- 4 | addField('field_1', 4, 3.4); 11 | $doc->addField('field_2', 1); 12 | 13 | print_r($doc->toArray()); 14 | ?> 15 | --EXPECT-- 16 | Array 17 | ( 18 | [document_boost] => 0 19 | [field_count] => 2 20 | [fields] => Array 21 | ( 22 | [0] => SolrDocumentField Object 23 | ( 24 | [name] => field_1 25 | [boost] => 3.4 26 | [values] => Array 27 | ( 28 | [0] => 4 29 | ) 30 | 31 | ) 32 | 33 | [1] => SolrDocumentField Object 34 | ( 35 | [name] => field_2 36 | [boost] => 0 37 | [values] => Array 38 | ( 39 | [0] => 1 40 | ) 41 | 42 | ) 43 | 44 | ) 45 | 46 | ) 47 | -------------------------------------------------------------------------------- /tests/057.solrinputdocument_clone.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument - clone 3 | --FILE-- 4 | setBoost(4); 9 | $doc->addField('id', 334455); 10 | $doc->addField('cat', 'Software', 4); 11 | $doc->addField('cat', 'Lucene'); 12 | 13 | $doc2 = clone $doc; 14 | $doc2->deleteField('id'); 15 | $doc2->addField('id', '88', 8); 16 | 17 | print_r($doc->toArray()); 18 | print_r($doc2->toArray()); 19 | ?> 20 | --EXPECTF-- 21 | Array 22 | ( 23 | [document_boost] => 4 24 | [field_count] => 2 25 | [fields] => Array 26 | ( 27 | [0] => SolrDocumentField Object 28 | ( 29 | [name] => id 30 | [boost] => 0 31 | [values] => Array 32 | ( 33 | [0] => 334455 34 | ) 35 | 36 | ) 37 | 38 | [1] => SolrDocumentField Object 39 | ( 40 | [name] => cat 41 | [boost] => 4 42 | [values] => Array 43 | ( 44 | [0] => Software 45 | [1] => Lucene 46 | ) 47 | 48 | ) 49 | 50 | ) 51 | 52 | ) 53 | Array 54 | ( 55 | [document_boost] => 4 56 | [field_count] => 2 57 | [fields] => Array 58 | ( 59 | [0] => SolrDocumentField Object 60 | ( 61 | [name] => cat 62 | [boost] => 4 63 | [values] => Array 64 | ( 65 | [0] => Software 66 | [1] => Lucene 67 | ) 68 | 69 | ) 70 | 71 | [1] => SolrDocumentField Object 72 | ( 73 | [name] => id 74 | [boost] => 8 75 | [values] => Array 76 | ( 77 | [0] => 88 78 | ) 79 | 80 | ) 81 | 82 | ) 83 | 84 | ) 85 | -------------------------------------------------------------------------------- /tests/058.solrinputdocument_deletefield.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::deleteField - Delete a field from SolrInputDocument 3 | --FILE-- 4 | addField('id', 334455); 10 | $doc->addField('cat', 'Software'); 11 | $doc->addField('cat', 'Lucene'); 12 | $doc->addField('deleteme', 'Lucene'); 13 | $doc->deleteField('deleteme'); 14 | 15 | print_r($doc->toArray()); 16 | ?> 17 | --EXPECT-- 18 | Array 19 | ( 20 | [document_boost] => 0 21 | [field_count] => 2 22 | [fields] => Array 23 | ( 24 | [0] => SolrDocumentField Object 25 | ( 26 | [name] => id 27 | [boost] => 0 28 | [values] => Array 29 | ( 30 | [0] => 334455 31 | ) 32 | 33 | ) 34 | 35 | [1] => SolrDocumentField Object 36 | ( 37 | [name] => cat 38 | [boost] => 0 39 | [values] => Array 40 | ( 41 | [0] => Software 42 | [1] => Lucene 43 | ) 44 | 45 | ) 46 | 47 | ) 48 | 49 | ) 50 | -------------------------------------------------------------------------------- /tests/059.solrinputdocument_clear.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::clear - Clear document fields 3 | --FILE-- 4 | addField('id', 334455); 11 | $doc->addField('cat', 'Software'); 12 | $doc->addField('cat', 'Lucene'); 13 | $doc->addField('z1', 'z1val'); 14 | 15 | $doc->clear(); 16 | 17 | var_dump($doc->toArray()); 18 | ?> 19 | --EXPECT-- 20 | array(3) { 21 | ["document_boost"]=> 22 | float(0) 23 | ["field_count"]=> 24 | int(0) 25 | ["fields"]=> 26 | array(0) { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/059.solrinputdocument_fieldexists.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::fieldExists 3 | --FILE-- 4 | addField('id', 1123); 10 | 11 | var_dump($doc->fieldExists('id')); 12 | var_dump($doc->fieldExists('features')); 13 | ?> 14 | --EXPECT-- 15 | bool(true) 16 | bool(false) -------------------------------------------------------------------------------- /tests/059.solrinputdocument_getboost.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::getBoost - Test document fieldnames 3 | --FILE-- 4 | setBoost(4); 9 | var_dump($doc->getBoost()); 10 | ?> 11 | --EXPECT-- 12 | float(4) -------------------------------------------------------------------------------- /tests/059.solrinputdocument_getfield.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::getField 3 | --FILE-- 4 | addField('id', 123); 10 | $doc->addField('cat', 'Software'); 11 | 12 | var_dump($doc->getField('id')); 13 | var_dump($doc->getField('non_existing_field')); 14 | ?> 15 | --EXPECT-- 16 | object(SolrDocumentField)#2 (3) { 17 | ["name"]=> 18 | string(2) "id" 19 | ["boost"]=> 20 | float(0) 21 | ["values"]=> 22 | array(1) { 23 | [0]=> 24 | string(3) "123" 25 | } 26 | } 27 | bool(false) 28 | -------------------------------------------------------------------------------- /tests/059.solrinputdocument_getfieldcount.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::getFieldCount 3 | --FILE-- 4 | addField('id', 123); 10 | $doc->addField('cat', 'Software'); 11 | $doc->addField('cat', 'Search Server'); 12 | $doc->addField('features', 'Software'); 13 | 14 | var_dump($doc->getFieldCount()); 15 | 16 | ?> 17 | --EXPECT-- 18 | int(3) -------------------------------------------------------------------------------- /tests/059.solrinputdocument_getfieldnames.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::getFieldNames - Test document fieldnames 3 | --FILE-- 4 | addField('id', 334455); 10 | $doc->addField('manu_id_s', 'apache'); 11 | $doc->addField('cat', 'Software'); 12 | 13 | print_r($doc->getFieldNames()); 14 | ?> 15 | --EXPECT-- 16 | Array 17 | ( 18 | [0] => id 19 | [1] => manu_id_s 20 | [2] => cat 21 | ) 22 | -------------------------------------------------------------------------------- /tests/059.solrinputdocument_set_getfieldboost.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::getFieldBoost 3 | --FILE-- 4 | addField('id', 123); 10 | $doc->addField('cat', 'Software'); 11 | 12 | $doc->setFieldBoost('cat', 2.1); 13 | var_dump($doc->getFieldBoost('cat')); 14 | 15 | ?> 16 | --EXPECT-- 17 | float(2.1) -------------------------------------------------------------------------------- /tests/059.solrinputdocument_setversion.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrInputDocument::setVersion - Set document version 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addField('id', 'IW-02'); 13 | 14 | $doc->setVersion(SolrInputDocument::VERSION_ASSERT_EXISTS); 15 | var_dump($doc->getVersion()); 16 | 17 | $doc->setVersion(SolrInputDocument::VERSION_ASSERT_NOT_EXISTS); 18 | var_dump($doc->getVersion()); 19 | 20 | $doc->setVersion(SolrInputDocument::VERSION_ASSERT_NONE); 21 | var_dump($doc->getVersion()); 22 | 23 | $doc->setVersion(1498562624496861184); 24 | var_dump($doc->getVersion()); 25 | 26 | try { 27 | $doc->setVersion('AAAA-3333'); 28 | } catch (SolrIllegalArgumentException $e) { 29 | echo $e->getMessage(); 30 | } catch (TypeError $e) { 31 | echo $e->getMessage(); 32 | } 33 | 34 | ?> 35 | --EXPECTF-- 36 | int(1) 37 | int(-1) 38 | int(0) 39 | int(1498562624496861184) 40 | %slrInputDocument::setVersion()%s, string given 41 | -------------------------------------------------------------------------------- /tests/060.solrquery_comon_query_params.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery - testing CommonQueryParameters 3 | --FILE-- 4 | getQuery(), 10 | $query->getTimeAllowed(), 11 | $query->getStart(), 12 | $query->getRows(), 13 | $query->getFields(), 14 | $query->getFilterQueries(), 15 | $query->getSortFields() 16 | ); 17 | $nullOutput = ob_get_clean(); 18 | 19 | $query->setParam('a', 1); 20 | $query->setParam('b', 2); 21 | $query->setParam('c', 3); 22 | 23 | $query->setStart(4)->setQuery('solr')->setTimeAllowed(500)->setRows(17); 24 | 25 | $query->addField('israel')->addField('joshua')->addField('june'); 26 | 27 | $query->addSortField('cat', SolrQuery::ORDER_ASC); 28 | 29 | $query->addFilterQuery('solr')->addFilterQuery('solr1')->addFilterQuery('solr2'); 30 | 31 | $query 32 | ->setShowDebugInfo(true) 33 | ->setExplainOther('id:SOL*') 34 | ->setOmitHeader(false) 35 | ->setEchoHandler(true) 36 | ->setEchoParams('all') 37 | ; 38 | 39 | echo $query . PHP_EOL . PHP_EOL; 40 | 41 | var_dump( 42 | $query->getQuery(), 43 | $query->getTimeAllowed(), 44 | $query->getStart(), 45 | $query->getRows(), 46 | $query->getFields(), 47 | $query->getFilterQueries(), 48 | $query->getSortFields() 49 | ); 50 | 51 | echo $nullOutput; 52 | ?> 53 | --EXPECT-- 54 | a=1&b=2&c=3&start=4&q=solr&timeAllowed=500&rows=17&fl=israel,joshua,june&sort=cat asc&fq=solr&fq=solr1&fq=solr2&debugQuery=true&explainOther=id:SOL*&omitHeader=false&echoHandler=true&echoParams=all 55 | 56 | string(4) "solr" 57 | int(500) 58 | int(4) 59 | int(17) 60 | array(3) { 61 | [0]=> 62 | string(6) "israel" 63 | [1]=> 64 | string(6) "joshua" 65 | [2]=> 66 | string(4) "june" 67 | } 68 | array(3) { 69 | [0]=> 70 | string(4) "solr" 71 | [1]=> 72 | string(5) "solr1" 73 | [2]=> 74 | string(5) "solr2" 75 | } 76 | array(1) { 77 | [0]=> 78 | string(7) "cat asc" 79 | } 80 | NULL 81 | NULL 82 | NULL 83 | NULL 84 | NULL 85 | NULL 86 | NULL -------------------------------------------------------------------------------- /tests/061.solrquery_simpleFacetParameters.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery - testing SimpleFacetParameters 3 | --FILE-- 4 | setFacet(0); 9 | 10 | $query->addFacetField('israel')->addFacetField('israel2'); 11 | 12 | $query->addFacetQuery('silk')->addFacetQuery('name:june'); 13 | 14 | $query->setFacetPrefix('A')->setFacetPrefix('C', 'june'); 15 | 16 | $query->setFacetSort(1)->setFacetSort(0, 'june'); 17 | 18 | $query->setFacetLimit(98)->setFacetLimit(44, 'june'); 19 | 20 | $query->setFacetOffset(110)->setFacetOffset(12, 'june'); 21 | 22 | $query->setFacetMinCount(4)->setFacetMinCount(30, 'june'); 23 | 24 | $query->setFacetMissing(1)->setFacetMissing(0, 'june'); 25 | 26 | $query->setFacetMethod('enum')->setFacetMethod('fc', 'june'); 27 | 28 | $query->setFacetEnumCacheMinDefaultFrequency(25); 29 | 30 | echo $query . PHP_EOL . PHP_EOL; 31 | 32 | var_dump( 33 | $query->getFacet(), 34 | $query->getFacetFields(), 35 | $query->getFacetQueries(), 36 | $query->getFacetPrefix(), 37 | $query->getFacetPrefix('june'), 38 | $query->getFacetSort(), 39 | $query->getFacetSort('june'), 40 | $query->getFacetLimit(), 41 | $query->getFacetLimit('june'), 42 | $query->getFacetOffset(), 43 | $query->getFacetOffset('june'), 44 | $query->getFacetMinCount(), 45 | $query->getFacetMinCount('june'), 46 | $query->getFacetMissing(), 47 | $query->getFacetMissing('june'), 48 | $query->getFacetMethod(), 49 | $query->getFacetMethod('june') 50 | ); 51 | ?> 52 | --EXPECTF-- 53 | facet=false&facet.field=israel&facet.field=israel2&facet.query=silk&facet.query=name:june&facet.prefix=A&f.june.facet.prefix=C&facet.sort=count&f.june.facet.sort=index&facet.limit=98&f.june.facet.limit=44&facet.offset=110&f.june.facet.offset=12&facet.mincount=4&f.june.facet.mincount=30&facet.missing=true&f.june.facet.missing=false&facet.method=enum&f.june.facet.method=fc&facet.enum.cache.minDf=25 54 | 55 | bool(false) 56 | array(2) { 57 | [0]=> 58 | string(6) "israel" 59 | [1]=> 60 | string(7) "israel2" 61 | } 62 | array(2) { 63 | [0]=> 64 | string(4) "silk" 65 | [1]=> 66 | string(9) "name:june" 67 | } 68 | string(1) "A" 69 | string(1) "C" 70 | int(1) 71 | int(0) 72 | int(98) 73 | int(44) 74 | int(110) 75 | int(12) 76 | int(4) 77 | int(30) 78 | bool(true) 79 | bool(false) 80 | string(4) "enum" 81 | string(2) "fc" 82 | -------------------------------------------------------------------------------- /tests/064.solrquery_StatsComponent.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery - testing StatsComponent 3 | --FILE-- 4 | getStats(), 10 | $query->getStatsFields(), 11 | $query->getStatsFacets() 12 | ); 13 | 14 | $nullOutput = ob_get_clean(); 15 | 16 | $query->setStats(0); 17 | 18 | $query 19 | ->addStatsField('hello') 20 | ->removeStatsField('hello') 21 | ->addStatsField('june') 22 | ->addStatsField('july') 23 | ; 24 | 25 | $query 26 | ->addStatsFacet('world') 27 | ->removeStatsFacet('world') 28 | ->addStatsFacet('pear') 29 | ->addStatsFacet('pecl') 30 | ; 31 | 32 | echo $query . PHP_EOL . PHP_EOL; 33 | 34 | var_dump( 35 | $query->getStats(), 36 | $query->getStatsFields(), 37 | $query->getStatsFacets() 38 | ); 39 | echo $nullOutput; 40 | ?> 41 | --EXPECTF-- 42 | stats=false&stats.field=june&stats.field=july&stats.facet=pear&stats.facet=pecl 43 | 44 | bool(false) 45 | array(2) { 46 | [0]=> 47 | string(4) "june" 48 | [1]=> 49 | string(4) "july" 50 | } 51 | array(2) { 52 | [0]=> 53 | string(4) "pear" 54 | [1]=> 55 | string(4) "pecl" 56 | } 57 | NULL 58 | NULL 59 | NULL -------------------------------------------------------------------------------- /tests/066.solrquery_TermsComponent.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery - testing TermsComponent 3 | --FILE-- 4 | getTerms(), 11 | $query->getTermsField(), 12 | $query->getTermsLowerBound(), 13 | $query->getTermsUpperBound(), 14 | $query->getTermsIncludeLowerBound(), 15 | $query->getTermsIncludeUpperBound(), 16 | $query->getTermsMinCount(), 17 | $query->getTermsMaxCount(), 18 | $query->getTermsPrefix(), 19 | $query->getTermsLimit(), 20 | $query->getTermsReturnRaw(), 21 | $query->getTermsSort() 22 | ); 23 | }; 24 | 25 | ob_start(); 26 | $dumpVars(); 27 | $nullOutput = ob_get_clean(); 28 | 29 | $query->setTerms(true); 30 | 31 | $query->setTermsField('israel'); 32 | 33 | $query->setTermsLowerBound('june'); 34 | 35 | $query->setTermsUpperBound('joshua'); 36 | 37 | $query->setTermsIncludeLowerBound(false); 38 | 39 | $query->setTermsIncludeUpperBound(0); 40 | 41 | $query->setTermsMinCount(50); 42 | 43 | $query->setTermsMaxCount(200); 44 | 45 | $query->setTermsPrefix('A'); 46 | 47 | $query->setTermsLimit(45); 48 | 49 | $query->setTermsReturnRaw(false); 50 | 51 | $query->setTermsSort(SolrQuery::TERMS_SORT_INDEX); 52 | 53 | echo $query . PHP_EOL . PHP_EOL; 54 | 55 | $dumpVars(); 56 | 57 | 58 | $query->setTermsSort(SolrQuery::TERMS_SORT_COUNT); 59 | echo PHP_EOL . $query . PHP_EOL . PHP_EOL; 60 | 61 | var_dump( 62 | $query->getTermsSort() 63 | ); 64 | 65 | echo $nullOutput; 66 | ?> 67 | --EXPECTF-- 68 | terms=true&terms.fl=israel&terms.lower=june&terms.upper=joshua&terms.lower.incl=false&terms.upper.incl=false&terms.mincount=50&terms.maxcount=200&terms.prefix=A&terms.limit=45&terms.raw=false&terms.sort=index 69 | 70 | bool(true) 71 | string(6) "israel" 72 | string(4) "june" 73 | string(6) "joshua" 74 | bool(false) 75 | bool(false) 76 | int(50) 77 | int(200) 78 | string(1) "A" 79 | int(45) 80 | bool(false) 81 | int(0) 82 | 83 | terms=true&terms.fl=israel&terms.lower=june&terms.upper=joshua&terms.lower.incl=false&terms.upper.incl=false&terms.mincount=50&terms.maxcount=200&terms.prefix=A&terms.limit=45&terms.raw=false&terms.sort=count 84 | 85 | int(1) 86 | NULL 87 | NULL 88 | NULL 89 | NULL 90 | NULL 91 | NULL 92 | NULL 93 | NULL 94 | NULL 95 | NULL 96 | NULL 97 | NULL 98 | -------------------------------------------------------------------------------- /tests/067.solrquery__construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery::_construct - Throws exception on illegal Argument 3 | --FILE-- 4 | getMessage(); 10 | } catch (TypeError $e) { 11 | echo $e->getMessage(); 12 | } 13 | ?> 14 | --EXPECTF-- 15 | SolrQuery::__construct()%s string, %s given 16 | -------------------------------------------------------------------------------- /tests/068.solrquery_parameters_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery - Invalid Parameters thorws exception Throws exception on illegal Argument 3 | --FILE-- 4 | setQuery(''); 12 | }catch (SolrIllegalArgumentException $e) 13 | { 14 | echo $e->getMessage().PHP_EOL; 15 | try { 16 | // simple list 17 | $query->addField(''); 18 | } catch (SolrIllegalArgumentException $e) { 19 | echo $e->getMessage().PHP_EOL; 20 | try { 21 | // argument list 22 | $query->addSortField(''); 23 | } catch (SolrIllegalArgumentException $e) { 24 | echo $e->getMessage().PHP_EOL; 25 | try { 26 | $params->addParam('',1); 27 | } catch (Exception $e) { 28 | echo $e->getMessage().PHP_EOL; 29 | } 30 | } 31 | } 32 | } 33 | ?> 34 | --EXPECT-- 35 | Invalid parameter value 36 | Invalid parameter value 37 | Invalid parameter value 38 | Invalid parameter name 39 | -------------------------------------------------------------------------------- /tests/070.solrquery_collapse.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery::collapse - Collapse Using a SolrCollapseFunction 3 | --FILE-- 4 | setMax(5); 9 | 10 | $query->collapse($collapseFunction); 11 | 12 | echo $query; 13 | ?> 14 | --EXPECTF-- 15 | q=lucene&fq={!collapse field=ISBN max=5} 16 | -------------------------------------------------------------------------------- /tests/071.solrquery_collapse_exception.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery::collapse - throws SolrMissingMandatoryParameterException 3 | --FILE-- 4 | collapse($collapseFunction); 10 | } catch (SolrMissingMandatoryParameterException $e) { 11 | echo PHP_EOL.sprintf('Exception %d: %s', $e->getCode(), $e->getMessage()); 12 | } 13 | ?> 14 | --EXPECTF-- 15 | Exception 4100: Mandatory parameter Missing: field 16 | -------------------------------------------------------------------------------- /tests/072.solrquery_expand.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery - Expand Component 3 | --FILE-- 4 | setExpand(true); 9 | $query->setExpandRows(50); 10 | $query->setExpandQuery('text:product'); 11 | $query->addExpandFilterQuery('manu:apple')->addExpandFilterQuery('inStock:true'); 12 | $query->addExpandSortField('score', SolrQuery::ORDER_DESC)->addExpandSortField('title', SolrQuery::ORDER_ASC); 13 | 14 | // removal test 15 | $query->addExpandFilterQuery('extra')->removeExpandFilterQuery('extra'); 16 | $query->addExpandSortField('extra', SolrQuery::ORDER_ASC)->removeExpandSortField('extra'); 17 | 18 | echo $query.PHP_EOL; 19 | var_dump($query->getExpand()).PHP_EOL; 20 | var_dump($query->getExpandRows()).PHP_EOL; 21 | var_dump($query->getExpandQuery()).PHP_EOL; 22 | var_dump($query->getExpandFilterQueries()).PHP_EOL; 23 | var_dump($query->getExpandSortFields()).PHP_EOL; 24 | ?> 25 | --EXPECTF-- 26 | q=lucene&expand=true&expand.rows=50&expand.q=text:product&expand.fq=manu:apple&expand.fq=inStock:true&expand.sort=score desc,title asc 27 | bool(true) 28 | int(50) 29 | string(12) "text:product" 30 | array(2) { 31 | [0]=> 32 | string(10) "manu:apple" 33 | [1]=> 34 | string(12) "inStock:true" 35 | } 36 | array(2) { 37 | [0]=> 38 | string(5) "score" 39 | [1]=> 40 | string(5) "title" 41 | } 42 | -------------------------------------------------------------------------------- /tests/080.solrutils_escapequerychars.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrUtils::escapeQueryChars() - Testing Lucene Reserved Characters 3 | --FILE-- 4 | 10 | --EXPECTF-- 11 | \+a \- q\{ \} \[\^test\] \|| \&& \(\) \^ \" \~ \* \? \: \\ \/ -------------------------------------------------------------------------------- /tests/082.solrutils_getsolrversion.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrUtils::getSolrVersion() - Returns solr dotted version 3 | --FILE-- 4 | 11 | --EXPECTF-- 12 | %d.%d.%d 13 | %d.%d.%d -------------------------------------------------------------------------------- /tests/083.solrutils_getsolrstats.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrUtils::getSolrStats() - Get Statistics about number of documents/clients..etc 3 | --FILE-- 4 | SOLR_SERVER_HOSTNAME, 11 | 'login' => SOLR_SERVER_USERNAME, 12 | 'password' => SOLR_SERVER_PASSWORD, 13 | 'port' => SOLR_SERVER_PORT, 14 | 'path' => SOLR_SERVER_PATH 15 | ); 16 | 17 | $client = new SolrClient ( $options ); 18 | 19 | $solrDoc = new SolrInputDocument(); 20 | 21 | $params = new SolrModifiableParams(); 22 | 23 | var_dump(SolrUtils::getSolrStats()); 24 | 25 | ?> 26 | --EXPECT-- 27 | array(3) { 28 | ["document_count"]=> 29 | int(0) 30 | ["client_count"]=> 31 | int(0) 32 | ["params_count"]=> 33 | int(0) 34 | } 35 | array(3) { 36 | ["document_count"]=> 37 | int(1) 38 | ["client_count"]=> 39 | int(1) 40 | ["params_count"]=> 41 | int(1) 42 | } 43 | -------------------------------------------------------------------------------- /tests/084.solrutils_queryphrase.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrUtils::queryPhrase() - Escapes a query phrase 3 | --FILE-- 4 | 9 | --EXPECT-- 10 | "Book Title\: Apache Solr Server" 11 | -------------------------------------------------------------------------------- /tests/090.solrserverexception_xml.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrServerException (xml) - Throw Exception on solr server exception using xml response writer 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH, 17 | // 'wt' => 'xml' 18 | ); 19 | 20 | $client = new SolrClient ( $options ); 21 | $query = new SolrQuery ( "lucene\\" ); 22 | try { 23 | $response = $client->query ( $query ); 24 | } catch ( SolrServerException $e ) { 25 | echo sprintf("code: %d", $e->getCode()).PHP_EOL; 26 | echo sprintf("message: %s", $e->getMessage()).PHP_EOL; 27 | print_r($e->getInternalInfo()); 28 | } 29 | 30 | ?> 31 | --EXPECTF-- 32 | code: %d 33 | message: %s 34 | Array 35 | ( 36 | [sourceline] => %d 37 | [sourcefile] => %s 38 | [zif_name] => %s 39 | ) 40 | -------------------------------------------------------------------------------- /tests/091.solrserverexception_json.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrServerException (json) - Throw Exception on solr server exception using json response writer 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH, 17 | 'wt' => 'json' 18 | ); 19 | 20 | $client = new SolrClient ( $options ); 21 | $query = new SolrQuery ( "lucene\\" ); 22 | try { 23 | $response = $client->query ( $query ); 24 | print_r ( $response ); 25 | } catch ( SolrServerException $e ) { 26 | echo sprintf("code: %d", $e->getCode()).PHP_EOL; 27 | echo sprintf("message: %s", $e->getMessage()).PHP_EOL; 28 | } 29 | 30 | ?> 31 | --EXPECTF-- 32 | code: %d 33 | message: %s -------------------------------------------------------------------------------- /tests/092.solrserverexception_php.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrServerException (phps) - Throw Exception on solr server exception using phps response writer 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH, 17 | 'wt' => 'phps' 18 | ); 19 | 20 | $client = new SolrClient ( $options ); 21 | $query = new SolrQuery ( "lucene\\" ); 22 | try { 23 | $response = $client->query ( $query ); 24 | print_r ( $response ); 25 | } catch ( SolrServerException $e ) { 26 | echo sprintf("code: %d", $e->getCode()).PHP_EOL; 27 | echo sprintf("message: %s", $e->getMessage()).PHP_EOL; 28 | } 29 | 30 | ?> 31 | --EXPECTF-- 32 | code: %d 33 | message: %s -------------------------------------------------------------------------------- /tests/100.solrresponse_json.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse::getResponse - JSON response writer 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH, 17 | 'wt' => 'json' 18 | ); 19 | 20 | $client = new SolrClient ( $options ); 21 | $query = new SolrQuery ( "lucene" ); 22 | 23 | $response = $client->query ( $query ); 24 | 25 | $x = $response->getResponse(); 26 | var_dump($x instanceof SolrObject); 27 | ?> 28 | --EXPECTF-- 29 | bool(true) -------------------------------------------------------------------------------- /tests/101.solrresponse_parseMode.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse - ParseMode 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH, 17 | 'wt' => 'xml' 18 | ); 19 | 20 | $client = new SolrClient ( $options ); 21 | $query = new SolrQuery ( "lucene" ); 22 | 23 | $response = $client->query ( $query ); 24 | 25 | $response->setParseMode(SolrResponse::PARSE_SOLR_DOC); 26 | $x = $response->getResponse(); 27 | var_dump($x->response->docs[0] instanceof SolrDocument); 28 | ?> 29 | --EXPECTF-- 30 | bool(true) -------------------------------------------------------------------------------- /tests/102.solrresponse_phps.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse::getResponse - PHPS response writer 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH, 17 | 'wt' => 'phps' 18 | ); 19 | 20 | $client = new SolrClient ( $options ); 21 | $query = new SolrQuery ( "lucene" ); 22 | 23 | $response = $client->query ( $query ); 24 | 25 | $x = $response->getResponse(); 26 | var_dump($x instanceof SolrObject); 27 | ?> 28 | --EXPECTF-- 29 | bool(true) -------------------------------------------------------------------------------- /tests/103.solrresponse_get_array_response.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse::getArrayResponse - For All response writers 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH, 17 | ); 18 | 19 | $client = new SolrClient ( $options ); 20 | 21 | 22 | $testArrayResponse = function ($writer) use ($client){ 23 | $client->setResponseWriter($writer); 24 | $q = new SolrQuery("lucene"); 25 | $response = $client->query ( $q ); 26 | $arrayResponse = $response->getArrayResponse(); 27 | return is_array($arrayResponse); 28 | }; 29 | 30 | var_dump($testArrayResponse('phps')); 31 | var_dump($testArrayResponse('xml')); 32 | var_dump($testArrayResponse('json')); 33 | ?> 34 | --EXPECTF-- 35 | bool(true) 36 | bool(true) 37 | bool(true) -------------------------------------------------------------------------------- /tests/104.solrresponse_get_response_maxscore.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse::getResponse() - maxScore 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH, 17 | 'wt'=> 'xml' 18 | ); 19 | 20 | $client = new SolrClient ( $options ); 21 | 22 | $q = new SolrQuery("lucene"); 23 | $q->addField('score'); 24 | $response = $client->query ( $q ); 25 | $arrayResponse = $response->getArrayResponse(); 26 | var_dump($arrayResponse['response']['maxScore']); 27 | var_dump($response->getResponse()->response->maxScore); 28 | var_dump($response->getResponse()->response->start); 29 | var_dump($response->getResponse()->response->numFound); 30 | var_dump(is_array($response->getResponse()->response->docs)); 31 | echo "------ W/O maxScore ------".PHP_EOL; 32 | $q->removeField('score'); 33 | $response = $client->query ( $q ); 34 | var_dump($response->getResponse()->response->start); 35 | var_dump($response->getResponse()->response->numFound); 36 | var_dump(is_array($response->getResponse()->response->docs)); 37 | var_dump(property_exists($response->getResponse()->response, 'maxScore')); 38 | ?> 39 | --EXPECTF-- 40 | float(%f) 41 | float(%f) 42 | int(%d) 43 | int(%d) 44 | bool(true) 45 | ------ W/O maxScore ------ 46 | int(0) 47 | int(1) 48 | bool(true) 49 | bool(false) -------------------------------------------------------------------------------- /tests/105.solrresponse_child_doc_response.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Response - Response with child documents 3 | --FILE-- 4 | 13 | --EXPECT-- 14 | SolrObject Object 15 | ( 16 | [response] => SolrObject Object 17 | ( 18 | [numFound] => 3 19 | [start] => 0 20 | [docs] => Array 21 | ( 22 | [0] => SolrObject Object 23 | ( 24 | [id] => parent_1 25 | [_childDocuments_] => Array 26 | ( 27 | [0] => SolrObject Object 28 | ( 29 | [id] => CHILD_1_1 30 | ) 31 | 32 | ) 33 | 34 | ) 35 | 36 | [1] => SolrObject Object 37 | ( 38 | [id] => parent_2 39 | [_childDocuments_] => Array 40 | ( 41 | [0] => SolrObject Object 42 | ( 43 | [id] => CHILD_2_1 44 | ) 45 | 46 | [1] => SolrObject Object 47 | ( 48 | [id] => CHILD_2_2 49 | ) 50 | 51 | ) 52 | 53 | ) 54 | 55 | [2] => SolrObject Object 56 | ( 57 | [id] => not_a_parent_1 58 | ) 59 | 60 | ) 61 | 62 | ) 63 | 64 | ) 65 | -------------------------------------------------------------------------------- /tests/107.solrresponse_getrawresponseheaders.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse::getRawResponseHeaders() - Get Raw Response Headers 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | 22 | $client = new SolrClient($options); 23 | 24 | $query = new SolrQuery(); 25 | 26 | $query->setQuery('lucene'); 27 | 28 | $query->setStart(0); 29 | 30 | $query->setRows(50); 31 | 32 | $query->addField('cat')->addField('features')->addField('id')->addField('timestamp'); 33 | 34 | $query_response = $client->query($query); 35 | 36 | $headers = $query_response->getRawResponseHeaders(); 37 | 38 | $filteredHeaders = implode( 39 | "\n", 40 | array_filter( 41 | explode("\r\n", $headers), 42 | function($header) { 43 | return strpos($header, 'HTTP') === 0 || strpos($header, 'Content-Type') === 0; 44 | } 45 | ) 46 | ); 47 | 48 | print_r($filteredHeaders); 49 | 50 | ?> 51 | --EXPECTF-- 52 | HTTP/%s 200 OK 53 | Content-Type: %s 54 | -------------------------------------------------------------------------------- /tests/108.solrresponse_getdigestedresponse.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse::getDigestedResponse() - Get Raw Response Headers 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | 22 | $client = new SolrClient($options); 23 | 24 | $query = new SolrQuery(); 25 | 26 | $query->setQuery('lucene'); 27 | 28 | $query->setStart(0); 29 | 30 | $query->setRows(50); 31 | 32 | $query->addField('cat')->addField('features')->addField('id')->addField('timestamp'); 33 | 34 | $query_response = $client->query($query); 35 | 36 | var_dump($query_response->getDigestedResponse()); 37 | $tmp = $query_response->getResponse(); 38 | $digestedResponse = $query_response->getDigestedResponse(); 39 | print_r($digestedResponse); 40 | ?> 41 | --EXPECTF-- 42 | string(1) " " 43 | O:10:"SolrObject":2:{s:14:"responseHeader";O:10:"SolrObject":3:{s:6:"status";i:0;s:5:"QTime";i:%d;s:%d:"params";O:10:"SolrObject":7:{s:1:"q";s:6:"lucene";s:6:"indent";s:2:"on";s:2:"fl";s:25:"cat,features,id,timestamp";s:5:"start";s:1:"0";s:4:"rows";s:2:"50";s:7:"version";s:3:"2.2";s:2:"wt";s:3:"xml";}}s:8:"response";O:10:"SolrObject":3:{s:8:"numFound";i:1;s:5:"start";i:0;s:4:"docs";a:1:{i:0;O:10:"SolrObject":3:{s:2:"id";s:8:"SOLR1000";s:3:"cat";a:2:{i:0;s:8:"software";i:1;s:6:"search";}s:8:"features";a:7:{i:0;s:51:"Advanced Full-Text Search Capabilities using Lucene";i:1;s:37:"Optimized for High Volume Web Traffic";i:2;s:46:"Standards Based Open Interfaces - XML and HTTP";i:3;s:44:"Comprehensive HTML Administration Interfaces";i:4;s:64:"Scalability - Efficient Replication to other Solr Search Servers";i:5;s:56:"Flexible and Adaptable with XML configuration and Schema";i:6;s:62:"Good unicode support: héllo (hello with an accent over the e)";}}}}} -------------------------------------------------------------------------------- /tests/109.solrresponse_gethttpstatus.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse::getHttpStatus() - getHttpStatusMessage() 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | 22 | $client = new SolrClient($options); 23 | 24 | $query = new SolrQuery(); 25 | 26 | $query->setQuery('lucene'); 27 | 28 | $query->setStart(0); 29 | 30 | $query->setRows(50); 31 | 32 | $query->addField('cat')->addField('features')->addField('id')->addField('timestamp'); 33 | 34 | $query_response = $client->query($query); 35 | 36 | var_dump($query_response->getHttpStatus()); 37 | var_dump($query_response->getHttpStatusMessage()); 38 | ?> 39 | --EXPECTF-- 40 | int(200) 41 | string(1) " " -------------------------------------------------------------------------------- /tests/109.solrresponse_getrequesturl.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse::getRequestUrl() - Get Raw Response Headers 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | 22 | $client = new SolrClient($options); 23 | 24 | $query = new SolrQuery(); 25 | 26 | $query->setQuery('lucene'); 27 | 28 | $query->setStart(0); 29 | 30 | $query->setRows(50); 31 | 32 | $query->addField('cat')->addField('features')->addField('id')->addField('timestamp'); 33 | 34 | $query_response = $client->query($query); 35 | 36 | echo $query_response->getRequestUrl(); 37 | ?> 38 | --EXPECTF-- 39 | http://%s:%s/solr/collection1/select/?version=2.2&indent=on&wt=xml -------------------------------------------------------------------------------- /tests/109.solrresponse_success.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrResponse::success() - Was the request successful 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH, 19 | ); 20 | 21 | 22 | $client = new SolrClient($options); 23 | 24 | $query = new SolrQuery(); 25 | 26 | $query->setQuery('lucene'); 27 | 28 | $query_response = $client->query($query); 29 | 30 | var_dump($query_response->success()); 31 | ?> 32 | --EXPECTF-- 33 | bool(true) -------------------------------------------------------------------------------- /tests/111.solrdismaxquery_boostquery.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDisMaxQuery - Boost Query 3 | --FILE-- 4 | addBoostQuery('cat', 'electronics', 5.1) 9 | ->addBoostQuery('cat', 'hard drive') 10 | ; 11 | // reverse 12 | echo $dismaxQuery.PHP_EOL; 13 | $dismaxQuery 14 | ->removeBoostQuery('cat'); 15 | echo $dismaxQuery.PHP_EOL; 16 | 17 | $dismaxQuery->setBoostQuery('cat:electronics manu:local^2'); 18 | echo $dismaxQuery.PHP_EOL; 19 | ?> 20 | --EXPECTF-- 21 | q=lucene&defType=edismax&bq=cat:electronics^5.1 cat:hard drive 22 | q=lucene&defType=edismax&bq=cat:hard drive 23 | 24 | Notice: SolrDisMaxQuery::setBoostQuery(): Parameter bq value(s) was overwritten by this call in %s on line %d 25 | q=lucene&defType=edismax&bq=cat:electronics manu:local^2 26 | -------------------------------------------------------------------------------- /tests/112.solrdismaxquery_query_parser.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDisMaxQuery - QueryParser Switch 3 | --FILE-- 4 | useDisMaxQueryParser(); 8 | echo $dismaxQuery.PHP_EOL; 9 | $dismaxQuery->useEDisMaxQueryParser(); 10 | echo $dismaxQuery.PHP_EOL; 11 | ?> 12 | --EXPECTF-- 13 | q=hard drive&defType=edismax 14 | q=hard drive&defType=dismax 15 | q=hard drive&defType=edismax -------------------------------------------------------------------------------- /tests/113.solrdismaxquery_bigramfields.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDisMaxQuery - BigramFields and slop (addBigramPhraseField, removeBigramPhraseField, setBigramPhraseFields) 3 | --FILE-- 4 | addBigramPhraseField('cat', 2, 5.1) 9 | ->addBigramPhraseField('feature', 4.5) 10 | ; 11 | echo $dismaxQuery.PHP_EOL; 12 | // reverse 13 | $dismaxQuery 14 | ->removeBigramPhraseField('cat'); 15 | echo $dismaxQuery.PHP_EOL; 16 | 17 | $dismaxQuery->setBigramPhraseFields("cat~5.1^2 feature^4.5"); 18 | echo $dismaxQuery.PHP_EOL; 19 | 20 | $dismaxQuery->setBigramPhraseSlop(2); 21 | echo $dismaxQuery.PHP_EOL; 22 | ?> 23 | --EXPECTF-- 24 | q=lucene&defType=%s&pf2=cat~5.1^2 feature^4.5 25 | q=lucene&defType=%s&pf2=feature^4.5 26 | 27 | Notice: SolrDisMaxQuery::setBigramPhraseFields(): Parameter pf2 value(s) was overwritten by this call in %s on line %d 28 | q=lucene&defType=%s&pf2=cat~5.1^2 feature^4.5 29 | q=lucene&defType=%s&pf2=cat~5.1^2 feature^4.5&ps2=2 30 | -------------------------------------------------------------------------------- /tests/114.solrdismaxquery_trigramfields.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDisMaxQuery - TrigramFields and slop (addTrigramPhraseField, removeTrigramPhraseField, setTrigramPhraseFields) 3 | --FILE-- 4 | addTrigramPhraseField('cat', 2, 5.1) 9 | ->addTrigramPhraseField('feature', 4.5) 10 | ; 11 | echo $dismaxQuery.PHP_EOL; 12 | // reverse 13 | $dismaxQuery 14 | ->removeTrigramPhraseField('cat'); 15 | echo $dismaxQuery.PHP_EOL; 16 | 17 | $dismaxQuery->setTrigramPhraseFields('cat~5.1^2 feature^4.5'); 18 | echo $dismaxQuery.PHP_EOL; 19 | 20 | $dismaxQuery->setTrigramPhraseSlop(2); 21 | echo $dismaxQuery.PHP_EOL; 22 | ?> 23 | --EXPECTF-- 24 | q=lucene&defType=%s&pf3=cat~5.1^2 feature^4.5 25 | q=lucene&defType=%s&pf3=feature^4.5 26 | 27 | Notice: SolrDisMaxQuery::setTrigramPhraseFields(): Parameter pf3 value(s) was overwritten by this call in %s on line %d 28 | q=lucene&defType=%s&pf3=cat~5.1^2 feature^4.5 29 | q=lucene&defType=%s&pf3=cat~5.1^2 feature^4.5&ps3=2 30 | -------------------------------------------------------------------------------- /tests/115.solrdismaxquery_userfields.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDisMaxQuery - UserFields (uf parameter) (addUserField) 3 | --FILE-- 4 | addUserField('cat') 8 | ->addUserField('text') 9 | ->addUserField('*_dt') 10 | ; 11 | echo $dismaxQuery.PHP_EOL; 12 | // // reverse 13 | $dismaxQuery 14 | ->removeUserField('text'); 15 | echo $dismaxQuery.PHP_EOL; 16 | 17 | $dismaxQuery->setUserFields('field1 field2 *_txt'); 18 | echo $dismaxQuery.PHP_EOL; 19 | 20 | ?> 21 | --EXPECTF-- 22 | q=lucene&defType=%s&uf=cat text *_dt 23 | q=lucene&defType=%s&uf=cat *_dt 24 | 25 | Notice: SolrDisMaxQuery::setUserFields(): Parameter uf value(s) was overwritten by this call in %s on line %d 26 | q=lucene&defType=edismax&uf=field1 field2 *_txt -------------------------------------------------------------------------------- /tests/116.solrdismaxquery_boostfunction.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDisMaxQuery - setBoostFunction 3 | --FILE-- 4 | setBoostFunction($boostRecentDocsFunction); 10 | 11 | echo $dismaxQuery.PHP_EOL; 12 | 13 | ?> 14 | --EXPECTF-- 15 | q=lucene&defType=%s&bf=recip(ms(NOW,mydatefield),3.16e-11,1,1) -------------------------------------------------------------------------------- /tests/130.parameters_simple_list_separator.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | simple_list_parameter type - Use of default, non-default separator 3 | --FILE-- 4 | addField("te")->addField("te2"); 8 | echo $query.PHP_EOL; 9 | 10 | $dismaxQuery = new SolrDisMaxQuery(); 11 | $dismaxQuery 12 | ->addUserField('cat') 13 | ->addUserField('text') 14 | ->addUserField('*_dt') 15 | ; 16 | echo $dismaxQuery.PHP_EOL; 17 | 18 | ?> 19 | --EXPECTF-- 20 | fl=te,te2 21 | defType=edismax&uf=cat text *_dt -------------------------------------------------------------------------------- /tests/150.solrcollapsefunction.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrCollapseFunction - string conversion 3 | --FILE-- 4 | setField('field2'); 9 | $func->setMax('max'); 10 | $func->setMin('min'); 11 | $func->setSize(1000); 12 | $func->setHint('hint'); 13 | $func->setNullPolicy(SolrCollapseFunction::NULLPOLICY_EXPAND); 14 | 15 | var_dump($func->getField()); 16 | var_dump($func->getMax()); 17 | var_dump($func->getMin()); 18 | var_dump($func->getSize()); 19 | var_dump($func->getHint()); 20 | var_dump($func->getNullPolicy()); 21 | 22 | var_dump((string)$func); 23 | $func->setMax('with space'); 24 | var_dump((string)$func); 25 | 26 | ?> 27 | --EXPECTF-- 28 | string(6) "field2" 29 | string(3) "max" 30 | string(3) "min" 31 | string(4) "1000" 32 | string(4) "hint" 33 | string(6) "expand" 34 | string(78) "{!collapse field=field2 max=max min=min size=1000 hint=hint nullPolicy=expand}" 35 | string(87) "{!collapse field=field2 max='with space' min=min size=1000 hint=hint nullPolicy=expand}" 36 | -------------------------------------------------------------------------------- /tests/151.solrcollapsefunction_illegal_operations.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrCollapseFunction - Illegal Operations 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getCode(), $e->getMessage()).PHP_EOL; 14 | } 15 | 16 | $func->setMax('max'); 17 | 18 | try { 19 | // known issue, object corruption 20 | $tmp = serialize($func); 21 | } catch (SolrIllegalOperationException $e) { 22 | echo PHP_EOL . sprintf('Code %d: %s', $e->getCode(), $e->getMessage()).PHP_EOL; 23 | } 24 | 25 | ?> 26 | --EXPECTF-- 27 | Code 4001: Cloning of SolrCollapseFunction objects is currently not supported 28 | 29 | Code 1001: Serialization of SolrCollapseFunction objects is currently not supported 30 | 31 | -------------------------------------------------------------------------------- /tests/180.solrdocumentfield_construct.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocumentField::__construct 3 | --FILE-- 4 | 11 | --EXPECT-- 12 | SolrDocumentField Object 13 | ( 14 | [name] => 15 | [boost] => 0 16 | [values] => 17 | ) 18 | -------------------------------------------------------------------------------- /tests/181.solrdocumentfield_write_property.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocumentField - exception - on write property 3 | --FILE-- 4 | myIllegalProperty = 1; 11 | } catch (SolrIllegalOperationException $e) { 12 | printf("Exception %d: %s", $e->getCode(), $e->getMessage()); 13 | } 14 | 15 | ?> 16 | --EXPECT-- 17 | Exception 1007: SolrDocumentField instances are read-only. Properties cannot be updated or removed. 18 | -------------------------------------------------------------------------------- /tests/182.solrdocumentfield_unset_property.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocumentField - exception - on unset property 3 | --FILE-- 4 | name); 12 | } catch (SolrIllegalOperationException $e) { 13 | printf("Exception %d: %s", $e->getCode(), $e->getMessage()); 14 | } 15 | 16 | ?> 17 | --EXPECT-- 18 | Exception 1007: SolrDocumentField instances are read-only. Properties cannot be updated or removed. -------------------------------------------------------------------------------- /tests/190.solrparams_setparam.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams::setParam() 3 | --FILE-- 4 | setParam('q', 'lucene') 10 | ->setParam('start', 0) 11 | ->setParam('rows', 10) 12 | ; 13 | 14 | echo $params; 15 | ?> 16 | --EXPECTF-- 17 | q=lucene&start=0&rows=10 18 | -------------------------------------------------------------------------------- /tests/191.solrparams_addparam.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams::addParam() 3 | --FILE-- 4 | addParam('fq', 'popularity:[10 TO *]') 10 | ->addParam('fq', 'section:0') 11 | ; 12 | 13 | echo $params; 14 | ?> 15 | --EXPECTF-- 16 | fq=popularity:[10 TO *]&fq=section:0 17 | -------------------------------------------------------------------------------- /tests/192.solrparams_getparam.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams::getParam() 3 | --FILE-- 4 | set('q', 'lucene') 10 | ->addParam('fq', 'popularity:[10 TO *]') 11 | ->addParam('fq', 'section:0') 12 | ; 13 | 14 | var_dump($params->get('fq')); 15 | var_dump($params->get('q')); 16 | ?> 17 | --EXPECT-- 18 | array(2) { 19 | [0]=> 20 | string(20) "popularity:[10 TO *]" 21 | [1]=> 22 | string(9) "section:0" 23 | } 24 | string(6) "lucene" -------------------------------------------------------------------------------- /tests/193.solrparams_getparams.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams::getParams() 3 | --FILE-- 4 | set('q', 'lucene') 10 | ->addParam('fq', 'popularity:[10 TO *]') 11 | ->addParam('fq', 'section:0') 12 | ; 13 | 14 | var_dump($params->getParams()); 15 | ?> 16 | --EXPECT-- 17 | array(2) { 18 | ["q"]=> 19 | array(1) { 20 | [0]=> 21 | string(6) "lucene" 22 | } 23 | ["fq"]=> 24 | array(2) { 25 | [0]=> 26 | string(20) "popularity:[10 TO *]" 27 | [1]=> 28 | string(9) "section:0" 29 | } 30 | } -------------------------------------------------------------------------------- /tests/194.solrparams_getpreparedparams.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams::getPreparedParams() 3 | --FILE-- 4 | set('q', 'lucene') 10 | ->addParam('fq', 'popularity:[10 TO *]') 11 | ->addParam('fq', 'section:0') 12 | ; 13 | 14 | var_dump($params->getPreparedParams()); 15 | ?> 16 | --EXPECT-- 17 | array(2) { 18 | ["q"]=> 19 | string(8) "q=lucene" 20 | ["fq"]=> 21 | string(50) "fq=popularity%3A%5B10%20TO%20%2A%5D&fq=section%3A0" 22 | } 23 | -------------------------------------------------------------------------------- /tests/195.solrparams_tostring.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams::toString() 3 | --FILE-- 4 | setParam('q', 'lucene') 10 | ->setParam('start', 0) 11 | ->setParam('rows', 10) 12 | ->addParam('fq', 'popularity:[10 TO *]') 13 | ->addParam('fq', 'section:0') 14 | ; 15 | 16 | echo $params->toString().PHP_EOL; 17 | echo $params->toString(true); 18 | ?> 19 | --EXPECTF-- 20 | q=lucene&start=0&rows=10&fq=popularity:[10 TO *]&fq=section:0 21 | q=lucene&start=0&rows=10&fq=popularity%3A%5B10%20TO%20%2A%5D&fq=section%3A0 -------------------------------------------------------------------------------- /tests/196.solrparams_serialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams::serialize() - serialize params 3 | --SKIPIF-- 4 | = 80100) die("skip PHP < 8.1 only"); ?> 5 | --FILE-- 6 | setParam('q', 'lucene') 12 | ->setParam('start', 0) 13 | ->setParam('rows', 10) 14 | ->addParam('fq', 'popularity:[10 TO *]') 15 | ->addParam('fq', 'section:0') 16 | ; 17 | 18 | echo serialize($params); 19 | ?> 20 | --EXPECTF-- 21 | C:20:"SolrModifiableParams":727:{ 22 | 23 | 24 | 25 | lucene 26 | 27 | 28 | 0 29 | 30 | 31 | 10 32 | 33 | 34 | popularity:[10 TO *] 35 | section:0 36 | 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tests/196.solrparams_serialize_php81.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams::serialize() - serialize params 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | setParam('q', 'lucene') 12 | ->setParam('start', 0) 13 | ->setParam('rows', 10) 14 | ->addParam('fq', 'popularity:[10 TO *]') 15 | ->addParam('fq', 'section:0') 16 | ; 17 | 18 | echo serialize($params); 19 | ?> 20 | --EXPECTF-- 21 | O:20:"SolrModifiableParams":1:{s:3:"xml";s:727:" 22 | 23 | 24 | 25 | lucene 26 | 27 | 28 | 0 29 | 30 | 31 | 10 32 | 33 | 34 | popularity:[10 TO *] 35 | section:0 36 | 37 | 38 | 39 | ";} 40 | -------------------------------------------------------------------------------- /tests/197.solrparams_unserialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams::unserialize() 3 | --FILE-- 4 | setParam('q', 'lucene') 10 | ->setParam('start', 0) 11 | ->setParam('rows', 10) 12 | ->addParam('fq', 'popularity:[10 TO *]') 13 | ->addParam('fq', 'section:0') 14 | ; 15 | 16 | $serializedString = serialize($params); 17 | 18 | $unserializedObject = unserialize($serializedString); 19 | echo $unserializedObject; 20 | ?> 21 | --EXPECTF-- 22 | q=lucene&start=0&rows=10&fq=popularity:[10 TO *]&fq=section:0 23 | -------------------------------------------------------------------------------- /tests/198.solrparams_clone.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrParams - clone [exception] 3 | --FILE-- 4 | setParam('q', 'lucene') 10 | ->setParam('start', 0) 11 | ->setParam('rows', 10) 12 | ->addParam('fq', 'popularity:[10 TO *]') 13 | ->addParam('fq', 'section:0') 14 | ; 15 | 16 | try { 17 | $params2 = clone $params; 18 | } catch (SolrIllegalOperationException $e) { 19 | echo sprintf("Exception %d: %s", $e->getCode(), $e->getMessage()).PHP_EOL; 20 | } 21 | 22 | ?> 23 | --EXPECTF-- 24 | Exception 4001: Cloning of SolrParams object instances is currently not supported 25 | -------------------------------------------------------------------------------- /tests/200.solrextractrequest_clone.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrExtractRequest - clone [exception] 3 | --FILE-- 4 | getCode(), $e->getMessage()).PHP_EOL; 14 | } 15 | 16 | ?> 17 | --EXPECTF-- 18 | Exception 4001: Cloning of SolrExtractRequest objects is currently not supported 19 | -------------------------------------------------------------------------------- /tests/201.solrextractrequest_serialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrExtractRequest - serialize [exception] 3 | --FILE-- 4 | getCode(), $e->getMessage()).PHP_EOL; 14 | } 15 | ?> 16 | --EXPECTF-- 17 | Exception 4001: SolrExtractRequest objects cannot be serialized or unserialized 18 | -------------------------------------------------------------------------------- /tests/202.solrdocument_new_serialize.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrDocument - new serialize api 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | parent_2'; 8 | $xml_length = strlen($xml_contents); 9 | $old = sprintf('C:12:"SolrDocument":%d:{%s}', $xml_length, $xml_contents); 10 | $new = sprintf('O:12:"SolrDocument":1:{s:3:"xml";s:%d:"%s";}', $xml_length, $xml_contents); 11 | 12 | /** @var SolrDocument $docOld */ 13 | $docOld = unserialize($old); 14 | /** @var SolrDocument $docNew */ 15 | $docNew = unserialize($new); 16 | var_dump( 17 | json_encode($docOld->toArray()) === json_encode($docNew->toArray()) 18 | ); 19 | var_dump($docNew->__serialize()); 20 | ?> 21 | --EXPECT-- 22 | bool(true) 23 | array(1) { 24 | ["xml"]=> 25 | string(172) " 26 | 27 | 28 | 29 | parent_2 30 | 31 | 32 | 33 | " 34 | } 35 | -------------------------------------------------------------------------------- /tests/203.solrquery_strict_types.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrQuery - Strict type parameters without BC break 3 | --FILE-- 4 | setStart(1); 9 | $query->setRows(2); 10 | $query->setTimeAllowed(300); 11 | $query->setGroupOffset(1); 12 | $query->setExpandRows(1); 13 | 14 | echo $query . "\n"; 15 | 16 | // Now with strings 17 | $query = new SolrQuery('lucene'); 18 | $query->setStart('1anystring'); // we don't do any checking 19 | $query->setRows('2'); 20 | $query->setTimeAllowed('300'); 21 | $query->setGroupOffset('1'); 22 | $query->setExpandRows('1'); 23 | 24 | echo $query . "\n"; 25 | 26 | try { $query->setStart(true); } catch (SolrIllegalArgumentException $e) { echo $e->getMessage() . "\n"; } 27 | 28 | $collapse = new SolrCollapseFunction(); 29 | $collapse->setSize(1); 30 | 31 | echo $collapse . "\n"; 32 | 33 | $d = new SolrDisMaxQuery('lucene'); 34 | $d->setPhraseSlop(2); 35 | $d->setQueryPhraseSlop(3); 36 | $d->setBigramPhraseSlop(4); 37 | $d->setTrigramPhraseSlop(5); 38 | 39 | echo $d . "\n"; 40 | 41 | --EXPECT-- 42 | q=lucene&start=1&rows=2&timeAllowed=300&group.offset=1&expand.rows=1 43 | q=lucene&start=1anystring&rows=2&timeAllowed=300&group.offset=1&expand.rows=1 44 | Argument 1 must be an int 45 | {!collapse size=1} 46 | q=lucene&defType=edismax&ps=2&qs=3&ps2=4&ps3=5 47 | 48 | -------------------------------------------------------------------------------- /tests/204.solrutils_empty_escapequerychars.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SolrUtils::escapeQueryChars() - Testing empty queryString 3 | --FILE-- 4 | 8 | --EXPECTF-- 9 | string(0) "" 10 | string(2) """" 11 | -------------------------------------------------------------------------------- /tests/bootstrap.inc: -------------------------------------------------------------------------------- 1 | getCode(), $e->getMessage()). PHP_EOL; 11 | } 12 | 13 | /** 14 | * Prints a test case title 15 | * 16 | * @param int $case_id 17 | * @param string $title 18 | */ 19 | function case_title(int $case_id, string $title) { 20 | $caseTemplate = PHP_EOL . "case #%d: %s" . PHP_EOL; 21 | echo sprintf($caseTemplate, $case_id, $title); 22 | } 23 | -------------------------------------------------------------------------------- /tests/bug_59511_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr bug #59511 - SolrClient::query() Timeout shall throw a SolrClientException 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 'anyhost', 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => SOLR_SERVER_PATH, 17 | 'timeout' => 2 18 | ); 19 | 20 | $client = new SolrClient($options); 21 | $query = new SolrQuery("lucene"); 22 | try { 23 | $query_response = $client->query($query); 24 | } catch (SolrClientException $e) { 25 | echo $e->getMessage().PHP_EOL; 26 | echo $e->getCode().PHP_EOL; 27 | } 28 | ?> 29 | --EXPECTF-- 30 | Solr HTTP Error %d: '%s' 31 | 1004 -------------------------------------------------------------------------------- /tests/bug_61836_error.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr bug #61836 - Extending SolrDocument 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | addField('testname', true); 19 | ?> 20 | --EXPECTF-- 21 | Fatal error: Class Model_SolrDocument %s final class %s 22 | -------------------------------------------------------------------------------- /tests/bug_67394.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Bug #67394 - Unable to parse response with NaN 3 | --FILE-- 4 | stats->stats_fields->date->stddev); 13 | 14 | $xmlFixture = file_get_contents(ROOT_DIRECTORY . '/files/bug67394.xml'); 15 | if (!json_decode($fixture)) { 16 | echo "PHP JSON DECODE failed with: ". json_last_error_msg().PHP_EOL; 17 | } 18 | $response = SolrUtils::digestXmlResponse($xmlFixture); 19 | 20 | var_dump($response->response->stats->stats_fields->currentPrice->mean); 21 | ?> 22 | --EXPECTF-- 23 | string(3) "NaN" 24 | float(NAN) -------------------------------------------------------------------------------- /tests/bug_68179.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Bug #68179 - Solr Params (Argument list) separator disappears 3 | --FILE-- 4 | addSortField('price', SolrQuery::ORDER_ASC); 7 | $dismaxQuery->addSortField('score', SolrQuery::ORDER_DESC); 8 | echo $dismaxQuery.PHP_EOL; 9 | ?> 10 | --EXPECTF-- 11 | q=score&defType=%s&sort=price asc,score desc -------------------------------------------------------------------------------- /tests/bug_68181.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Bug #68181 - Conflict occurs when using SolrDisMax::addBoostQuery and setBoostQuery 3 | --FILE-- 4 | setBoostQuery("failing:val^3") 7 | ->addBoostQuery('category','software',2) 8 | ->setBoostQuery("end:result^4"); 9 | 10 | echo $dismaxQuery.PHP_EOL; 11 | ?> 12 | --EXPECTF-- 13 | Notice: SolrDisMaxQuery::addBoostQuery(): Parameter bq value(s) was overwritten by this call in %s on line %d 14 | 15 | Notice: SolrDisMaxQuery::setBoostQuery(): Parameter bq value(s) was overwritten by this call in %s on line %d 16 | q=lucene&defType=%s&bq=end:result^4 -------------------------------------------------------------------------------- /tests/bug_69156.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Bug #69156 - segfault on 500 response from Solr 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 13 | 'login' => SOLR_SERVER_USERNAME, 14 | 'password' => SOLR_SERVER_PASSWORD, 15 | 'port' => SOLR_SERVER_PORT, 16 | 'path' => 'solr/collection44444', 17 | 'wt' => 'phps' 18 | ); 19 | 20 | $client = new SolrClient($options); 21 | $query = new SolrQuery("lucene"); 22 | try { 23 | $query_response = $client->query($query); 24 | } catch (Exception $e) { 25 | } 26 | ?> 27 | --EXPECTF-- 28 | Notice: SolrClient::query(): Unable to parse serialized php response in %s on line %d 29 | -------------------------------------------------------------------------------- /tests/bug_70482.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Bug #70482 - Segmentation fault on server 500 response with no msg field XML RW 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 12 | 'login' => SOLR_SERVER_USERNAME, 13 | 'password' => SOLR_SERVER_PASSWORD, 14 | 'port' => SOLR_SERVER_PORT, 15 | 'path' => SOLR_SERVER_PATH, 16 | 'wt' => 'xml' 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $query = new SolrQuery('*:*'); 22 | 23 | $func = new SolrCollapseFunction('manu_id_s'); 24 | 25 | $func->setMax('sum(cscore(),field(manu_id_s))'); 26 | $func->setSize(100); 27 | $func->setNullPolicy(SolrCollapseFunction::NULLPOLICY_EXPAND); 28 | 29 | $query->collapse($func); 30 | try { 31 | $queryResponse = $client->query($query); 32 | } catch (SolrServerException $e) { 33 | printf("Exception code %d", $e->getCode()); 34 | assert(strlen($e->getMessage()) > 0, 'Exception message is empty'); 35 | echo PHP_EOL; 36 | } 37 | 38 | ?> 39 | OK 40 | --EXPECTF-- 41 | Exception code %d 42 | OK -------------------------------------------------------------------------------- /tests/bug_70495.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Bug #70495 - Failed to parse 500 error response when Solr it lacks msg JSON RW 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 12 | 'login' => SOLR_SERVER_USERNAME, 13 | 'password' => SOLR_SERVER_PASSWORD, 14 | 'port' => SOLR_SERVER_PORT, 15 | 'path' => SOLR_SERVER_PATH, 16 | 'wt' => 'json' 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $query = new SolrQuery('*:*'); 22 | 23 | $func = new SolrCollapseFunction('manu_id_s'); 24 | 25 | $func->setMax('sum(cscore(),field(manu_id_s))'); 26 | $func->setSize(100); 27 | $func->setNullPolicy(SolrCollapseFunction::NULLPOLICY_EXPAND); 28 | 29 | $query->collapse($func); 30 | try { 31 | $queryResponse = $client->query($query); 32 | } catch (SolrServerException $e) { 33 | printf("Exception code %d", $e->getCode()); 34 | assert(strlen($e->getMessage()) > 0, 'Exception message is empty'); 35 | } 36 | 37 | ?> 38 | 39 | OK 40 | --EXPECTF-- 41 | Exception code 500 42 | OK -------------------------------------------------------------------------------- /tests/bug_70496.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Bug #70496 - Failed to parse 500 error response when Solr it lacks msg PHPS RW 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 12 | 'login' => SOLR_SERVER_USERNAME, 13 | 'password' => SOLR_SERVER_PASSWORD, 14 | 'port' => SOLR_SERVER_PORT, 15 | 'path' => SOLR_SERVER_PATH, 16 | 'wt' => 'phps' 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $query = new SolrQuery('*:*'); 22 | 23 | $func = new SolrCollapseFunction('manu_id_s'); 24 | 25 | $func->setMax('sum(cscore(),field(manu_id_s))'); 26 | $func->setNullPolicy(SolrCollapseFunction::NULLPOLICY_EXPAND); 27 | 28 | $query->collapse($func); 29 | try { 30 | $queryResponse = $client->query($query); 31 | } catch (SolrServerException $e) { 32 | printf("Exception code %d", $e->getCode()); 33 | assert(strlen($e->getMessage()) > 0, 'Exception message is empty'); 34 | } 35 | 36 | ?> 37 | 38 | OK 39 | --EXPECTF-- 40 | Exception code 500 41 | OK -------------------------------------------------------------------------------- /tests/bug_72033.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Bug #72033 - Real Time Get requests fails if it wasn't the first request 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | SOLR_SERVER_HOSTNAME, 15 | 'login' => SOLR_SERVER_USERNAME, 16 | 'password' => SOLR_SERVER_PASSWORD, 17 | 'port' => SOLR_SERVER_PORT, 18 | 'path' => SOLR_SERVER_PATH 19 | ); 20 | 21 | $client = new SolrClient($options); 22 | 23 | $doc = new SolrInputDocument(); 24 | 25 | $doc->addField('id', 'some_id'); 26 | $doc->addField('field1', 'val1'); 27 | 28 | $client->addDocument($doc); 29 | 30 | $client->commit(); 31 | 32 | $response = $client->getById('some_id'); 33 | 34 | var_dump(isset($response->getArrayResponse()['doc'])).PHP_EOL; 35 | var_dump($response->getResponse()->doc->id) . PHP_EOL; 36 | // pointless request just to fill the request buffer 37 | $client->commit(); 38 | 39 | 40 | $response = $client->getByIds(['GB18030TEST', '6H500F0']); 41 | 42 | var_dump($response->getResponse()->response->docs[0]->id, $response->getResponse()->response->docs[1]->id); 43 | ?> 44 | --EXPECTF-- 45 | bool(true) 46 | string(7) "some_id" 47 | string(11) "GB18030TEST" 48 | string(7) "6H500F0" 49 | -------------------------------------------------------------------------------- /tests/bug_unknown.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Solr Bug #70496 - Failed to parse 500 error response when Solr it lacks msg PHPS RW 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | SOLR_SERVER_HOSTNAME, 12 | 'login' => SOLR_SERVER_USERNAME, 13 | 'password' => SOLR_SERVER_PASSWORD, 14 | 'port' => SOLR_SERVER_PORT, 15 | 'path' => SOLR_SERVER_PATH, 16 | 'wt' => 'phps' 17 | ); 18 | 19 | $client = new SolrClient($options); 20 | 21 | $query = new SolrQuery('*:*'); 22 | 23 | $func = new SolrCollapseFunction('manu_id_s'); 24 | 25 | $func->setMax('sum(cscore(),field(manu_id_s))'); 26 | $func->setNullPolicy(SolrCollapseFunction::NULLPOLICY_EXPAND); 27 | 28 | $query->collapse($func); 29 | try { 30 | $queryResponse = $client->query($query); 31 | } catch (SolrServerException $e) { 32 | printf("Exception code %d", $e->getCode()); 33 | assert(strlen($e->getMessage()) > 0, 'Exception message is empty'); 34 | } 35 | 36 | ?> 37 | 38 | OK 39 | --EXPECTF-- 40 | Exception code 500 41 | OK -------------------------------------------------------------------------------- /tests/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM solr:6.3 2 | 3 | COPY collections collections 4 | 5 | RUN solr start &&\ 6 | solr create -c collection1 &&\ 7 | solr create -c metal_store &&\ 8 | solr create -c myfiles &&\ 9 | curl 'http://localhost:8983/solr/collection1/update/json?commit=true' --data-binary @collections/collection1.json -H 'Content-type:application/json' &&\ 10 | curl 'http://localhost:8983/solr/metal_store/update/json?commit=true' --data-binary @collections/metal_store.json -H 'Content-type:application/json' &&\ 11 | solr stop 12 | -------------------------------------------------------------------------------- /tests/files/bug67394.json: -------------------------------------------------------------------------------- 1 | { 2 | "responseHeader": { 3 | "status": 0, 4 | "QTime": 5, 5 | "params": { 6 | "fl": "date", 7 | "indent": "true", 8 | "start": "0", 9 | "stats": "true", 10 | "stats.field": "date", 11 | "q": "bahruz", 12 | "_": "1402067668264", 13 | "wt": "json", 14 | "rows": "1" 15 | } 16 | }, 17 | "response": { 18 | "numFound": 1039, 19 | "start": 0, 20 | "docs": [ 21 | { 22 | "date": "2012-10-10T15:05:18Z" 23 | } 24 | ] 25 | }, 26 | "stats": { 27 | "stats_fields": { 28 | "date": { 29 | "min": "2011-10-20T11:16:34Z", 30 | "max": "2014-06-04T13:41:45Z", 31 | "count": 1039, 32 | "missing": 0, 33 | "sum": "47085-11-30T17:59:27.999Z", 34 | "mean": "2013-06-03T17:17:43.684Z", 35 | "sumOfSquares": -234260129500201700000, 36 | "stddev": "NaN", 37 | "facets": {} 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/files/bug67394.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 72 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 0 14 | 0 15 | 0.0 16 | 0.0 17 | NaN 18 | 0.0 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/files/extract_file.1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php/pecl-search_engine-solr/9a8452d7ddc06f18f97752b34198d9b36499d29d/tests/files/extract_file.1.pdf -------------------------------------------------------------------------------- /tests/files/response_xml.2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | parent_1 6 | 7 | CHILD_1_1 8 | 9 | 10 | 11 | parent_2 12 | 13 | CHILD_2_1 14 | 15 | 16 | CHILD_2_2 17 | 18 | 19 | 20 | not_a_parent_1 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/files/response_xml.3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | parent_1 6 | 7 | Solr adds block join support 8 | 9 | 10 | CHILD_1_1 11 | 12 | SolrCloud supports it too! 13 | 14 | 15 | 16 | 17 | parent_2 18 | 19 | CHILD_2_1 20 | 21 | Cool features 22 | 23 | 24 | 25 | CHILD_2_2 26 | 27 | Cool features 28 | 29 | 30 | 31 | 32 | parent_3 33 | 34 | CHILD_3_1 35 | 36 | Cool features 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /tests/files/response_xml.4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 0 6 | 7 | *:* 8 | 0 9 | 2 10 | xml 11 | 12 | 13 | 14 | 15 | GB18030TEST 16 | 17 | Test with some GB18030 encoded characters 18 | 19 | 20 | No accents here 21 | 这是一个功能 22 | This is a feature (translated) 23 | 这份文件是很有光泽 24 | This document is very shiny (translated) 25 | 26 | 27 | 0.0 28 | 29 | 30 | true 31 | 32 | 1513324811722424320 33 | 34 | 35 | SP2514N 36 | 37 | Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - 38 | ATA-133 39 | 40 | 41 | Samsung Electronics Co. Ltd. 42 | 43 | samsung 44 | 45 | electronics 46 | hard drive 47 | 48 | 49 | 7200RPM, 8MB cache, IDE Ultra ATA-133 50 | NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing 51 | (FDB) motor 52 | 53 | 54 | 92.0 55 | 56 | 57 | 6 58 | 59 | 60 | true 61 | 62 | 2006-02-13T15:26:37Z 63 | 64 | 35.0752,-97.032 65 | 66 | 1513324812366249984 67 | 68 | 69 | -------------------------------------------------------------------------------- /tests/files/sample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Welcome to Solr 4 | 5 | 6 |

7 | Here is some text 8 |

9 |

distinct
words

10 |
Here is some text in a div
11 |
This has a link.
12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/files/sample_1.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php/pecl-search_engine-solr/9a8452d7ddc06f18f97752b34198d9b36499d29d/tests/files/sample_1.xlsx -------------------------------------------------------------------------------- /tests/files/solr-word.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/php/pecl-search_engine-solr/9a8452d7ddc06f18f97752b34198d9b36499d29d/tests/files/solr-word.pdf -------------------------------------------------------------------------------- /tests/skip.if.server_not_configured.inc: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /tests/test.config.inc: -------------------------------------------------------------------------------- 1 | 59 | -------------------------------------------------------------------------------- /travis/pecl/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Michael Wallner . 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /travis/pecl/README.md: -------------------------------------------------------------------------------- 1 | # travis-pecl 2 | 3 | These few lines of code support building and testing PHP extensions on Travis-CI. 4 | 5 | ## Usage 6 | 7 | First, we'll add this repo to our extension as submodule: 8 | 9 | git submodule add -n travis-pecl https://github.com/m6w6/travis-pecl.git travis/pecl 10 | git submodule update --init 11 | 12 | Let's build a `.travis.yml`by example. We'll use a simple PHP script, e.g. `gen_travis_yml.php`, 13 | which will generate the configuration for us: 14 | 15 | #!/usr/bin/env php 16 | # file generated by gen_travis_yml.php, do not edit! 17 | 18 | # use the container infrastructure 19 | sudo: false 20 | 21 | # we want to build a C library 22 | language: c 23 | 24 | # use the system's PHP to run this script 25 | addons: 26 | apt: 27 | packages: 28 | - php5-cli 29 | - php-pear 30 | 31 | # now we'll specify the build matrix environment 32 | env: 33 | ["5.4", "5.5", "5.6"], 42 | # test debug and non-debug builds 43 | "enable_debug", 44 | # test threadsafe and non-threadsafe builds 45 | "enable_maintainer_zts", 46 | # test with ext/json enabled an disabled 47 | "enable_json", 48 | # always build with iconv support 49 | "with_iconv" => ["yes"], 50 | ]); 51 | 52 | # output the build matrix 53 | foreach ($env as $e) { 54 | printf(" - %s\n", %e); 55 | } 56 | 57 | ?> 58 | 59 | before_script: 60 | # build the matrix' PHP version 61 | - make -f travis/pecl/Makefile php 62 | # build the extension, the PECL variable expects the extension name 63 | # and optionally the soname and a specific version of the extension 64 | # separeated by double colon, e.g. PECL=myext:ext:1.7.5 65 | - make -f travis/pecl/Makefile ext PECL=myext 66 | 67 | script: 68 | # run the PHPT test suite 69 | - make -f travis/pecl/Makefile test 70 | 71 | 72 | That's it, more TBD. 73 | -------------------------------------------------------------------------------- /travis/pecl/check-packagexml.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | \n", $argv[0]); 8 | exit(1); 9 | } 10 | 11 | require_once "PEAR/Config.php"; 12 | require_once "PEAR/PackageFile.php"; 13 | 14 | define("PACKAGE_XML", $argv[1]); 15 | define("PACKAGE_DIR", dirname(PACKAGE_XML)); 16 | 17 | $factory = new PEAR_PackageFile(PEAR_Config::singleton()); 18 | $pf = $factory->fromPackageFile($argv[1], PEAR_VALIDATE_NORMAL); 19 | 20 | if (PEAR::isError($pf)) { 21 | fprintf(STDERR, "ERROR: %s\n", $pf->getMessage()); 22 | exit(1); 23 | } 24 | 25 | foreach ($pf->getValidationWarnings() as $warning) { 26 | fprintf(STDERR, "%s: %s\n", strtoupper($warning["level"]), $warning["message"]); 27 | } 28 | 29 | $exit = 0; 30 | foreach ($pf->getFilelist() as $file => $attr) { 31 | if (!file_exists(PACKAGE_DIR."/".$file)) { 32 | $exit++; 33 | fprintf(STDERR, "File '%s' with role '%s' not found in '%s'\n", 34 | $file, $attr["role"], PACKAGE_DIR); 35 | } 36 | } 37 | 38 | if ($exit) { 39 | fprintf(STDERR, "%3d failure(s)\n", $exit); 40 | exit(1); 41 | } 42 | -------------------------------------------------------------------------------- /travis/pecl/cppcheck.suppressions: -------------------------------------------------------------------------------- 1 | *:*/Zend/* 2 | varFuncNullUB 3 | variableScope 4 | -------------------------------------------------------------------------------- /travis/pecl/fetch-master.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if test -d php-master; then 4 | cd php-master 5 | git pull 6 | else 7 | git clone --depth 1 -b master https://github.com/php/php-src php-master 8 | cd php-master 9 | fi 10 | 11 | ./buildconf 12 | -------------------------------------------------------------------------------- /travis/pecl/gen-matrix.php: -------------------------------------------------------------------------------- 1 | $values) { 5 | if (is_numeric($key) && is_string($values)) { 6 | $key = $values; 7 | $values = ["no","yes"]; 8 | } 9 | if (empty($apc)) { 10 | // seed 11 | foreach ($values as $val) { 12 | $apc[] = "$key=$val"; 13 | } 14 | } else { 15 | // combine 16 | $cpc = $apc; 17 | $apc = []; 18 | foreach ($values as $val) { 19 | foreach ($cpc as $e) { 20 | $apc[] = "$e $key=$val"; 21 | } 22 | } 23 | } 24 | } 25 | return $apc; 26 | }; 27 | -------------------------------------------------------------------------------- /travis/pecl/php-version-url-dist.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | $r) { 28 | printf("%s\t%s\tcurl -sSL %s%s | tar xj\n", $v, $r, $mirror, 29 | $versions[$r]["source"][0]["filename"]); 30 | } 31 | -------------------------------------------------------------------------------- /travis/pecl/php-version-url-qa.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | $r) { 28 | printf("%s\t%s\tcurl -sSL %s | tar xj\n", $v, 29 | $versions["releases"][$r]["version"], 30 | $versions["releases"][$r]["files"]["bz2"]["path"]); 31 | } 32 | -------------------------------------------------------------------------------- /travis/pecl/php-version.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 |