diff --git a/README.textile b/README.textile
index 75ca749..3f77ba9 100644
--- a/README.textile
+++ b/README.textile
@@ -1,21 +1,29 @@
h1. A custom SimilarityProvider example for Elasticseach
-This plugin contains a custom @Similarity@ class that can be used in an index:
+This plugin contains a custom @Similarity@ class that can be used as follows.
+
+Build the plugin with maven, then put the jar file into @$ES_PATH/lib@.
+
+Then, declare it in the settings section of your index:
-curl -XPOST 'http://host:port/tweeter/' -d '
-{
- "settings": {
- "similarity": {
- "index": {
- "type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"
- },
- "search": {
- "type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"
- }
+"settings" : {
+ "similarity" : {
+ "my_similarity" : {
+ "type" : "org.elasticsearch.index.similarity.CustomSimilarityProvider"
}
}
-}'
+}
+
+
+After that, you can refer to @my_similarity@ when defining fields:
+
+
+"book" : {
+ "properties" : {
+ "title" : { "type" : "string", "similarity" : "my_similarity" }
+ }
+}
Enjoy
diff --git a/pom.xml b/pom.xml
index 2b5c6d1..c1e6611 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,15 +3,28 @@
4.0.0
fr.tlrx
- elasticsearch-custom-similarity-provider
- 1.0-SNAPSHOT
+ elasticsearch-constant-similarity-provider
+ 1.0
jar
- A custom SimilarityProvider example for Elasticsearch
- https://github.com/tlrx/elasticsearch-custom-similarity-provider
+ A constant SimilarityProvider for Elasticsearch
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.3
+
+ 1.7
+ 1.7
+
+
+
+
UTF-8
- 0.20.0.Beta1-SNAPSHOT
+ 1.7.0
@@ -27,5 +40,5 @@
${elasticsearch.version}
-
+
diff --git a/src/main/java/org/elasticsearch/index/similarity/CustomSimilarity.java b/src/main/java/org/elasticsearch/index/similarity/CustomSimilarity.java
index ec3dc32..c19256d 100644
--- a/src/main/java/org/elasticsearch/index/similarity/CustomSimilarity.java
+++ b/src/main/java/org/elasticsearch/index/similarity/CustomSimilarity.java
@@ -1,6 +1,6 @@
package org.elasticsearch.index.similarity;
-import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.similarities.DefaultSimilarity;
/**
* Custom similarity class
@@ -12,7 +12,7 @@
public class CustomSimilarity extends DefaultSimilarity {
@Override
- public float idf(int docFreq, int numDocs) {
+ public float idf(long docFreq, long numDocs) {
return 1.0f;
}
}
diff --git a/src/main/java/org/elasticsearch/index/similarity/CustomSimilarityProvider.java b/src/main/java/org/elasticsearch/index/similarity/CustomSimilarityProvider.java
index d28d0bc..8cb25a5 100644
--- a/src/main/java/org/elasticsearch/index/similarity/CustomSimilarityProvider.java
+++ b/src/main/java/org/elasticsearch/index/similarity/CustomSimilarityProvider.java
@@ -12,18 +12,16 @@
* @author tlrx
*
*/
-public class CustomSimilarityProvider extends AbstractSimilarityProvider {
+public class CustomSimilarityProvider extends AbstractSimilarityProvider {
- private CustomSimilarity similarity;
+ private final CustomSimilarity similarity = new CustomSimilarity();
@Inject
- public CustomSimilarityProvider(Index index,
- @IndexSettings Settings indexSettings, @Assisted String name,
- @Assisted Settings settings) {
- super(index, indexSettings, name);
- this.similarity = new CustomSimilarity();
+ public CustomSimilarityProvider(@Assisted String name, @Assisted Settings settings) {
+ super(name);
}
+ @Override
public CustomSimilarity get() {
return similarity;
}