see on GitHub

Commands : Transformers : How to transform query results using transformer?

Query results can be transformed on the server-side by passing the name and parameters (if necessary) of a transformer, along with the query. The following examples will demonstrate how to do this using commands:

Example I

// query for all orders with 'Company' equal to 'companies/1' using 'Orders/Totals' index
// and transform results using 'Order/Statistics' transformer
QueryResult result = store
	.DatabaseCommands
	.Query(
		"Orders/Totals",
		new IndexQuery
		{
			Query = "Company:companies/1",
			ResultsTransformer = "Order/Statistics"
		});

Example II

// query for all orders with 'Company' equal to 'companies/1' using 'Orders/Totals' index
// and transform results using 'Order/Statistics' transformer
// stream the results
QueryHeaderInformation queryHeaderInfo;
IEnumerator<RavenJObject> result = store
	.DatabaseCommands
	.StreamQuery(
		"Orders/Totals",
		new IndexQuery
		{
			Query = "Company:companies/1",
			ResultsTransformer = "Order/Statistics"
		},
		out queryHeaderInfo);

Example III

// Search for similar documents to 'articles/1'
// using 'Articles/MoreLikeThis' index, search only field 'Body'
// and transform results using 'Articles/NoComments' transformer
QueryHeaderInformation queryHeaderInfo;
MultiLoadResult result = store
	.DatabaseCommands
	.MoreLikeThis(
		new MoreLikeThisQuery
		{
			IndexName = "Articles/MoreLikeThis",
			DocumentId = "articles/1",
			Fields = new[] { "Body" },
			ResultsTransformer = "Articles/NoComments"
		});