diff --git a/.github/workflows/linux-tests.yml b/.github/workflows/linux-tests.yml index e601e331..f1d84529 100644 --- a/.github/workflows/linux-tests.yml +++ b/.github/workflows/linux-tests.yml @@ -41,10 +41,10 @@ jobs: - name: Run tests env: SOLR_SERVER_CONFIGURED: 1 - run: TEST_PHP_ARGS="$TEST_PHP_ARGS -q" make test + run: TEST_PHP_ARGS="$TEST_PHP_ARGS -q --show-diff" make test services: solr: - image: omars44/pecl-solr-test:latest + image: omarskem/pecl-solr-server:solr7-slim ports: - 8983:8983 diff --git a/Dockerfile b/Dockerfile index a54c6162..c5bfa227 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,11 @@ -FROM php:8.4-cli +FROM php:8.4-cli-alpine3.20 -RUN apt update && apt install libxml2-dev libcurl4-gnutls-dev --yes +RUN apk add --no-cache libxml2-dev libcurl-dev \ + && docker-php-ext-install xml curl \ + && rm -rf /var/cache/apk/* -RUN apt install vim --yes +RUN apk add --no-cache vim \ + && rm -rf /var/cache/apk/* COPY .docker/entrypoint.sh /opt/ @@ -12,4 +15,4 @@ COPY ./ /opt/solr2 WORKDIR /opt/solr2 -ENTRYPOINT ["sh","/opt/entrypoint.sh"] +ENTRYPOINT ["sh","/opt/entrypoint.sh"] \ No newline at end of file diff --git a/README.INSTALLATION b/README.INSTALLATION index 2b9d18f1..41cb5449 100644 --- a/README.INSTALLATION +++ b/README.INSTALLATION @@ -2,7 +2,7 @@ PHP VERSION Dependencies ================================================================================ -PHP version 7.0 or later is needed +PHP version 8.0 or later is needed ================================================================================ Extension Dependencies @@ -224,10 +224,8 @@ http://windows.php.net/downloads/snaps/php-5.3/php-5.3-src-latest.zip How to Report Bugs ================================================================================ -Please report bugs to omars@php.net +Please report bugs to -You can also register bugs here - -http://pecl.php.net/bugs/report.php?package=solr +https://github.com/php/pecl-search_engine-solr/issues Thank you for using PHP diff --git a/README.md b/README.md index 4df7bf15..c4a9d157 100644 --- a/README.md +++ b/README.md @@ -31,15 +31,34 @@ For RHEL/Fedora/CentOS/Scientific linux Please make sure to install them before proceeding to the compilation process ```bash - phpize - ./configure - make - make test - sudo make install +phpize +./configure +make +make test +sudo make install ``` more details on README.INSTALLATION +Local Dev Environment +--------------------- + +```bash +docker-compose up -d +# OR +docker-compose up --build -d + +phpize +./configure +make + +export SOLR_SERVER_CONFIGURED=1 +php run-tests.php -q -d extension=$PWD/modules/solr.so --show-diff +# OR run a single test +php run-tests.php -q -d extension=$PWD/modules/solr.so --show-diff tests/004.solrclient_query_terms.phpt + +``` + Contributions ------------- All forms of contributions are welcome! Whether contributing to tests, or the source. diff --git a/docker-compose.yml b/docker-compose.yml index 46e7e44c..24acbf36 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,6 @@ -version: '2.1' - services: solr: + image: omarskem/pecl-solr-server:solr7-slim build: tests/docker/ ports: - - "8983:8983" + - "127.0.0.1:8983:8983" diff --git a/tests/001.solrclient_addDocument_partial.phpt b/tests/001.solrclient_addDocument_partial.phpt index be92c400..749ce418 100644 --- a/tests/001.solrclient_addDocument_partial.phpt +++ b/tests/001.solrclient_addDocument_partial.phpt @@ -28,13 +28,14 @@ $client->commit(); $initialDoc = new SolrInputDocument(); +// multivalued str _ss, _s string, _i suffixes for dynamic fields for schema tech products $initialDoc->addField('id', 'testing_partials'); -$initialDoc->addField('field1', 'existing value'); -$initialDoc->addField('field1', 'remove me please'); -$initialDoc->addField('field1', '15/01/2007'); +$initialDoc->addField('field1_ss', 'existing value'); +$initialDoc->addField('field1_ss', 'remove me please'); +$initialDoc->addField('field1_ss', '15/01/2007'); $initialDoc->addField('field2_s', 'initialField'); $initialDoc->addField('field3_i', 0); -$initialDoc->addField('field4', 'val1'); +$initialDoc->addField('field4_ss', 'val1'); $initialDoc->addField('field5_s', 'unmodified field'); $client->addDocument($initialDoc); @@ -44,11 +45,11 @@ $printDocument(); $doc = new SolrInputDocument(); $doc->addField('id', 'testing_partials'); -$doc->updateField('field1', SolrInputDocument::UPDATE_MODIFIER_ADD, 'newly added value'); -$doc->updateField('field1', SolrInputDocument::UPDATE_MODIFIER_REMOVE, 'remove me please'); +$doc->updateField('field1_ss', SolrInputDocument::UPDATE_MODIFIER_ADD, 'newly added value'); +$doc->updateField('field1_ss', SolrInputDocument::UPDATE_MODIFIER_REMOVE, 'remove me please'); $doc->updateField('field3_i', SolrInputDocument::UPDATE_MODIFIER_INC, 5); $doc->updateField('field2_s', SolrInputDocument::UPDATE_MODIFIER_SET, 'updated string'); -$doc->updateField('field1', SolrInputDocument::UPDATE_MODIFIER_REMOVEREGEX, '[\d]{2}/[\d]{2}/[\d]{4}'); +$doc->updateField('field1_ss', SolrInputDocument::UPDATE_MODIFIER_REMOVEREGEX, '[\d]{2}/[\d]{2}/[\d]{4}'); $response = $client->addDocument($doc); $client->commit(); @@ -66,7 +67,7 @@ SolrObject Object [doc] => SolrObject Object ( [id] => testing_partials - [field1] => Array + [field1_ss] => Array ( [0] => existing value [1] => remove me please @@ -75,7 +76,7 @@ SolrObject Object [field2_s] => initialField [field3_i] => 0 - [field4] => Array + [field4_ss] => Array ( [0] => val1 ) @@ -90,9 +91,9 @@ SolrObject Object testing_partials - newly added value - remove me please - [\d]{2}/[\d]{2}/[\d]{4} + newly added value + remove me please + [\d]{2}/[\d]{2}/[\d]{4} 5 updated string @@ -103,7 +104,7 @@ SolrObject Object [doc] => SolrObject Object ( [id] => testing_partials - [field1] => Array + [field1_ss] => Array ( [0] => existing value [1] => newly added value @@ -111,7 +112,7 @@ SolrObject Object [field2_s] => updated string [field3_i] => 5 - [field4] => Array + [field4_ss] => Array ( [0] => val1 ) diff --git a/tests/004.solrclient_query_terms.phpt b/tests/004.solrclient_query_terms.phpt index 227b13f6..93353b2f 100644 --- a/tests/004.solrclient_query_terms.phpt +++ b/tests/004.solrclient_query_terms.phpt @@ -27,7 +27,9 @@ $query->setTerms(true); $query->setTermsField('name'); -$query->setTermsLowerBound('a'); +$query->setTermsLowerBound('c'); + +$query->setTermsUpperBound('d'); $query->setTermsSort(SolrQuery::TERMS_SORT_INDEX); @@ -39,7 +41,7 @@ print_r($query_response->getResponse()); ?> --EXPECTF-- -http://%s/solr/collection1/terms/?version=2.2&indent=on&wt=xml +http://127.0.0.1:8983/solr/collection1/terms/?version=2.2&indent=on&wt=xml SolrObject Object ( [responseHeader] => SolrObject Object @@ -52,7 +54,13 @@ SolrObject Object ( [name] => SolrObject Object ( - [iPod & iPod Mini USB 2.0 Cable] => %d + [cable] => %d + [canon] => %d + [card] => %d + [channel] => %d + [characters] => %d + [cord] => %d + [corsair] => %d ) ) diff --git a/tests/bug_72033.phpt b/tests/bug_72033.phpt index 01645540..edde4b65 100644 --- a/tests/bug_72033.phpt +++ b/tests/bug_72033.phpt @@ -23,7 +23,7 @@ $client = new SolrClient($options); $doc = new SolrInputDocument(); $doc->addField('id', 'some_id'); -$doc->addField('field1', 'val1'); +$doc->addField('field1_s', 'val1'); $client->addDocument($doc); diff --git a/tests/docker/Dockerfile b/tests/docker/Dockerfile index d2295aa4..ad08d5fb 100644 --- a/tests/docker/Dockerfile +++ b/tests/docker/Dockerfile @@ -1,11 +1,13 @@ -FROM solr:6.3 +FROM solr:7-slim -COPY collections collections +USER root -RUN solr start &&\ - solr create -c collection1 &&\ - solr create -c metal_store &&\ - solr create -c myfiles &&\ - curl 'http://localhost:8983/solr/collection1/update/json?commit=true' --data-binary @collections/collection1.json -H 'Content-type:application/json' &&\ - curl 'http://localhost:8983/solr/metal_store/update/json?commit=true' --data-binary @collections/metal_store.json -H 'Content-type:application/json' &&\ - solr stop +RUN apt-get update && \ + apt-get install -y --no-install-recommends curl && \ + rm -rf /var/lib/apt/lists/* + +COPY collections /opt/solr-configs + +COPY --chmod=755 init-solr.sh /docker-entrypoint-initdb.d/init-solr.sh + +USER solr \ No newline at end of file diff --git a/tests/docker/init-solr.sh b/tests/docker/init-solr.sh new file mode 100644 index 00000000..78b1c468 --- /dev/null +++ b/tests/docker/init-solr.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -e + +echo "Starting temporary Solr server for initialization..." +solr start +echo "Solr server is running." + +create_and_index() { + CORE_NAME=$1 + DATA_FILE=$2 + + echo "Checking if core '$CORE_NAME' exists..." + + if curl -s "http://localhost:8983/solr/admin/cores?action=STATUS&core=$CORE_NAME" | grep -q "uptime"; then + echo "Core '$CORE_NAME' already exists. Skipping creation and indexing." + else + echo "Core '$CORE_NAME' not found. Creating..." + + # Force use of the common strict configset (schema-full not schemaless) + solr create -c "$CORE_NAME" -d /opt/solr/server/solr/configsets/sample_techproducts_configs/conf + + if [ -n "$DATA_FILE" ] && [ -f "$DATA_FILE" ]; then + echo "Indexing data for '$CORE_NAME' from $DATA_FILE..." + curl "http://localhost:8983/solr/$CORE_NAME/update/json?commit=true" --data-binary @"$DATA_FILE" -H 'Content-type:application/json' + else + echo "No data file provided or found for '$CORE_NAME'. Skipping indexing." + fi + fi +} + +create_and_index "collection1" "/opt/solr-configs/collection1.json" +create_and_index "metal_store" "/opt/solr-configs/metal_store.json" + +create_and_index "myfiles" "" + +echo "Data initialization finished. Stopping temporary Solr server..." +solr stop +echo "Solr initialization complete." \ No newline at end of file diff --git a/tests/docker/solr7-techproducts-schema.xml b/tests/docker/solr7-techproducts-schema.xml new file mode 100644 index 00000000..b6d3d165 --- /dev/null +++ b/tests/docker/solr7-techproducts-schema.xml @@ -0,0 +1,1187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +