Last active
August 29, 2015 13:57
-
-
Save brusic/9786587 to your computer and use it in GitHub Desktop.
Norm Removal Machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public float tf(float freq) { | |
//original: return (float)Math.sqrt(freq); | |
return (float)Math.sqrt(Math.min(10, freq)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.elasticsearch.index.similarity; | |
import org.apache.lucene.search.similarities.DefaultSimilarity; | |
import org.elasticsearch.common.logging.ESLogger; | |
import org.elasticsearch.common.logging.Loggers; | |
public class NormRemovalSimilarity extends DefaultSimilarity { | |
private ESLogger logger; | |
public NormRemovalSimilarity() { | |
logger = Loggers.getLogger(getClass()); | |
} | |
/** | |
* Eliminate the field norm value | |
* @param b ignored | |
* @return Always return 1.0 | |
*/ | |
@Override | |
public float decodeNormValue(byte b) { | |
if (logger.isDebugEnabled()) { | |
float norm = super.decodeNormValue(b); | |
logger.debug(String.format("Ignore norm: %s => %s", b, norm)); | |
} | |
return 1.0f; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.elasticsearch.index.similarity; | |
import org.elasticsearch.common.inject.Inject; | |
import org.elasticsearch.common.inject.assistedinject.Assisted; | |
import org.elasticsearch.common.settings.Settings; | |
public class NormRemovalSimilarityProvider extends AbstractSimilarityProvider { | |
private NormRemovalSimilarity similarity; | |
@Inject | |
public NormRemovalSimilarityProvider(@Assisted String name, @Assisted Settings settings) { | |
super(name); | |
this.similarity = new NormRemovalSimilarity(); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public NormRemovalSimilarity get() { | |
return similarity; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>example</groupId> | |
<artifactId>norm_removal_similarity</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>jar</packaging> | |
<properties> | |
<elasticsearch.version>1.1.0</elasticsearch.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.elasticsearch</groupId> | |
<artifactId>elasticsearch</artifactId> | |
<version>${elasticsearch.version}</version> | |
<scope>compile</scope> | |
</dependency> | |
</dependencies> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment