Jestem nowy w RavenDB. Próbuję użyć funkcji indeksu wielu map, choć nie jestem pewien, czy jest to najlepsze podejście do mojego problemu. Mam więc trzy dokumenty: Unit, Car, People.Indeks RavenDB MultiMap
dokument Samochód wygląda następująco:
{
Id: "cars/123",
PersonId: "people/1235",
UnitId: "units/4321",
Make: "Toyota",
Model: "Prius"
}
Ludzie dokument wygląda następująco:
{
Id: "people/1235",
FirstName: "test",
LastName: "test"
}
I jednostka doc:
{
Id: "units/4321",
Address: "blah blah"
}
Jest to skrócona przykład w moim rzeczywistym W aplikacji jest znacznie więcej pól, więc dezaktualizacja danych byłaby moją ostatnią deską ratunku.
Potrzebuję utworzyć i zindeksować, że wszystkie trzy dokumenty dołączą do jednego dokumentu. Coś takiego:
{
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"
}
w relacyjnej bazie danych będzie po prostu użyć dwóch dołącza do ludzi i stoły jednostkowej identyfikatorów i mój stół samochód byłby agregat podmiot.
Oto definicja indeksu że mam:
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);
}
}
Kiedy RavenDb prowadzi ten indeks widzę błędy, gdy próbuje uruchomić funkcję Reduce mam pod warunkiem. Zgłasza błąd, gdy próbuję dopasować rekord, w którym istnieje imię i nazwisko osoby, tak samo dzieje się z jednostką.
Przesyłka krzyżowa z listą adresową: https://groups.google.com/forum/?fromgroups#!topic/ravendb/Uym2tkvMaH8 –
[Ten wpis] (http://ayende.com/blog/156225/relational -searching-sucks-donrsquo-t-try-to-replicate-it) bezpośrednio odpowiada na to pytanie. –