<commit_before><link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel='import' href='../mustache.html'>
<link rel='import' href='../lodash.html'>

<script>
(function() {
  'use strict';
  Polymer({
    is: 'query-builder',

    properties: {
      /**
       * The elastic search query which this element builds
       */
      query: {
        type: Object,
        notify: true,
        readOnly: true
      },

      /**
       * The query template object passed in from the config.
       */
      queryTemplate: {
        type: Object,
        notify: true
      },

      /**
       * The elasticsearch field on which to perform query
       */
      field: {
        type: String,
        notify: true

      }, 

      /**
       * The value of the elasticsearch field
       */
      value: {
        type: Object,
        notify: true
      },


      /**
       * Alternatively, you can provide the path to the queryTemplate value that needs to be changed
       */
      pathToValue: {
        type: String,
        notify: true
      }


    },
    observers: [
      'buildElasticQuery(queryTemplate, field, value)',
      'buildElasticQuery(queryTemplate, pathToValue, value)'
    ],

    /**
     * Build a query from query string parameters and a query template
     */
    buildElasticQuery: function() {
      /* globals Mustache, _ */

      var query = {};
      if(this.field) {
          var view = {
            field: this.field,
            value: encodeURIComponent(this.value)
          };
          
          query = JSON.parse(decodeURIComponent(Mustache.render(JSON.stringify(this.queryTemplate), view)));
          this._setQuery(query);
        
      } else if(this.pathToValue) {
          _.set(this.queryTemplate, this.pathToValue, this.value);
          this._setQuery(this.queryTemplate);
      }
    }

  });
})();
</script>
<commit_msg>Splitting up build query function into two functions.<commit_after><link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel='import' href='../mustache.html'>
<link rel='import' href='../lodash.html'>

<script>
(function() {
  'use strict';
  Polymer({
    is: 'query-builder',

    properties: {
      /**
       * The elastic search query which this element builds
       */
      query: {
        type: Object,
        notify: true,
        readOnly: true
      },

      /**
       * The query template object passed in from the config.
       */
      queryTemplate: {
        type: Object,
        notify: true
      },

      /**
       * The elasticsearch field on which to perform query
       */
      field: {
        type: String,
        notify: true

      }, 

      /**
       * The value of the elasticsearch field
       */
      value: {
        type: Object,
        notify: true
      },


      /**
       * Alternatively, you can provide the path to the queryTemplate value that needs to be changed
       */
      pathToValue: {
        type: String,
        notify: true
      }


    },
    observers: [
      'buildElasticQueryWithField(queryTemplate, field, value)',
      'buildElasticQueryWithPath(queryTemplate, pathToValue, value)'
    ],

    /**
     * Build a query from query string parameters and a query template
     */
    buildElasticQueryWithField: function() {
      /* globals Mustache */

      var query = {};
      var view = {
        field: this.field,
        value: encodeURIComponent(this.value)
      };
      
      query = JSON.parse(decodeURIComponent(Mustache.render(JSON.stringify(this.queryTemplate), view)));
      this._setQuery(query);
      
    },
    buildElasticQueryWithPath: function() {
      /* globals _ */

      _.set(this.queryTemplate, this.pathToValue, this.value);
      this._setQuery(this.queryTemplate);
    }


  });
})();
</script>

{'fraction_non_alphanumeric': 0.12184326998177558, 'fraction_numerical': 0.0, 'mean_word_length': 1.860759493670886, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2226009', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1065, 'n_words': 271}