From 27d41bf9ad852e609961fd304b440a74b8f5c37b Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Tue, 12 Oct 2021 15:36:36 +0200 Subject: [PATCH] fix(facetOrdering): make sure ordered facets is a dense array Otherwise the "undefined" values (are ordered, but not in the results) take up place and it messes up the limits. --- src/SearchResults/index.js | 4 + .../getFacetValues-facetOrdering.js | 19 + .../SearchResults/getFacetValues/sparse.json | 348 ++++++++++++++++++ 3 files changed, 371 insertions(+) create mode 100644 test/spec/SearchResults/getFacetValues/sparse.json diff --git a/src/SearchResults/index.js b/src/SearchResults/index.js index b41ddf334..9f9a424cb 100644 --- a/src/SearchResults/index.js +++ b/src/SearchResults/index.js @@ -728,6 +728,10 @@ function sortViaFacetOrdering(facetValues, facetOrdering) { } }); + orderedFacets = orderedFacets.filter(function(facet) { + return facet; + }); + var sortRemainingBy = facetOrdering.sortRemainingBy; var ordering; if (sortRemainingBy === 'hidden') { diff --git a/test/spec/SearchResults/getFacetValues-facetOrdering.js b/test/spec/SearchResults/getFacetValues-facetOrdering.js index d32c3807d..de52cdd5b 100644 --- a/test/spec/SearchResults/getFacetValues-facetOrdering.js +++ b/test/spec/SearchResults/getFacetValues-facetOrdering.js @@ -779,3 +779,22 @@ describe('hierarchical facet', function() { expect(facetValues).toEqual(expected); }); }); + +test('customer issue', function() { + var rawResults = require('./getFacetValues/sparse.json'); + 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} + ]); +}); diff --git a/test/spec/SearchResults/getFacetValues/sparse.json b/test/spec/SearchResults/getFacetValues/sparse.json new file mode 100644 index 000000000..9aef9b171 --- /dev/null +++ b/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 + } + ] +}