Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RavenDB - setting up an index for proper collection LuceneQuery

Tags:

ravendb

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?

like image 698
Ciel Avatar asked Dec 01 '15 00:12

Ciel


1 Answers

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.

like image 139
Ricardo Brandão Avatar answered Nov 15 '22 09:11

Ricardo Brandão