I've got an entity with a collection on it, and I'd like to index it, but am having a hard time figuring out how to go about this. The problem is that I'm hoping to search for it the same way I can a dynamic index, using Lucene. It's not a complicated object, though. A simple example;
{
Id: "object/id",
Items: [
{ Id: "1", Name: "One" },
{ Id: "2", Name: "Two" },
{ Id: "3", Name: "Three" }
]
}
And I can query the built in raven dynamic index index easily, with Lucene;
Items,Name: "One"
This seems clean and efficient, and perfect for some things I need to do, but I'm trying to reproduce the behavior in my own Index and failing pretty bad. I tell it to Index the field, but it still refuses to let me call by it;
public class Things_ByItemProperties : AbstractIndexCreationTask<Thing>
{
public Things_ByItemProperties()
{
Map = things => from thing in things
select new
{
Id = thing.Id,
Items = thing.Items
};
Index(n => n.Items, FieldIndexing.Analyzed);
}
}
I know that I can add a specific part of the collection to the index, like this;
public class Things_ByItemProperties : AbstractIndexCreationTask<Thing>
{
public Things_ByItemProperties()
{
Map = things => from thing in things
select new
{
Id = thing.Id,
Items = thing.Items,
Items_Name = this.Select( r => r.Name)
};
Index(n => n.Items, FieldIndexing.Analyzed);
}
}
but that isn't what I'm trying to do, I was trying to set it up to query it with lucene much like a dynamic index. Is there just no way this can be done?
Yes, it can be done. However it is not trivial. I suggest you take a look at the documentation. I am on the phone right now but if you have some problems with it I can give you an example tomorrow. In the meanwhile you can take a look at this SO answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With