The index code follows with comments inline.
public class Designs_Search : AbstractIndexCreationTask<JObject, DesignSearchResult>
{
public Designs_Search()
{
Map = docs => docs
.WhereEntityIs<JObject>("Forms", "Designs")
.Select(item => new
{
Form = item["@metadata"]["Raven-Entity-Name"].Equals("Forms") ? item : null,
Design = item["@metadata"]["Raven-Entity-Name"].Equals("Designs") ? item : null,
})
.Select(item => new
{
Form = item.Form,
Design = item.Design,
FormId = item.Form != null
? item.Form["Id"]
: item.Design["FormId"]
})
.Select(item => new
{
FormId = item.FormId,
FormName = item.Form != null ? item.Form["Name"] : null,
DesignId = item.Design != null ? item.Design["Id"] : null,
DesignName = item.Design != null ? item.Design["Name"] : null,
DesignDescription = item.Design != null ? item.Design["Description"] : null,
DesignPublishedDescription = item.Design != null ? item.Design["PublishedDescription"] : null,
DesignBarcodeSymbologies = item.Design != null
? item.Design["Shapes"]
: null,
/*
* Shapes is a list of items and I need the value of the Symbology
* property from every item in the list that has one.
*
* I've tried item.Design["Shapes"].Children()["Symbology"] - the
* index is created but this throws an error when indexing occurs
* because Raven.Database.Linq.DynamicJsonObject.DynamicList
* doesn't know about the Children() method.
*
* I've tried item.Design["Shapes"].Select(...) - the index isn't
* created due to an exception: "Cannot use a lambda expression as an argument
* to a dynamically dispatched operation without first casting it to a
* delegate or expression tree type"
*/
});
Indexes.Add(x => x.FormId, FieldIndexing.Analyzed);
Indexes.Add(x => x.FormName, FieldIndexing.Analyzed);
Indexes.Add(x => x.DesignId, FieldIndexing.Analyzed);
Indexes.Add(x => x.DesignName, FieldIndexing.Analyzed);
Indexes.Add(x => x.DesignDescription, FieldIndexing.Analyzed);
Indexes.Add(x => x.DesignPublishedDescription, FieldIndexing.Analyzed);
Indexes.Add(x => x.DesignBarcodeSymbologies, FieldIndexing.Analyzed);
}
}