# Help to Implement New Similarity Function

**URL:** <https://discuss.elastic.co/t/help-to-implement-new-similarity-function/106465>\
**Category:** Elasticsearch\
**Created:** [November 6, 2017, 6:07am UTC](https://discuss.elastic.co/t/help-to-implement-new-similarity-function/106465 "2017-11-06T06:07:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESlearner](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@ESlearner](https://discuss.elastic.co/u/ESlearner)\
**Post date:** [November 6, 2017, 6:07am UTC](https://discuss.elastic.co/t/help-to-implement-new-similarity-function/106465/1 "2017-11-06T06:07:19Z")

</div>

Hello - I am trying to implement a new similarity function .  
Here is the formula :  
f(q,d)=1/ |d| log2(clicksd+1) ∑ TF log2(N+1/ DFt+1)  
t∈q t,d

After looking at the link [https://github.com/stefansavev/elasticsearch-custom-similarity-example/blob/master/src/main/java/stefansavev/esplugins/OverlapSimilarity.java](https://github.com/stefansavev/elasticsearch-custom-similarity-example/blob/master/src/main/java/stefansavev/esplugins/OverlapSimilarity.java).

Here is the initial declaration:  
protected float score(BasicStats stats, float tf, float docLen, long docValue)

I then wrote this piece and here is where I need help. The error that I get when I compile are all pointing to stats.getdocLen . The error says "cannot find symbol" right after stats. at the period position. The error re-occurs for the remaining stats.xxxx declarations - a total of 5.

float score = (float) (1/stats.getdocLen()) \* ((Math.log(stats.getdocValue()+1))/Math.log(2)) \* stats.gettf \* ((Math.log(stats.getnumberofDocments()+1)/(stats.getdocFreq()+1))/ Math.log(2));

Any help is much appreciated...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 4, 2017, 6:07am UTC](https://discuss.elastic.co/t/help-to-implement-new-similarity-function/106465/2 "2017-12-04T06:07:34Z")

</div>

Closed on December 4, 2017, 6:07am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
