That was _wonderful_, exactly the right way to do that, yes.
[Fact]
public void CanQueryInReverse()
{
using (EmbeddableDocumentStore store = NewDocumentStore())
{
store.DatabaseCommands.PutIndex("StringReverseIndex",
new IndexDefinition
{
Map =
"from doc in docs select new { doc.Name, ReverseName = doc.Name.Reverse())}"
});
using (IDocumentSession documentSession = store.OpenSession())
{
documentSession.Store(new User { Name = "Ayende" });
documentSession.Store(new User { Name = "Itamar" });
documentSession.Store(new User { Name = "Pure Krome" });
documentSession.Store(new User { Name = "John Skeet" });
documentSession.Store(new User { Name = "StackOverflow" });
documentSession.Store(new User { Name = "Wow" });
documentSession.SaveChanges();
}
using (IDocumentSession documentSession = store.OpenSession())
{
var users = documentSession
.Query<ReversedResult>("StringReverseIndex")
.Customize(x => x.WaitForNonStaleResults())
.Where(x=>x.ReverseName.StartsWith("edn"))
.As<User>()
.ToList();
Assert.Empty(store.DocumentDatabase.Statistics.Errors);
Assert.True(users.Count > 0);