Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

fix(facetOrdering): make sure ordered facets is a dense array #879

Merged
merged 2 commits into from Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/SearchResults/index.js
Expand Up @@ -728,6 +728,10 @@ function sortViaFacetOrdering(facetValues, facetOrdering) {
}
});

orderedFacets = orderedFacets.filter(function(facet) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data manipulation seems complicated. We can rather not push the facet in the array when we detect that it's undefined? (~line 725)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the thing is that it's not pushed, but set in a specific position. Imagine if you after release need to set something on position 0 and position 5, you'll get [a, , , , , b]. You can't push, as the order of the items that get inserted is the one of the order, not the order of the facet values itself.

Alternative I can think of is searching the facet value for each value in order, but that's On^m instead of Om*n

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, let's keep it that way.

return facet;
});

var sortRemainingBy = facetOrdering.sortRemainingBy;
var ordering;
if (sortRemainingBy === 'hidden') {
Expand Down
19 changes: 19 additions & 0 deletions test/spec/SearchResults/getFacetValues-facetOrdering.js
Expand Up @@ -779,3 +779,22 @@ describe('hierarchical facet', function() {
expect(facetValues).toEqual(expected);
});
});

test('does not return empty items', function() {
var rawResults = require('./getFacetValues/sparse.json');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are the undefined values in the dataset?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The undefined happens because there are pinned values that aren't in the result set. A simpler example:

const ordering = ['a', 'b', 'c', 'd']
const values = { a: 5, c: 4, d: 10}

const oldOutput = [{a: 5}, undefined, {c: 4}, {d: 10}]
const newOutput = [{a: 5}, {c: 4}, {d: 10}]

The reason empty elements get added is because we don't know what order the items will come in, so you can't just push, you need to set the items in a specific order. Densifying the array at the end seems to me to be the simple solution to avoid empty arrays.

relevant code:

orderedFacets[reverseOrder[name]] = item;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah OK I misunderstood the test because of the missing test name and the PR post.

var results = new SearchResults(new SearchParameters({
disjunctiveFacets: ['brands']
}), rawResults.results);

expect(results.getFacetValues('brands', {facetOrdering: true})).toEqual([
{name: 'Addo', count: 321, isRefined: false},
{name: 'Paw Patrol', count: 130, isRefined: false},
{name: 'Mattel', count: 586, isRefined: false},
{name: 'Nick Jr.', count: 147, isRefined: false},
{name: 'Early Learning Centre', count: 292, isRefined: false},
{name: 'Hot Wheels', count: 94, isRefined: false},
{name: 'Fisher-Price', count: 104, isRefined: false},
{name: 'Funko', count: 187, isRefined: false},
{name: 'Nickelodeon', count: 230, isRefined: false}
]);
});
348 changes: 348 additions & 0 deletions test/spec/SearchResults/getFacetValues/sparse.json
@@ -0,0 +1,348 @@
{
"results": [
{
"hits": [],
"nbHits": 5859,
"page": 0,
"nbPages": 50,
"hitsPerPage": 20,
"facets": {
"brands": {
"Search by brand": 4809,
"Mattel": 586,
"Addo": 321,
"Early Learning Centre": 292,
"LEGO": 277,
"Disney": 247,
"Nickelodeon": 230,
"Funko": 187,
"Marvel": 174,
"Nick Jr.": 147,
"Playmobil": 144,
"Paw Patrol": 130,
"Barbie": 129,
"VTech": 127,
"Ravensburger": 124,
"Star Wars": 111,
"Fisher-Price": 104,
"Thomas & Friends": 99,
"Hot Wheels": 94,
"Disney Princess": 93
}
},
"exhaustiveFacetsCount": true,
"exhaustiveNbHits": true,
"exhaustiveTypo": true,
"query": "",
"params": "query=%20&highlightPreTag=__ais-highlight__&highlightPostTag=__%2Fais-highlight__&page=0&clickAnalytics=true&userToken=test&maxValuesPerFacet=20&facets=%5B%22ageRange%22%2C%22brands%22%5D&tagFilters=",
"index": "test",
"renderingContent": {
"facetOrdering": {
"values": {
"brands": {
"order": [
"Superman",
"Nintendo",
"Zoomer",
"Swingball",
"Friends",
"Blippi",
"Addo",
"L.O.L. Surprise O.M.G. Series Dolls",
"Pop! Exclusive",
"Hornby",
"Jacks",
"Out There",
"Mattel Games",
"L.O.L. Surprise Boy Series Dolls",
"Boom City Racers",
"Rainbow High",
"Evi Love",
"Baby Alive Dolls",
"Paw Patrol",
"Nerf Fortnite",
"Star Wars: Episode IX",
"Mattel",
"LEGO Vidiyo",
"Oh My Gif",
"Nerf Alpha Strike",
"B Friends Playsets and Accessories",
"DC Super Hero Girls",
"Star Wars Forces of Destiny",
"Disney Pixar Toy Story 4",
"Smashers",
"Hatchimals Colleggtibles",
"LEGO Minecraft",
"Pop! DC Comics",
"Monsterverse",
"Nick Jr.",
"Nickelodeon Experimake ",
"Marvel Super Hero Mashers",
"Tobi Friends",
"Beanie Boo Buddies",
"Captain Marvel",
"The Original Fidget Cube",
"Playmobil Wildlife",
"Fortnite",
"Bunchems",
"Crate Creatures",
"Ready Steady Dough Nick Jr",
"Black Widow",
"Cool Create",
"Star Wars The Black Series",
"Little Senses",
"Pop! WWE",
"Early Learning Centre",
"LEGO Marvel Comics Super Heroes",
"Hot Wheels",
"Geomag",
"Pikmi Pops Surprise",
"Itty Bitty Pretty",
"Sandsational",
"LEGO Jurassic World",
"Whizz World",
"Fisher-Price",
"Pitter Patter Pets",
"Blaze and the Monster Machines",
"Rainbocorns",
"My Little Pony: The Movie",
"Woodlets",
"Twisty Petz",
"Owleez",
"Hairdorables",
"Weebles",
"Num Noms",
"Fingerlings",
"Elf",
"Bing",
"Star Wars - The Mandalorian",
"Laugh & Learn",
"Playskool Marvel Super Hero Adventures",
"Pop! Disney",
"Busy Me",
"Pop! Retro Toys",
"Collins Key",
"Scooby Doo",
"JoJo Bows",
"Justice League",
"Scruff A Luvs",
"Vex Robotics",
"Fart Ninja ",
"Wubble",
"Pop! Women of Power",
"Star Wars - The Last Jedi",
"B Friends",
"Unique Boutique",
"The LEGO Movie 2",
"Pop! Marvel",
"PJ Masks",
"Pop! Movies",
"Disney Cars 3",
"VTech Toot Toot Friends",
"L.O.L Surprise Dolls",
"Ricky Zoom",
"Disney Princess Belle",
"Disney Princess Rapunzel",
"Dolls World",
"Lollipets",
"Playmobil Country",
"B Friends Clothes",
"LEGO Avengers Endgame",
"Real Littles ",
"Tom & Jerry ",
"Playmobil Fairies",
"Transformers Construct Bots",
"Bakugan",
"K'nex",
"Super Mario",
"Mr Potato Head",
"Love Diana ",
"Jurassic World",
"Playgro",
"Baby Clementoni",
"Playmobil Spirit",
"Muddy Puddle Walk",
"VTech Kiddi",
"Playmobil Summer Fun",
"Disney Incredibles 2",
"LEGO Disney Princess",
"Pop! My Little Pony",
"Bush Baby World",
"Dreamworks Dragons",
"Shopkins",
"Big City",
"My Little Pony",
"Capsule Chix",
"Mini Artist",
"Happyland",
"Paw Patrol Jungle Rescue",
"Top Wing",
"Dreamworks Trolls Toys",
"Sylvanian Families Town",
"Hatchimals",
"Paw Patrol Sea Patrol",
"Kindi Kids Minis",
"Playskool",
"Paw Patrol Dino Rescue",
"Playmobil City",
"Little Lot",
"LEGO Star Wars Episodes I -VI",
"Paw Patrol Ultimate Rescue",
"Ka Wazie",
"Rosebud Village",
"Pop! Keychain",
"L.O.L. Surprise Remix Series Dolls",
"Thomas & Friends Trackmaster",
"B Friends Furniture",
"Orchard Toys",
"Steffi",
"Funko",
"Disney Frozen Fever",
"Pop! Games",
"Secret Crush",
"Out and About",
"Moon and Me",
"Marvel Super Hero Mashers Micro",
"Kinetic Sand",
"Micro Machines",
"Build-A-Bear Workshop",
"Pomsies",
"Baby Shark",
"Playmobil Princess",
"Sparkle Girlz",
"All Elite Wrestling",
"BABY Born Interactive",
"Nickelodeon",
"LEGO City Airport",
"Cutetitos",
"Hatchimals Surprise",
"Vet Squad",
"Starlink",
"Scalextric",
"CupCake",
"Vtech Pre-school",
"Ryan's World ",
"BTS - Bangtan Boys",
"VTech Toot Toot Animals",
"L.O.L. Surprise J.K. Series Dolls",
"LEGO City Coast Guard",
"Cra-Z-Art",
"L.O.L. Surprise Present Surprise Series Dolls",
"Play & Win",
"Blume Dolls",
"Rizmo",
"Boxer Robot",
"Dolu",
"Stretch Armstrong",
"Stickle Bricks",
"Stormblasters",
"Disney Princess Cinderella",
"Steffi Love",
"Feber",
"Pop! Rocks",
"Minions Movie",
"Luvabella",
"LEGO City Space",
"Fast and Furious",
"Top Trumps",
"LEGO Trolls",
"DC Super Friends",
"Nerf Laser Ops",
"Nickelodeon Liquid Lava Sand",
"LEGO City Police",
"LEGO BrickHeadz",
"Minecraft",
"Out of the Box",
"5 Surprise",
"Avengers: Endgame",
"Disney Princess Ariel",
"Block Tech",
"Out To Impress",
"Moonlite",
"Transformers: Bumblebee",
"Play-Doh Kitchen Creations",
"Superthings",
"Nickelodeon Liquid Lava Putty",
"Star Wars Rogue One",
"FailFix",
"Peppa Pig Holiday",
"LEGO City Great Vehicles",
"LEGO Dots",
"Marvel Black Panther",
"Goo Jit Zu",
"Playmobil Special Plus",
"Matchbox",
"Engino",
"Pop! Television",
"Polly Pocket",
"Despicable Me",
"Bunch O Balloons",
"Match Attax",
"Science Museum Toys",
"Monster Jam",
"Fingerlings Untamed",
"Disney Frozen 2",
"Roblox",
"LEGO City Fire",
"VTech Toot Toot",
"Hero Mashers",
"Sonic The Hedgehog",
"LEGO DC Comics Super Heroes",
"Ty Beanie Babies",
"Playmobil 123",
"Be My Baby",
"Transformers Studio Series",
"Kindi Kids",
"Star Wars The Rise of Skywalker",
"LEGO Super Mario",
"LEGO City Town",
"Squishmallows",
"B Friends Dolls",
"Titan Hero",
"Batman-Missions",
"Pop! Animation",
"Little Live Pets",
"Back To The Future",
"Mi-Mic",
"Addo Games",
"Robot Wars",
"Playskool Heroes Rescue Bots",
"LEGO Speed Champions",
"Paw Patrol Mighty Pups",
"Fuggler",
"DC Comics",
"Schleich",
"Care Bears",
"Paw Patrol Mission",
"Masha and The Bear",
"Pop! Star Wars",
"Pop! AD Icons",
"Snapstar",
"Teletubbies",
"Spirit",
"Imaginext",
"Robo Alive",
"Enchantimals",
"Blossom Farm",
"Transformers Cyberverse",
"Playmobil Family Fun",
"Disney Frozen",
"Candylocks",
"Fisher Price Little People",
"Snuggle Buddies",
"Transformers Generations",
"X Shot",
"Star Wars The Force Awakens",
"Awesome Animals",
"Cool Create IDO3D",
"Cave Club"
],
"sortRemainingBy": "hidden"
}
}
}
},
"processingTimeMS": 1
}
]
}