Developer forum

Forum » Development » Building a search handler

Building a search handler

Rasmus Andersen
Reply

Hi DW folks, 

I am trying to build a service for acccessing products and facets from an ashx handler, this should allow me to provide some custom JSON to my frontend developer.
So far I am able to do searches using: 

var queryService = new QueryService();
var search = queryService.Search(
    query,
    facets,
    new Dictionary<string, object>
    {
        { "param1", "value1" },
        { "param2", "value2" },
    }, 
    0, 
    24);

This returns the products with the parameters matching, however I would like to access my facets including the options, which is not returned by above code.
When i debug the following code, I see the facets but not the options (the facets and options can be retrieved from the product catalouge module).

var facets = queryService.LoadFacets("somepath/Products.facets");

How can I access the options from my handler?

Thank you ;)

 


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Rasmus,

There are a couple of things you need to consider with this approach: Is it necessary to have this happen in a handler, and is the headache of handling facets manually -- finding labels for custom field values and manufacturers, dealing with list facets, etc. -- worth it?

Don't get me wrong, it can be done. I would argue, though, that it's a lot of work for a relatively small payoff. Handling facets is not trivial and it will be time-consuming to cover all scenarios. My recommendation, if you couldn't tell, is to not do it. Use a Product Catalog module on a page with a simple JSON template. Then call this page asynchronously from the actual frontend. It will function exactly the same from the perspective of your frontenders and it will save you heaps of time.

If you decide to press on with your initial idea, then you need to use FacetGroup.Items as the collection to iterate through and you need get results using IQueryResult.FacetGroupResult.GetFacetResults(item.QueryParameter). This might throw an exception, so use IQueryResult.FacetGroupResult.ContainsFacetResults(item.QueryParameter) to check whether results exist. You also need to decide how to handle different types of facets, facet data and selected values including values from arrays and all that good stuff ;)

I hope this provides some guidance and perspective on how to proceed. If not, then please let me know and I'll provide any additional information if I can.

- Jeppe

 

You must be logged in to post in the forum