2
votes

After a few hours of figuring out Lucene, I gave up. Hope you can help.

Setting

In our current Sitecore tree, we have template 2 template inheritance levels. (Let's say Vehicle -> Car -> Formula One / Vehicle -> Boat).

What I would need to fetch through Lucene now, is every ContentItem inheritting either directly, or indirectly, from a certain Template.

For instance:

  • Get vehicles -> returns: "Generic" Vehicles, Cars, F1 Cars and boats
  • Get cars -> returns: Cars, F1 Cars

What I thought was using the _templates-field in Lucene, ie:
Get Vehicles -> _templates contains Vehicle-template-guid. Get Cars -> _templates contains Car-template-guid.

The problem

The main problem I experience is that Content Items of the F1 Car-template contain only the Cars and F1 Car in the _templates-field, and not the generic "Vehicle".

I probably misinterpret the _templates-field, but am wondering if there's any other options.


Sitecore configuration:

Content items:

  • sitecore
    • content
      • Home
        • ACategory
          • A Child 1
          • A Child 1.1
          • A Child 2

Templates (levels = inheritance):

  • Main entity
    • Child entity 1
      • Child entity 1.1
    • Child entity 2
  • Category
1
What Lucene approach are you taking? The "old" Lucene approach or the "new" one? Are you using the Advanced Database Crawler? - Mark Ursino
We're working on a custom index, maintained by a custom crawler inheriting Sitecore.Search.Crawlers.DatabaseCrawler. This crawler adds a few of our custom fields to the item as well. - Currently, the solution I'm trying is writing item.Template.ID.Guid and (recursively) each baseTemplate.Guid to a new field. I think this would work (it's pretty similar as the _path-field, only for template inheritance instead), I'll let you know. - sanderd

1 Answers

2
votes

Create an new indexer which inherits Sitecore.Data.Indexing.Index, and override the AddFields method as below:

protected override void AddFields(Item item, Document document)
{   
    // Add base fields
    base.AddFields(item, document);

    // Add all inherited templates id to a field 
    string TEMPLATE-PATH="get template path for this item here";
    document.Add(new Field("template-path", TEMPLATE-PATH, Field.Store.NO, Field.Index.TOKENIZED)); 
}

Then you can search it by "template-path" field.