Developer forum

Forum » Development » Index Term added with ProductIndexBuilderExtender gives 0 results in facet

Index Term added with ProductIndexBuilderExtender gives 0 results in facet

Marie Louise Veigert
Reply

Hi,

I have made a ProductIndexBuilderExtender to create a facet for 'In stock' true/false.
I renders fine as a facet, but when used (or added manually in the url) it always give 0 result.

Code:

public class ProductIndexBuilderExtender : IndexBuilderExtenderBase<ProductIndexBuilder>
{
    public override void ExtendDocument(IndexDocument indexDocument)
    {
        try
        {
           
            var productStockObj = indexDocument["ProductStock"];
         
            bool instock = false;

            if (productStockObj != null)
            {
                if (Double.TryParse(productStockObj.ToString(), out double productStock))
                {
                    instock = productStock > 0;
                }
                indexDocument.AddTermValue("ProductInStock", instock);
            }
        }
        catch (Exception e)
        {
            // log error
        }
    }
}

public static class IndexBuilderExtenderExtensions
{
    public static void AddTermValue(this IndexDocument document, string fieldName, object fieldValue)
    {
        if (!document.ContainsKey(fieldName))
        {
            document.Add(fieldName, fieldValue);
        }
        else
        {
            document[fieldName] = fieldValue;
        }
    }
}

The index:

The query: (it set to AND and the InStock is a boolean)

The facet:

what the facet renders:

The end of the url when filtered:

?InStock=%5BTrue%5D


Any ideas whats wrong?

 

BR Marie Louise


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Marie Louise,

 

What you are showing seems accurate to me, and we've done something similar in the past.

 

Seems like the querystring is adding the value between square brackets [ ] - that's what %5B and %5D stands for.

 

Did you customize the Facets? What version is this for?


BR,

Nuno Aguiar

 
Marie Louise Veigert
Reply

Hi,

Its DynamicWeb 9.17.6 with a Rapido (but more and more full custom FE).

I have tested towards the feed mainly.

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Marie,

 

But did you get it working? I would assume so. Without a URL it's hard for me to help you further.

 
Marie Louise Veigert
Reply

Hi Nuno,

No we didn't.
Can I sent a link to an email ? Its a client site :)

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Marie,

 

Sure, I can try to help. Send it to nag@dynamicwebusa.com 

 

Best Regards,

Nuno Aguiar

 

You must be logged in to post in the forum