(function (jIO, RSVP, elasticlunr) {
  "use strict";
  
(function (jIO, RSVP) {
  
  function ElasticlunrStorage(spec) {
    var that = this, i;
    that._index = elasticlunr(function () {
      for (i = 0; i < spec.keys.length; i++) {
        this.addField(spec.keys[i]);
      }
    this.setRef('id')
    });
  }
  
  ElasticlunrStorage.prototype.put = function (id, metadata) {
    var that = this;
    metadata['id'] = id;
    that._index.addDoc(metadata);
  };
  
  ElasticlunrStorage.prototype.get = function (id) {
    var that = this;
    return that._index.search(id);
  };
  
  ElasticlunrStorage.prototype.buildQuery = function (query) {
    var that = this;
    var docstore_dict = that._index.toJSON().documentStore.docs;
    console.log(docstore_dict)
    return Object.keys(docstore_dict).map(function(key){
    return docstore_dict[key]});
  };
  
  ElasticlunrStorage.prototype.hasCapacity = function (name) {
    return (name === "list");
  };

  jIO.addStorage('ElasticlunrStorage', ElasticlunrStorage);

}(jIO, RSVP));

}(jIO, RSVP, elasticlunr));