Skip to content

Commit 4156ac9

Browse files
authored
Merge pull request #87 from omars44/update-solr-docker
Tests: stabilize tests against solr 7
2 parents 38de3b9 + c9cda00 commit 4156ac9

11 files changed

Lines changed: 1300 additions & 45 deletions

.github/workflows/linux-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ jobs:
4141
- name: Run tests
4242
env:
4343
SOLR_SERVER_CONFIGURED: 1
44-
run: TEST_PHP_ARGS="$TEST_PHP_ARGS -q" make test
44+
run: TEST_PHP_ARGS="$TEST_PHP_ARGS -q --show-diff" make test
4545

4646
services:
4747
solr:
48-
image: omars44/pecl-solr-test:latest
48+
image: omarskem/pecl-solr-server:solr7-slim
4949
ports:
5050
- 8983:8983

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
FROM php:8.4-cli
1+
FROM php:8.4-cli-alpine3.20
22

3-
RUN apt update && apt install libxml2-dev libcurl4-gnutls-dev --yes
3+
RUN apk add --no-cache libxml2-dev libcurl-dev \
4+
&& docker-php-ext-install xml curl \
5+
&& rm -rf /var/cache/apk/*
46

5-
RUN apt install vim --yes
7+
RUN apk add --no-cache vim \
8+
&& rm -rf /var/cache/apk/*
69

710
COPY .docker/entrypoint.sh /opt/
811

README.INSTALLATION

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
PHP VERSION Dependencies
33
================================================================================
44

5-
PHP version 7.0 or later is needed
5+
PHP version 8.0 or later is needed
66

77
================================================================================
88
Extension Dependencies
@@ -224,10 +224,8 @@ http://windows.php.net/downloads/snaps/php-5.3/php-5.3-src-latest.zip
224224
How to Report Bugs
225225
================================================================================
226226

227-
Please report bugs to omars@php.net
227+
Please report bugs to
228228

229-
You can also register bugs here
230-
231-
http://pecl.php.net/bugs/report.php?package=solr
229+
https://github.com/php/pecl-search_engine-solr/issues
232230

233231
Thank you for using PHP

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,34 @@ For RHEL/Fedora/CentOS/Scientific linux
3131

3232
Please make sure to install them before proceeding to the compilation process
3333
```bash
34-
phpize
35-
./configure
36-
make
37-
make test
38-
sudo make install
34+
phpize
35+
./configure
36+
make
37+
make test
38+
sudo make install
3939
```
4040

4141
more details on README.INSTALLATION
4242

43+
Local Dev Environment
44+
---------------------
45+
46+
```bash
47+
docker-compose up -d
48+
# OR
49+
docker-compose up --build -d
50+
51+
phpize
52+
./configure
53+
make
54+
55+
export SOLR_SERVER_CONFIGURED=1
56+
php run-tests.php -q -d extension=$PWD/modules/solr.so --show-diff
57+
# OR run a single test
58+
php run-tests.php -q -d extension=$PWD/modules/solr.so --show-diff tests/004.solrclient_query_terms.phpt
59+
60+
```
61+
4362
Contributions
4463
-------------
4564
All forms of contributions are welcome! Whether contributing to tests, or the source.

docker-compose.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
version: '2.1'
2-
31
services:
42
solr:
3+
image: omarskem/pecl-solr-server:solr7-slim
54
build: tests/docker/
65
ports:
7-
- "8983:8983"
6+
- "127.0.0.1:8983:8983"

tests/001.solrclient_addDocument_partial.phpt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ $client->commit();
2828

2929
$initialDoc = new SolrInputDocument();
3030

31+
// multivalued str _ss, _s string, _i suffixes for dynamic fields for schema tech products
3132
$initialDoc->addField('id', 'testing_partials');
32-
$initialDoc->addField('field1', 'existing value');
33-
$initialDoc->addField('field1', 'remove me please');
34-
$initialDoc->addField('field1', '15/01/2007');
33+
$initialDoc->addField('field1_ss', 'existing value');
34+
$initialDoc->addField('field1_ss', 'remove me please');
35+
$initialDoc->addField('field1_ss', '15/01/2007');
3536
$initialDoc->addField('field2_s', 'initialField');
3637
$initialDoc->addField('field3_i', 0);
37-
$initialDoc->addField('field4', 'val1');
38+
$initialDoc->addField('field4_ss', 'val1');
3839
$initialDoc->addField('field5_s', 'unmodified field');
3940

4041
$client->addDocument($initialDoc);
@@ -44,11 +45,11 @@ $printDocument();
4445

4546
$doc = new SolrInputDocument();
4647
$doc->addField('id', 'testing_partials');
47-
$doc->updateField('field1', SolrInputDocument::UPDATE_MODIFIER_ADD, 'newly added value');
48-
$doc->updateField('field1', SolrInputDocument::UPDATE_MODIFIER_REMOVE, 'remove me please');
48+
$doc->updateField('field1_ss', SolrInputDocument::UPDATE_MODIFIER_ADD, 'newly added value');
49+
$doc->updateField('field1_ss', SolrInputDocument::UPDATE_MODIFIER_REMOVE, 'remove me please');
4950
$doc->updateField('field3_i', SolrInputDocument::UPDATE_MODIFIER_INC, 5);
5051
$doc->updateField('field2_s', SolrInputDocument::UPDATE_MODIFIER_SET, 'updated string');
51-
$doc->updateField('field1', SolrInputDocument::UPDATE_MODIFIER_REMOVEREGEX, '[\d]{2}/[\d]{2}/[\d]{4}');
52+
$doc->updateField('field1_ss', SolrInputDocument::UPDATE_MODIFIER_REMOVEREGEX, '[\d]{2}/[\d]{2}/[\d]{4}');
5253

5354
$response = $client->addDocument($doc);
5455
$client->commit();
@@ -66,7 +67,7 @@ SolrObject Object
6667
[doc] => SolrObject Object
6768
(
6869
[id] => testing_partials
69-
[field1] => Array
70+
[field1_ss] => Array
7071
(
7172
[0] => existing value
7273
[1] => remove me please
@@ -75,7 +76,7 @@ SolrObject Object
7576

7677
[field2_s] => initialField
7778
[field3_i] => 0
78-
[field4] => Array
79+
[field4_ss] => Array
7980
(
8081
[0] => val1
8182
)
@@ -90,9 +91,9 @@ SolrObject Object
9091
<add overwrite="true">
9192
<doc>
9293
<field name="id">testing_partials</field>
93-
<field name="field1" update="add">newly added value</field>
94-
<field name="field1" update="remove">remove me please</field>
95-
<field name="field1" update="removeregex">[\d]{2}/[\d]{2}/[\d]{4}</field>
94+
<field name="field1_ss" update="add">newly added value</field>
95+
<field name="field1_ss" update="remove">remove me please</field>
96+
<field name="field1_ss" update="removeregex">[\d]{2}/[\d]{2}/[\d]{4}</field>
9697
<field name="field3_i" update="inc">5</field>
9798
<field name="field2_s" update="set">updated string</field>
9899
</doc>
@@ -103,15 +104,15 @@ SolrObject Object
103104
[doc] => SolrObject Object
104105
(
105106
[id] => testing_partials
106-
[field1] => Array
107+
[field1_ss] => Array
107108
(
108109
[0] => existing value
109110
[1] => newly added value
110111
)
111112

112113
[field2_s] => updated string
113114
[field3_i] => 5
114-
[field4] => Array
115+
[field4_ss] => Array
115116
(
116117
[0] => val1
117118
)

tests/004.solrclient_query_terms.phpt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ $query->setTerms(true);
2727

2828
$query->setTermsField('name');
2929

30-
$query->setTermsLowerBound('a');
30+
$query->setTermsLowerBound('c');
31+
32+
$query->setTermsUpperBound('d');
3133

3234
$query->setTermsSort(SolrQuery::TERMS_SORT_INDEX);
3335

@@ -39,7 +41,7 @@ print_r($query_response->getResponse());
3941

4042
?>
4143
--EXPECTF--
42-
http://%s/solr/collection1/terms/?version=2.2&indent=on&wt=xml
44+
http://127.0.0.1:8983/solr/collection1/terms/?version=2.2&indent=on&wt=xml
4345
SolrObject Object
4446
(
4547
[responseHeader] => SolrObject Object
@@ -52,7 +54,13 @@ SolrObject Object
5254
(
5355
[name] => SolrObject Object
5456
(
55-
[iPod & iPod Mini USB 2.0 Cable] => %d
57+
[cable] => %d
58+
[canon] => %d
59+
[card] => %d
60+
[channel] => %d
61+
[characters] => %d
62+
[cord] => %d
63+
[corsair] => %d
5664
)
5765

5866
)

tests/bug_72033.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $client = new SolrClient($options);
2323
$doc = new SolrInputDocument();
2424

2525
$doc->addField('id', 'some_id');
26-
$doc->addField('field1', 'val1');
26+
$doc->addField('field1_s', 'val1');
2727

2828
$client->addDocument($doc);
2929

tests/docker/Dockerfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
FROM solr:6.3
1+
FROM solr:7-slim
22

3-
COPY collections collections
3+
USER root
44

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
5+
RUN apt-get update && \
6+
apt-get install -y --no-install-recommends curl && \
7+
rm -rf /var/lib/apt/lists/*
8+
9+
COPY collections /opt/solr-configs
10+
11+
COPY --chmod=755 init-solr.sh /docker-entrypoint-initdb.d/init-solr.sh
12+
13+
USER solr

tests/docker/init-solr.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Starting temporary Solr server for initialization..."
5+
solr start
6+
echo "Solr server is running."
7+
8+
create_and_index() {
9+
CORE_NAME=$1
10+
DATA_FILE=$2
11+
12+
echo "Checking if core '$CORE_NAME' exists..."
13+
14+
if curl -s "http://localhost:8983/solr/admin/cores?action=STATUS&core=$CORE_NAME" | grep -q "uptime"; then
15+
echo "Core '$CORE_NAME' already exists. Skipping creation and indexing."
16+
else
17+
echo "Core '$CORE_NAME' not found. Creating..."
18+
19+
# Force use of the common strict configset (schema-full not schemaless)
20+
solr create -c "$CORE_NAME" -d /opt/solr/server/solr/configsets/sample_techproducts_configs/conf
21+
22+
if [ -n "$DATA_FILE" ] && [ -f "$DATA_FILE" ]; then
23+
echo "Indexing data for '$CORE_NAME' from $DATA_FILE..."
24+
curl "http://localhost:8983/solr/$CORE_NAME/update/json?commit=true" --data-binary @"$DATA_FILE" -H 'Content-type:application/json'
25+
else
26+
echo "No data file provided or found for '$CORE_NAME'. Skipping indexing."
27+
fi
28+
fi
29+
}
30+
31+
create_and_index "collection1" "/opt/solr-configs/collection1.json"
32+
create_and_index "metal_store" "/opt/solr-configs/metal_store.json"
33+
34+
create_and_index "myfiles" ""
35+
36+
echo "Data initialization finished. Stopping temporary Solr server..."
37+
solr stop
38+
echo "Solr initialization complete."

0 commit comments

Comments
 (0)