With more than I little help from Oren/Itamar, there's now a new feature available in RavenDB.
The issue is that Lucene indexes are essentially "flat", but Raven can obviously store hierachial data, i.e. a POCO with an embedded list of other POCO's (for instance).
So If you have the following POCO:
public class TShirt
{
public String Id { get; set; }
public String Name { get; set; }
public int BarcodeNumber { get; set; }
public List<TShirtType> Types { get; set; }
}
public class TShirtType
{
public String Colour { get; set; }
public String Size { get; set; }
}
Up to now you've not been able to say, "Give me all the TShirts that have (Colour = Blue, Size = Small) AND (Colour = Gray, Size = Large)".
Note: you could do that search if you put an "OR" in there, but not "AND".
But now you can do this type of query (and others) using the Intersect() LINQ extension method, like so (note: it supports ordering & paging):
var shirts = session.Query<TShirt>("TShirtNested")
.OrderBy(x=>x.BarcodeNumber)
.Where(x => x.Name == "Wolf")
.Intersect()
.Where(x => x.Types.Any(t => t.Colour == "Blue" && t.Size == "Small"))
.Intersect()
.Where(x => x.Types.Any(t => t.Colour == "Gray" && t.Size == "Large"))
.ToList();
Querying against an index that looks like this:
store.DatabaseCommands.PutIndex("TShirtNested",
new IndexDefinition
{
Map =
@"from s in docs.TShirts
from t in s.Types
select new { s.Name, Types_Colour = t.Colour, Types_Size = t.Size, s.BarcodeNumber }",
SortOptions = new Dictionary<String, SortOptions> {{"BarcodeNumber", SortOptions.Int}}
});
I'll post some better documentation early next week and I'll try and put together a couple more code samples that show the functionality, but in the meantime you can take a look at
the existing unit tests
Any questions, comments?