# Sorting document by the number of keywords found

**URL:** <https://forum.opensearch.org/t/sorting-document-by-the-number-of-keywords-found/19924>\
**Category:** OpenSearch\
**Created:** [June 20, 2024, 11:13am UTC](https://forum.opensearch.org/t/sorting-document-by-the-number-of-keywords-found/19924 "2024-06-20T11:13:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maknaka](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Maknaka](https://forum.opensearch.org/u/Maknaka)\
**Post date:** [June 20, 2024, 11:13am UTC](https://forum.opensearch.org/t/sorting-document-by-the-number-of-keywords-found/19924/1 "2024-06-20T11:13:55Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):

**Describe the issue** :  
I got documents and I want to search them for 1 or more words/phrases.  
I got results sorted by \_score value. But It is not what I am looking for. I want documents with higher number of keywords found to be ranked higher.  
Example: I am looking for a 2 keywords “fluffy” and “cat”  
What I need: I want the document with total count of found words “fluffy” and “cat” equals 20 to be ranked higher that a document with the number of keywords equal 15. 15 should be above one with 12 keywords etc.

**Configuration** :

**Relevant Logs or Screenshots** :

---

<div class="post-metadata">

**Author:** ![Maknaka](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Maknaka](https://forum.opensearch.org/u/Maknaka)\
**Post date:** [June 24, 2024, 2:17pm UTC](https://forum.opensearch.org/t/sorting-document-by-the-number-of-keywords-found/19924/2 "2024-06-24T14:17:07Z")

</div>

I found the solution myself. I had to change the standard Okapi BM25 algorithm setting to one below. This has to be done when creating index.

BM25 params:

- k1 - is a tuning parameter (usually set between 1.2 and 2.0) it controls the term frequency saturation. Increasing k1 increases the saturation effect.

- b - is another tuning parameter (usually set around 0.75) – it controls the length normalization. A value of 1.0 fully normalizes document length, while 0.0 ignores length normalization.
