@@ -28,7 +28,22 @@ define([
28
28
minQuerySuggestions : 4 ,
29
29
30
30
/**
31
- * Initialize search results using Algolia's InstantSearch.js library v4
31
+ * Load and display search results using Algolia's InstantSearch.js library v4
32
+ *
33
+ * This is the main entry point for building the Magento InstantSearch experience.
34
+ *
35
+ * Rough overview of build process:
36
+ *
37
+ * - Initializes dependencies
38
+ * - Creates the DOM elements where InstantSearch widgets will be inserted on the PLP
39
+ * - Creates the InstantSearch object with configured options
40
+ * - All widgets are preconfigured using the `allWidgetConfiguration` object
41
+ * - This object houses all widgets to be displayed in the frontend experience and is important for customization
42
+ * - Passed to `beforeWidgetInitialization` hook
43
+ * - Implementation is specific to Magento index object data structure
44
+ * - Loads `allWidgetConfiguration` into InstantSearch
45
+ * - Starts InstantSearch which adds the widgets to the DOM and performs first search
46
+ *
32
47
* Docs: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/
33
48
*/
34
49
async buildInstantSearch ( ) {
@@ -151,6 +166,8 @@ define([
151
166
*
152
167
* Any facet builders returned by this function will take precedence over getFacetConfig()
153
168
*
169
+ * Triggers the hook: beforeFacetInitialization
170
+ *
154
171
* @returns {Object<string, function> }
155
172
* @see getFacetConfig
156
173
*/
@@ -386,6 +403,10 @@ define([
386
403
} ,
387
404
388
405
/**
406
+ * Loads refinements management capabilities
407
+ * i.e. As refinements are applied to search results via faceting,
408
+ * this feature allows you to selectively remove one or all refinements.
409
+ *
389
410
* @param allWidgetConfiguration
390
411
* @returns {* }
391
412
*/
@@ -667,6 +688,15 @@ define([
667
688
} ) ;
668
689
} ,
669
690
691
+ /**
692
+ * Load the supplied widget configuration into InstantSearch
693
+ *
694
+ * Triggers the hook: beforeWidgetInitialization
695
+ *
696
+ * @param search
697
+ * @param allWidgetConfiguration
698
+ * @param mockAlgoliaBundle
699
+ */
670
700
initializeWidgets ( search , allWidgetConfiguration , mockAlgoliaBundle ) {
671
701
allWidgetConfiguration = algoliaCommon . triggerHooks (
672
702
'beforeWidgetInitialization' ,
@@ -690,6 +720,11 @@ define([
690
720
} ,
691
721
692
722
/**
723
+ * Get the configuration options for creating the InstantSearch object
724
+ * Docs: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/#options
725
+ *
726
+ * Triggers the hook: beforeInstantsearchInit
727
+ *
693
728
* @param mockAlgoliaBundle to be removed in a future release
694
729
* @returns {* }
695
730
*/
@@ -705,6 +740,9 @@ define([
705
740
) ;
706
741
} ,
707
742
743
+ /**
744
+ * NOTE: The initial (relevant) sort is based on the main index
745
+ */
708
746
prepareSortingIndices ( ) {
709
747
algoliaConfig . sortingIndices . unshift ( {
710
748
name : this . getProductIndexName ( ) ,
@@ -796,7 +834,8 @@ define([
796
834
} ,
797
835
798
836
/**
799
- * Build wrapper DOM object to contain InstantSearch
837
+ * Build wrapper DOM object to contain InstantSearch widgets
838
+ *
800
839
* @param templateProcessor
801
840
*/
802
841
setupWrapper ( templateProcessor ) {
@@ -921,6 +960,18 @@ define([
921
960
return attributes ;
922
961
} ,
923
962
963
+ /**
964
+ * Starts InstantSearch which adds all pre-loaded widgets to the DOM and triggers the first search
965
+ *
966
+ * Docs: https://www.algolia.com/doc/api-reference/widgets/instantsearch/js/#widget-param-start
967
+ *
968
+ * Triggers the hooks:
969
+ * - beforeInstantsearchStart
970
+ * - afterInstantsearchStart
971
+ *
972
+ * @param search
973
+ * @param mockAlgoliaBundle
974
+ */
924
975
startInstantSearch ( search , mockAlgoliaBundle ) {
925
976
if ( this . isStarted ) {
926
977
return ;
@@ -976,6 +1027,9 @@ define([
976
1027
return this . getFacetConfig ( facet ) ;
977
1028
} ,
978
1029
1030
+ /**
1031
+ * Docs: https://www.algolia.com/doc/api-reference/widgets/range-input/js/
1032
+ */
979
1033
getRangeInputFacetConfig ( facet , panelOptions ) {
980
1034
return [
981
1035
'rangeInput' ,
@@ -1055,7 +1109,7 @@ define([
1055
1109
) ,
1056
1110
attribute : facet . attribute ,
1057
1111
pips : false ,
1058
- panelOptions : panelOptions ,
1112
+ panelOptions,
1059
1113
tooltips : {
1060
1114
format ( value ) {
1061
1115
return facet . attribute . match ( / p r i c e / ) === null
0 commit comments