<commit_before>import map from 'lodash-es/map'
import fetch from 'isomorphic-fetch'
import { slugify, processURLAddress } from '@vue-storefront/core/helpers'
import queryString from 'query-string'
import { currentStoreView, prepareStoreView } from '@vue-storefront/core/lib/multistore'
import { SearchQuery } from 'storefront-query-builder'
import HttpQuery from '@vue-storefront/core/types/search/HttpQuery'
import { SearchResponse } from '@vue-storefront/core/types/search/SearchResponse'
import config from 'config'
import getApiEndpointUrl from '@vue-storefront/core/helpers/getApiEndpointUrl';

export class SearchAdapter {
  public entities: any

  public constructor () {
    this.entities = []
    this.initBaseTypes()
  }

  protected decompactItem (item, fieldsToCompact) {
    for (let key in fieldsToCompact) {
      const value = fieldsToCompact[key]
      if (typeof item[value] !== 'undefined') {
        item[key] = item[value]
        delete item[value]
      }
    }
    return item
  }

  public async search (Request) {
    const rawQueryObject = Request.searchQuery
    if (!this.entities[Request.type]) {
      throw new Error('No entity type registered for ' + Request.type)
    }
    if (!(Request.searchQuery instanceof SearchQuery)) {
      throw new Error('The only supported type of the "Request.searchQuery" is "SearchQuery"')
    }
    if (Request.hasOwnProperty('groupId') && Request.groupId !== null) {
      rawQueryObject['groupId'] = Request.groupId
    }
    if (Request.hasOwnProperty('groupToken') && Request.groupToken !== null) {
      rawQueryObject['groupToken'] = Request.groupToken
    }
    const storeView = (Request.store === null) ? currentStoreView() : await prepareStoreView(Request.store)
    Request.index = storeView.elasticsearch.index

    let url = processURLAddress(getApiEndpointUrl(storeView.elasticsearch, 'host'))<commit_msg>Update `api-search-query` search-adapter to support new `storefront-query-builder` sorting<commit_after>import map from 'lodash-es/map'
import fetch from 'isomorphic-fetch'
import { slugify, processURLAddress } from '@vue-storefront/core/helpers'
import queryString from 'query-string'
import { currentStoreView, prepareStoreView } from '@vue-storefront/core/lib/multistore'
import { SearchQuery } from 'storefront-query-builder'
import HttpQuery from '@vue-storefront/core/types/search/HttpQuery'
import { SearchResponse } from '@vue-storefront/core/types/search/SearchResponse'
import config from 'config'
import getApiEndpointUrl from '@vue-storefront/core/helpers/getApiEndpointUrl';

export class SearchAdapter {
  public entities: any

  public constructor () {
    this.entities = []
    this.initBaseTypes()
  }

  protected decompactItem (item, fieldsToCompact) {
    for (let key in fieldsToCompact) {
      const value = fieldsToCompact[key]
      if (typeof item[value] !== 'undefined') {
        item[key] = item[value]
        delete item[value]
      }
    }
    return item
  }

  public async search (Request) {
    const rawQueryObject = Request.searchQuery
    if (!this.entities[Request.type]) {
      throw new Error('No entity type registered for ' + Request.type)
    }
    if (!(Request.searchQuery instanceof SearchQuery)) {
      throw new Error('The only supported type of the "Request.searchQuery" is "SearchQuery"')
    }
    if (Request.hasOwnProperty('groupId') && Request.groupId !== null) {
      rawQueryObject['groupId'] = Request.groupId
    }
    if (Request.hasOwnProperty('groupToken') && Request.groupToken !== null) {
      rawQueryObject['groupToken'] = Request.groupToken
    }
    if (Request.sort) {
      const [ field, options ] = Request.sort.split(':')
      rawQueryObject.applySort({ field, options })
      delete Request.sort
    }
    const storeView = (Request.store === null) ? currentStoreView() : await prepareStoreView(Request.store)
    Request.index = storeView.elasticsearch.index

    let url = processURLAddress(getApiEndpointUrl(storeView.elasticsearch, 'host'))
{'fraction_non_alphanumeric': 0.11512584101669573, 'fraction_numerical': 0.0, 'mean_word_length': 4.049056603773585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5214231', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1128, 'n_words': 279}