Skip to content

Commit d759ceb

Browse files
Docs for XML vs JSON requests (#1044)
1 parent 46fabfc commit d759ceb

7 files changed

Lines changed: 52 additions & 7 deletions

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ setlocale(LC_NUMERIC, $currentLocale);
5353
PHP 8.0 has made the float to string conversion locale-independent and will always use the `.` decimal separator.
5454
The workaround is no longer necessary with PHP versions ≥ 8.0.
5555

56+
### Future pitfall when upgrading to 7.x
57+
58+
Solarium 7 will change the default request format for update queries from XML to JSON.
59+
60+
You can already test your code with JSON requests to ensure a seamless transition.
61+
62+
```php
63+
// get an update query instance
64+
$update = $client->createUpdate();
65+
66+
// set JSON request format
67+
$update->setRequestFormat($update::REQUEST_FORMAT_JSON);
68+
```
69+
70+
If you do require XML specific functionality, set the request format to XML explicitly instead to avoid issues when upgrading.
71+
72+
```php
73+
$update->setRequestFormat($update::REQUEST_FORMAT_XML);
74+
```
75+
5676
### Pitfalls when upgrading from 3.x or 4.x or 5.x
5777

5878
#### Setting a timeout

docs/documents.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,28 @@ $doc->reaction = $reaction;
223223
$doc->setField('reaction', $reaction);
224224
```
225225

226-
**Note:** Solarium can't index this single nested child correctly at the moment. For more info see [known limitations](#known-limitations).
226+
**Note:** You have to use the JSON request format to index a labelled single nested child document. For more info see [known limitations](#known-limitations).
227227

228228
#### Anonymous children
229229

230230
If you use `_childDocuments_` as the field name, the child documents are indexed anonymously. This is not recommended by Solr.
231231

232232
#### Known limitations
233233

234-
- It's currently impossible to index a labelled single nested child document with Solarium because of [SOLR-16183](https://issues.apache.org/jira/browse/SOLR-16183). Any child document you index this way will end up as an anonymous nested child.
235-
- Atomic updates of child documents aren't fully supported in Solarium because of [SOLR-12677](https://issues.apache.org/jira/browse/SOLR-12677).
234+
Some child document functionality isn't supported by XML formatted update requests.
235+
236+
- It's impossible to index a labelled single nested child document because of [SOLR-16183](https://issues.apache.org/jira/browse/SOLR-16183). Any child document you index this way will end up as an anonymous nested child.
237+
- Atomic updates of child documents aren't fully supported because of [SOLR-12677](https://issues.apache.org/jira/browse/SOLR-12677).
238+
239+
Make sure to set the request format to JSON if you require this functionality.
240+
241+
```php
242+
// get an update query instance
243+
$update = $client->createUpdate();
244+
245+
// set JSON request format
246+
$update->setRequestFormat($update::REQUEST_FORMAT_JSON);
247+
```
236248

237249
### Atomic updates
238250

@@ -330,7 +342,7 @@ The document has `getVersion` and `setVersion` methods. By default no version is
330342

331343
But you can also set a custom version (specific ID).
332344

333-
For more info on versioning please see this blogpost: <http://yonik.com/solr/optimistic-concurrency/>
345+
For more info on versioning please see this blogpost: <https://yonik.com/solr/optimistic-concurrency/>.
334346

335347
### Boosts
336348

@@ -340,6 +352,7 @@ You can set the document boost with the `setBoost` method.
340352

341353
Field boosts can be set with the `setFieldBoost` method, or with optional parameters of the `setField` and `addField` methods. See the API docs for details.
342354

355+
Index-time boosts have been removed from Solr 7 and will be ignored. Even with older Solr versions, they aren't supported by JSON formatted update requests.
343356

344357
Custom document
345358
---------------

docs/queries/update-query/best-practices-for-updates.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ If you need to use rollbacks (outside of testing) that usually indicates there i
2828

2929
While 'optimizing' sounds like it's always a good thing to do, you should use it with care, as it can have a negative performance impact *during the optimize process*. If possible use try to use it outside peak hours / at intervals.
3030

31+
### XML vs JSON formatted update requests
32+
33+
Solarium issues XML formatted update requests by default. This will change to JSON format when Solarium 7 is released. You can set this to JSON if you want to test your code in advance. If you require XML specific functionality, you should already set this to XML explicitly to ensure a seamless transition.
34+
3135
### Raw XML update commands
3236

3337
Solarium makes it easy to build update commands without having to know the underlying XML structure. If you already have XML formatted update commands, you can add them directly to an update query. Make sure they are valid as Solarium will not check this.

docs/queries/update-query/building-an-update-query/building-an-update-query.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ However, if you do need to customize them for a special case, you can.
1010

1111
### RequestFormat
1212

13-
Solarium sends XML formatted update requests by default. You can change this to JSON formatted requests.
13+
Solarium issues XML formatted update requests by default. This will change to JSON format when Solarium 7 is released. You can set this to JSON if you want to test your code in advance. If you require XML specific functionality, you should already set this to XML explicitly to ensure a seamless transition.
1414

1515
### ResultClass
1616

docs/queries/update-query/building-an-update-query/rawxml-command.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ You can use this command to add XML formatted update commands to an update query
22

33
Make sure the XML is valid as Solarium will not check this. If you are constructing these strings in your own code, you should probably be using the other commands Solarium provides to build your update query.
44

5+
This command can only be used with the XML request format.
6+
57
Options
68
-------
79

@@ -22,6 +24,9 @@ $client = new Solarium\Client($adapter, $eventDispatcher, $config);
2224
// get an update query instance
2325
$update = $client->createUpdate();
2426

27+
// set XML request format
28+
$update->setRequestFormat($update::REQUEST_FORMAT_XML);
29+
2530
// create an XML string with a valid update command
2631
$xml = '
2732
<add>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Update queries allow you to add, delete, commit, optimize and rollback commands. For all the details about the Solr update handler please see the Solr documentation, but some important notes:
22

33
- Solr has no 'update' command. But if you add a document with a value for the 'unique key' field that already exists in the index that existing document will be overwritten by your new document.
4-
- You can only add complete documents. If you want to update only a single field you still need to 'add' the whole document.
4+
- If you want to update only a single field you either need to 'add' the whole document or use atomic updates if your schema is configured to support this.
55
- Always use a database or other persistent storage as the source for building documents to add. Don't be tempted to emulate an update command by selecting a document, altering it and adding it. Almost all schemas will have fields that are indexed and not stored. You will lose the data in those fields.
66
- The best way to use update queries is also related to your Solr config. If you are for instance using the autocommit feature of Solr you probably don't want to use a commit command in your update queries. Make sure you know the configuration details of the Solr core you use.
7-
7+
- Some functionality is only available with XML formatted or JSON formatted update queries, but not both. Set the appropriate request format if necessary.

examples/2.2.6-rawxml.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// get an update query instance
1010
$update = $client->createUpdate();
1111

12+
// set XML request format
13+
$update->setRequestFormat($update::REQUEST_FORMAT_XML);
14+
1215
// create an XML string with a valid update command
1316
$xml = '
1417
<add>

0 commit comments

Comments
 (0)