1

Why are live projections a part of the index (TransformResults property)? An Index is used for document querying, while projection is used for document transformation. So why should they be combined?

If live projections weren't a part of an Index, it would be possible to have several live projections for the same index. As result there would be less indexes and I guess RavenDb performance would be a bit better.

Update. It would be great to have live projections working by Select statement placed on the query (like Where for filtering).

casperOne
  • 73,706
  • 19
  • 184
  • 253
SiberianGuy
  • 24,674
  • 56
  • 152
  • 266

3 Answers3

4

It's actually a fair question. I think the answer is that putting TransformResults in the index is the most common use case and was easier to implement given the existing indexing structure in RavenDB.

If there are genuine scenarios where you would want to define the TransformResults at querying time, in an ad-hoc fashion, post a feature request on the mailing list.

However I'm pretty sure the answer will be

I'd accept a pull-request for that

As you're the first person to ask for this feature ;-)

Matt Warren
  • 10,279
  • 7
  • 48
  • 63
  • 1
    It is not the feature which I can't live without. But I always thought projections work by Select statement, so I was surprised to find projections working not by Select. – SiberianGuy Jan 27 '12 at 13:03
  • You have some options, see this answer http://stackoverflow.com/a/7836337/4500 – Matt Warren Jan 29 '12 at 17:56
3

Because we need a place to put them, most indexes have only one transform result function, so that was a good place to do that. It also reduce the number of things that you have to know about RavenDB. Otherwise, you would have a top level concern called Transformers, which would usually be used only with a single index, therefor, raising the question why they are separated.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • What about putting projections into Select method of a query? So I can use Order for ordering, Where for filtering and it would be nice to be able to use Select for projecting. – SiberianGuy Jan 29 '12 at 17:22
  • You can do this to some extent, see http://stackoverflow.com/a/7836337/4500 – Matt Warren Jan 29 '12 at 17:57
2

Take a look here: http://ravendb.net/docs/client-api/querying/handling-document-relationships

The important part is this:

The function declared in TransformResults will be executed on the results on the query

That means, the TransformResults function will be executed at query time, not indexing time. That's a fundamental difference obviously.

Daniel Lang
  • 6,819
  • 4
  • 28
  • 54
  • You are right, they are different. But the question was why they being so different are both placed inside index. For me live projections looks more like a part of query (like Where cluase) than part of index. – SiberianGuy Jan 27 '12 at 07:30