You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by eh...@apache.org on 2015/09/09 01:52:17 UTC
svn commit: r1701883 - in /lucene/dev/trunk/solr: ./
core/src/test-files/solr/collection1/conf/
core/src/test/org/apache/solr/update/processor/ example/files/conf/
Author: ehatcher
Date: Tue Sep 8 23:52:16 2015
New Revision: 1701883
URL: http://svn.apache.org/r1701883
Log:
SOLR-7978: Fixed example/files update-script.js to be Java 7 and 8 compatible
Added:
lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/cross-compatible.js (with props)
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-script-updateprocessor.xml
lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java
lucene/dev/trunk/solr/example/files/conf/update-script.js
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1701883&r1=1701882&r2=1701883&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Tue Sep 8 23:52:16 2015
@@ -195,6 +195,8 @@ Bug Fixes
* SOLR-8001: Fixed bugs in field(foo,min) and field(foo,max) when some docs have no values
(David Smiley, hossman)
+* SOLR-7978: Fixed example/files update-script.js to be Java 7 and 8 compatible. (Erik Hatcher)
+
Optimizations
----------------------
Added: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/cross-compatible.js
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/cross-compatible.js?rev=1701883&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/cross-compatible.js (added)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/cross-compatible.js Tue Sep 8 23:52:16 2015
@@ -0,0 +1,53 @@
+function get_class(name) {
+ var clazz;
+ try {
+ // Java8 Nashorn
+ clazz = eval("Java.type(name).class");
+ } catch(e) {
+ // Java7 Rhino
+ clazz = eval("Packages."+name);
+ }
+
+ return clazz;
+}
+
+function processAdd(cmd) {
+ var doc = cmd.getSolrInputDocument();
+
+ var analyzer =
+ req.getCore().getLatestSchema()
+ .getFieldTypeByName("text")
+ .getIndexAnalyzer();
+
+ var token_stream =
+ analyzer.tokenStream("subject", doc.getFieldValue("subject"));
+
+ var cta_class = get_class("org.apache.lucene.analysis.tokenattributes.CharTermAttribute");
+ var term_att = token_stream.getAttribute(cta_class);
+ token_stream.reset();
+ while (token_stream.incrementToken()) {
+ doc.addField("term_s", term_att.toString());
+ }
+ token_stream.end();
+ token_stream.close();
+
+ return true;
+}
+
+// // //
+
+function processDelete() {
+ // NOOP
+}
+function processCommit() {
+ // NOOP
+}
+function processRollback() {
+ // NOOP
+}
+function processMergeIndexes() {
+ // NOOP
+}
+function finish() {
+ // NOOP
+}
Modified: lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-script-updateprocessor.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-script-updateprocessor.xml?rev=1701883&r1=1701882&r2=1701883&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-script-updateprocessor.xml (original)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/collection1/conf/solrconfig-script-updateprocessor.xml Tue Sep 8 23:52:16 2015
@@ -103,10 +103,17 @@
<str name="script">throw.error.on.add.updateprocessor.js</str>
</processor>
</updateRequestProcessorChain>
+
<updateRequestProcessorChain name="missing-functions">
<processor class="solr.StatelessScriptUpdateProcessorFactory">
<str name="script">missing.functions.updateprocessor.js</str>
</processor>
</updateRequestProcessorChain>
+ <updateRequestProcessorChain name="javascript-compatibility">
+ <processor class="solr.StatelessScriptUpdateProcessorFactory">
+ <str name="script">cross-compatible.js</str>
+ </processor>
+ </updateRequestProcessorChain>
+
</config>
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java?rev=1701883&r1=1701882&r2=1701883&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactoryTest.java Tue Sep 8 23:52:16 2015
@@ -268,4 +268,14 @@ public class StatelessScriptUpdateProces
fail("Did not get exception from script");
}
+ public void testJavaScriptCompatibility() throws Exception {
+ final String chain = "javascript-compatibility";
+ SolrInputDocument d = processAdd(chain,
+ doc(f("id", "5"),
+ f("name", " foo "),
+ f("subject", "BAR")));
+ assertEquals("bar", d.getFieldValue("term_s"));
+
+ }
+
}
Modified: lucene/dev/trunk/solr/example/files/conf/update-script.js
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/example/files/conf/update-script.js?rev=1701883&r1=1701882&r2=1701883&view=diff
==============================================================================
--- lucene/dev/trunk/solr/example/files/conf/update-script.js (original)
+++ lucene/dev/trunk/solr/example/files/conf/update-script.js Tue Sep 8 23:52:16 2015
@@ -1,6 +1,15 @@
-/*
- See http://wiki.apache.org/solr/ScriptUpdateProcessor for more details.
-*/
+function get_class(name) {
+ var clazz;
+ try {
+ // Java8 Nashorn
+ clazz = eval("Java.type(name).class");
+ } catch(e) {
+ // Java7 Rhino
+ clazz = eval("Packages."+name);
+ }
+
+ return clazz;
+}
function processAdd(cmd) {
@@ -69,9 +78,9 @@ function processAdd(cmd) {
.getIndexAnalyzer();
var token_stream =
- analyzer.tokenStream("content", new java.io.StringReader(doc.getFieldValue("content")));
- var term_att = token_stream.getAttribute(org.apache.lucene.analysis.tokenattributes.CharTermAttribute.class);
- var type_att = token_stream.getAttribute(org.apache.lucene.analysis.tokenattributes.TypeAttribute.class);
+ analyzer.tokenStream("content", doc.getFieldValue("content"));
+ var term_att = token_stream.getAttribute(get_class("org.apache.lucene.analysis.tokenattributes.CharTermAttribute"));
+ var type_att = token_stream.getAttribute(get_class("org.apache.lucene.analysis.tokenattributes.TypeAttribute"));
token_stream.reset();
while (token_stream.incrementToken()) {
doc.addField(type_att.type().replace(/\<|\>/g,'').toLowerCase()+"_ss", term_att.toString());