You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jb...@apache.org on 2018/08/27 18:16:53 UTC

lucene-solr:branch_7x: SOLR-12687: Add to math expressions user guide

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x d81f8ec69 -> e93f6db47


SOLR-12687: Add to math expressions user guide


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/e93f6db4
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e93f6db4
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e93f6db4

Branch: refs/heads/branch_7x
Commit: e93f6db478072d6461eb1373f9f3b1fb50a4698f
Parents: d81f8ec
Author: Joel Bernstein <jb...@apache.org>
Authored: Mon Aug 27 14:14:46 2018 -0400
Committer: Joel Bernstein <jb...@apache.org>
Committed: Mon Aug 27 14:16:39 2018 -0400

----------------------------------------------------------------------
 solr/solr-ref-guide/src/math-expressions.adoc |   2 +-
 solr/solr-ref-guide/src/variables.adoc        | 185 ++++++++++++++++++++-
 2 files changed, 185 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e93f6db4/solr/solr-ref-guide/src/math-expressions.adoc
----------------------------------------------------------------------
diff --git a/solr/solr-ref-guide/src/math-expressions.adoc b/solr/solr-ref-guide/src/math-expressions.adoc
index 69ce5aa..27600b6 100644
--- a/solr/solr-ref-guide/src/math-expressions.adoc
+++ b/solr/solr-ref-guide/src/math-expressions.adoc
@@ -34,7 +34,7 @@ record in your Solr Cloud cluster computable.
 
 *<<vector-math.adoc#vector-math,Vector Math>>*: Vector math expressions and vector manipulation.
 
-*<<variables.adoc#variables,Variables>>*: Assigning and using variable.
+*<<variables.adoc#variables,Variables and Caching>>*: Assigning and caching variables.
 
 *<<matrix-math.adoc#matrix-math,Matrix Math>>*: Matrix creation, manipulation, and matrix math.
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e93f6db4/solr/solr-ref-guide/src/variables.adoc
----------------------------------------------------------------------
diff --git a/solr/solr-ref-guide/src/variables.adoc b/solr/solr-ref-guide/src/variables.adoc
index b5afd11..f1ac26c 100644
--- a/solr/solr-ref-guide/src/variables.adoc
+++ b/solr/solr-ref-guide/src/variables.adoc
@@ -144,4 +144,187 @@ responds with:
     ]
   }
 }
-----
\ No newline at end of file
+----
+
+== Caching Variables
+
+Variables can be cached in-memory on the Solr node where the math expression
+was run. A cached variable can then be used in future expressions. Any object
+that can be set to a variable, including data structures and mathematical models can
+be cached in-memory for future use.
+
+The `putCache` function adds a variable to the cache.
+
+In the example below an array is cached in the *workspace* workspace1
+and bound to the *key* key1. The workspace allows different users to cache
+objects in their own workspace. The`putCache` function returns
+the variable that was added to the cache.
+
+[source,text]
+----
+let(a=array(1, 2, 3),
+    b=array(10, 20, 30),
+    c=ebeAdd(a, b),
+    d=putCache(workspace1, key1, c))
+----
+
+When this expression is sent to the /stream handler it
+responds with:
+
+[source,json]
+----
+{
+  "result-set": {
+    "docs": [
+      {
+        "d": [
+          11,
+          22,
+          33
+        ]
+      },
+      {
+        "EOF": true,
+        "RESPONSE_TIME": 11
+      }
+    ]
+  }
+}
+----
+
+The `getCache` function retrieves an object from the
+cache by its workspace and key.
+
+In the example below the `getCache` function retrieves
+the array the was cached above and assigns it to variable *a*.
+
+
+[source,text]
+----
+let(a=getCache(workspace1, key1))
+----
+
+When this expression is sent to the /stream handler it
+responds with:
+
+[source,json]
+----
+{
+  "result-set": {
+    "docs": [
+      {
+        "d": [
+          11,
+          22,
+          33
+        ]
+      },
+      {
+        "EOF": true,
+        "RESPONSE_TIME": 11
+      }
+    ]
+  }
+}
+----
+
+The `listCache` function can be used to list the workspaces or the
+keys in a specific workspace.
+
+In the example below `listCache` returns all the workspaces in the cache
+as an array of strings.
+
+[source,text]
+----
+let(a=listCache())
+----
+
+When this expression is sent to the /stream handler it
+responds with:
+
+[source,json]
+----
+{
+  "result-set": {
+    "docs": [
+      {
+        "a": [
+          "workspace1"
+        ]
+      },
+      {
+        "EOF": true,
+        "RESPONSE_TIME": 0
+      }
+    ]
+  }
+}
+----
+
+
+In the example below all the keys in a specific workspace are listed:
+
+
+[source,text]
+----
+let(a=listCache(workspace1))
+----
+
+When this expression is sent to the /stream handler it
+responds with:
+
+[source,json]
+----
+{
+  "result-set": {
+    "docs": [
+      {
+        "a": [
+          "key1"
+        ]
+      },
+      {
+        "EOF": true,
+        "RESPONSE_TIME": 0
+      }
+    ]
+  }
+}
+----
+
+The `removeCache` function can be used to remove a a key from a specific
+workspace. This `removeCache` function removes the key from the cache
+and returns the object that was removed.
+
+In the example below the array that was cached above is removed from the
+cache.
+
+
+[source,text]
+----
+let(a=removeCache(workspace1, key1))
+----
+
+When this expression is sent to the /stream handler it
+responds with:
+
+[source,json]
+----
+{
+  "result-set": {
+    "docs": [
+      {
+        "a": [
+          11,
+          22,
+          33
+        ]
+      },
+      {
+        "EOF": true,
+        "RESPONSE_TIME": 0
+      }
+    ]
+  }
+}
+----