From eeb4bdbb3464a250adac39966d287ac91b1c4411 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Sun, 24 Feb 2013 22:32:11 +0100 Subject: [PATCH] Move to Elasticsearch 0.21.0.Beta1 Due to refactoring in 0.21.x we have to update this plugin Closes #3. --- README.md | 4 +- pom.xml | 4 +- .../JavaScriptScriptEngineService.java | 6 +- .../JavaScriptScriptSearchTests.java | 98 +++++++++---------- 4 files changed, 56 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 9239e39a02f27..cd0ac0a960bac 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ In order to install the plugin, simply run: `bin/plugin -install elasticsearch/e ---------------------------------------- | JavaScript Plugin | ElasticSearch | ---------------------------------------- - | master | 0.19 -> master | + | master | 0.21 -> master | ---------------------------------------- - | 1.2.0 | 0.19 -> master | + | 1.2.0 | 0.19 -> 0.20 | ---------------------------------------- | 1.1.0 | 0.19 -> master | ---------------------------------------- diff --git a/pom.xml b/pom.xml index 4150a1cc10e2b..8213f90164d2c 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ - 0.19.0 + 0.21.0.Beta1-SNAPSHOT @@ -141,4 +141,4 @@ - \ No newline at end of file + diff --git a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java index d1d35d453bb2e..419a588d703b9 100644 --- a/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java +++ b/src/main/java/org/elasticsearch/script/javascript/JavaScriptScriptEngineService.java @@ -19,7 +19,7 @@ package org.elasticsearch.script.javascript; -import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.search.Scorer; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; @@ -220,8 +220,8 @@ public void setScorer(Scorer scorer) { } @Override - public void setNextReader(IndexReader reader) { - lookup.setNextReader(reader); + public void setNextReader(AtomicReaderContext context) { + lookup.setNextReader(context); } @Override diff --git a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java index 110fe81709aa2..78d939627c216 100644 --- a/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java +++ b/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptSearchTests.java @@ -94,11 +94,11 @@ public void testJavaScriptFilter() throws Exception { .addScriptField("sNum1", "js", "doc['num1'].value", null) .execute().actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(1).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0)); + assertThat(response.getHits().totalHits(), equalTo(2l)); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(2.0)); + assertThat(response.getHits().getAt(1).id(), equalTo("3")); + assertThat((Double) response.getHits().getAt(1).fields().get("sNum1").values().get(0), equalTo(3.0)); logger.info("running doc['num1'].value > param1"); response = client.prepareSearch() @@ -107,9 +107,9 @@ public void testJavaScriptFilter() throws Exception { .addScriptField("sNum1", "js", "doc['num1'].value", null) .execute().actionGet(); - assertThat(response.hits().totalHits(), equalTo(1l)); - assertThat(response.hits().getAt(0).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0)); + assertThat(response.getHits().totalHits(), equalTo(1l)); + assertThat(response.getHits().getAt(0).id(), equalTo("3")); + assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(3.0)); logger.info("running doc['num1'].value > param1"); response = client.prepareSearch() @@ -118,13 +118,13 @@ public void testJavaScriptFilter() throws Exception { .addScriptField("sNum1", "js", "doc['num1'].value", null) .execute().actionGet(); - assertThat(response.hits().totalHits(), equalTo(3l)); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat((Double) response.hits().getAt(0).fields().get("sNum1").values().get(0), equalTo(1.0)); - assertThat(response.hits().getAt(1).id(), equalTo("2")); - assertThat((Double) response.hits().getAt(1).fields().get("sNum1").values().get(0), equalTo(2.0)); - assertThat(response.hits().getAt(2).id(), equalTo("3")); - assertThat((Double) response.hits().getAt(2).fields().get("sNum1").values().get(0), equalTo(3.0)); + assertThat(response.getHits().totalHits(), equalTo(3l)); + assertThat(response.getHits().getAt(0).id(), equalTo("1")); + assertThat((Double) response.getHits().getAt(0).fields().get("sNum1").values().get(0), equalTo(1.0)); + assertThat(response.getHits().getAt(1).id(), equalTo("2")); + assertThat((Double) response.getHits().getAt(1).fields().get("sNum1").values().get(0), equalTo(2.0)); + assertThat(response.getHits().getAt(2).id(), equalTo("3")); + assertThat((Double) response.getHits().getAt(2).fields().get("sNum1").values().get(0), equalTo(3.0)); } @Test @@ -147,21 +147,21 @@ public void testScriptFieldUsingSource() throws Exception { .addScriptField("s_obj2_arr2", "js", "_source.obj2.arr2", null) .execute().actionGet(); - Map sObj1 = (Map) response.hits().getAt(0).field("_source.obj1").value(); + Map sObj1 = (Map) response.getHits().getAt(0).field("_source.obj1").value(); assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); + assertThat(response.getHits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - sObj1 = (Map) response.hits().getAt(0).field("s_obj1").value(); + sObj1 = (Map) response.getHits().getAt(0).field("s_obj1").value(); assertThat(sObj1.get("test").toString(), equalTo("something")); - assertThat(response.hits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); + assertThat(response.getHits().getAt(0).field("s_obj1_test").value().toString(), equalTo("something")); - Map sObj2 = (Map) response.hits().getAt(0).field("s_obj2").value(); + Map sObj2 = (Map) response.getHits().getAt(0).field("s_obj2").value(); List sObj2Arr2 = (List) sObj2.get("arr2"); assertThat(sObj2Arr2.size(), equalTo(2)); assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); - sObj2Arr2 = (List) response.hits().getAt(0).field("s_obj2_arr2").value(); + sObj2Arr2 = (List) response.getHits().getAt(0).field("s_obj2_arr2").value(); assertThat(sObj2Arr2.size(), equalTo(2)); assertThat(sObj2Arr2.get(0).toString(), equalTo("arr_value1")); assertThat(sObj2Arr2.get(1).toString(), equalTo("arr_value2")); @@ -199,11 +199,11 @@ public void testCustomScriptBoost() throws Exception { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat(response.getHits().getAt(1).id(), equalTo("1")); logger.info("running -doc['num1'].value"); response = client.search(searchRequest() @@ -211,11 +211,11 @@ public void testCustomScriptBoost() throws Exception { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("-doc['num1'].value").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("1")); - assertThat(response.hits().getAt(1).id(), equalTo("2")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("1")); + assertThat(response.getHits().getAt(1).id(), equalTo("2")); logger.info("running pow(doc['num1'].value, 2)"); @@ -224,11 +224,11 @@ public void testCustomScriptBoost() throws Exception { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.pow(doc['num1'].value, 2)").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat(response.getHits().getAt(1).id(), equalTo("1")); logger.info("running max(doc['num1'].value, 1)"); response = client.search(searchRequest() @@ -236,11 +236,11 @@ public void testCustomScriptBoost() throws Exception { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("Math.max(doc['num1'].value, 1)").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat(response.getHits().getAt(1).id(), equalTo("1")); logger.info("running doc['num1'].value * _score"); response = client.search(searchRequest() @@ -248,11 +248,11 @@ public void testCustomScriptBoost() throws Exception { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("doc['num1'].value * _score").lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); - assertThat(response.hits().getAt(0).id(), equalTo("2")); - assertThat(response.hits().getAt(1).id(), equalTo("1")); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); + assertThat(response.getHits().getAt(0).id(), equalTo("2")); + assertThat(response.getHits().getAt(1).id(), equalTo("1")); logger.info("running param1 * param2 * _score"); response = client.search(searchRequest() @@ -260,8 +260,8 @@ public void testCustomScriptBoost() throws Exception { .source(searchSource().explain(true).query(customScoreQuery(termQuery("test", "value")).script("param1 * param2 * _score").param("param1", 2).param("param2", 2).lang("js"))) ).actionGet(); - assertThat(response.hits().totalHits(), equalTo(2l)); - logger.info("Hit[0] {} Explanation {}", response.hits().getAt(0).id(), response.hits().getAt(0).explanation()); - logger.info("Hit[1] {} Explanation {}", response.hits().getAt(1).id(), response.hits().getAt(1).explanation()); + assertThat(response.getHits().totalHits(), equalTo(2l)); + logger.info("Hit[0] {} Explanation {}", response.getHits().getAt(0).id(), response.getHits().getAt(0).explanation()); + logger.info("Hit[1] {} Explanation {}", response.getHits().getAt(1).id(), response.getHits().getAt(1).explanation()); } }