azure-contrib / node-azure-search

A JavaScript client library for the Azure Search service, which works from either from Node.js or the browser
42 stars 28 forks source link

Facets #10

Closed ramon-tomas-c closed 8 years ago

ramon-tomas-c commented 8 years ago

Hello,

When adding the json object with parameters in the search call, you cannot add multiple facets in json.

Regards.

richorama commented 8 years ago

Hi, thanks for reporting this.

Would you be able provide a sample JSON object demonstrating the problem?

ramon-tomas-c commented 8 years ago

Yes, sure.

I have no problem when I try to add other parameters such as filter, orderby, select, .. as they all are comma separated. But when it comes to facets, they have to be inserted as { facet=facetA, facet=facetB , .. }

client.search(indexName, queryBuilder, function (err, results, raw)

function queryBuilder(content, predicate, suggesterName) { var result = {}; result.search = content ? content : '*';

    for (var propertyName in predicate) {
        var obj = predicate[propertyName];
        if (ko.isObservable(obj) && (!obj() || obj().length === 0)) {
            continue;
        }

        switch (propertyName) {
            case constants.predicateTypes.filter:
                result.$filter = predicate.filter().toODataFragment();
                break;
            case constants.predicateTypes.orderBy:
                result.$orderby = predicate.orderBy().join(",");
                break;                
            case constants.predicateTypes.select:
                result.$select = predicate.select().join(",");
                break;
            case constants.predicateTypes.highlight:
                result.highlightPreTag = "<b>";
                result.highlightPostTag = "</b>";
                result.highlight = predicate.highlight().join(",");
                break;
            **case constants.predicateTypes.facets:
                result.facet = facetA;
                result.facet = facetB;
               break;**
            case constants.predicateTypes.isInlineCount:
                result.$count = predicate.isInlineCount();
                break;
            case constants.predicateTypes.skip:
                result.$skip = predicate.skip();
                break;
            case constants.predicateTypes.take:
                result.$top = predicate.take();
                break;
        }
    }
    return result;
}
richorama commented 8 years ago

I see what you mean. This is an interesting problem. Could this be solved with an approach like this:

var result = { facet:"A", facet:"B"}
glombek commented 8 years ago

Javascript appears to only use the last provided definition for a property.

So, var result = { facet:"A", facet:"B"} will result in the object { facet: "B" }.

richorama commented 8 years ago

@glombek yes, this is a limitation of JSON. I'll need to do some plumbing to work around it...