Developer forum

Forum » CMS - Standard features » Distinguish Index on IndexBuilderExtender

Distinguish Index on IndexBuilderExtender

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

We have an old site that we're slowly refactoring. We reached the Repository that has some logic that no longer applies. We're using the product schema extender and have far too many query expressions and wacky grouping and logic, that make refactoring tricky.

 

We're starting from scratch with a new index, new fields, new query, new facets. Eventually at some point we'll simply update the paragraph app settings to point to the new query and new facet group and voilá.

 

My struggle now is on the IndexBuilderExtender. Because it inherits from the type of builder (ProductIndexBuilder), it will trigger for both of my indexes. Is there a way that I can identify the actual Index, so that I wrap the logic around some if statement, until such a time comes that I can delete the old code?

 

I am looking for something like this

public override void ExtendDocument(IndexDocument doc)
{
    var index = HowToFindTheCurrentIndex?();

    if(index == "my_old_index.index")
    {
        // Run old legacy code
    }
    else
    {
        // Run new code
    }
}

Can this be achieve somehow?

 

Best Regards,

Nuno Aguiar


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Look at the IndexBuilder property on the base class in a debugger:

this.IndexBuilder.*

It should have information enought for you to find it.

BR Nicolai

Votes for this answer: 1
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Perfect, that does it for me, thanks

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

I spoke too soon as I could only get back to this just now. It does look promissing, but this is null (check attachment).

 

Anything else I could use? Or if this could even be changed somehow so that I could use it?

 

I tested in 9.8.7 and 9.9.7 with the same result (can't upgrade to 9.10 just yet FYI).

 

Best Regards,

Nuno Aguiar

IndexBuilder.gif
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

bump

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

Can this be fixed for the next release? We're starting to work with a gorwing number of indexes and being able to use this would be very useful.

 

To recap, as mentioned in a previous post, the this.IndexBuilder is null when extending a document and we'd like to be able to get to it, so we could do an if or switch statement for when we have multiple instances of the same builder.

 

Best Regards,

Nuno Aguiar

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

Could someone fix this please? I just tested in 9.10.9 and it's still returning null.

 

Best Regards,

Nuno Aguiar

 

You must be logged in to post in the forum