Skip to content

Commit

Permalink
Upgrade to elasticsearch 1.4.0
Browse files Browse the repository at this point in the history
Fixes #8
  • Loading branch information
imotov committed Nov 10, 2014
1 parent c5ed8ee commit 1254c48
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 12 deletions.
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<!-- The Elasticsearch version that the project will be built with -->
<!-- ============================================================= -->
<properties>
<elasticsearch.version>1.3.4</elasticsearch.version>
<lucene.version>4.9.1</lucene.version>
<elasticsearch.version>1.4.0</elasticsearch.version>
<lucene.version>4.10.2</lucene.version>
</properties>

<!-- ============================================================= -->
Expand Down Expand Up @@ -91,7 +91,13 @@
<version>1.3</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>randomizedtesting-runner</artifactId>
<version>2.1.10</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Map;

import org.apache.lucene.search.Scorer;
import org.elasticsearch.script.ScriptException;

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

final static public String SCRIPT_NAME = "cosine_sim_script_score";

@Override
public void setScorer(Scorer scorer) {
// ignore
}

/**
* Factory that is registered in
* {@link org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin#onModule(org.elasticsearch.script.ScriptModule)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Map;

import org.apache.lucene.search.Scorer;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.index.fielddata.ScriptDocValues;
import org.elasticsearch.script.AbstractSearchScript;
Expand Down Expand Up @@ -34,6 +35,11 @@ public class LanguageModelScoreScript extends AbstractSearchScript {

final static public String SCRIPT_NAME = "language_model_script_score";

@Override
public void setScorer(Scorer scorer) {
// ignore
}

/**
* Factory that is registered in
* {@link org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin#onModule(org.elasticsearch.script.ScriptModule)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Iterator;
import java.util.Map;

import org.apache.lucene.search.Scorer;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.script.AbstractSearchScript;
import org.elasticsearch.script.ExecutableScript;
Expand All @@ -29,6 +30,11 @@ public class PhraseScoreScript extends AbstractSearchScript {

final static public String SCRIPT_NAME = "phrase_script_score";

@Override
public void setScorer(Scorer scorer) {
// ignore
}

/**
* Factory that is registered in
* {@link org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin#onModule(org.elasticsearch.script.ScriptModule)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.elasticsearch.examples.nativescript.script;

import org.apache.lucene.search.Scorer;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
Expand All @@ -8,6 +9,7 @@
import org.elasticsearch.script.NativeScriptFactory;
import org.elasticsearch.script.ScriptException;

import java.io.IOException;
import java.util.Map;

/**
Expand Down Expand Up @@ -36,21 +38,33 @@ private static class PopularityScoreScript extends AbstractFloatSearchScript {

private final String field;

private Scorer scorer;

public PopularityScoreScript(String field) {
this.field = field;
}

@Override
public void setScorer(Scorer scorer) {
this.scorer = scorer;
}

@Override
public float runAsFloat() {
ScriptDocValues docValue = (ScriptDocValues) doc().get(field);
if (docValue != null && !docValue.isEmpty()) {
ScriptDocValues.Longs fieldData = (ScriptDocValues.Longs) docValue;
double boost = 1 + Math.log10(fieldData.getValue() + 1);
// Because this script is used in custom_score script the value of score() is populated.
// In all other cases doc().getScore() should be used instead.
return (float) boost * score();
try {
ScriptDocValues docValue = (ScriptDocValues) doc().get(field);
if (docValue != null && !docValue.isEmpty()) {
ScriptDocValues.Longs fieldData = (ScriptDocValues.Longs) docValue;
double boost = 1 + Math.log10(fieldData.getValue() + 1);
// Because this script is used in custom_score script the value of score() is populated.
// In all other cases doc().getScore() should be used instead.
return (float) boost * scorer.score();

}
return scorer.score();
} catch (IOException ex) {
return 0.0f;
}
return score();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.elasticsearch.examples.nativescript.script;

import org.apache.lucene.search.Scorer;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.fielddata.ScriptDocValues;
Expand Down Expand Up @@ -50,6 +51,11 @@ private RandomSortScript() {
public long runAsLong() {
return random.nextLong();
}

@Override
public void setScorer(Scorer scorer) {
// we are not using it - ignore
}
}

private static class PseudoRandomSortScript extends AbstractLongSearchScript {
Expand Down Expand Up @@ -79,5 +85,10 @@ public long runAsLong() {
return -1;
}
}

@Override
public void setScorer(Scorer scorer) {
// we are not using it - ignore
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Map;

import org.apache.lucene.search.Scorer;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.script.AbstractSearchScript;
import org.elasticsearch.script.ExecutableScript;
Expand All @@ -28,6 +29,11 @@ public class TFIDFScoreScript extends AbstractSearchScript {

final static public String SCRIPT_NAME = "tfidf_script_score";

@Override
public void setScorer(Scorer scorer) {
// ignore
}

/**
* Factory that is registered in
* {@link org.elasticsearch.examples.nativescript.plugin.NativeScriptExamplesPlugin#onModule(org.elasticsearch.script.ScriptModule)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
*/
@ClusterScope(scope = Scope.SUITE, numDataNodes = 1)
public class AbstractSearchScriptTests extends ElasticsearchIntegrationTest {
public abstract class AbstractSearchScriptTests extends ElasticsearchIntegrationTest {

@Override
public Settings indexSettings() {
Expand Down

0 comments on commit 1254c48

Please sign in to comment.