# Custom similarity without TF/IDF scoring

**URL:** <https://discuss.elastic.co/t/custom-similarity-without-tf-idf-scoring/243930>\
**Category:** Elasticsearch\
**Created:** [August 5, 2020, 8:24pm UTC](https://discuss.elastic.co/t/custom-similarity-without-tf-idf-scoring/243930 "2020-08-05T20:24:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_D](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Alex\_D](https://discuss.elastic.co/u/Alex_D)\
**Post date:** [August 5, 2020, 8:24pm UTC](https://discuss.elastic.co/t/custom-similarity-without-tf-idf-scoring/243930/1 "2020-08-05T20:24:21Z")

</div>

Hi all !

It isn't necessary to use TF / IDF scoring relevance for my full-text search task.  
I am trying to receive score in range 0-100 based only on **doc.length** variable.

My formula:

```auto
"similarity": {
  "custom_similarity": {
    "type": "scripted",
    "script": {
      "source": "double norm = 100/doc.length; return norm * query.boost;"
    }
  }
}

```

I receive expected results if **count of tokens in query** \<= **count of tokens in document**.

Suppose my query: "`big bang theory`"  
Results:

```auto
"big bang theory", score: 100%
"big bang theory stub1", score: 75%
"big bang theory stub1 stub2", score: 60%

```

But with the same query in cases:

```auto
"big", score: 100%
"big bang", score: 100%

```

scoring doesn't work properly for me.

Some summaries

```auto
---------------------------------------------------
| Tokens_count | Score | Score |
|----------------------------| expected | current |
| Query | Document | Matches | | |
---------------------------------------------------
| 3 | 3 | 3 | 100 % | 100 % |
| 3 | 6 | 3 | 50 % | 50 % |
| 3 | 9 | 3 | 33 % | 33 % |
| 3 | 1 | 1 | 33 % | 100 % | <-- current algorithm does not provide expected result
| 3 | 2 | 2 | 66 % | 100 % | <-- the same point
| 3 | 2 | 1 | 33 % | 100 % | <-- the same point
---------------------------------------------------

```

Would be glad to any advise how to update my formula or maybe to find a workaround,  
thanks 🙂

---

<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:** [September 2, 2020, 8:24pm UTC](https://discuss.elastic.co/t/custom-similarity-without-tf-idf-scoring/243930/2 "2020-09-02T20:24:23Z")

</div>

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