"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function _indexer() {
  const data = require("./indexer");

  _indexer = function () {
    return data;
  };

  return data;
}

function _stopwords() {
  const data = _interopRequireDefault(require("./stopwords"));

  _stopwords = function () {
    return data;
  };

  return data;
}

const boost = {
  name: 5,
  tokenizedName: 4,
  stemmedName: 3,
  functionNames: 2,
  tokenizedFunctionNames: 2,
  minDescription: 1,
  stemmedMinDescription: 0.5
};

function queryItem(field, queryStr) {
  return {
    AND: {
      [field]: queryStr.toLowerCase().split(' ')
    },
    BOOST: boost[field]
  };
}

function buildQuery(queryStr) {
  const queryStrWithoutStopwords = queryStr.split(' ').filter(word => !_stopwords().default.includes(word)).join(' ');
  const tokenizedQuery = (0, _indexer().tokenizeStr)(queryStr);
  const query = [];
  query.push(queryItem('name', queryStr));
  query.push(queryItem('tokenizedName', tokenizedQuery));
  query.push(queryItem('stemmedName', (0, _indexer().stem)(tokenizedQuery)));
  query.push(queryItem('functionNames', queryStr));
  query.push(queryItem('tokenizedFunctionNames', tokenizedQuery));
  query.push(queryItem('minDescription', queryStrWithoutStopwords));
  query.push(queryItem('stemmedMinDescription', (0, _indexer().stem)(queryStrWithoutStopwords)));
  return query;
}

var _default = buildQuery;
exports.default = _default;