Do you need any help with Migration?

Not Now Yes, Contact Support

You are currently browsing legacy 4.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Migration: How to Migrate MoreLikeThis from 3.x

MoreLikeThis functionality has been merged into RQL. To reflect this change the Client API has integrated this feature into the session.Query and session.Advanced.DocumentQuery. The following migration samples will focus on the session.Query - the most common and recommended way of interaction with querying capabilities on RavenDB.

Namespaces

3.x
using Raven.Abstractions.Data;
using Raven.Client.Bundles.MoreLikeThis;
using Raven.Client.Document;
4.0
using Raven.Client.Documents;
using Raven.Client.Documents.Queries.MoreLikeThis;

Example I

3.x
Article[] articles = session
    .Advanced
    .MoreLikeThis<Article>(
        "Articles/MoreLikeThis",
        null,
        new MoreLikeThisQuery
        {
            IndexName = "Articles/MoreLikeThis",
            DocumentId = "articles/1",
            Fields = new[] { "Body" }
        });
4.0
List<Article> articles = session
    .Query<Article>("Articles/MoreLikeThis")
    .MoreLikeThis(builder => builder
        .UsingDocument(x => x.Id == "articles/1")
        .WithOptions(new MoreLikeThisOptions
        {
            Fields = new[] { "Body" }
        }))
    .ToList();

Example II

3.x
Article[] articles = session
    .Advanced
    .MoreLikeThis<Article>(
        "Articles/MoreLikeThis",
        null,
        new MoreLikeThisQuery
        {
            IndexName = "Articles/MoreLikeThis",
            DocumentId = "articles/1",
            Fields = new[] { "Body" },
            AdditionalQuery = "Category:IT"
        });
4.0
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();

Remarks

Information

You can read more about MoreLikeThis in a dedicated Client API article that can be found here.