`searchDisjunctiveFaceting` missing in JavaScript client?

I noticed the Swift client for iOS has a method to handle faceted search with disjunctive faceting searchDisjunctiveFaceting

Is this available for the JS client or are we left to implement this ourselves?

Additionally, the Swift tutorial suggests only two requests would be required for the following query:

let query = Query(query: "luxury")
query.facets = ["facilities", "stars"]
let refinements = [
    "facilities": ["wifi"],
    "stars": ["4", "5"]
]
index.searchDisjunctiveFaceting(query, disjunctiveFacets: ["stars"], refinements: refinements) { (content, error) in
    // [...]
}
  1. index.search("luxury", { facets: "facilities", filters: "facilities:wifi AND (stars:4 OR stars:5)" })

  2. index.search("luxury", { facets: "stars", filters: "facilities:wifi" })

However the first request would surely fail to return the alternative ‘facilities’, e.g. ‘swimming pool’ so I believe there should be a third request:

  1. index.search("luxury", { facets: "facilities", filters: "stars:4 OR stars:5" })

In JS, you’d use the helper for requests requiring multiple queries, although we recommend using InstantSearch in all cases (there exists versions with most JS frameworks, and even without rendering baked in at all, if you prefer to go that way :slight_smile:)

Thanks for getting back to me @haroen – unfortunately SEO is very important for our product so we can’t risk relying only on client side rendering which means we need to take ownership of the data fetching to be able to fetch both server and client side.

I can’t tell whether the JS helper would work in Node (at a glance the API looks very oriented towards the client and helping with client side rendering?)

Also, could you confirm whether I’m right re: the Swift tutorial neglecting to mention a third request, as I’m concerned my understanding is incorrect?

The swift question I can’t answer, but @guy.daher will be able to.

The js helper works perfectly in node too. It’s how we make server side rendering work for e.g. react InstantSearch

1 Like

Interesting – I’ll take a look!

As an aside, is there a JS API to parse / stringify the filter str? e.g.

{
    filters: `category:tshirts AND (color:red OR color:pink)`
}

// becomes ->

{
    filters: {
        category: ['tshirts'],
        color: ['red', 'pink']
    }
}

// and vice versa

Not exactly, but you can use facetFilters instead; this is a array-based format, and thus doesn’t need to be parsed by the user etc.

What also is cool (but likely not what you’re looking for: https://github.com/algolia/algolia-filters-js-syntax-validator)

2 Likes

Hello @richard.scarrott,

To respond to your Swift question, you actually only need 2 requests in your case since you didn’t specify facilities as a disjunctive facet (you specified the following: disjunctiveFacets: ["stars"]), so it will not look for the alternative facilities such as swimming pool.

@guy.daher I see, I guess I was thrown by the example response in the swift tutorial which says (implies?) the response does come back with alternative facilities such as swimming pool?

{
  "hits": [ /* ... */ ],
  "facets": {
    "facilities": {
      "wifi": 13,
      "swimming pool": 5
    }
  },
  "disjunctiveFacets": {
    "stars": {
       "1": 6,
       "2": 17,
       "3": 24,
       "4": 8,
       "5": 5
    }
  }
}

@richard.scarrott I see what you mean. The reason for that is the following: a hit could potentially have more than 1 facilities (for example wifi and swimming pool) and in that case, in the results, you will see both mentioned in the facilities even though this facet is being treated as conjunctive.

Got it, thanks for explaining!