@infrab4a/connect 3.9.0-beta.5 → 3.9.0-beta.7

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.
@@ -1899,38 +1899,61 @@
1899
1899
  });
1900
1900
  });
1901
1901
  };
1902
- ProductsIndex.prototype.search = function (searchTerm) {
1902
+ ProductsIndex.prototype.search = function (searchTerm, total, shop) {
1903
1903
  return __awaiter(this, void 0, void 0, function () {
1904
- var search;
1904
+ var size, fields, filter, search;
1905
1905
  return __generator(this, function (_a) {
1906
1906
  switch (_a.label) {
1907
- case 0: return [4 /*yield*/, this.adapter.query(this.index, {
1908
- query: {
1909
- bool: {
1910
- must: {
1911
- multi_match: {
1912
- query: "" + searchTerm,
1913
- fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
1914
- fuzziness: 2,
1915
- },
1916
- },
1917
- should: {
1918
- match_phrase_prefix: {
1919
- 'name.search': {
1907
+ case 0:
1908
+ size = total >= 10 ? 500 : 9;
1909
+ fields = [
1910
+ 'EAN',
1911
+ 'brand',
1912
+ 'id',
1913
+ 'images',
1914
+ 'miniatures',
1915
+ 'name',
1916
+ 'price',
1917
+ 'sku',
1918
+ 'stock',
1919
+ 'slug',
1920
+ 'reviews',
1921
+ 'hasVariants',
1922
+ 'rate',
1923
+ ];
1924
+ filter = [{ term: { published: true } }];
1925
+ if (size > 9) {
1926
+ fields.push.apply(fields, ['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
1927
+ }
1928
+ else {
1929
+ filter.push({ term: { tags: shop == exports.Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
1930
+ }
1931
+ return [4 /*yield*/, this.adapter.query(this.index, {
1932
+ size: size,
1933
+ _source: fields,
1934
+ query: {
1935
+ bool: {
1936
+ must: {
1937
+ multi_match: {
1920
1938
  query: "" + searchTerm,
1921
- slop: 10,
1939
+ fields: ['name', 'name.folded', 'name.search', 'description', 'brand'],
1940
+ fuzziness: 2,
1941
+ },
1942
+ },
1943
+ should: {
1944
+ match_phrase_prefix: {
1945
+ 'name.search': {
1946
+ query: "" + searchTerm,
1947
+ slop: 10,
1948
+ },
1922
1949
  },
1923
1950
  },
1951
+ filter: filter,
1924
1952
  },
1925
- filter: [{ term: { published: true } }],
1926
1953
  },
1927
- },
1928
- })];
1954
+ })];
1929
1955
  case 1:
1930
1956
  search = _a.sent();
1931
- search.hits.forEach(function (row) {
1932
- row._source.price = Object.assign(Object.assign({}, row._source.price), (!!row._source.price.Glamshop && row._source.price.Glamshop));
1933
- });
1934
1957
  search.hits = search.hits.filter(function (e) { return e._source.name !== ''; });
1935
1958
  return [2 /*return*/, search];
1936
1959
  }