Skip to content

Commit

Permalink
CouchDB River: Custom script does not convert the modified doc proper…
Browse files Browse the repository at this point in the history
…ly to be indexed, closes #1225.
  • Loading branch information
kimchy committed Aug 10, 2011
1 parent 25c3e89 commit d06a7e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Expand Up @@ -59,6 +59,7 @@ public class ScriptFieldsSearchHitPhase implements SearchHitPhase {
Object value;
try {
value = scriptField.script().run();
value = scriptField.script().unwrap(value);
} catch (RuntimeException e) {
if (scriptField.ignoreException()) {
continue;
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.hamcrest.MatcherAssert.*;
Expand Down Expand Up @@ -94,6 +95,21 @@ public class JavaScriptScriptEngineTests {
assertThat((String) ((Map<String, Object>) ctx.get("obj2")).get("prop2"), equalTo("value2"));
}

@Test public void testJavaScriptInnerArrayCreation() {
Map<String, Object> ctx = new HashMap<String, Object>();
Map<String, Object> doc = new HashMap<String, Object>();
ctx.put("doc", doc);

Object complied = se.compile("ctx.doc.field1 = ['value1', 'value2']");
ExecutableScript script = se.executable(complied, new HashMap<String, Object>());
script.setNextVar("ctx", ctx);
script.run();

Map<String, Object> unwrap = (Map<String, Object>) script.unwrap(ctx);

assertThat(((Map) unwrap.get("doc")).get("field1"), instanceOf(List.class));
}

@Test public void testAccessListInScript() {
Map<String, Object> vars = new HashMap<String, Object>();
Map<String, Object> obj2 = MapBuilder.<String, Object>newMapBuilder().put("prop2", "value2").map();
Expand Down
Expand Up @@ -213,6 +213,8 @@ private String processLine(String s, BulkRequestBuilder bulk) {
script.setNextVar("ctx", ctx);
try {
script.run();
// we need to unwrap the ctx...
ctx = (Map<String, Object>) script.unwrap(ctx);
} catch (Exception e) {
logger.warn("failed to script process {}, ignoring", e, ctx);
return seq;
Expand Down

0 comments on commit d06a7e9

Please sign in to comment.