@usereactify/search 5.59.0 → 5.59.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/package.json +7 -5
- package/dist/src/components/ClearAll/ClearAll.d.ts +1 -1
- package/dist/src/components/ClearAll/ClearAll.js +4 -9
- package/dist/src/components/ClearAll/ClearAll.js.map +1 -1
- package/dist/src/components/CustomComponent/CustomComponent.d.ts +1 -1
- package/dist/src/components/CustomComponent/CustomComponent.js +2 -2
- package/dist/src/components/CustomComponent/CustomComponent.js.map +1 -1
- package/dist/src/components/Example/ExampleClearAll.d.ts +2 -2
- package/dist/src/components/Example/ExampleClearAll.js +2 -5
- package/dist/src/components/Example/ExampleClearAll.js.map +1 -1
- package/dist/src/components/Example/ExampleCustomComponent.d.ts +1 -1
- package/dist/src/components/Example/ExampleCustomComponent.js +3 -7
- package/dist/src/components/Example/ExampleCustomComponent.js.map +1 -1
- package/dist/src/components/Example/ExampleFilterList.d.ts +2 -2
- package/dist/src/components/Example/ExampleFilterList.js +31 -66
- package/dist/src/components/Example/ExampleFilterList.js.map +1 -1
- package/dist/src/components/Example/ExampleFilterRange.d.ts +2 -2
- package/dist/src/components/Example/ExampleFilterRange.js +2 -12
- package/dist/src/components/Example/ExampleFilterRange.js.map +1 -1
- package/dist/src/components/Example/ExampleFilterSlider.d.ts +2 -2
- package/dist/src/components/Example/ExampleFilterSlider.js +11 -18
- package/dist/src/components/Example/ExampleFilterSlider.js.map +1 -1
- package/dist/src/components/Example/ExampleFilters.d.ts +1 -1
- package/dist/src/components/Example/ExampleFilters.js +3 -8
- package/dist/src/components/Example/ExampleFilters.js.map +1 -1
- package/dist/src/components/Example/ExampleFiltersSelected.d.ts +2 -2
- package/dist/src/components/Example/ExampleFiltersSelected.js +3 -24
- package/dist/src/components/Example/ExampleFiltersSelected.js.map +1 -1
- package/dist/src/components/Example/ExampleHookUseFilters.d.ts +1 -1
- package/dist/src/components/Example/ExampleHookUseFilters.js +3 -10
- package/dist/src/components/Example/ExampleHookUseFilters.js.map +1 -1
- package/dist/src/components/Example/ExampleHookUseResults.d.ts +1 -1
- package/dist/src/components/Example/ExampleHookUseResults.js +3 -8
- package/dist/src/components/Example/ExampleHookUseResults.js.map +1 -1
- package/dist/src/components/Example/ExampleHookUseSearch.js +2 -2
- package/dist/src/components/Example/ExampleHookUseSearch.js.map +1 -1
- package/dist/src/components/Example/ExampleHookUseSortBy.js +2 -1
- package/dist/src/components/Example/ExampleHookUseSortBy.js.map +1 -1
- package/dist/src/components/Example/ExampleProductCardWeight.d.ts +1 -1
- package/dist/src/components/Example/ExampleProductCardWeight.js +14 -47
- package/dist/src/components/Example/ExampleProductCardWeight.js.map +1 -1
- package/dist/src/components/Example/ExampleReactiveSearchProviderCollection.d.ts +1 -1
- package/dist/src/components/Example/ExampleReactiveSearchProviderCollection.js +2 -6
- package/dist/src/components/Example/ExampleReactiveSearchProviderCollection.js.map +1 -1
- package/dist/src/components/Example/ExampleReactiveSearchProviderInstantSearch.d.ts +1 -1
- package/dist/src/components/Example/ExampleReactiveSearchProviderInstantSearch.js +2 -6
- package/dist/src/components/Example/ExampleReactiveSearchProviderInstantSearch.js.map +1 -1
- package/dist/src/components/Example/ExampleReactiveSearchProviderSearch.d.ts +1 -1
- package/dist/src/components/Example/ExampleReactiveSearchProviderSearch.js +2 -6
- package/dist/src/components/Example/ExampleReactiveSearchProviderSearch.js.map +1 -1
- package/dist/src/components/Example/ExampleResultCardCallout.d.ts +1 -1
- package/dist/src/components/Example/ExampleResultCardCallout.js +2 -4
- package/dist/src/components/Example/ExampleResultCardCallout.js.map +1 -1
- package/dist/src/components/Example/ExampleResultCardProduct.d.ts +2 -2
- package/dist/src/components/Example/ExampleResultCardProduct.js +2 -12
- package/dist/src/components/Example/ExampleResultCardProduct.js.map +1 -1
- package/dist/src/components/Example/ExampleResultPaginationInfiniteScroll.d.ts +2 -2
- package/dist/src/components/Example/ExampleResultPaginationInfiniteScroll.js +2 -5
- package/dist/src/components/Example/ExampleResultPaginationInfiniteScroll.js.map +1 -1
- package/dist/src/components/Example/ExampleResultPaginationLoadMore.d.ts +2 -2
- package/dist/src/components/Example/ExampleResultPaginationLoadMore.js +2 -5
- package/dist/src/components/Example/ExampleResultPaginationLoadMore.js.map +1 -1
- package/dist/src/components/Example/ExampleResultPaginationNextPrev.d.ts +2 -2
- package/dist/src/components/Example/ExampleResultPaginationNextPrev.js +2 -7
- package/dist/src/components/Example/ExampleResultPaginationNextPrev.js.map +1 -1
- package/dist/src/components/Example/ExampleResultPaginationNumbered.d.ts +2 -2
- package/dist/src/components/Example/ExampleResultPaginationNumbered.js +6 -20
- package/dist/src/components/Example/ExampleResultPaginationNumbered.js.map +1 -1
- package/dist/src/components/Example/ExampleResults.d.ts +1 -1
- package/dist/src/components/Example/ExampleResults.js +7 -10
- package/dist/src/components/Example/ExampleResults.js.map +1 -1
- package/dist/src/components/Example/ExampleSearch.d.ts +1 -1
- package/dist/src/components/Example/ExampleSearch.js +2 -2
- package/dist/src/components/Example/ExampleSearch.js.map +1 -1
- package/dist/src/components/Example/ExampleSortBy.d.ts +2 -2
- package/dist/src/components/Example/ExampleSortBy.js +2 -5
- package/dist/src/components/Example/ExampleSortBy.js.map +1 -1
- package/dist/src/components/Example/ExampleStats.d.ts +2 -2
- package/dist/src/components/Example/ExampleStats.js +2 -8
- package/dist/src/components/Example/ExampleStats.js.map +1 -1
- package/dist/src/components/Example/ExampleSuggestions.d.ts +2 -2
- package/dist/src/components/Example/ExampleSuggestions.js +2 -7
- package/dist/src/components/Example/ExampleSuggestions.js.map +1 -1
- package/dist/src/components/Example/index.d.ts +6 -6
- package/dist/src/components/Example/index.js +6 -6
- package/dist/src/components/Example/index.js.map +1 -1
- package/dist/src/components/Filter/Filter.d.ts +1 -1
- package/dist/src/components/Filter/Filter.js +30 -35
- package/dist/src/components/Filter/Filter.js.map +1 -1
- package/dist/src/components/Filter/Filters.d.ts +4 -4
- package/dist/src/components/Filter/Filters.js +3 -6
- package/dist/src/components/Filter/Filters.js.map +1 -1
- package/dist/src/components/Filter/FiltersSelected.d.ts +1 -1
- package/dist/src/components/Filter/FiltersSelected.js +4 -9
- package/dist/src/components/Filter/FiltersSelected.js.map +1 -1
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.d.ts +2 -2
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js +20 -8
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js.map +1 -1
- package/dist/src/components/Result/ResultCardCallout.d.ts +2 -2
- package/dist/src/components/Result/ResultCardCallout.js +3 -2
- package/dist/src/components/Result/ResultCardCallout.js.map +1 -1
- package/dist/src/components/Result/ResultCardProduct.d.ts +1 -1
- package/dist/src/components/Result/ResultCardProduct.js +4 -3
- package/dist/src/components/Result/ResultCardProduct.js.map +1 -1
- package/dist/src/components/Result/ResultPaginationInfiniteScroll.d.ts +3 -3
- package/dist/src/components/Result/ResultPaginationInfiniteScroll.js +3 -6
- package/dist/src/components/Result/ResultPaginationInfiniteScroll.js.map +1 -1
- package/dist/src/components/Result/ResultPaginationLoadMore.d.ts +3 -3
- package/dist/src/components/Result/ResultPaginationLoadMore.js +3 -6
- package/dist/src/components/Result/ResultPaginationLoadMore.js.map +1 -1
- package/dist/src/components/Result/ResultPaginationNextPrev.d.ts +3 -3
- package/dist/src/components/Result/ResultPaginationNextPrev.js +3 -6
- package/dist/src/components/Result/ResultPaginationNextPrev.js.map +1 -1
- package/dist/src/components/Result/ResultPaginationNumbered.d.ts +3 -3
- package/dist/src/components/Result/ResultPaginationNumbered.js +3 -6
- package/dist/src/components/Result/ResultPaginationNumbered.js.map +1 -1
- package/dist/src/components/Result/ResultStateProvider.d.ts +2 -2
- package/dist/src/components/Result/ResultStateProvider.js +3 -3
- package/dist/src/components/Result/ResultStateProvider.js.map +1 -1
- package/dist/src/components/Result/Results.d.ts +2 -2
- package/dist/src/components/Result/Results.js +50 -52
- package/dist/src/components/Result/Results.js.map +1 -1
- package/dist/src/components/Result/index.d.ts +4 -4
- package/dist/src/components/Result/index.js +4 -4
- package/dist/src/components/Result/index.js.map +1 -1
- package/dist/src/components/Search/Search.d.ts +1 -1
- package/dist/src/components/Search/Search.js +3 -6
- package/dist/src/components/Search/Search.js.map +1 -1
- package/dist/src/components/Sensor/SensorCollection.d.ts +1 -1
- package/dist/src/components/Sensor/SensorCollection.js +2 -2
- package/dist/src/components/Sensor/SensorCollection.js.map +1 -1
- package/dist/src/components/Sensor/SensorCustom.d.ts +1 -2
- package/dist/src/components/Sensor/SensorCustom.js +5 -6
- package/dist/src/components/Sensor/SensorCustom.js.map +1 -1
- package/dist/src/components/Sensor/SensorExplain.js +2 -2
- package/dist/src/components/Sensor/SensorExplain.js.map +1 -1
- package/dist/src/components/Sensor/SensorInventoryAvailable.d.ts +1 -1
- package/dist/src/components/Sensor/SensorInventoryAvailable.js +2 -2
- package/dist/src/components/Sensor/SensorInventoryAvailable.js.map +1 -1
- package/dist/src/components/Sensor/SensorPublished.d.ts +1 -1
- package/dist/src/components/Sensor/SensorPublished.js +2 -2
- package/dist/src/components/Sensor/SensorPublished.js.map +1 -1
- package/dist/src/components/Sensor/SensorSearchTerm.d.ts +1 -2
- package/dist/src/components/Sensor/SensorSearchTerm.js +19 -124
- package/dist/src/components/Sensor/SensorSearchTerm.js.map +1 -1
- package/dist/src/components/Sensor/SensorSort.d.ts +1 -1
- package/dist/src/components/Sensor/SensorSort.js +2 -2
- package/dist/src/components/Sensor/SensorSort.js.map +1 -1
- package/dist/src/components/Sensor/Sensors.d.ts +1 -3
- package/dist/src/components/Sensor/Sensors.js +13 -46
- package/dist/src/components/Sensor/Sensors.js.map +1 -1
- package/dist/src/components/Sensor/index.d.ts +7 -9
- package/dist/src/components/Sensor/index.js +6 -10
- package/dist/src/components/Sensor/index.js.map +1 -1
- package/dist/src/components/SortBy/SortBy.d.ts +1 -1
- package/dist/src/components/SortBy/SortBy.js +3 -6
- package/dist/src/components/SortBy/SortBy.js.map +1 -1
- package/dist/src/components/Stats/Stats.d.ts +2 -2
- package/dist/src/components/Stats/Stats.js +2 -5
- package/dist/src/components/Stats/Stats.js.map +1 -1
- package/dist/src/components/Suggestions/Suggestions.d.ts +1 -1
- package/dist/src/components/Suggestions/Suggestions.js +7 -8
- package/dist/src/components/Suggestions/Suggestions.js.map +1 -1
- package/dist/src/components/Utility/UtilityAuthenticatedReactiveBase.d.ts +1 -1
- package/dist/src/components/Utility/UtilityAuthenticatedReactiveBase.js +3 -3
- package/dist/src/components/Utility/UtilityAuthenticatedReactiveBase.js.map +1 -1
- package/dist/src/components/Utility/index.js.map +1 -1
- package/dist/src/components/index.d.ts +2 -2
- package/dist/src/components/index.js +2 -2
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/hooks/index.d.ts +11 -11
- package/dist/src/hooks/index.js +11 -11
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/react-slider/useReactSliderProps.d.ts +2 -2
- package/dist/src/hooks/react-slider/useReactSliderProps.js +6 -6
- package/dist/src/hooks/react-slider/useReactSliderProps.js.map +1 -1
- package/dist/src/hooks/reactivesearch/useReactiveBaseProps.d.ts +1 -1
- package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js +2 -2
- package/dist/src/hooks/reactivesearch/useReactiveBaseProps.js.map +1 -1
- package/dist/src/hooks/useAnalytics.js.map +1 -1
- package/dist/src/hooks/useConfig.d.ts +1 -1
- package/dist/src/hooks/useConfig.js +1 -1
- package/dist/src/hooks/useConfig.js.map +1 -1
- package/dist/src/hooks/useCuration.d.ts +1 -1
- package/dist/src/hooks/useCuration.js +9 -25
- package/dist/src/hooks/useCuration.js.map +1 -1
- package/dist/src/hooks/useDebugger.js +3 -3
- package/dist/src/hooks/useDebugger.js.map +1 -1
- package/dist/src/hooks/useFilterCollapsedState.d.ts +1 -1
- package/dist/src/hooks/useFilterCollapsedState.js.map +1 -1
- package/dist/src/hooks/useFilterListProps.d.ts +2 -2
- package/dist/src/hooks/useFilterListProps.js +7 -11
- package/dist/src/hooks/useFilterListProps.js.map +1 -1
- package/dist/src/hooks/useFilterRangeProps.d.ts +1 -1
- package/dist/src/hooks/useFilterRangeProps.js +11 -14
- package/dist/src/hooks/useFilterRangeProps.js.map +1 -1
- package/dist/src/hooks/useFilterSliderProps.d.ts +1 -1
- package/dist/src/hooks/useFilterSliderProps.js +10 -9
- package/dist/src/hooks/useFilterSliderProps.js.map +1 -1
- package/dist/src/hooks/useFilters.d.ts +1 -1
- package/dist/src/hooks/useFilters.js +4 -7
- package/dist/src/hooks/useFilters.js.map +1 -1
- package/dist/src/hooks/useIndices.js +2 -2
- package/dist/src/hooks/useIndices.js.map +1 -1
- package/dist/src/hooks/usePagination.d.ts +1 -1
- package/dist/src/hooks/usePagination.js +6 -14
- package/dist/src/hooks/usePagination.js.map +1 -1
- package/dist/src/hooks/usePaginationLoadable.d.ts +1 -1
- package/dist/src/hooks/usePaginationLoadable.js +3 -5
- package/dist/src/hooks/usePaginationLoadable.js.map +1 -1
- package/dist/src/hooks/useProductPrice.d.ts +1 -1
- package/dist/src/hooks/useProductPrice.js +3 -1
- package/dist/src/hooks/useProductPrice.js.map +1 -1
- package/dist/src/hooks/useReactifySearchContext.d.ts +1 -1
- package/dist/src/hooks/useReactifySearchContext.js.map +1 -1
- package/dist/src/hooks/useResults.d.ts +1 -1
- package/dist/src/hooks/useResults.js +4 -4
- package/dist/src/hooks/useResults.js.map +1 -1
- package/dist/src/hooks/useSearch.d.ts +1 -1
- package/dist/src/hooks/useSearch.js +8 -9
- package/dist/src/hooks/useSearch.js.map +1 -1
- package/dist/src/hooks/useSortBy.d.ts +1 -1
- package/dist/src/hooks/useSortBy.js +1 -1
- package/dist/src/hooks/useSortBy.js.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/search-request-builder/base-builders.d.ts +18 -0
- package/dist/src/search-request-builder/base-builders.js +184 -0
- package/dist/src/search-request-builder/base-builders.js.map +1 -0
- package/dist/src/search-request-builder/curation-builders.d.ts +2 -0
- package/dist/src/search-request-builder/curation-builders.js +44 -0
- package/dist/src/search-request-builder/curation-builders.js.map +1 -0
- package/dist/src/search-request-builder/index.d.ts +3 -0
- package/dist/src/search-request-builder/index.js +12 -0
- package/dist/src/search-request-builder/index.js.map +1 -0
- package/dist/src/search-request-builder/search-request-builder.d.ts +3 -0
- package/dist/src/search-request-builder/search-request-builder.js +54 -0
- package/dist/src/search-request-builder/search-request-builder.js.map +1 -0
- package/dist/src/search-request-builder/types.d.ts +105 -0
- package/dist/src/search-request-builder/types.js +30 -0
- package/dist/src/search-request-builder/types.js.map +1 -0
- package/dist/src/search-request-builder/utils.d.ts +27 -0
- package/dist/src/search-request-builder/utils.js +144 -0
- package/dist/src/search-request-builder/utils.js.map +1 -0
- package/dist/src/types/config.d.ts +1 -1
- package/dist/src/types/config.js.map +1 -1
- package/dist/src/types/elastic.d.ts +8 -11
- package/dist/src/types/elastic.js.map +1 -1
- package/dist/src/types/firestore.d.ts +5 -5
- package/dist/src/types/firestore.js.map +1 -1
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/reactivesearch.d.ts +1 -1
- package/dist/src/types/reactivesearch.js.map +1 -1
- package/dist/src/types/shopify.d.ts +1 -1
- package/dist/src/types/shopify.js.map +1 -1
- package/dist/src/utility/config.d.ts +1 -1
- package/dist/src/utility/config.js +1 -1
- package/dist/src/utility/config.js.map +1 -1
- package/dist/src/utility/curation.d.ts +2 -2
- package/dist/src/utility/curation.js +1 -1
- package/dist/src/utility/curation.js.map +1 -1
- package/dist/src/utility/debug.js +1 -1
- package/dist/src/utility/debug.js.map +1 -1
- package/dist/src/utility/filters.d.ts +2 -2
- package/dist/src/utility/filters.js.map +1 -1
- package/dist/src/utility/liquid.d.ts +2 -2
- package/dist/src/utility/liquid.js +2 -5
- package/dist/src/utility/liquid.js.map +1 -1
- package/dist/src/utility/props.d.ts +7 -226
- package/dist/src/utility/props.js +61 -108
- package/dist/src/utility/props.js.map +1 -1
- package/dist/src/utility/server.d.ts +1 -1
- package/dist/src/utility/server.js +3 -3
- package/dist/src/utility/server.js.map +1 -1
- package/dist/src/utility/sortOption.d.ts +2 -2
- package/dist/src/utility/sortOption.js.map +1 -1
- package/package.json +7 -5
- package/dist/src/components/Sensor/SensorCollectionWeighted.d.ts +0 -1
- package/dist/src/components/Sensor/SensorCollectionWeighted.js +0 -21
- package/dist/src/components/Sensor/SensorCollectionWeighted.js.map +0 -1
- package/dist/src/components/Sensor/SensorSearchWeighted.d.ts +0 -1
- package/dist/src/components/Sensor/SensorSearchWeighted.js +0 -22
- package/dist/src/components/Sensor/SensorSearchWeighted.js.map +0 -1
- package/dist/src/utility/queries.d.ts +0 -393
- package/dist/src/utility/queries.js +0 -197
- package/dist/src/utility/queries.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-builders.js","sourceRoot":"","sources":["../../../src/search-request-builder/base-builders.ts"],"names":[],"mappings":";;AAuBA,8DAuBC;AA6CD,0EAGC;AAED,kEAkBC;AAGD,kEAmFC;AAED,0EA4BC;AAtOD,mCAWiB;AACjB,mCAOiB;AAGjB,iCAAiC;AACjC,SAAgB,yBAAyB,CAAC,OAAqC;;IAC7E,IAAI,IAAA,2BAAmB,EAAC,OAAO,CAAC,EAAE,CAAC;QACjC,yBAAyB;QACzB,MAAM,OAAO,GAAG,MAAA,MAAA,OAAO,CAAC,QAAQ,0CAAE,OAAO,mCAAI,EAAE,CAAC;QAChD,OAAO,+BAA+B,CAAC;YACrC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;YAC1C,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAA,uBAAe,EAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,mBAAmB;QACnB,MAAM,OAAO,GAAG,MAAA,MAAA,OAAO,CAAC,QAAQ,0CAAE,OAAO,mCAAI,EAAE,CAAC;QAChD,OAAO,yBAAyB,CAAC;YAC/B,UAAU,EAAE,OAA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MAAM,GAAG,CAAC,YAAY,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACL,KAAK,EAAE;YACL,IAAI,EAAE,SAAS;SAChB;QACD,SAAS,EAAE;YACT,GAAG,YAAY;YACf,GAAG,IAAA,6BAAqB,EAAC,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;SAC3F;QACD,UAAU,EAAE,KAAK;QACjB,UAAU,EAAE,SAAS;KACtB,CAAC;AACJ,CAAC;AAED,SAAgB,+BAA+B,CAAC,OAK/C;IACC,MAAM,WAAW,GAAqB;QACpC;YACE,MAAM,EAAE;gBACN,IAAI,EAAE,aAAa;gBACnB,KAAK,EAAE;oBACL,IAAI,EAAE,EAAE,oBAAoB,EAAE,OAAO,CAAC,gBAAgB,EAAE;iBACzD;aACF;SACF;KACF,CAAC;IAEF,MAAM,YAAY,GAAG,IAAA,6BAAqB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5D,IAAI,YAAY;QAAE,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAEjD,OAAO;QACL,KAAK,EAAE;YACL,IAAI,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;SAC5B;QACD,SAAS,EAAE,IAAA,6BAAqB,EAAC,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;QAClG,UAAU,EAAE,KAAK;QACjB,UAAU,EAAE,SAAS;KACtB,CAAC;AACJ,CAAC","sourcesContent":["import {\n BaseSearchRequestMode,\n type CollectionSearchRequestOptions,\n type FunctionScoreContainer,\n type FunctionScoreQuery,\n type GenerateSearchRequestOptions,\n isCollectionOptions,\n isSearchOptions,\n type QueryContainer,\n type SearchRequest,\n type TermSearchRequestOptions,\n} from \"./types\";\nimport {\n generateBoostingRules,\n generateMarketsClause,\n generateMarketsFilter,\n generateMultiMatchQueries,\n prepareRelevanceFields,\n validateSearchInputs,\n} from \"./utils\";\nimport type { Boosting, SearchableField } from \"../types/firestore\";\n\n// Base Search Request Generation\nexport function generateBaseSearchRequest(options: GenerateSearchRequestOptions): SearchRequest {\n if (isCollectionOptions(options)) {\n // Collection search mode\n const markets = options.curation?.markets ?? [];\n return generateCollectionSearchRequest({\n collectionHandle: options.collectionHandle,\n markets: markets,\n });\n }\n\n if (isSearchOptions(options)) {\n // Term search mode\n const markets = options.curation?.markets ?? [];\n return generateTermSearchRequest({\n searchTerm: options.searchTerm,\n baseSearchRequestMode: options.baseSearchRequestMode,\n relevanceFields: options.relevanceFields,\n searchableFields: options.searchableFields,\n markets: markets,\n });\n }\n\n throw new Error(\"Invalid options: must be either search or collection options\");\n}\n\n// Term Search Request Generation\nfunction generateTermSearchRequest(options: TermSearchRequestOptions): SearchRequest {\n validateSearchInputs(options);\n\n if (options.baseSearchRequestMode === BaseSearchRequestMode.Weighted) {\n return generateWeightedTermSearchRequest(options);\n }\n\n return generateRelevanceTermSearchRequest(options);\n}\n\nfunction generateWeightedTermSearchRequest(options: TermSearchRequestOptions): SearchRequest {\n if (!options.searchableFields) {\n throw new Error(\"SearchableFields required for weighted search\");\n }\n\n const functionScoreQuery = generateWeightedSearchQuery({\n searchTerm: options.searchTerm,\n searchableFields: options.searchableFields,\n boostingRules: [],\n markets: options.markets,\n });\n\n return { query: { function_score: functionScoreQuery } };\n}\n\nfunction generateRelevanceTermSearchRequest(options: TermSearchRequestOptions): SearchRequest {\n const fieldMappings = prepareRelevanceFields(options.relevanceFields);\n const multiMatchQueries = generateMultiMatchQueries(options.searchTerm, fieldMappings);\n const query = buildRelevanceQueryStructure(multiMatchQueries, options.markets);\n return { query };\n}\n\nfunction buildRelevanceQueryStructure(multiMatchQueries: QueryContainer[], markets: string[]): QueryContainer {\n return {\n bool: {\n must: [{ bool: { should: multiMatchQueries, minimum_should_match: \"1\" } }],\n filter: generateMarketsFilter(markets),\n },\n };\n}\n\n// Collection Search Request Generation\nexport function generateCollectionSearchRequest(options: CollectionSearchRequestOptions): SearchRequest {\n const query = generateCollectionBaseQuery(options);\n return { query };\n}\n\nexport function generateCollectionBaseQuery(options: CollectionSearchRequestOptions): QueryContainer {\n const mustClauses: QueryContainer[] = [\n {\n nested: {\n path: \"collections\",\n query: {\n term: { \"collections.handle\": options.collectionHandle },\n },\n },\n },\n ];\n\n const marketClause = generateMarketsFilter(options.markets);\n if (marketClause.length > 0) {\n mustClauses.push(...marketClause);\n }\n\n return { bool: { must: mustClauses } };\n}\n\n// Weighted Search Implementation - using corrected property names\nexport function generateWeightedSearchQuery(options: {\n searchTerm: string;\n searchableFields: SearchableField[];\n boostingRules: Boosting[];\n markets: string[];\n market?: string;\n}): FunctionScoreQuery {\n const searchTerms = options.searchTerm?.split(\" \") ?? [];\n\n const searchQueries: QueryContainer[] = [];\n for (const searchableField of options.searchableFields) {\n const baseField = searchableField.field;\n const maxEdits = searchableField.maxEdits;\n for (const searchTerm of searchTerms) {\n searchQueries.push({\n match: { [baseField]: { query: searchTerm, fuzziness: maxEdits, analyzer: \"regular_analyzer\" } },\n });\n if (searchableField.synonymEnabled) {\n searchQueries.push({\n match: { [baseField]: { query: searchTerm, fuzziness: maxEdits, analyzer: \"synonym_analyzer\" } },\n });\n }\n }\n }\n\n const searchScores: FunctionScoreContainer[] = [];\n for (const field of options.searchableFields) {\n const baseField = field.field;\n const maxPoints = field.points;\n const maxEdits = field.maxEdits;\n\n for (let edits = 0; edits <= maxEdits; edits++) {\n const weightMaxEdits = Math.max(maxPoints - maxEdits * (maxPoints / (100 / field.mistakePenaltyPercent)), 0);\n const weightSomeEdits = maxPoints / (100 / field.mistakePenaltyPercent);\n const weightBase = edits === maxEdits ? weightMaxEdits : weightSomeEdits;\n\n for (const searchTerm of searchTerms) {\n searchScores.push({\n filter: {\n match: { [baseField]: { query: searchTerm, fuzziness: edits, analyzer: \"regular_analyzer\" } },\n },\n weight: weightBase,\n });\n\n if (field.synonymEnabled && field.synonymPenaltyPercent > 0) {\n const weightSynonyms = weightBase * (1 - field.synonymPenaltyPercent / 100);\n\n searchScores.push({\n filter: {\n bool: {\n must_not: {\n match: { [baseField]: { query: searchTerm, fuzziness: edits, analyzer: \"regular_analyzer\" } },\n },\n must: {\n match: { [baseField]: { query: searchTerm, fuzziness: edits, analyzer: \"synonym_analyzer\" } },\n },\n },\n },\n weight: weightSynonyms,\n });\n }\n }\n }\n }\n\n const marketClause = generateMarketsClause(options.markets);\n const boolQuery: any = { should: [...searchQueries] };\n\n if (marketClause) {\n boolQuery.filter = [marketClause];\n }\n\n return {\n query: {\n bool: boolQuery,\n },\n functions: [\n ...searchScores,\n ...generateBoostingRules({ boostingRules: options.boostingRules, market: options.market }),\n ],\n score_mode: \"sum\",\n boost_mode: \"replace\",\n };\n}\n\nexport function generateWeightedCollectionQuery(options: {\n collectionHandle: string;\n boostingRules: Boosting[];\n markets: string[];\n market?: string;\n}): FunctionScoreQuery {\n const mustClauses: QueryContainer[] = [\n {\n nested: {\n path: \"collections\",\n query: {\n term: { \"collections.handle\": options.collectionHandle },\n },\n },\n },\n ];\n\n const marketClause = generateMarketsClause(options.markets);\n if (marketClause) mustClauses.push(marketClause);\n\n return {\n query: {\n bool: { must: mustClauses },\n },\n functions: generateBoostingRules({ boostingRules: options.boostingRules, market: options.market }),\n score_mode: \"sum\",\n boost_mode: \"replace\",\n };\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateCurationSearchRequest = generateCurationSearchRequest;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function generateCurationSearchRequest(options) {
|
|
7
|
+
if (options.curationSearchRequestMode === types_1.CurationSearchRequestMode.Weighted) {
|
|
8
|
+
return generateWeightedCurationSearchRequest(options);
|
|
9
|
+
}
|
|
10
|
+
return generateBoostedCurationSearchRequest(options);
|
|
11
|
+
}
|
|
12
|
+
function generateWeightedCurationSearchRequest(options) {
|
|
13
|
+
const curationRules = extractCurationRules(options.curation);
|
|
14
|
+
return {
|
|
15
|
+
query: {
|
|
16
|
+
function_score: {
|
|
17
|
+
query: { match_all: {} }, // Add required query field
|
|
18
|
+
functions: curationRules.boostingRules
|
|
19
|
+
.map((boostingRule) => (0, utils_1.generateBoostingRule)({ boostingRule, market: options.market }))
|
|
20
|
+
.filter(Boolean),
|
|
21
|
+
score_mode: "sum",
|
|
22
|
+
boost_mode: "replace",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// This `sort` field is handled by SensorSort.
|
|
28
|
+
// ReactiveSearch does not combine multiple top-level `sort` fields; a `SearchRequest` is limited to one.
|
|
29
|
+
function generateBoostedCurationSearchRequest(_options) {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
// Supporting Functions
|
|
33
|
+
function extractCurationRules(curation) {
|
|
34
|
+
var _a, _b, _c, _d, _e;
|
|
35
|
+
if (!curation) {
|
|
36
|
+
return { boostingRules: [], groupings: [], sortings: [] };
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
boostingRules: (_a = curation.boostings) !== null && _a !== void 0 ? _a : [],
|
|
40
|
+
groupings: (_c = (_b = curation.boosting) === null || _b === void 0 ? void 0 : _b.groupings) !== null && _c !== void 0 ? _c : [],
|
|
41
|
+
sortings: (_e = (_d = curation.boosting) === null || _d === void 0 ? void 0 : _d.sortings) !== null && _e !== void 0 ? _e : [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=curation-builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curation-builders.js","sourceRoot":"","sources":["../../../src/search-request-builder/curation-builders.ts"],"names":[],"mappings":";;AAUA,sEAMC;AAhBD,mCAOiB;AACjB,mCAA+C;AAE/C,SAAgB,6BAA6B,CAAC,OAAqC;IACjF,IAAI,OAAO,C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uration,\n type CurationRules,\n CurationSearchRequestMode,\n type GenerateSearchRequestOptions,\n type SearchCuration,\n type SearchRequest,\n} from \"./types\";\nimport { generateBoostingRule } from \"./utils\";\n\nexport function generateCurationSearchRequest(options: GenerateSearchRequestOptions): Partial<SearchRequest> {\n if (options.curationSearchRequestMode === CurationSearchRequestMode.Weighted) {\n return generateWeightedCurationSearchRequest(options);\n }\n\n return generateBoostedCurationSearchRequest(options);\n}\n\nfunction generateWeightedCurationSearchRequest(options: GenerateSearchRequestOptions): Partial<SearchRequest> {\n const curationRules = extractCurationRules(options.curation);\n\n return {\n query: {\n function_score: {\n query: { match_all: {} }, // Add required query field\n functions: curationRules.boostingRules\n .map((boostingRule) => generateBoostingRule({ boostingRule, market: options.market }))\n .filter(Boolean),\n score_mode: \"sum\",\n boost_mode: \"replace\",\n },\n },\n };\n}\n\n// This `sort` field is handled by SensorSort.\n// ReactiveSearch does not combine multiple top-level `sort` fields; a `SearchRequest` is limited to one.\nfunction generateBoostedCurationSearchRequest(_options: GenerateSearchRequestOptions): Partial<SearchRequest> {\n return {};\n}\n\n// Supporting Functions\nfunction extractCurationRules(curation?: SearchCuration | CollectionCuration): CurationRules {\n if (!curation) {\n return { boostingRules: [], groupings: [], sortings: [] };\n }\n\n return {\n boostingRules: curation.boostings ?? [],\n groupings: curation.boosting?.groupings ?? [],\n sortings: curation.boosting?.sortings ?? [],\n };\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurationSearchRequestMode = exports.BaseSearchRequestMode = exports.generateSearchRequest = exports.determineSearchRequestModes = void 0;
|
|
4
|
+
// Main public API exports
|
|
5
|
+
var search_request_builder_1 = require("./search-request-builder");
|
|
6
|
+
Object.defineProperty(exports, "determineSearchRequestModes", { enumerable: true, get: function () { return search_request_builder_1.determineSearchRequestModes; } });
|
|
7
|
+
Object.defineProperty(exports, "generateSearchRequest", { enumerable: true, get: function () { return search_request_builder_1.generateSearchRequest; } });
|
|
8
|
+
// Runtime enums (can be used as values)
|
|
9
|
+
var types_1 = require("./types");
|
|
10
|
+
Object.defineProperty(exports, "BaseSearchRequestMode", { enumerable: true, get: function () { return types_1.BaseSearchRequestMode; } });
|
|
11
|
+
Object.defineProperty(exports, "CurationSearchRequestMode", { enumerable: true, get: function () { return types_1.CurationSearchRequestMode; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/search-request-builder/index.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AAC1B,mEAA8F;AAArF,qIAAA,2BAA2B,OAAA;AAAE,+HAAA,qBAAqB,OAAA;AAG3D,wCAAwC;AACxC,iCAA2E;AAAlE,8GAAA,qBAAqB,OAAA;AAAE,kHAAA,yBAAyB,OAAA","sourcesContent":["// Main public API exports\nexport { determineSearchRequestModes, generateSearchRequest } from \"./search-request-builder\";\n// Types and enums (commonly used)\nexport type { GenerateSearchRequestOptions, SearchRequest, SearchRequestModes } from \"./types\";\n// Runtime enums (can be used as values)\nexport { BaseSearchRequestMode, CurationSearchRequestMode } from \"./types\";\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type GenerateSearchRequestOptions, type SearchRequest, type SearchRequestModes } from "./types";
|
|
2
|
+
export declare function generateSearchRequest(options: GenerateSearchRequestOptions): SearchRequest;
|
|
3
|
+
export declare function determineSearchRequestModes(flags: string[]): SearchRequestModes;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSearchRequest = generateSearchRequest;
|
|
4
|
+
exports.determineSearchRequestModes = determineSearchRequestModes;
|
|
5
|
+
const base_builders_1 = require("./base-builders");
|
|
6
|
+
const curation_builders_1 = require("./curation-builders");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
// Main Entry Point - Search Request Strategy Router
|
|
9
|
+
function generateSearchRequest(options) {
|
|
10
|
+
const baseSearchRequest = (0, base_builders_1.generateBaseSearchRequest)(options);
|
|
11
|
+
// Only apply curation enhancements if curation exists
|
|
12
|
+
if (options.curation) {
|
|
13
|
+
const curationSearchRequest = (0, curation_builders_1.generateCurationSearchRequest)(options);
|
|
14
|
+
return combineSearchRequest(baseSearchRequest, curationSearchRequest);
|
|
15
|
+
}
|
|
16
|
+
return baseSearchRequest;
|
|
17
|
+
}
|
|
18
|
+
// Combine Search Request Function
|
|
19
|
+
function combineSearchRequest(baseRequestSearch, curationSearchRequest) {
|
|
20
|
+
return Object.assign(Object.assign(Object.assign({}, baseRequestSearch), curationSearchRequest), (baseRequestSearch.query &&
|
|
21
|
+
curationSearchRequest.query && {
|
|
22
|
+
query: mergeQueries(baseRequestSearch.query, curationSearchRequest.query),
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
function mergeQueries(baseQuery, enhancementQuery) {
|
|
26
|
+
if ("function_score" in enhancementQuery && enhancementQuery.function_score) {
|
|
27
|
+
return {
|
|
28
|
+
function_score: {
|
|
29
|
+
query: baseQuery,
|
|
30
|
+
functions: enhancementQuery.function_score.functions || [],
|
|
31
|
+
score_mode: enhancementQuery.function_score.score_mode,
|
|
32
|
+
boost_mode: enhancementQuery.function_score.boost_mode,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return enhancementQuery;
|
|
37
|
+
}
|
|
38
|
+
// Search Request Mode Detection Functions
|
|
39
|
+
function determineSearchRequestModes(flags) {
|
|
40
|
+
const baseSearchRequestMode = detectBaseSearchRequestMode(flags);
|
|
41
|
+
const curationSearchRequestMode = detectCurationSearchRequestMode(flags);
|
|
42
|
+
return { baseSearchRequestMode, curationSearchRequestMode };
|
|
43
|
+
}
|
|
44
|
+
function detectBaseSearchRequestMode(flags) {
|
|
45
|
+
return (flags === null || flags === void 0 ? void 0 : flags.includes("use_weighted_base_search_request"))
|
|
46
|
+
? types_1.BaseSearchRequestMode.Weighted
|
|
47
|
+
: types_1.BaseSearchRequestMode.Relevance;
|
|
48
|
+
}
|
|
49
|
+
function detectCurationSearchRequestMode(flags) {
|
|
50
|
+
return (flags === null || flags === void 0 ? void 0 : flags.includes("use_weighted_curation_search_request"))
|
|
51
|
+
? types_1.CurationSearchRequestMode.Weighted
|
|
52
|
+
: types_1.CurationSearchRequestMode.Boosted;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=search-request-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-request-builder.js","sourceRoot":"","sources":["../../../src/search-request-builder/search-request-builder.ts"],"names":[],"mappings":";;AAYA,sDAUC;AAiCD,kEAIC;AA3DD,mDAA4D;AAC5D,2DAAoE;AACpE,mCAOiB;AAEjB,oDAAoD;AACpD,SAAgB,qBAAqB,CAAC,OAAqC;IACzE,MAAM,iBAAiB,GAAG,IAAA,yCAAyB,EAAC,OAAO,CAAC,CAAC;IAE7D,sDAAsD;IACtD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,MAAM,qBAAqB,GAAG,IAAA,iDAA6B,EAAC,OAAO,CAAC,CAAC;QACrE,OAAO,oBAAoB,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,kCAAkC;AAClC,SAAS,oBAAoB,CAC3B,iBAAgC,EAChC,qBAA6C;IAE7C,qDACK,iBAAiB,GACjB,qBAAqB,GACrB,CAAC,iBAAiB,CAAC,KAAK;QACzB,qBAAqB,CAAC,KAAK,IAAI;QAC7B,KAAK,EAAE,YAAY,CAAC,iBAAiB,CAAC,KAAK,EAAE,qBAAqB,CAAC,KAAK,CAAC;KAC1E,CAAC,EACJ;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,SAAyB,EAAE,gBAAgC;IAC/E,IAAI,gBAAgB,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,cAAc,EAAE,CAAC;QAC5E,OAAO;YACL,cAAc,EAAE;gBACd,KAAK,EAAE,SAAS;gBAChB,SAAS,EAAE,gBAAgB,CAAC,cAAc,CAAC,SAAS,IAAI,EAAE;gBAC1D,UAAU,EAAE,gBAAgB,CAAC,cAAc,CAAC,UAAU;gBACtD,UAAU,EAAE,gBAAgB,CAAC,cAAc,CAAC,UAAU;aACvD;SACF,CAAC;IACJ,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,0CAA0C;AAC1C,SAAgB,2BAA2B,CAAC,KAAe;IACzD,MAAM,qBAAqB,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;IACjE,MAAM,yBAAyB,GAAG,+BAA+B,CAAC,KAAK,CAAC,CAAC;IACzE,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,CAAC;AAC9D,CAAC;AAED,SAAS,2BAA2B,CAAC,KAAgB;IACnD,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,CAAC,kCAAkC,CAAC;QACxD,CAAC,CAAC,6BAAqB,CAAC,QAAQ;QAChC,CAAC,CAAC,6BAAqB,CAAC,SAAS,CAAC;AACtC,CAAC;AAED,SAAS,+BAA+B,CAAC,KAAgB;IACvD,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,CAAC,sCAAsC,CAAC;QAC5D,CAAC,CAAC,iCAAyB,CAAC,QAAQ;QACpC,CAAC,CAAC,iCAAyB,CAAC,OAAO,CAAC;AACxC,CAAC","sourcesContent":["import { generateBaseSearchRequest } from \"./base-builders\";\nimport { generateCurationSearchRequest } from \"./curation-builders\";\nimport {\n BaseSearchRequestMode,\n CurationSearchRequestMode,\n type GenerateSearchRequestOptions,\n type QueryContainer,\n type SearchRequest,\n type SearchRequestModes,\n} from \"./types\";\n\n// Main Entry Point - Search Request Strategy Router\nexport function generateSearchRequest(options: GenerateSearchRequestOptions): SearchRequest {\n const baseSearchRequest = generateBaseSearchRequest(options);\n\n // Only apply curation enhancements if curation exists\n if (options.curation) {\n const curationSearchRequest = generateCurationSearchRequest(options);\n return combineSearchRequest(baseSearchRequest, curationSearchRequest);\n }\n\n return baseSearchRequest;\n}\n\n// Combine Search Request Function\nfunction combineSearchRequest(\n baseRequestSearch: SearchRequest,\n curationSearchRequest: Partial<SearchRequest>\n): SearchRequest {\n return {\n ...baseRequestSearch,\n ...curationSearchRequest,\n ...(baseRequestSearch.query &&\n curationSearchRequest.query && {\n query: mergeQueries(baseRequestSearch.query, curationSearchRequest.query),\n }),\n };\n}\n\nfunction mergeQueries(baseQuery: QueryContainer, enhancementQuery: QueryContainer): QueryContainer {\n if (\"function_score\" in enhancementQuery && enhancementQuery.function_score) {\n return {\n function_score: {\n query: baseQuery,\n functions: enhancementQuery.function_score.functions || [],\n score_mode: enhancementQuery.function_score.score_mode,\n boost_mode: enhancementQuery.function_score.boost_mode,\n },\n };\n }\n\n return enhancementQuery;\n}\n\n// Search Request Mode Detection Functions\nexport function determineSearchRequestModes(flags: string[]): SearchRequestModes {\n const baseSearchRequestMode = detectBaseSearchRequestMode(flags);\n const curationSearchRequestMode = detectCurationSearchRequestMode(flags);\n return { baseSearchRequestMode, curationSearchRequestMode };\n}\n\nfunction detectBaseSearchRequestMode(flags?: string[]): BaseSearchRequestMode {\n return flags?.includes(\"use_weighted_base_search_request\")\n ? BaseSearchRequestMode.Weighted\n : BaseSearchRequestMode.Relevance;\n}\n\nfunction detectCurationSearchRequestMode(flags?: string[]): CurationSearchRequestMode {\n return flags?.includes(\"use_weighted_curation_search_request\")\n ? CurationSearchRequestMode.Weighted\n : CurationSearchRequestMode.Boosted;\n}\n"]}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type BoostGrouping, type Boosting, type BoostSorting, type Curation, CurationType, type Relevance, type SearchableField } from "../types/firestore";
|
|
2
|
+
export declare const BaseSearchRequestMode: {
|
|
3
|
+
readonly Relevance: "relevance";
|
|
4
|
+
readonly Weighted: "weighted";
|
|
5
|
+
};
|
|
6
|
+
export type BaseSearchRequestMode = (typeof BaseSearchRequestMode)[keyof typeof BaseSearchRequestMode];
|
|
7
|
+
export declare const CurationSearchRequestMode: {
|
|
8
|
+
readonly Boosted: "boosted";
|
|
9
|
+
readonly Weighted: "weighted";
|
|
10
|
+
};
|
|
11
|
+
export type CurationSearchRequestMode = (typeof CurationSearchRequestMode)[keyof typeof CurationSearchRequestMode];
|
|
12
|
+
export interface SearchRequestModes {
|
|
13
|
+
baseSearchRequestMode: BaseSearchRequestMode;
|
|
14
|
+
curationSearchRequestMode: CurationSearchRequestMode;
|
|
15
|
+
}
|
|
16
|
+
export interface GenerateSearchRequestBaseOptions {
|
|
17
|
+
relevanceFields?: Relevance[];
|
|
18
|
+
searchableFields?: SearchableField[];
|
|
19
|
+
market?: string;
|
|
20
|
+
baseSearchRequestMode: BaseSearchRequestMode;
|
|
21
|
+
curationSearchRequestMode: CurationSearchRequestMode;
|
|
22
|
+
}
|
|
23
|
+
export interface GenerateSearchRequestSearchOptions extends GenerateSearchRequestBaseOptions {
|
|
24
|
+
searchTerm: string;
|
|
25
|
+
curation?: SearchCuration;
|
|
26
|
+
}
|
|
27
|
+
export interface GenerateSearchRequestCollectionOptions extends GenerateSearchRequestBaseOptions {
|
|
28
|
+
collectionHandle: string;
|
|
29
|
+
curation?: CollectionCuration;
|
|
30
|
+
}
|
|
31
|
+
export type GenerateSearchRequestOptions = GenerateSearchRequestSearchOptions | GenerateSearchRequestCollectionOptions;
|
|
32
|
+
export interface SearchCuration extends Curation {
|
|
33
|
+
type: CurationType.Search;
|
|
34
|
+
searchTerm: string;
|
|
35
|
+
}
|
|
36
|
+
export interface CollectionCuration extends Curation {
|
|
37
|
+
type: CurationType.Collection;
|
|
38
|
+
collectionHandle: string;
|
|
39
|
+
}
|
|
40
|
+
export interface CurationRules {
|
|
41
|
+
boostingRules: Boosting[];
|
|
42
|
+
groupings: BoostGrouping[];
|
|
43
|
+
sortings: BoostSorting[];
|
|
44
|
+
}
|
|
45
|
+
export interface TermSearchRequestOptions {
|
|
46
|
+
searchTerm: string;
|
|
47
|
+
baseSearchRequestMode: BaseSearchRequestMode;
|
|
48
|
+
relevanceFields?: Relevance[];
|
|
49
|
+
searchableFields?: SearchableField[];
|
|
50
|
+
markets: string[];
|
|
51
|
+
}
|
|
52
|
+
export interface CollectionSearchRequestOptions {
|
|
53
|
+
collectionHandle: string;
|
|
54
|
+
markets: string[];
|
|
55
|
+
}
|
|
56
|
+
export interface SearchRequest {
|
|
57
|
+
query?: QueryContainer;
|
|
58
|
+
sort?: SortOptions;
|
|
59
|
+
}
|
|
60
|
+
export interface QueryContainer {
|
|
61
|
+
bool?: BoolQuery;
|
|
62
|
+
function_score?: FunctionScoreQuery;
|
|
63
|
+
multi_match?: MultiMatchQuery;
|
|
64
|
+
match?: Record<string, any>;
|
|
65
|
+
match_all?: Record<string, any>;
|
|
66
|
+
term?: Record<string, any>;
|
|
67
|
+
terms?: Record<string, string[]>;
|
|
68
|
+
wildcard?: Record<string, string>;
|
|
69
|
+
range?: Record<string, any>;
|
|
70
|
+
nested?: NestedQuery;
|
|
71
|
+
}
|
|
72
|
+
export interface BoolQuery {
|
|
73
|
+
must?: QueryContainer | QueryContainer[];
|
|
74
|
+
should?: QueryContainer[];
|
|
75
|
+
must_not?: QueryContainer | QueryContainer[];
|
|
76
|
+
filter?: QueryContainer[];
|
|
77
|
+
minimum_should_match?: string | number;
|
|
78
|
+
}
|
|
79
|
+
export interface FunctionScoreQuery {
|
|
80
|
+
query: QueryContainer;
|
|
81
|
+
functions: FunctionScoreContainer[];
|
|
82
|
+
score_mode: FunctionScoreMode;
|
|
83
|
+
boost_mode: FunctionBoostMode;
|
|
84
|
+
}
|
|
85
|
+
export interface FunctionScoreContainer {
|
|
86
|
+
filter: QueryContainer;
|
|
87
|
+
weight: number;
|
|
88
|
+
}
|
|
89
|
+
export interface MultiMatchQuery {
|
|
90
|
+
query: string;
|
|
91
|
+
fields: string[];
|
|
92
|
+
type: "cross_fields" | "phrase" | "phrase_prefix";
|
|
93
|
+
operator: "and" | "or";
|
|
94
|
+
}
|
|
95
|
+
export interface NestedQuery {
|
|
96
|
+
path: string;
|
|
97
|
+
query: QueryContainer;
|
|
98
|
+
}
|
|
99
|
+
export type SortOptions = Record<string, any>[] | Record<string, any>;
|
|
100
|
+
export type FunctionScoreMode = "sum" | "multiply" | "avg" | "max" | "min" | "first";
|
|
101
|
+
export type FunctionBoostMode = "multiply" | "replace" | "sum" | "avg" | "max" | "min";
|
|
102
|
+
export declare function isSearchOptions(options: GenerateSearchRequestOptions): options is GenerateSearchRequestSearchOptions;
|
|
103
|
+
export declare function isCollectionOptions(options: GenerateSearchRequestOptions): options is GenerateSearchRequestCollectionOptions;
|
|
104
|
+
export declare function isSearchCuration(curation?: Curation): curation is SearchCuration;
|
|
105
|
+
export declare function isCollectionCuration(curation?: Curation): curation is CollectionCuration;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurationSearchRequestMode = exports.BaseSearchRequestMode = void 0;
|
|
4
|
+
exports.isSearchOptions = isSearchOptions;
|
|
5
|
+
exports.isCollectionOptions = isCollectionOptions;
|
|
6
|
+
exports.isSearchCuration = isSearchCuration;
|
|
7
|
+
exports.isCollectionCuration = isCollectionCuration;
|
|
8
|
+
const firestore_1 = require("../types/firestore");
|
|
9
|
+
exports.BaseSearchRequestMode = {
|
|
10
|
+
Relevance: "relevance",
|
|
11
|
+
Weighted: "weighted",
|
|
12
|
+
};
|
|
13
|
+
exports.CurationSearchRequestMode = {
|
|
14
|
+
Boosted: "boosted",
|
|
15
|
+
Weighted: "weighted",
|
|
16
|
+
};
|
|
17
|
+
// Type guards for runtime type checking
|
|
18
|
+
function isSearchOptions(options) {
|
|
19
|
+
return "searchTerm" in options;
|
|
20
|
+
}
|
|
21
|
+
function isCollectionOptions(options) {
|
|
22
|
+
return "collectionHandle" in options;
|
|
23
|
+
}
|
|
24
|
+
function isSearchCuration(curation) {
|
|
25
|
+
return (curation === null || curation === void 0 ? void 0 : curation.type) === firestore_1.CurationType.Search;
|
|
26
|
+
}
|
|
27
|
+
function isCollectionCuration(curation) {
|
|
28
|
+
return (curation === null || curation === void 0 ? void 0 : curation.type) === firestore_1.CurationType.Collection;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/search-request-builder/types.ts"],"names":[],"mappings":";;;AAwIA,0CAEC;AAED,kDAIC;AAED,4CAEC;AAED,oDAEC;AAxJD,kDAQ4B;AAEf,QAAA,qBAAqB,GAAG;IACnC,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAGE,QAAA,yBAAyB,GAAG;IACvC,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;CACZ,CAAC;AAoHX,wCAAwC;AACxC,SAAgB,eAAe,CAAC,OAAqC;IACnE,OAAO,YAAY,IAAI,OAAO,CAAC;AACjC,CAAC;AAED,SAAgB,mBAAmB,CACjC,OAAqC;IAErC,OAAO,kBAAkB,IAAI,OAAO,CAAC;AACvC,CAAC;AAED,SAAgB,gBAAgB,CAAC,QAAmB;IAClD,OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,wBAAY,CAAC,MAAM,CAAC;AAChD,CAAC;AAED,SAAgB,oBAAoB,CAAC,QAAmB;IACtD,OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,wBAAY,CAAC,UAAU,CAAC;AACpD,CAAC","sourcesContent":["import {\n type BoostGrouping,\n type Boosting,\n type BoostSorting,\n type Curation,\n CurationType,\n type Relevance,\n type SearchableField,\n} from \"../types/firestore\";\n\nexport const BaseSearchRequestMode = {\n Relevance: \"relevance\",\n Weighted: \"weighted\",\n} as const;\nexport type BaseSearchRequestMode = (typeof BaseSearchRequestMode)[keyof typeof BaseSearchRequestMode];\n\nexport const CurationSearchRequestMode = {\n Boosted: \"boosted\",\n Weighted: \"weighted\",\n} as const;\nexport type CurationSearchRequestMode = (typeof CurationSearchRequestMode)[keyof typeof CurationSearchRequestMode];\n\nexport interface SearchRequestModes {\n baseSearchRequestMode: BaseSearchRequestMode;\n curationSearchRequestMode: CurationSearchRequestMode;\n}\n\n// Base options shared by all search request types\nexport interface GenerateSearchRequestBaseOptions {\n relevanceFields?: Relevance[];\n searchableFields?: SearchableField[];\n market?: string;\n baseSearchRequestMode: BaseSearchRequestMode;\n curationSearchRequestMode: CurationSearchRequestMode;\n}\n\n// Search-specific options\nexport interface GenerateSearchRequestSearchOptions extends GenerateSearchRequestBaseOptions {\n searchTerm: string;\n curation?: SearchCuration;\n}\n\n// Collection-specific options\nexport interface GenerateSearchRequestCollectionOptions extends GenerateSearchRequestBaseOptions {\n collectionHandle: string;\n curation?: CollectionCuration;\n}\n\n// Union type for the main interface\nexport type GenerateSearchRequestOptions = GenerateSearchRequestSearchOptions | GenerateSearchRequestCollectionOptions;\n\n// Refined curation types with better type safety\nexport interface SearchCuration extends Curation {\n type: CurationType.Search;\n searchTerm: string;\n}\n\nexport interface CollectionCuration extends Curation {\n type: CurationType.Collection;\n collectionHandle: string;\n}\n\nexport interface CurationRules {\n boostingRules: Boosting[];\n groupings: BoostGrouping[];\n sortings: BoostSorting[];\n}\n\nexport interface TermSearchRequestOptions {\n searchTerm: string;\n baseSearchRequestMode: BaseSearchRequestMode;\n relevanceFields?: Relevance[];\n searchableFields?: SearchableField[];\n markets: string[];\n}\n\nexport interface CollectionSearchRequestOptions {\n collectionHandle: string;\n markets: string[];\n}\n\n// Elasticsearch/OpenSearch type aliases - using basic types to avoid external dependency\nexport interface SearchRequest {\n query?: QueryContainer;\n sort?: SortOptions;\n}\n\nexport interface QueryContainer {\n bool?: BoolQuery;\n function_score?: FunctionScoreQuery;\n multi_match?: MultiMatchQuery;\n match?: Record<string, any>;\n match_all?: Record<string, any>;\n term?: Record<string, any>;\n terms?: Record<string, string[]>;\n wildcard?: Record<string, string>;\n range?: Record<string, any>;\n nested?: NestedQuery;\n}\n\nexport interface BoolQuery {\n must?: QueryContainer | QueryContainer[];\n should?: QueryContainer[];\n must_not?: QueryContainer | QueryContainer[];\n filter?: QueryContainer[];\n minimum_should_match?: string | number;\n}\n\nexport interface FunctionScoreQuery {\n query: QueryContainer;\n functions: FunctionScoreContainer[];\n score_mode: FunctionScoreMode;\n boost_mode: FunctionBoostMode;\n}\n\nexport interface FunctionScoreContainer {\n filter: QueryContainer;\n weight: number;\n}\n\nexport interface MultiMatchQuery {\n query: string;\n fields: string[];\n type: \"cross_fields\" | \"phrase\" | \"phrase_prefix\";\n operator: \"and\" | \"or\";\n}\n\nexport interface NestedQuery {\n path: string;\n query: QueryContainer;\n}\n\nexport type SortOptions = Record<string, any>[] | Record<string, any>;\nexport type FunctionScoreMode = \"sum\" | \"multiply\" | \"avg\" | \"max\" | \"min\" | \"first\";\nexport type FunctionBoostMode = \"multiply\" | \"replace\" | \"sum\" | \"avg\" | \"max\" | \"min\";\n// Type guards for runtime type checking\nexport function isSearchOptions(options: GenerateSearchRequestOptions): options is GenerateSearchRequestSearchOptions {\n return \"searchTerm\" in options;\n}\n\nexport function isCollectionOptions(\n options: GenerateSearchRequestOptions\n): options is GenerateSearchRequestCollectionOptions {\n return \"collectionHandle\" in options;\n}\n\nexport function isSearchCuration(curation?: Curation): curation is SearchCuration {\n return curation?.type === CurationType.Search;\n}\n\nexport function isCollectionCuration(curation?: Curation): curation is CollectionCuration {\n return curation?.type === CurationType.Collection;\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type FunctionScoreContainer, type QueryContainer, type TermSearchRequestOptions } from "./types";
|
|
2
|
+
import { type Boosting, type Relevance } from "../types/firestore";
|
|
3
|
+
export declare function generateQueryField(options: {
|
|
4
|
+
fieldName: string;
|
|
5
|
+
market?: string;
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function generateMarketsFilter(markets: string[]): QueryContainer[];
|
|
8
|
+
export declare function generateMarketsClause(markets: string[]): QueryContainer | null;
|
|
9
|
+
export declare function generateBoostingRule(options: {
|
|
10
|
+
boostingRule: Boosting;
|
|
11
|
+
market?: string;
|
|
12
|
+
}): FunctionScoreContainer;
|
|
13
|
+
export declare function generateBoostingRules(options: {
|
|
14
|
+
boostingRules: Boosting[];
|
|
15
|
+
market?: string;
|
|
16
|
+
}): FunctionScoreContainer[];
|
|
17
|
+
export declare function validateSearchInputs(options: TermSearchRequestOptions): void;
|
|
18
|
+
export declare function prepareRelevanceFields(relevanceFields?: Relevance[]): {
|
|
19
|
+
crossFields: string[];
|
|
20
|
+
phrase: string[];
|
|
21
|
+
phrasePrefix: string[];
|
|
22
|
+
};
|
|
23
|
+
export declare function generateMultiMatchQueries(searchTerm: string, fieldMappings: {
|
|
24
|
+
crossFields: string[];
|
|
25
|
+
phrase: string[];
|
|
26
|
+
phrasePrefix: string[];
|
|
27
|
+
}): QueryContainer[];
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateQueryField = generateQueryField;
|
|
4
|
+
exports.generateMarketsFilter = generateMarketsFilter;
|
|
5
|
+
exports.generateMarketsClause = generateMarketsClause;
|
|
6
|
+
exports.generateBoostingRule = generateBoostingRule;
|
|
7
|
+
exports.generateBoostingRules = generateBoostingRules;
|
|
8
|
+
exports.validateSearchInputs = validateSearchInputs;
|
|
9
|
+
exports.prepareRelevanceFields = prepareRelevanceFields;
|
|
10
|
+
exports.generateMultiMatchQueries = generateMultiMatchQueries;
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
const firestore_1 = require("../types/firestore");
|
|
13
|
+
// Field and market utilities
|
|
14
|
+
function generateQueryField(options) {
|
|
15
|
+
if (!options.market) {
|
|
16
|
+
if (options.fieldName === "price")
|
|
17
|
+
return "price_min";
|
|
18
|
+
return options.fieldName;
|
|
19
|
+
}
|
|
20
|
+
if (options.fieldName === "price") {
|
|
21
|
+
return `price_min_market_${options.market}`;
|
|
22
|
+
}
|
|
23
|
+
if (options.fieldName === "price_min") {
|
|
24
|
+
return `price_min_market_${options.market}`;
|
|
25
|
+
}
|
|
26
|
+
if (options.fieldName === "price_max") {
|
|
27
|
+
return `price_max_market_${options.market}`;
|
|
28
|
+
}
|
|
29
|
+
if (options.fieldName === "inventory_total") {
|
|
30
|
+
return `inventory_quantity_market_${options.market}`;
|
|
31
|
+
}
|
|
32
|
+
return options.fieldName;
|
|
33
|
+
}
|
|
34
|
+
function generateMarketsFilter(markets) {
|
|
35
|
+
if (!(markets === null || markets === void 0 ? void 0 : markets.length))
|
|
36
|
+
return [];
|
|
37
|
+
return [{ terms: { markets: markets } }];
|
|
38
|
+
}
|
|
39
|
+
function generateMarketsClause(markets) {
|
|
40
|
+
if (!markets.length)
|
|
41
|
+
return null;
|
|
42
|
+
return { terms: { markets: markets } };
|
|
43
|
+
}
|
|
44
|
+
// Boosting utilities
|
|
45
|
+
function generateBoostingRule(options) {
|
|
46
|
+
const fieldName = generateQueryField({ fieldName: options.boostingRule.fieldName, market: options.market });
|
|
47
|
+
if (options.boostingRule.operation === firestore_1.Operation.Contains) {
|
|
48
|
+
return {
|
|
49
|
+
filter: { wildcard: { [fieldName]: `*${options.boostingRule.value}*` } },
|
|
50
|
+
weight: options.boostingRule.points,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (options.boostingRule.operation === firestore_1.Operation.NotContains) {
|
|
54
|
+
return {
|
|
55
|
+
filter: { bool: { must_not: { wildcard: { [fieldName]: `*${options.boostingRule.value}*` } } } },
|
|
56
|
+
weight: options.boostingRule.points,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (options.boostingRule.operation === firestore_1.Operation.Equals) {
|
|
60
|
+
return {
|
|
61
|
+
filter: { term: { [fieldName]: options.boostingRule.value } },
|
|
62
|
+
weight: options.boostingRule.points,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (options.boostingRule.operation === firestore_1.Operation.GreaterThan) {
|
|
66
|
+
return {
|
|
67
|
+
filter: { range: { [fieldName]: { gt: parseFloat(options.boostingRule.value) } } },
|
|
68
|
+
weight: options.boostingRule.points,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (options.boostingRule.operation === firestore_1.Operation.LessThan) {
|
|
72
|
+
return {
|
|
73
|
+
filter: { range: { [fieldName]: { lt: parseFloat(options.boostingRule.value) } } },
|
|
74
|
+
weight: options.boostingRule.points,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Unable to process rule`);
|
|
78
|
+
}
|
|
79
|
+
function generateBoostingRules(options) {
|
|
80
|
+
return options.boostingRules
|
|
81
|
+
.map((boostingRule) => generateBoostingRule({ boostingRule: boostingRule, market: options.market }))
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
}
|
|
84
|
+
// Validation
|
|
85
|
+
function validateSearchInputs(options) {
|
|
86
|
+
var _a, _b, _c;
|
|
87
|
+
if (!((_a = options.searchTerm) === null || _a === void 0 ? void 0 : _a.trim())) {
|
|
88
|
+
throw new Error("Search term is required");
|
|
89
|
+
}
|
|
90
|
+
if (options.baseSearchRequestMode === types_1.BaseSearchRequestMode.Weighted && !((_b = options.searchableFields) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
91
|
+
throw new Error("SearchableFields required for weighted search");
|
|
92
|
+
}
|
|
93
|
+
if (options.baseSearchRequestMode === types_1.BaseSearchRequestMode.Relevance && !((_c = options.relevanceFields) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
94
|
+
throw new Error("RelevanceFields required for relevance search");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Relevance field utilities
|
|
98
|
+
function prepareRelevanceFields(relevanceFields) {
|
|
99
|
+
if (!relevanceFields)
|
|
100
|
+
return { crossFields: [], phrase: [], phrasePrefix: [] };
|
|
101
|
+
const enabledFields = relevanceFields.filter((field) => field.enabled);
|
|
102
|
+
return {
|
|
103
|
+
crossFields: enabledFields.map((field) => `${field.field}^${field.importance}`),
|
|
104
|
+
phrase: enabledFields.map((field) => `${field.field}^${field.importance}`),
|
|
105
|
+
phrasePrefix: enabledFields
|
|
106
|
+
.filter((field) => !field.field.includes("."))
|
|
107
|
+
.map((field) => `${field.field}^${field.importance}`),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function generateMultiMatchQueries(searchTerm, fieldMappings) {
|
|
111
|
+
const queries = [];
|
|
112
|
+
if (fieldMappings.crossFields.length > 0) {
|
|
113
|
+
queries.push({
|
|
114
|
+
multi_match: {
|
|
115
|
+
query: searchTerm,
|
|
116
|
+
fields: fieldMappings.crossFields,
|
|
117
|
+
type: "cross_fields",
|
|
118
|
+
operator: "and",
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (fieldMappings.phrase.length > 0) {
|
|
123
|
+
queries.push({
|
|
124
|
+
multi_match: {
|
|
125
|
+
query: searchTerm,
|
|
126
|
+
fields: fieldMappings.phrase,
|
|
127
|
+
type: "phrase",
|
|
128
|
+
operator: "and",
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (fieldMappings.phrasePrefix.length > 0) {
|
|
133
|
+
queries.push({
|
|
134
|
+
multi_match: {
|
|
135
|
+
query: searchTerm,
|
|
136
|
+
fields: fieldMappings.phrasePrefix,
|
|
137
|
+
type: "phrase_prefix",
|
|
138
|
+
operator: "and",
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return queries;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot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AAC,IAAI,CAAC;YACX,WAAW,EAAE;gBACX,KAAK,EAAE,UAAU;gBACjB,MAAM,EAAE,aAAa,CAAC,WAAW;gBACjC,IAAI,EAAE,cAAuB;gBAC7B,QAAQ,EAAE,KAAc;aACzB;SACF,CAAC,CAAC;IACL,CAAC;IAED,IAAI,aAAa,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC;YACX,WAAW,EAAE;gBACX,KAAK,EAAE,UAAU;gBACjB,MAAM,EAAE,aAAa,CAAC,MAAM;gBAC5B,IAAI,EAAE,QAAiB;gBACvB,QAAQ,EAAE,KAAc;aACzB;SACF,CAAC,CAAC;IACL,CAAC;IAED,IAAI,aAAa,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1C,OAAO,CAAC,IAAI,CAAC;YACX,WAAW,EAAE;gBACX,KAAK,EAAE,UAAU;gBACjB,MAAM,EAAE,aAAa,CAAC,YAAY;gBAClC,IAAI,EAAE,eAAwB;gBAC9B,QAAQ,EAAE,KAAc;aACzB;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import {\n BaseSearchRequestMode,\n type FunctionScoreContainer,\n type QueryContainer,\n type TermSearchRequestOptions,\n} from \"./types\";\nimport { type Boosting, Operation, type Relevance } from \"../types/firestore\";\n\n// Field and market utilities\nexport function generateQueryField(options: { fieldName: string; market?: string }) {\n if (!options.market) {\n if (options.fieldName === \"price\") return \"price_min\";\n return options.fieldName;\n }\n\n if (options.fieldName === \"price\") {\n return `price_min_market_${options.market}`;\n }\n if (options.fieldName === \"price_min\") {\n return `price_min_market_${options.market}`;\n }\n if (options.fieldName === \"price_max\") {\n return `price_max_market_${options.market}`;\n }\n if (options.fieldName === \"inventory_total\") {\n return `inventory_quantity_market_${options.market}`;\n }\n\n return options.fieldName;\n}\n\nexport function generateMarketsFilter(markets: string[]): QueryContainer[] {\n if (!markets?.length) return [];\n return [{ terms: { markets: markets } }];\n}\n\nexport function generateMarketsClause(markets: string[]): QueryContainer | null {\n if (!markets.length) return null;\n return { terms: { markets: markets } };\n}\n\n// Boosting utilities\nexport function generateBoostingRule(options: { boostingRule: Boosting; market?: string }): FunctionScoreContainer {\n const fieldName = generateQueryField({ fieldName: options.boostingRule.fieldName, market: options.market });\n\n if (options.boostingRule.operation === Operation.Contains) {\n return {\n filter: { wildcard: { [fieldName]: `*${options.boostingRule.value}*` } },\n weight: options.boostingRule.points,\n };\n }\n if (options.boostingRule.operation === Operation.NotContains) {\n return {\n filter: { bool: { must_not: { wildcard: { [fieldName]: `*${options.boostingRule.value}*` } } } },\n weight: options.boostingRule.points,\n };\n }\n if (options.boostingRule.operation === Operation.Equals) {\n return {\n filter: { term: { [fieldName]: options.boostingRule.value } },\n weight: options.boostingRule.points,\n };\n }\n if (options.boostingRule.operation === Operation.GreaterThan) {\n return {\n filter: { range: { [fieldName]: { gt: parseFloat(options.boostingRule.value) } } },\n weight: options.boostingRule.points,\n };\n }\n if (options.boostingRule.operation === Operation.LessThan) {\n return {\n filter: { range: { [fieldName]: { lt: parseFloat(options.boostingRule.value) } } },\n weight: options.boostingRule.points,\n };\n }\n throw new Error(`Unable to process rule`);\n}\n\nexport function generateBoostingRules(options: {\n boostingRules: Boosting[];\n market?: string;\n}): FunctionScoreContainer[] {\n return options.boostingRules\n .map((boostingRule) => generateBoostingRule({ boostingRule: boostingRule, market: options.market }))\n .filter(Boolean);\n}\n\n// Validation\nexport function validateSearchInputs(options: TermSearchRequestOptions) {\n if (!options.searchTerm?.trim()) {\n throw new Error(\"Search term is required\");\n }\n\n if (options.baseSearchRequestMode === BaseSearchRequestMode.Weighted && !options.searchableFields?.length) {\n throw new Error(\"SearchableFields required for weighted search\");\n }\n\n if (options.baseSearchRequestMode === BaseSearchRequestMode.Relevance && !options.relevanceFields?.length) {\n throw new Error(\"RelevanceFields required for relevance search\");\n }\n}\n\n// Relevance field utilities\nexport function prepareRelevanceFields(relevanceFields?: Relevance[]) {\n if (!relevanceFields) return { crossFields: [], phrase: [], phrasePrefix: [] };\n\n const enabledFields = relevanceFields.filter((field) => field.enabled);\n\n return {\n crossFields: enabledFields.map((field) => `${field.field}^${field.importance}`),\n phrase: enabledFields.map((field) => `${field.field}^${field.importance}`),\n phrasePrefix: enabledFields\n .filter((field) => !field.field.includes(\".\"))\n .map((field) => `${field.field}^${field.importance}`),\n };\n}\n\nexport function generateMultiMatchQueries(\n searchTerm: string,\n fieldMappings: { crossFields: string[]; phrase: string[]; phrasePrefix: string[] }\n): QueryContainer[] {\n const queries = [];\n\n if (fieldMappings.crossFields.length > 0) {\n queries.push({\n multi_match: {\n query: searchTerm,\n fields: fieldMappings.crossFields,\n type: \"cross_fields\" as const,\n operator: \"and\" as const,\n },\n });\n }\n\n if (fieldMappings.phrase.length > 0) {\n queries.push({\n multi_match: {\n query: searchTerm,\n fields: fieldMappings.phrase,\n type: \"phrase\" as const,\n operator: \"and\" as const,\n },\n });\n }\n\n if (fieldMappings.phrasePrefix.length > 0) {\n queries.push({\n multi_match: {\n query: searchTerm,\n fields: fieldMappings.phrasePrefix,\n type: \"phrase_prefix\" as const,\n operator: \"and\" as const,\n },\n });\n }\n\n return queries;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Antonym, Callout, Curation, FilterFacet, FilterGroup, Market, MerchandisingCalloutAutofillBehaviour, Redirect, Relevance, SearchableField, Sort, Synonym } from "./firestore";
|
|
1
|
+
import type { Antonym, Callout, Curation, FilterFacet, FilterGroup, Market, MerchandisingCalloutAutofillBehaviour, Redirect, Relevance, SearchableField, Sort, Synonym } from "./firestore";
|
|
2
2
|
export type Config = {
|
|
3
3
|
index: string;
|
|
4
4
|
endpoint: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/types/config.ts"],"names":[],"mappings":"","sourcesContent":["import {\n Antonym,\n Callout,\n Curation,\n FilterFacet,\n FilterGroup,\n Market,\n MerchandisingCalloutAutofillBehaviour,\n Redirect,\n Relevance,\n SearchableField,\n Sort,\n Synonym,\n} from \"./firestore\";\n\n// when exposed as config, most resources have the `enabled` and `keywords` attributes removed\n// curation boosting groupings and sortings both have a json encoded elastic query added to them\n\nexport type Config = {\n index: string;\n endpoint: string;\n cluster: string;\n version: string;\n key: string;\n cache: {\n enabled: boolean;\n seconds: number;\n };\n merchandising: {\n calloutAutofillBehaviour: MerchandisingCalloutAutofillBehaviour;\n };\n sort: Array<ConfigSort>;\n fields: Array<ConfigField>;\n searchableFields: Array<ConfigSeachableField>;\n filters: Array<ConfigFilter>;\n redirects: Array<ConfigRedirect>;\n curations: Array<ConfigCuration>;\n antonyms: Array<ConfigAntonym>;\n synonyms: Array<ConfigSynonym>;\n callouts: Array<ConfigCallout>;\n markets: Array<Market>;\n suggestions: {\n exclude: Array<string>;\n };\n sensors: {\n search: Array<unknown>;\n collection: Array<unknown>;\n };\n featureFlags: string[];\n};\n\nexport type ConfigAntonym = Omit<Antonym, \"enabled\">;\nexport type ConfigSynonym = Omit<Synonym, \"enabled\">;\nexport type ConfigCallout = Omit<Callout, \"enabled\">;\nexport type ConfigSort = Omit<Sort, \"enabled\">;\nexport type ConfigField = Omit<Relevance, \"enabled\">;\nexport type ConfigSeachableField = Omit<SearchableField, \"enabled\">;\nexport type ConfigRedirect = Omit<Redirect, \"enabled\" | \"keywords\">;\nexport type ConfigFilter = Omit<FilterGroup, \"enabled\" | \"keywords\"> & {\n options: Omit<FilterFacet, \"enabled\">[];\n};\nexport type ConfigFilterFacet = Omit<FilterFacet, \"enabled\">;\nexport type ConfigCuration = Omit
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/types/config.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Antonym,\n Callout,\n Curation,\n FilterFacet,\n FilterGroup,\n Market,\n MerchandisingCalloutAutofillBehaviour,\n Redirect,\n Relevance,\n SearchableField,\n Sort,\n Synonym,\n} from \"./firestore\";\n\n// when exposed as config, most resources have the `enabled` and `keywords` attributes removed\n// curation boosting groupings and sortings both have a json encoded elastic query added to them\n\nexport type Config = {\n index: string;\n endpoint: string;\n cluster: string;\n version: string;\n key: string;\n cache: {\n enabled: boolean;\n seconds: number;\n };\n merchandising: {\n calloutAutofillBehaviour: MerchandisingCalloutAutofillBehaviour;\n };\n sort: Array<ConfigSort>;\n fields: Array<ConfigField>;\n searchableFields: Array<ConfigSeachableField>;\n filters: Array<ConfigFilter>;\n redirects: Array<ConfigRedirect>;\n curations: Array<ConfigCuration>;\n antonyms: Array<ConfigAntonym>;\n synonyms: Array<ConfigSynonym>;\n callouts: Array<ConfigCallout>;\n markets: Array<Market>;\n suggestions: {\n exclude: Array<string>;\n };\n sensors: {\n search: Array<unknown>;\n collection: Array<unknown>;\n };\n featureFlags: string[];\n};\n\nexport type ConfigAntonym = Omit<Antonym, \"enabled\">;\nexport type ConfigSynonym = Omit<Synonym, \"enabled\">;\nexport type ConfigCallout = Omit<Callout, \"enabled\">;\nexport type ConfigSort = Omit<Sort, \"enabled\">;\nexport type ConfigField = Omit<Relevance, \"enabled\">;\nexport type ConfigSeachableField = Omit<SearchableField, \"enabled\">;\nexport type ConfigRedirect = Omit<Redirect, \"enabled\" | \"keywords\">;\nexport type ConfigFilter = Omit<FilterGroup, \"enabled\" | \"keywords\"> & {\n options: Omit<FilterFacet, \"enabled\">[];\n};\nexport type ConfigFilterFacet = Omit<FilterFacet, \"enabled\">;\nexport type ConfigCuration = Omit<Curation, \"keywords\" | \"boosting\" | \"longRunningTask\" | \"callouts\"> & {\n boosting: {\n groupings: Array<NonNullable<NonNullable<Curation[\"boosting\"]>[\"groupings\"]>[0] & { query: string }>;\n sortings: Array<NonNullable<NonNullable<Curation[\"boosting\"]>[\"sortings\"]>[0] & { query: string }>;\n };\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Callout } from "./firestore";
|
|
2
|
-
import { Maybe,
|
|
1
|
+
import type { Callout } from "./firestore";
|
|
2
|
+
import type { Maybe, MetafieldValueType, ProductVariantInventoryPolicy } from "./graphql";
|
|
3
3
|
export declare enum ElasticDocumentType {
|
|
4
4
|
Callout = "callout",
|
|
5
5
|
Product = "product"
|
|
@@ -217,15 +217,12 @@ export type ElasticBulkOperationUpdate = [
|
|
|
217
217
|
doc_as_upsert?: true;
|
|
218
218
|
}
|
|
219
219
|
];
|
|
220
|
-
export type ElasticBulkOperationIndex = [
|
|
221
|
-
{
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
},
|
|
227
|
-
ElasticDocument
|
|
228
|
-
];
|
|
220
|
+
export type ElasticBulkOperationIndex = [{
|
|
221
|
+
index: {
|
|
222
|
+
_index: string;
|
|
223
|
+
_id: string;
|
|
224
|
+
};
|
|
225
|
+
}, ElasticDocument];
|
|
229
226
|
export type ElasticBulkOperation = ElasticBulkOperationUpdate | ElasticBulkOperationIndex;
|
|
230
227
|
export type ElasticSearchResult<T = ElasticDocument> = {
|
|
231
228
|
hits: {
|