You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by no...@apache.org on 2023/06/10 00:51:50 UTC
[solr] branch branch_9x updated: SOLR-16812: Reference guide (#1698)
This is an automated email from the ASF dual-hosted git repository.
noble pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new b9959c19e7f SOLR-16812: Reference guide (#1698)
b9959c19e7f is described below
commit b9959c19e7f57ac9cc3d590f1f1d16d7742cc4ff
Author: Noble Paul <no...@users.noreply.github.com>
AuthorDate: Sat Jun 10 10:50:33 2023 +1000
SOLR-16812: Reference guide (#1698)
---
.../modules/indexing-guide/indexing-nav.adoc | 1 +
.../indexing-guide/pages/indexing-with-cbor.adoc | 161 +++++++++++++++++++++
.../query-guide/pages/response-writers.adoc | 51 +++++++
3 files changed, 213 insertions(+)
diff --git a/solr/solr-ref-guide/modules/indexing-guide/indexing-nav.adoc b/solr/solr-ref-guide/modules/indexing-guide/indexing-nav.adoc
index 1f10acc9f83..532f56eb10c 100644
--- a/solr/solr-ref-guide/modules/indexing-guide/indexing-nav.adoc
+++ b/solr/solr-ref-guide/modules/indexing-guide/indexing-nav.adoc
@@ -51,6 +51,7 @@
* Indexing & Data Operations
** xref:indexing-with-update-handlers.adoc[]
*** xref:transforming-and-indexing-custom-json.adoc[]
+** xref:indexing-with-cbor.adoc[]
** xref:indexing-with-tika.adoc[]
** xref:indexing-nested-documents.adoc[]
** xref:post-tool.adoc[]
diff --git a/solr/solr-ref-guide/modules/indexing-guide/pages/indexing-with-cbor.adoc b/solr/solr-ref-guide/modules/indexing-guide/pages/indexing-with-cbor.adoc
new file mode 100644
index 00000000000..54d69ef8845
--- /dev/null
+++ b/solr/solr-ref-guide/modules/indexing-guide/pages/indexing-with-cbor.adoc
@@ -0,0 +1,161 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+= Indexing with Update CBOR data format
+
+Solr supports http://cbor.io/[CBOR] format for indexing as well as querying. It supports most popular languages and platforms. It's much faster and efficient compared to JSON.
+
+== Python example
+
+Save the following as `cbor_post.py`
+[,python]
+----
+import json
+import requests
+import cbor2
+
+# JSON data to send (list of dictionaries)
+json_data = [
+ {
+ "id" : "1",
+ "name_s": "John Doe",
+ "age_i": 30,
+ "city_s": "New York"
+ },
+ {
+ "id": "2",
+ "name_s": "Jane Smith",
+ "age_i": 25,
+ "city_s": "London"
+ }
+]
+# If there is only a single doc you can use the following
+# json_data = {
+# "id" : "6",
+# "name_s": "John Doe",
+# "age_i": 30,
+# "city_s": "New York"
+# }
+
+
+# Convert JSON data to CBOR
+cbor_data = cbor2.dumps(json_data)
+
+# Set the endpoint URL
+# ensure that the collection 'coll1' is already created
+url = "http://localhost:8983/solr/coll1/update/cbor?commit=true"
+
+# Send a POST request with CBOR data
+response = requests.post(url, data=cbor_data, headers={"Content-Type": "application/cbor"})
+
+# Check the response status
+if response.status_code == 200:
+ print("POST request sent successfully!")
+ print("Response Body:", response.text)
+else:
+ print("Unexpected response status:", response.status_code)
+----
+
+=== Running the program
+
+1. Install Python
+2. Ensure that the dependencies are installed
+
+ pip install requests cbor2
+
+3. Run the program
+
+ python3 cbor_post.py
+
+4. Check the output
+
+ POST request sent successfully!
+ Response Body: {
+ "responseHeader":{
+ "rf":1,
+ "status":0,
+ "QTime":70
+ }
+ }
+
+== Node.js example
+
+Save the following program into a a file called `script.js`
+
+[,javascript]
+----
+const cbor = require('cbor');
+const axios = require('axios');
+
+async function main() {
+// JSON data to send (list of JSON objects)
+const jsonData = [
+{
+"id" : "1",
+"name_s": "John Doe",
+"age_i": 30,
+"city_s": "New York"
+},
+{
+"id": "2",
+"name_s": "Jane Smith",
+"age_i": 25,
+"city_s": "London"
+},
+];
+
+ // Convert JSON data to CBOR
+ const cborData = cbor.encode(jsonData);
+
+ // Set the endpoint URL
+ const url = "http://localhost:8983/solr/coll1/update/cbor?commit=true"
+
+ try {
+ // Send a POST request with CBOR data
+ const response = await axios.post(url, cborData, {
+ headers: {
+ 'Content-Type': 'application/cbor',
+ },
+ });
+
+ // Process the response
+ console.log('POST request sent successfully!');
+ console.log('Response:', response.data);
+ } catch (error) {
+ console.error('Error sending POST request:', error.message);
+ }
+}
+
+main();
+----
+[]
+
+=== Running the program
+
+1. Install Node.js
+2. Ensure that the dependencies are installed
+
+ npm install cbor axios
+
+3. Execute the script
+
+ node script.js
+
+4. Check the output
+
+ POST request sent successfully!
+ Response: { responseHeader: { rf: 1, status: 0, QTime: 187 } }
\ No newline at end of file
diff --git a/solr/solr-ref-guide/modules/query-guide/pages/response-writers.adoc b/solr/solr-ref-guide/modules/query-guide/pages/response-writers.adoc
index 35e22993f0e..bbc08e04478 100644
--- a/solr/solr-ref-guide/modules/query-guide/pages/response-writers.adoc
+++ b/solr/solr-ref-guide/modules/query-guide/pages/response-writers.adoc
@@ -395,6 +395,57 @@ F8V7067-APL-KIT,"electronics,connector",Belkin Mobile Power Cord for iPod w/ Doc
MA147LL/A,"electronics,music",Apple 60 GB iPod with Video Playback Black,10,399.0,0.2446348
----
+== CBOR Response Writer
+
+Solr supports CBOR format which is more compact and fast.
+
+=== Example Python program
+
+save the following program as `cbor_query.py`
+
+[,python]
+----
+import cbor2
+import json
+import requests
+
+// replace 'coll1' with your own collection name. And use appropriate query params
+url = "http://localhost:8983/solr/coll1/select?q=*:*&wt=cbor"
+
+# Make the HTTP request
+response = requests.get(url, headers={"Accept": "application/cbor"})
+
+# Check the response status
+if response.status_code == requests.codes.ok:
+ # Decode the CBOR response payload
+ cbor_data = response.content
+ json_data = cbor2.loads(cbor_data)
+
+ # Dump the JSON data to a file
+ with open("response.json", "w") as file:
+ json.dump(json_data, file, indent=4)
+ print("CBOR response payload dumped to response.json")
+else:
+ print("HTTP request failed with status code:", response.status_code)
+
+----
+[]
+
+
+==== Running the program
+
+1. Install Python
+
+2. Install the dependencies
+
+ pip install requests cbor2
+
+3. Run the program
+
+ python3 cbor_query.py
+
+
+
== Smile Response Writer
The Smile format is a JSON-compatible binary format, described in detail here: https://en.wikipedia.org/wiki/Smile_%28data_interchange_format%29[https://en.wikipedia.org/wiki/Smile_(data_interchange_format)]