Using Raven 3.0 embedded, I'm attempting to convert my index to a scripted index[2] that writes it's reduce results to documents in their own right. If fact, I am replacing this c# code:
_store.Changes().ForIndex(new RollformingStatisticsIndex().IndexName)
.Where(rs => rs.Type == IndexChangeTypes.ReduceCompleted).Subscribe(_ =>
{
using (var session = _store.OpenSession())
{
var rollformingStatistics = session.Query<RollformingStatistics, RollformingStatisticsIndex>().ToList();
foreach (var rs in rollformingStatistics)
{
session.Store(rs);
}
session.SaveChanges();
}
});
Q1: How can I tell that the ScriptedIndexResults bundle has been configured properly? I expected to see some UI for IndexScript on the index in the management console, but I don't. I don't see anything related in Settings->Database Settings->Data either.
My index and delete script look like this (c#):
IndexScript = @"var stat = LoadDocument(key); if (stat == null) return; PutDocument(key, this);";
DeleteScript = @"var stat = LoadDocument(key); if(stat == null) return; delete key;";
Q2: Does this script seem correct? I'm not getting any errors (neither exceptions nor logged errors in the admin console). But not seeing results either.
Q3: Where can I find breakdown of the functions, keywords, etc, available to the javascript in a scripted index? Stuff like what `this`, `key`, `delete`, and other non-standard js stuff is. I've been going off the examples in the scripted index docs[1].
Q4: Is there a better way? The whole reason I am storing my reduction result as documents is so I can both use them, and create another index that reduces them further. I tried simply passing the reduced type as the TDocument type param of the AbstractScriptedIndexCreationTask but it didn't work. I considered coding that second index such that it does the same reduction plus further reduction. I'd be duplicating logic and the index crunching work though.
Thanks,
Josh
[2] Here's my abridged index definition:
namespace AMS.Eclipse.Business.Data.Indexes
{
public class RollformingStatisticsIndex : AbstractScriptedIndexCreationTask<ProductionEvent, RollformingStatistics>
{
public RollformingStatisticsIndex()
{
Map = prodEvents => from prodEvent in prodEvents
select new RollformingStatistics
{ ...
};
Reduce = results => from result in results
group result by new {result.MachineNumber, result.StartShiftCode}
into g
select new RollformingStatistics
{ ...
};
IndexScript = @"var stat = LoadDocument(key); if (stat == null) return; PutDocument(key, this);";
DeleteScript = @"var stat = LoadDocument(key); if(stat == null) return; delete key;";
}
}
}