/*! elastic.js - v1.0.0 - 2013-01-15 * https://github.com/fullscale/elastic.js * Copyright (c) 2013 FullScale Labs, LLC; Licensed MIT */ (function(){"use strict";var e=this,t=e&&e.ejs,n=Array.prototype,r=Object.prototype,i=n.slice,s=r.toString,o=r.hasOwnProperty,u=n.forEach,a=Array.isArray,f={},l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L;typeof exports!="undefined"?L=exports:L=e.ejs={},l=function(e,t){return o.call(e,t)},c=function(e,t,n){if(e==null)return;if(u&&e.forEach===u)e.forEach(t,n);else if(e.length===+e.length){for(var r=0,i=e.length;r0&&(n=["_all"]),e.routing!=null?i=e.routing:i="",{sort:function(){var e,n;l(t,"sort")||(t.sort=[]);if(arguments.length===0)return t.sort;if(arguments.length===1){var r=arguments[0];if(v(r))t.sort.push(r);else if(C(r))t.sort.push(r._self());else{if(!p(r))throw new TypeError("Argument must be string, Sort, or array");t.sort=[];for(e=0,n=r.length;e0&&(n=["_all"]),this},types:function(e){if(e==null)return r;if(v(e))r=[e];else{if(!p(e))throw new TypeError("Argument must be a string or array");r=e}return n.length===0&&r.length>0&&(n=["_all"]),this},facet:function(e){if(e==null)return t.facets;t.facets==null&&(t.facets={});if(!E(e))throw new TypeError("Argument must be a Facet");return h(t.facets,e._self()),this},filter:function(e){if(e==null)return t.filter;if(!w(e))throw new TypeError("Argument must be a Filter");return t.filter=e._self(),this},highlight:function(e){if(e==null)return t.highlight;if(!k(e))throw new TypeError("Argument must be a Highlight object");return t.highlight=e._self(),this},scriptField:function(e){if(e==null)return t.script_fields;t.script_fields==null&&(t.script_fields={});if(!S(e))throw new TypeError("Argument must be a ScriptField");return h(t.script_fields,e._self()),this},preference:function(e){return e==null?t.preference:(t.preference=e,this)},indexBoost:function(e,n){return t.indices_boost==null&&(t.indices_boost={}),arguments.length===0?t.indices_boost:(t.indices_boost[e]=n,this)},explain:function(e){return e==null?t.explain:(t.explain=e,this)},version:function(e){return e==null?t.version:(t.version=e,this)},minScore:function(e){return e==null?t.min_score:(t.min_score=e,this)},toString:function(){return JSON.stringify(t)},_type:function(){return"request"},_self:function(){return t},doSearch:function(e){var s=JSON.stringify(t),o="";if(L.client==null)throw new Error("No Client Set");return n.length>0&&(o=o+"/"+n.join()),r.length>0&&(o=o+"/"+r.join()),o+="/_search",i!==""&&(o=o+"?routing="+encodeURIComponent(i)),L.client.post(o,s,e)}}},L.ScriptField=function(e){var t={};return t[e]={},{lang:function(n){return n==null?t[e].lang:(t[e].lang=n,this)},script:function(n){return n==null?t[e].script:(t[e].script=n,this)},params:function(n){return n==null?t[e].params:(t[e].params=n,this)},toString:function(){return JSON.stringify(t)},_type:function(){return"script field"},_self:function(){return t}}},L.Shape=function(e,t){var n={},r=function(e){var t=!1;if(e==="point"||e==="linestring"||e==="polygon"||e==="multipoint"||e==="envelope"||e==="multipolygon")t=!0;return t};return e=e.toLowerCase(),r(e)&&(n.type=e,n.coordinates=t),{type:function(e){return e==null?n.type:(e=e.toLowerCase(),r(e)&&(n.type=e),this)},coordinates:function(e){return e==null?n.coordinates:(n.coordinates=e,this)},toString:function(){return JSON.stringify(n)},_type:function(){return"shape"},_self:function(){return n}}},L.Sort=function(e){e==null&&(e="_score");var t={},n=e,r="_geo_distance",i="_script";return t[n]={},{field:function(r){var i=t[n];return r==null?e:(delete t[n],e=r,n=r,t[n]=i,this)},geoDistance:function(i){var s=t[n];if(i==null)return t[n][e];if(!x(i))throw new TypeError("Argument must be a GeoPoint");return delete t[n],n=r,t[n]=s,t[n][e]=i._self(),this},script:function(e){var r=t[n];return e==null?t[n].script:(delete t[n],n=i,t[n]=r,t[n].script=e,this)},order:function(e){if(e==null)return t[n].order;e=e.toLowerCase();if(e==="asc"||e==="desc")t[n].order=e;return this},asc:function(){return t[n].order="asc",this},desc:function(){return t[n].order="desc",this},reverse:function(e){return e==null?t[n].reverse:(t[n].reverse=e,this)},missing:function(e){return e==null?t[n].missing:(t[n].missing=e,this)},ignoreUnmapped:function(e){return e==null?t[n].ignore_unmapped:(t[n].ignore_unmapped=e,this)},unit:function(e){if(e==null)return t[n].unit;e=e.toLowerCase();if(e==="mi"||e==="km")t[n].unit=e;return this},normalize:function(e){return e==null?t[n].normalize:(t[n].normalize=e,this)},distanceType:function(e){if(e==null)return t[n].distance_type;e=e.toLowerCase();if(e==="arc"||e==="plane")t[n].distance_type=e;return this},params:function(e){return e==null?t[n].params:(t[n].params=e,this)},lang:function(e){return e==null?t[n].lang:(t[n].lang=e,this)},type:function(e){if(e==null)return t[n].type;e=e.toLowerCase();if(e==="string"||e==="number")t[n].type=e;return this},toString:function(){return JSON.stringify(t)},_type:function(){return"sort"},_self:function(){return t}}},L.noConflict=function(){return e.ejs=t,this}}).call(this);