---
title: "Using MoreLikeThis"
url: "https://docs.ravendb.net/6.2/client-api/session/querying/how-to-use-morelikethis"
version: "6.2"
language: "csharp"
---

# Using MoreLikeThis

> Client language: C#. Also available for [Java](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-use-morelikethis.java.md), [Python](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-use-morelikethis.python.md), [PHP](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-use-morelikethis.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-use-morelikethis.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

`MoreLikeThis` is available through query extension methods and will return similar documents according to the provided criteria and options.

## Syntax

```csharp
IRavenQueryable<T> MoreLikeThis<T>(MoreLikeThisBase moreLikeThis);

IRavenQueryable<T> MoreLikeThis<T>(Action<IMoreLikeThisBuilder<T>> builder);
```

| Parameters | | |
| - | - | - |
| **moreLikeThis** | `MoreLikeThisBase` | Defines the type of MoreLikeThis that should be executed |
| **builder** | `Action<IMoreLikeThisFactory<T>>` | Builder with fluent API that constructs the `MoreLikeThisBase` instance |

### Builder

```csharp
IMoreLikeThisOperations<T> UsingAnyDocument();

IMoreLikeThisOperations<T> UsingDocument(string documentJson);

IMoreLikeThisOperations<T> UsingDocument(Expression<Func<T, bool>> predicate);

IMoreLikeThisOperations<T> WithOptions(MoreLikeThisOptions options);
```

| Parameters | | |
| - | - | - |
| **documentJson** | string | Inline JSON document that will be used as a base for operation |
| **predicate** | `Expression<Func<T, bool>>` | Filtering expression utilized to find a document that will be used as a base for operation |
| **options** | `MoreLikeThisOptions` | Non-default options that should be used for operation |

### Options

```csharp
public int? MinimumTermFrequency { get; set; } = 2;

public int? MaximumQueryTerms { get; set; } = 25;

public int? MaximumNumberOfTokensParsed { get; set; } = 5000;

public int? MinimumWordLength { get; set; } = 0;

public int? MaximumWordLength { get; set; } = 0;

public int? MinimumDocumentFrequency { get; set; } = 5;

public int? MaximumDocumentFrequency { get; set; } = int.MaxValue;

public int? MaximumDocumentFrequencyPercentage { get; set; }

public bool? Boost { get; set; } = false;

public float? BoostFactor { get; set; } = 1;

public string StopWordsDocumentId { get; set; }

public string[] Fields { get; set; }
```

| Options | | |
| - | - | - |
| **MinimumTermFrequency** | int? | Ignores terms with less than this frequency in the source doc |
| **MaximumQueryTerms** | int? | Returns a query with no more than this many terms |
| **MaximumNumberOfTokensParsed** | int? | The maximum number of tokens to parse in each example doc field that is not stored with TermVector support |
| **MinimumWordLength** | int? | Ignores words less than this length or, if 0, then this has no effect |
| **MaximumWordLength** | int? | Ignores words greater than this length or if 0 then this has no effect |
| **MinimumDocumentFrequency** | int? | Ignores words which do not occur in at least this many documents |
| **MaximumDocumentFrequency** | int? | Ignores words which occur in more than this many documents |
| **MaximumDocumentFrequencyPercentage** | int? | Ignores words which occur in more than this percentage of documents |
| **Boost** | bool? | Boost terms in query based on score |
| **BoostFactor** | float? | Boost factor when boosting based on score |
| **StopWordsDocumentId** | string | Document ID containing custom stop words |
| **Fields** | string\[] | Fields to compare |

## Example I

### Sync

```csharp
// Search for similar articles to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'Body'
List<Article> articles = session
  .Query<Article>("Articles/MoreLikeThis")
  .MoreLikeThis(builder => builder
      .UsingDocument(x => x.Id == "articles/1")
      .WithOptions(new MoreLikeThisOptions
      {
          Fields = new[] { "Body" }
      }))
  .ToList();
```

### Async

```csharp
// Search for similar articles to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'Body'
List<Article> articles = await asyncSession
  .Query<Article>("Articles/MoreLikeThis")
  .MoreLikeThis(builder => builder
      .UsingDocument(x => x.Id == "articles/1")
      .WithOptions(new MoreLikeThisOptions
      {
          Fields = new[] { "Body" }
      }))
  .ToListAsync();
```

### RQL

```sql
from index 'Articles/MoreLikeThis' 
where morelikethis(id() = 'articles/1', '{ "Fields" : [ "Body" ] }')
```

## Example II

### Sync

```csharp
// Search for similar articles to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'Body'
// where article category is 'IT'
List<Article> articles = session
  .Query<Article>("Articles/MoreLikeThis")
  .MoreLikeThis(builder => builder
      .UsingDocument(x => x.Id == "articles/1")
      .WithOptions(new MoreLikeThisOptions
      {
          Fields = new[] { "Body" }
      }))
  .Where(x => x.Category == "IT")
  .ToList();
```

### Async

```csharp
// Search for similar articles to 'articles/1'
// using 'Articles/MoreLikeThis' index and search only field 'Body'
// where article category is 'IT'
List<Article> articles = await asyncSession
  .Query<Article>("Articles/MoreLikeThis")
  .MoreLikeThis(builder => builder
      .UsingDocument(x => x.Id == "articles/1")
      .WithOptions(new MoreLikeThisOptions
      {
          Fields = new[] { "Body" }
      }))
  .Where(x => x.Category == "IT")
  .ToListAsync();
```

### RQL

```sql
from index 'Articles/MoreLikeThis' 
where morelikethis(id() = 'articles/1', '{ "Fields" : [ "Body" ] }') and Category == 'IT'
```

## Remarks

Do not forget to add the following **using** statement which contains necessary extensions:

```csharp
using Raven.Client.Documents;
```

## See also

- [How to Query](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.md)
- [MoreLikeThis](https://docs.ravendb.net/6.2/indexes/querying/morelikethis.md)
