Sono nuovo di RavenDB. Sto cercando di utilizzare una funzione di indice multi mappa, anche se non sono sicuro che sia l'approccio migliore al mio problema. Quindi ho tre documenti: Unità, Macchina, Persone.RavenDB MultiMap Index
documento Car è simile al seguente:
{
Id: "cars/123",
PersonId: "people/1235",
UnitId: "units/4321",
Make: "Toyota",
Model: "Prius"
}
documento
persone si presenta così:
{
Id: "people/1235",
FirstName: "test",
LastName: "test"
}
E unità doc:
{
Id: "units/4321",
Address: "blah blah"
}
Questo è un esempio abbreviato, nel mio vero app ci sono molti più campi, quindi la de-normalizzazione dei dati sarebbe la mia ultima risorsa.
Ho bisogno di creare e indicizzare che avranno tutti questi tre documenti riuniti in un unico documento. Qualcosa di simile a questo:
{
CarId: "cars/123",
PersonId: "people/1235",
UnitId: "units/4321",
Make: "Toyota",
Model: "Prius"
FirstName: "test",
LastName: "test"
Address: "blah blah"
}
// same unit different person owns a different car
{
CarId: "cars/122",
PersonId: "people/1236",
UnitId: "units/4321",
Make: "Toyota",
Model: "4runner"
FirstName: "test",
LastName: "test"
Address: "blah blah"
}
In un database relazionale vorrei solo usare due si unisce alle Persone e alle tabelle di unità da IDS e la mia tabella di macchina sarebbe un'entità aggregata.
Ecco la definizione indice che ho:
public class MyMultiIndex : AbstractMultiMapIndexCreationTask<JoinedDocument>
{
public MyMultiIndex()
{
// creating maps
AddMap<Car>(cars => cars.Select(e => new { e.CarId, e.Make, e.Model, PersonId = e.PersonId, UnitId = e.UnitId, FirstName = (null)string, LastName = (null)string, Address = (nul)string }));
AddMap<People>(people => people.Select(e => new { CarId = (string)null, Make = (string)null, Model = (string)null, PersonId = e.Id, UnitId = (null)string, FirstName = e.FirstName, LastName = e.LastName, Address = (nul)string }));
AddMap<Unit>(people => people.Select(e => new { CarId = (string)null, Make = (string)null, Model = (string)null, PersonId = (null)string, UnitId = e.null, FirstName = (nul)string , LastName = (nul)string , Address = e.Address }));
Reduce = results => from result in results
group result by result.CarId
into g
select new JoinedDocument
{
CarId = g.Key,
PersonId = g.First(e => e.CarId == g.Key).PersonId,
UnitId = g.First(e => e.CarId == g.Key).UnitId,
Model = g.First(e => e.CarId == g.Key).Model,
Make = g.First(e => e.CarId == g.Key).Make,
**// this never works. It is like result set does not contain anything with this personId. It looks like AddMap for people document did not work.**
FirstName = results.First(e => e.PersonId == g.First(ie => ie.CarId == g.Key).PersonId).FirstName,
**// this never works. It is like result set does not contain anything with this personId. It looks like AddMap for people document did not work.**
LastName = results.First(e => e.PersonId == g.First(ie => ie.CarId == g.Key).PersonId).LastName,
**// this never works. It is like result set does not contain anything with this personId. It looks like AddMap for unit document did not work.**
UnitAddress = results.First(e => e.UnitId == g.First(ie => ie.CarId == g.Key).UnitId).LastName,
};
Index(map => map.Model, FieldIndexing.Analyzed);
Index(map => map.Make, FieldIndexing.Analyzed);
Index(map => map.LastName, FieldIndexing.Analyzed);
Index(map => map.FirstName, FieldIndexing.Analyzed);
Index(map => map.Make, FieldIndexing.Analyzed);
Index(map => map.UnitAddress, FieldIndexing.Analyzed);
}
}
Quando RavenDB gestisce questo indice vedo errori quando si sta cercando di eseguire la funzione Ridurre ho fornito. Genera errore quando sto cercando di abbinare un record in cui esistono il nome e il cognome della persona, lo stesso accade con l'unità.
Cross post con mailing-list: https://groups.google.com/forum/?fromgroups#!topic/ravendb/Uym2tkvMaH8 –
[Questo post] (http://ayende.com/blog/156225/relational -searching-sucks-donrsquo-t-try-to-replicate-it) affronta direttamente questa domanda. –