6

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?

Ciel
  • 4,290
  • 8
  • 51
  • 110

1 Answers1

1

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.

Community
  • 1
  • 1
Ricardo Brandão
  • 1,050
  • 7
  • 15
  • I got stuck on a problem and forgot I needed to finish this. If I award you credit now, will you still get the bonus points from the bounty? Or do I need to spend points again to re-open it so they can be awarded? – Ciel Dec 30 '15 at 17:59
  • No problem. I think that I will not win the bounty but that's fine. If this helped you just mark this as the answer. Were you able to do what you intended to do in the first place? – Ricardo Brandão Dec 30 '15 at 19:21
  • Alright... I'm finally getting back around to this. No, I'm not going to be "that person". If I make a bounty again, and then award your answer credit, will it work? – Ciel Mar 07 '16 at 19:54
  • I guess so (please refer to http://stackoverflow.com/help/bounty). I think that you can make a one day bounty and then atribute the bounty to this answer. Thanks – Ricardo Brandão Mar 08 '16 at 22:45