Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support adjusted splitting behavior for arrays of length one #193

Closed
gregkohn opened this issue Jul 23, 2021 · 2 comments
Closed

Support adjusted splitting behavior for arrays of length one #193

gregkohn opened this issue Jul 23, 2021 · 2 comments

Comments

@gregkohn
Copy link
Contributor

Currently when splitting elements, if an element has an array of just one thing for the relevant key, that record isn't split and it gets the entire array.

https://github.com/riasvdv/craft-scout/blob/bf30a01602a4e5db45c09ce43233be7b512abba6/src/engines/Engine.php#L36-L40

This is in contrast to an element that does need to be split, where each record gets one of the array children without the wrapping array.

I'm not sure if this is a bug per se but it's giving me some grief because I can't count on the structure of the value for my split key. Any chance I'm missing something obvious? I'd be more than happy to open a PR for a setting that adjusts this behavior so there's no breaking change, but I figured I'd start a conversation first.

In my case, I'm splitting Craft Commerce products on their variants. So there is a record per variant, and variants of a product all share a distinctID. But products with one variant end up with it being wrapped in an array, while products with multiple variants don't, making it exceedingly difficult to manipulate and filter the data for our purposes.

Minimal example:

{
  "distinctID": 266507,
  "objectID": "266507",
  "variant": [{
    "id": 266508,
    "sku": "TA-2238CS",
  }]
}
{
  "objectID": "475523_5",
  "distinctID": 475523,
  "variant": {
    "id": 475529,
    "sku": "m0359-ss",
  },
}

Thanks for a great plugin!

@joshuapease
Copy link
Contributor

Thought I'd follow up on this issue and see if Greg's solution was still something you'd consider.

We've been using a forked version of Scout... and that's been serving us well, but it would be really great to get back on the canonical plugin at some point.

Cheers!

@janhenckens
Copy link
Member

Hey @joshuapease @gregkohn, thanks for putting in the work and sorry about the delay, still coming to grips with every nook and cranny of this plugin :).

This is out in 2.7.0 so you should be good to switch back to the released version of the plugin now!
(merging this into the Craft 4 beta later too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants