{"size": 1522, "ext": "js", "max_stars_repo_path": "core/lib/search/adapter/api/elasticsearch/multimatch.js", "max_stars_repo_name": "magumbo/vue-storefront", "max_stars_repo_stars_event_min_datetime": "2019-09-23T07:12:56.000Z", "max_stars_repo_stars_event_max_datetime": "2020-06-12T02:50:23.000Z", "max_issues_repo_path": "core/lib/search/adapter/api/elasticsearch/multimatch.js", "max_issues_repo_name": "magumbo/vue-storefront", "max_issues_repo_issues_event_min_datetime": "2021-04-28T01:01:58.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-17T01:02:44.000Z", "max_forks_repo_path": "core/lib/search/adapter/api/elasticsearch/multimatch.js", "max_forks_repo_name": "magumbo/vue-storefront", "max_forks_repo_forks_event_min_datetime": "2019-12-01T15:46:16.000Z", "max_forks_repo_forks_event_max_datetime": "2020-04-14T22:05:49.000Z"}
{"max_stars_count": 3, "max_issues_count": 59, "max_forks_count": 5, "avg_line_length": 47.5625, "max_line_length": 131, "alphanum_fraction": 0.7562417871}
import config from 'config'

export default function getMultiMatchConfig (queryText) {
  return getConfig(queryText)
}

function getConfig (queryText) {
  let scoringConfig = config.elasticsearch.hasOwnProperty('searchScoring') ? config.elasticsearch.searchScoring : {}
  let minimumShouldMatch = ''
  if (config.elasticsearch.queryMethod === 'GET') {
    // minimum_should_match param must be have a "%" suffix, which is an illegal char while sending over query string
    minimumShouldMatch = scoringConfig.hasOwnProperty('minimum_should_match') ? scoringConfig.minimum_should_match + '25' : '75%25'
  } else {
    minimumShouldMatch = scoringConfig.hasOwnProperty('minimum_should_match') ? scoringConfig.minimum_should_match : '75%'
  }
  // Create config for multi match query
  let multiMatchConfig = {
    'query': queryText,
    'operator': scoringConfig.operator ? scoringConfig.operator : 'or',
    'fuzziness': scoringConfig.fuzziness ? scoringConfig.fuzziness : '2',
    'cutoff_frequency': scoringConfig.cutoff_frequency ? scoringConfig.cutoff_frequency : '0.01',
    'max_expansions': scoringConfig.max_expansions ? scoringConfig.max_expansions : '3',
    'prefix_length': scoringConfig.prefix_length ? scoringConfig.prefix_length : '1',
    'minimum_should_match': minimumShouldMatch,
    'tie_breaker': scoringConfig.tie_breaker ? scoringConfig.tie_breaker : '1'
  }
  if (scoringConfig.hasOwnProperty('analyzer')) {
    multiMatchConfig['analyzer'] = scoringConfig.analyzer
  }
  return multiMatchConfig
}
