Skip to content

Commit 1254c48

Browse files
committed
Upgrade to elasticsearch 1.4.0
Fixes elastic#8
1 parent c5ed8ee commit 1254c48

File tree

8 files changed

+67
-12
lines changed

8 files changed

+67
-12
lines changed

pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
<!-- The Elasticsearch version that the project will be built with -->
3939
<!-- ============================================================= -->
4040
<properties>
41-
<elasticsearch.version>1.3.4</elasticsearch.version>
42-
<lucene.version>4.9.1</lucene.version>
41+
<elasticsearch.version>1.4.0</elasticsearch.version>
42+
<lucene.version>4.10.2</lucene.version>
4343
</properties>
4444

4545
<!-- ============================================================= -->
@@ -91,7 +91,13 @@
9191
<version>1.3</version>
9292
<scope>test</scope>
9393
</dependency>
94-
94+
95+
<dependency>
96+
<groupId>com.carrotsearch.randomizedtesting</groupId>
97+
<artifactId>randomizedtesting-runner</artifactId>
98+
<version>2.1.10</version>
99+
<scope>test</scope>
100+
</dependency>
95101

96102
</dependencies>
97103

src/main/java/org/elasticsearch/examples/nativescript/script/CosineSimilarityScoreScript.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.Map;
66

7+
import org.apache.lucene.search.Scorer;
78
import org.elasticsearch.script.ScriptException;
89

910
import org.elasticsearch.common.Nullable;
@@ -32,6 +33,11 @@ public class CosineSimilarityScoreScript extends AbstractSearchScript {
3233

3334
final static public String SCRIPT_NAME = "cosine_sim_script_score";
3435

36+
@Override
37+
public void setScorer(Scorer scorer) {
38+
// ignore
39+
}
40+
3541
/**
3642
* Factory that is registered in
3743
* {@link org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin#onModule(org.elasticsearch.script.ScriptModule)}

src/main/java/org/elasticsearch/examples/nativescript/script/LanguageModelScoreScript.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.Map;
66

7+
import org.apache.lucene.search.Scorer;
78
import org.elasticsearch.common.Nullable;
89
import org.elasticsearch.index.fielddata.ScriptDocValues;
910
import org.elasticsearch.script.AbstractSearchScript;
@@ -34,6 +35,11 @@ public class LanguageModelScoreScript extends AbstractSearchScript {
3435

3536
final static public String SCRIPT_NAME = "language_model_script_score";
3637

38+
@Override
39+
public void setScorer(Scorer scorer) {
40+
// ignore
41+
}
42+
3743
/**
3844
* Factory that is registered in
3945
* {@link org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin#onModule(org.elasticsearch.script.ScriptModule)}

src/main/java/org/elasticsearch/examples/nativescript/script/PhraseScoreScript.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Iterator;
55
import java.util.Map;
66

7+
import org.apache.lucene.search.Scorer;
78
import org.elasticsearch.common.Nullable;
89
import org.elasticsearch.script.AbstractSearchScript;
910
import org.elasticsearch.script.ExecutableScript;
@@ -29,6 +30,11 @@ public class PhraseScoreScript extends AbstractSearchScript {
2930

3031
final static public String SCRIPT_NAME = "phrase_script_score";
3132

33+
@Override
34+
public void setScorer(Scorer scorer) {
35+
// ignore
36+
}
37+
3238
/**
3339
* Factory that is registered in
3440
* {@link org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin#onModule(org.elasticsearch.script.ScriptModule)}

src/main/java/org/elasticsearch/examples/nativescript/script/PopularityScoreScriptFactory.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.elasticsearch.examples.nativescript.script;
22

3+
import org.apache.lucene.search.Scorer;
34
import org.elasticsearch.common.Nullable;
45
import org.elasticsearch.common.xcontent.support.XContentMapValues;
56
import org.elasticsearch.index.fielddata.ScriptDocValues;
@@ -8,6 +9,7 @@
89
import org.elasticsearch.script.NativeScriptFactory;
910
import org.elasticsearch.script.ScriptException;
1011

12+
import java.io.IOException;
1113
import java.util.Map;
1214

1315
/**
@@ -36,21 +38,33 @@ private static class PopularityScoreScript extends AbstractFloatSearchScript {
3638

3739
private final String field;
3840

41+
private Scorer scorer;
42+
3943
public PopularityScoreScript(String field) {
4044
this.field = field;
4145
}
4246

47+
@Override
48+
public void setScorer(Scorer scorer) {
49+
this.scorer = scorer;
50+
}
51+
4352
@Override
4453
public float runAsFloat() {
45-
ScriptDocValues docValue = (ScriptDocValues) doc().get(field);
46-
if (docValue != null && !docValue.isEmpty()) {
47-
ScriptDocValues.Longs fieldData = (ScriptDocValues.Longs) docValue;
48-
double boost = 1 + Math.log10(fieldData.getValue() + 1);
49-
// Because this script is used in custom_score script the value of score() is populated.
50-
// In all other cases doc().getScore() should be used instead.
51-
return (float) boost * score();
54+
try {
55+
ScriptDocValues docValue = (ScriptDocValues) doc().get(field);
56+
if (docValue != null && !docValue.isEmpty()) {
57+
ScriptDocValues.Longs fieldData = (ScriptDocValues.Longs) docValue;
58+
double boost = 1 + Math.log10(fieldData.getValue() + 1);
59+
// Because this script is used in custom_score script the value of score() is populated.
60+
// In all other cases doc().getScore() should be used instead.
61+
return (float) boost * scorer.score();
62+
63+
}
64+
return scorer.score();
65+
} catch (IOException ex) {
66+
return 0.0f;
5267
}
53-
return score();
5468
}
5569
}
5670
}

src/main/java/org/elasticsearch/examples/nativescript/script/RandomSortScriptFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.elasticsearch.examples.nativescript.script;
22

3+
import org.apache.lucene.search.Scorer;
34
import org.elasticsearch.common.Nullable;
45
import org.elasticsearch.common.xcontent.support.XContentMapValues;
56
import org.elasticsearch.index.fielddata.ScriptDocValues;
@@ -50,6 +51,11 @@ private RandomSortScript() {
5051
public long runAsLong() {
5152
return random.nextLong();
5253
}
54+
55+
@Override
56+
public void setScorer(Scorer scorer) {
57+
// we are not using it - ignore
58+
}
5359
}
5460

5561
private static class PseudoRandomSortScript extends AbstractLongSearchScript {
@@ -79,5 +85,10 @@ public long runAsLong() {
7985
return -1;
8086
}
8187
}
88+
89+
@Override
90+
public void setScorer(Scorer scorer) {
91+
// we are not using it - ignore
92+
}
8293
}
8394
}

src/main/java/org/elasticsearch/examples/nativescript/script/TFIDFScoreScript.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.Map;
66

7+
import org.apache.lucene.search.Scorer;
78
import org.elasticsearch.common.Nullable;
89
import org.elasticsearch.script.AbstractSearchScript;
910
import org.elasticsearch.script.ExecutableScript;
@@ -28,6 +29,11 @@ public class TFIDFScoreScript extends AbstractSearchScript {
2829

2930
final static public String SCRIPT_NAME = "tfidf_script_score";
3031

32+
@Override
33+
public void setScorer(Scorer scorer) {
34+
// ignore
35+
}
36+
3137
/**
3238
* Factory that is registered in
3339
* {@link org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin#onModule(org.elasticsearch.script.ScriptModule)}

src/test/java/org/elasticsearch/examples/nativescript/script/AbstractSearchScriptTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
*/
1515
@ClusterScope(scope = Scope.SUITE, numDataNodes = 1)
16-
public class AbstractSearchScriptTests extends ElasticsearchIntegrationTest {
16+
public abstract class AbstractSearchScriptTests extends ElasticsearchIntegrationTest {
1717

1818
@Override
1919
public Settings indexSettings() {

0 commit comments

Comments
 (0)