Creating a Lucene index on values in a collection

Skip to first unread message


Sep 22, 2011, 9:48:15 AM9/22/11
to ravendb
I'm fairly new to RavenDB and Lucene, so hoping that someone can help
me out with how to create this index.

Our core Product object has a collection of Attributes, which are
essentially a dynamic set of key/value pairs with information on the
product -- and the set of keys in the list varies from one product to
the next. I need to figure out how to create an Lucene index on the
values in that collection.

A simple version of the document (and in actuality, you may be looking
at more like 50 AttributeValue objects and a series of other
collections besides):

"ProductId": 4,
"SiteId": 8,
"AttributeValues": {
ABC.Core]], mscorlib",
"$values": [
"AttributeId": 1,
"AttributeName": "Description",
"Value": "My Product Description",
"Id": null
"AttributeId": 2,
"AttributeName": "Is On Sale",
"Value": "No",
"Id": null
"AttributeId": 4,
"AttributeName": "Color",
"Value": "Green",
"Id": null

Easy enough to create an index on, say, the product id, but can't
quite figure out the collection.

I did find this:

which opened up the idea of making AttributeValue a separate document
with a product id property and getting the complete object in two
separate pulls, but while that would certainly make the indexing far
more trivial, I'm not comfortable creating a document from something
that is most definitely not an aggregate root.



Ayende Rahien

Sep 22, 2011, 9:54:53 AM9/22/11


Sep 23, 2011, 11:02:16 AM9/23/11
to ravendb
Just what I needed. Thanks.

On Sep 22, 8:54 am, Ayende Rahien <> wrote:
> See the discussion here:
> >


Sep 23, 2011, 12:48:00 PM9/23/11
to ravendb
So a followup...

I have created a working AbstractIndexCreationTask as follows:

public class SiteProduct_ByAttributeValues :
public SiteProduct_ByAttributeValues()
Map = products => from product in products
select new
_ =

attributeValue =>
Field(attributeValue.AttributeName, attributeValue.Value,
Field.Store.NO, Field.Index.ANALYZED))

That works very well, builds the index. But next I'm trying to wire
up a custom analyzer...or even a different Lucene analyzer. Say,
StandardAnalyzer. Analyzers.Add is there, but since the index is off
of a projection instead of the Product object itself, I'm not sure
what my lambda expression for the field name should look like.

So I'm at:

Analyzers.Add(x => ???, "CustomAnalyzer");

Ayende Rahien

Sep 23, 2011, 1:02:18 PM9/23/11
No near the code now, but we have a way to specify analyzers per field per document, so you can extend the way ravendb works at that level, look at the classes in the Plugins namespace it is one of those
Reply all
Reply to author
0 new messages