Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.2 kB
2
Indexable
Never
function mdm_elastic_query_output_controller(options) {
  var _this = JSON.parse(this) || {};
  var response = {};

  response.total = typeof _this.hits.total === 'object' ? _this.hits.total.value : _this.hits.total;
  response.hits = _this.hits.hits.reduce(function(acc, hit) {
    var _source = hit._source;

    var response = {
      uniquename : _source.id,
      id : _source.washi_id,
      tipo: _source.tipo,
      creation_date: _source.data_creazione,
      pubblication_date: _source.data_pubblicazione,
      title : _source.titolo,
      summary : _source.sommario,
      label : _source.etichetta,
      titoli_corpo: _source.livelli,
      sommari_corpo: _source.materie,
      corpo: _source.testo,
      image: _source.immagini['landscape'] || _source.immagini['default'],
      weblink: _source.siti && _source.siti[0] ? _source.siti[0].relative_url : undefined,
    };

    acc.push(response);

    return acc;
  }, []);

  return options.fn(response);
}

function mdm_elastic_query_input_controller(options) {
  var _this = JSON.parse(this) || {};
  var query = {};

  switch (_this.mode) {
    case 'archive':
      query = mdm_archive(_this);
      return options.fn(query);
    default:
      query = mdm_archive(_this);
      return options.fn(query);
  }
}

function mdm_archive(_this) {
  return {
    from: _this.from,
    size: _this.pageSize,
    query: {
      bool: {
        filter: [
          {
            term: {
                tipo: "articolo"
            }
          },
          {
            nested: {
              path: "siti",
              query: {
                term: {
                    "siti.nome": {
                    value: "m'illumino di meno"
                    }
                }
              }
            }
          }
        ]
      }
    },
    sort: [
      {
        data_pubblicazione: {
          order: "desc"
        }
      }
    ]
  };
}


Handlebars.registerHelper('controllers/mdm-elastic-query-input', mdm_elastic_query_input_controller);
Handlebars.registerHelper('controllers/mdm-elastic-query-output', mdm_elastic_query_output_controller);
Leave a Comment