elastic.js 602 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993
  1. /*! elastic.js - v1.0.0 - 2013-04-04
  2. * https://github.com/fullscale/elastic.js
  3. * Copyright (c) 2013 FullScale Labs, LLC; Licensed MIT */
  4. /**
  5. @namespace
  6. @name ejs
  7. @desc All elastic.js modules are organized under the ejs namespace.
  8. */
  9. (function () {
  10. 'use strict';
  11. var
  12. // save reference to global object
  13. // `window` in browser
  14. // `exports` on server
  15. root = this,
  16. // save the previous version of ejs
  17. _ejs = root && root.ejs,
  18. // from underscore.js, used in utils
  19. ArrayProto = Array.prototype,
  20. ObjProto = Object.prototype,
  21. slice = ArrayProto.slice,
  22. toString = ObjProto.toString,
  23. hasOwnProp = ObjProto.hasOwnProperty,
  24. nativeForEach = ArrayProto.forEach,
  25. nativeIsArray = Array.isArray,
  26. breaker = {},
  27. has,
  28. each,
  29. extend,
  30. isArray,
  31. isObject,
  32. isString,
  33. isNumber,
  34. isFunction,
  35. isEJSObject, // checks if valid ejs object
  36. isQuery, // checks valid ejs Query object
  37. isFilter, // checks valid ejs Filter object
  38. isFacet, // checks valid ejs Facet object
  39. isScriptField, // checks valid ejs ScriptField object
  40. isGeoPoint, // checks valid ejs GeoPoint object
  41. isIndexedShape, // checks valid ejs IndexedShape object
  42. isShape, // checks valid ejs Shape object
  43. isSort, // checks valid ejs Sort object
  44. isHighlight, // checks valid ejs Highlight object
  45. isSuggest, // checks valid ejs Suggest object
  46. isGenerator, // checks valid ejs Generator object
  47. // create ejs object
  48. ejs;
  49. if (typeof exports !== 'undefined') {
  50. ejs = exports;
  51. } else {
  52. ejs = root.ejs = {};
  53. }
  54. /* Utility methods, most of which are pulled from underscore.js. */
  55. // Shortcut function for checking if an object has a given property directly
  56. // on itself (in other words, not on a prototype).
  57. has = function (obj, key) {
  58. return hasOwnProp.call(obj, key);
  59. };
  60. // The cornerstone, an `each` implementation, aka `forEach`.
  61. // Handles objects with the built-in `forEach`, arrays, and raw objects.
  62. // Delegates to **ECMAScript 5**'s native `forEach` if available.
  63. each = function (obj, iterator, context) {
  64. if (obj == null) {
  65. return;
  66. }
  67. if (nativeForEach && obj.forEach === nativeForEach) {
  68. obj.forEach(iterator, context);
  69. } else if (obj.length === +obj.length) {
  70. for (var i = 0, l = obj.length; i < l; i++) {
  71. if (iterator.call(context, obj[i], i, obj) === breaker) {
  72. return;
  73. }
  74. }
  75. } else {
  76. for (var key in obj) {
  77. if (has(obj, key)) {
  78. if (iterator.call(context, obj[key], key, obj) === breaker) {
  79. return;
  80. }
  81. }
  82. }
  83. }
  84. };
  85. // Extend a given object with all the properties in passed-in object(s).
  86. extend = function (obj) {
  87. each(slice.call(arguments, 1), function (source) {
  88. for (var prop in source) {
  89. obj[prop] = source[prop];
  90. }
  91. });
  92. return obj;
  93. };
  94. // Is a given value an array?
  95. // Delegates to ECMA5's native Array.isArray
  96. // switched to ===, not sure why underscore used ==
  97. isArray = nativeIsArray || function (obj) {
  98. return toString.call(obj) === '[object Array]';
  99. };
  100. // Is a given variable an object?
  101. isObject = function (obj) {
  102. return obj === Object(obj);
  103. };
  104. // switched to ===, not sure why underscore used ==
  105. isString = function (obj) {
  106. return toString.call(obj) === '[object String]';
  107. };
  108. // switched to ===, not sure why underscore used ==
  109. isNumber = function (obj) {
  110. return toString.call(obj) === '[object Number]';
  111. };
  112. // switched to ===, not sure why underscore used ==
  113. if (typeof (/./) !== 'function') {
  114. isFunction = function (obj) {
  115. return typeof obj === 'function';
  116. };
  117. } else {
  118. isFunction = function (obj) {
  119. return toString.call(obj) === '[object Function]';
  120. };
  121. }
  122. // Is a given value an ejs object?
  123. // Yes if object and has "_type", "_self", and "toString" properties
  124. isEJSObject = function (obj) {
  125. return (isObject(obj) &&
  126. has(obj, '_type') &&
  127. has(obj, '_self') &&
  128. has(obj, 'toString'));
  129. };
  130. isQuery = function (obj) {
  131. return (isEJSObject(obj) && obj._type() === 'query');
  132. };
  133. isFilter = function (obj) {
  134. return (isEJSObject(obj) && obj._type() === 'filter');
  135. };
  136. isFacet = function (obj) {
  137. return (isEJSObject(obj) && obj._type() === 'facet');
  138. };
  139. isScriptField = function (obj) {
  140. return (isEJSObject(obj) && obj._type() === 'script field');
  141. };
  142. isGeoPoint = function (obj) {
  143. return (isEJSObject(obj) && obj._type() === 'geo point');
  144. };
  145. isIndexedShape = function (obj) {
  146. return (isEJSObject(obj) && obj._type() === 'indexed shape');
  147. };
  148. isShape = function (obj) {
  149. return (isEJSObject(obj) && obj._type() === 'shape');
  150. };
  151. isSort = function (obj) {
  152. return (isEJSObject(obj) && obj._type() === 'sort');
  153. };
  154. isHighlight = function (obj) {
  155. return (isEJSObject(obj) && obj._type() === 'highlight');
  156. };
  157. isSuggest = function (obj) {
  158. return (isEJSObject(obj) && obj._type() === 'suggest');
  159. };
  160. isGenerator = function (obj) {
  161. return (isEJSObject(obj) && obj._type() === 'generator');
  162. };
  163. /**
  164. @class
  165. <p>The DateHistogram facet works with time-based values by building a histogram across time
  166. intervals of the <code>value</code> field. Each value is <em>rounded</em> into an interval (or
  167. placed in a bucket), and statistics are provided per interval/bucket (count and total).</p>
  168. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  169. better. You can also construct several <em>"groups"</em> at once by simply
  170. specifying multiple facets.</p>
  171. <div class="alert-message block-message info">
  172. <p>
  173. <strong>Tip: </strong>
  174. For more information on faceted navigation, see
  175. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  176. Wikipedia article on Faceted Classification.
  177. </p>
  178. </div>
  179. @name ejs.DateHistogramFacet
  180. @desc
  181. <p>A facet which returns the N most frequent terms within a collection
  182. or set of collections.</p>
  183. @param {String} name The name which be used to refer to this facet. For instance,
  184. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  185. <code>name</code> to <code>Authors</code> would allow you to refer to the
  186. facet by that name, possibly simplifying some of the display logic.
  187. */
  188. ejs.DateHistogramFacet = function (name) {
  189. /**
  190. The internal facet object.
  191. @member ejs.DateHistogramFacet
  192. @property {Object} facet
  193. */
  194. var facet = {};
  195. facet[name] = {
  196. date_histogram: {}
  197. };
  198. return {
  199. /**
  200. Sets the field to be used to construct the this facet.
  201. @member ejs.DateHistogramFacet
  202. @param {String} fieldName The field name whose data will be used to construct the facet.
  203. @returns {Object} returns <code>this</code> so that calls can be chained.
  204. */
  205. field: function (fieldName) {
  206. if (fieldName == null) {
  207. return facet[name].date_histogram.field;
  208. }
  209. facet[name].date_histogram.field = fieldName;
  210. return this;
  211. },
  212. /**
  213. Allows you to specify a different key field to be used to group intervals.
  214. @member ejs.DateHistogramFacet
  215. @param {String} fieldName The name of the field to be used.
  216. @returns {Object} returns <code>this</code> so that calls can be chained.
  217. */
  218. keyField: function (fieldName) {
  219. if (fieldName == null) {
  220. return facet[name].date_histogram.key_field;
  221. }
  222. facet[name].date_histogram.key_field = fieldName;
  223. return this;
  224. },
  225. /**
  226. Allows you to specify a different value field to aggrerate over.
  227. @member ejs.DateHistogramFacet
  228. @param {String} fieldName The name of the field to be used.
  229. @returns {Object} returns <code>this</code> so that calls can be chained.
  230. */
  231. valueField: function (fieldName) {
  232. if (fieldName == null) {
  233. return facet[name].date_histogram.value_field;
  234. }
  235. facet[name].date_histogram.value_field = fieldName;
  236. return this;
  237. },
  238. /**
  239. Sets the bucket interval used to calculate the distribution.
  240. @member ejs.DateHistogramFacet
  241. @param {String} timeInterval The bucket interval. Valid values are <code>year, month, week, day, hour,</code> and <code>minute</code>.
  242. @returns {Object} returns <code>this</code> so that calls can be chained.
  243. */
  244. interval: function (timeInterval) {
  245. if (timeInterval == null) {
  246. return facet[name].date_histogram.interval;
  247. }
  248. facet[name].date_histogram.interval = timeInterval;
  249. return this;
  250. },
  251. /**
  252. <p>By default, time values are stored in UTC format.<p>
  253. <p>This method allows users to set a time zone value that is then used
  254. to compute intervals before rounding on the interval value. Equalivent to
  255. <coe>preZone</code>. Use <code>preZone</code> if possible. The
  256. value is an offset from UTC.<p>
  257. <p>For example, to use EST you would set the value to <code>-5</code>.</p>
  258. @member ejs.DateHistogramFacet
  259. @param {Integer} tz An offset value from UTC.
  260. @returns {Object} returns <code>this</code> so that calls can be chained.
  261. */
  262. timeZone: function (tz) {
  263. if (tz == null) {
  264. return facet[name].date_histogram.time_zone;
  265. }
  266. facet[name].date_histogram.time_zone = tz;
  267. return this;
  268. },
  269. /**
  270. <p>By default, time values are stored in UTC format.<p>
  271. <p>This method allows users to set a time zone value that is then used to
  272. compute intervals before rounding on the interval value. The value is an
  273. offset from UTC.<p>
  274. <p>For example, to use EST you would set the value to <code>-5</code>.</p>
  275. @member ejs.DateHistogramFacet
  276. @param {Integer} tz An offset value from UTC.
  277. @returns {Object} returns <code>this</code> so that calls can be chained.
  278. */
  279. preZone: function (tz) {
  280. if (tz == null) {
  281. return facet[name].date_histogram.pre_zone;
  282. }
  283. facet[name].date_histogram.pre_zone = tz;
  284. return this;
  285. },
  286. /**
  287. <p>Enables large date interval conversions (day and up).</p>
  288. <p>Set to true to enable and then set the <code>interval</code> to an
  289. interval greater than a day.</p>
  290. @member ejs.DateHistogramFacet
  291. @param {Boolean} trueFalse A valid boolean value.
  292. @returns {Object} returns <code>this</code> so that calls can be chained.
  293. */
  294. preZoneAdjustLargeInterval: function (trueFalse) {
  295. if (trueFalse == null) {
  296. return facet[name].date_histogram.pre_zone_adjust_large_interval;
  297. }
  298. facet[name].date_histogram.pre_zone_adjust_large_interval = trueFalse;
  299. return this;
  300. },
  301. /**
  302. <p>By default, time values are stored in UTC format.<p>
  303. <p>This method allows users to set a time zone value that is then used to compute
  304. intervals after rounding on the interval value. The value is an offset from UTC.
  305. The tz offset value is simply added to the resulting bucket's date value.<p>
  306. <p>For example, to use EST you would set the value to <code>-5</code>.</p>
  307. @member ejs.DateHistogramFacet
  308. @param {Integer} tz An offset value from UTC.
  309. @returns {Object} returns <code>this</code> so that calls can be chained.
  310. */
  311. postZone: function (tz) {
  312. if (tz == null) {
  313. return facet[name].date_histogram.post_zone;
  314. }
  315. facet[name].date_histogram.post_zone = tz;
  316. return this;
  317. },
  318. /**
  319. Set's a specific pre-rounding offset. Format is 1d, 1h, etc.
  320. @member ejs.DateHistogramFacet
  321. @param {String} offset The offset as a string (1d, 1h, etc)
  322. @returns {Object} returns <code>this</code> so that calls can be chained.
  323. */
  324. preOffset: function (offset) {
  325. if (offset == null) {
  326. return facet[name].date_histogram.pre_offset;
  327. }
  328. facet[name].date_histogram.pre_offset = offset;
  329. return this;
  330. },
  331. /**
  332. Set's a specific post-rounding offset. Format is 1d, 1h, etc.
  333. @member ejs.DateHistogramFacet
  334. @param {String} offset The offset as a string (1d, 1h, etc)
  335. @returns {Object} returns <code>this</code> so that calls can be chained.
  336. */
  337. postOffset: function (offset) {
  338. if (offset == null) {
  339. return facet[name].date_histogram.post_offset;
  340. }
  341. facet[name].date_histogram.post_offset = offset;
  342. return this;
  343. },
  344. /**
  345. <p>The date histogram works on numeric values (since time is stored
  346. in milliseconds since the epoch in UTC).<p>
  347. <p>But, sometimes, systems will store a different resolution (like seconds since UTC)
  348. in a numeric field. The factor parameter can be used to change the value in the field
  349. to milliseconds to actual do the relevant rounding, and then be applied again to get to
  350. the original unit.</p>
  351. <p>For example, when storing in a numeric field seconds resolution,
  352. the factor can be set to 1000.<p>
  353. @member ejs.DateHistogramFacet
  354. @param {Integer} f The conversion factor.
  355. @returns {Object} returns <code>this</code> so that calls can be chained.
  356. */
  357. factor: function (f) {
  358. if (f == null) {
  359. return facet[name].date_histogram.factor;
  360. }
  361. facet[name].date_histogram.factor = f;
  362. return this;
  363. },
  364. /**
  365. Allows you modify the <code>value</code> field using a script. The modified value
  366. is then used to compute the statistical data.
  367. @member ejs.DateHistogramFacet
  368. @param {String} scriptCode A valid script string to execute.
  369. @returns {Object} returns <code>this</code> so that calls can be chained.
  370. */
  371. valueScript: function (scriptCode) {
  372. if (scriptCode == null) {
  373. return facet[name].date_histogram.value_script;
  374. }
  375. facet[name].date_histogram.value_script = scriptCode;
  376. return this;
  377. },
  378. /**
  379. <p>Sets the type of ordering that will be performed on the date
  380. buckets. Valid values are:<p>
  381. <dl>
  382. <dd><code>time</code> - the default, sort by the buckets start time in milliseconds.</dd>
  383. <dd><code>count</code> - sort by the number of items in the bucket</dd>
  384. <dd><code>total</code> - sort by the sum/total of the items in the bucket</dd>
  385. <dl>
  386. @member ejs.DateHistogramFacet
  387. @param {String} o The ordering method: time, count, or total.
  388. @returns {Object} returns <code>this</code> so that calls can be chained.
  389. */
  390. order: function (o) {
  391. if (o == null) {
  392. return facet[name].date_histogram.order;
  393. }
  394. o = o.toLowerCase();
  395. if (o === 'time' || o === 'count' || o === 'total') {
  396. facet[name].date_histogram.order = o;
  397. }
  398. return this;
  399. },
  400. /**
  401. The script language being used. Currently supported values are
  402. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  403. @member ejs.DateHistogramFacet
  404. @param {String} language The language of the script.
  405. @returns {Object} returns <code>this</code> so that calls can be chained.
  406. */
  407. lang: function (language) {
  408. if (language == null) {
  409. return facet[name].date_histogram.lang;
  410. }
  411. facet[name].date_histogram.lang = language;
  412. return this;
  413. },
  414. /**
  415. Sets parameters that will be applied to the script. Overwrites
  416. any existing params.
  417. @member ejs.DateHistogramFacet
  418. @param {Object} p An object where the keys are the parameter name and
  419. values are the parameter value.
  420. @returns {Object} returns <code>this</code> so that calls can be chained.
  421. */
  422. params: function (p) {
  423. if (p == null) {
  424. return facet[name].date_histogram.params;
  425. }
  426. facet[name].date_histogram.params = p;
  427. return this;
  428. },
  429. /**
  430. <p>Allows you to reduce the documents used for computing facet results.</p>
  431. @member ejs.DateHistogramFacet
  432. @param {Object} oFilter A valid <code>Filter</code> object.
  433. @returns {Object} returns <code>this</code> so that calls can be chained.
  434. */
  435. facetFilter: function (oFilter) {
  436. if (oFilter == null) {
  437. return facet[name].facet_filter;
  438. }
  439. if (!isFilter(oFilter)) {
  440. throw new TypeError('Argument must be a Filter');
  441. }
  442. facet[name].facet_filter = oFilter._self();
  443. return this;
  444. },
  445. /**
  446. <p>Computes values across the entire index</p>
  447. @member ejs.DateHistogramFacet
  448. @param {Boolean} trueFalse Calculate facet counts globally or not.
  449. @returns {Object} returns <code>this</code> so that calls can be chained.
  450. */
  451. global: function (trueFalse) {
  452. if (trueFalse == null) {
  453. return facet[name].global;
  454. }
  455. facet[name].global = trueFalse;
  456. return this;
  457. },
  458. /**
  459. <p>Sets the mode the facet will use.<p>
  460. <dl>
  461. <dd><code>collector</code></dd>
  462. <dd><code>post</code></dd>
  463. <dl>
  464. @member ejs.DateHistogramFacet
  465. @param {String} m The mode: collector or post.
  466. @returns {Object} returns <code>this</code> so that calls can be chained.
  467. */
  468. mode: function (m) {
  469. if (m == null) {
  470. return facet[name].mode;
  471. }
  472. m = m.toLowerCase();
  473. if (m === 'collector' || m === 'post') {
  474. facet[name].mode = m;
  475. }
  476. return this;
  477. },
  478. /**
  479. <p>Computes values across the the specified scope</p>
  480. @deprecated since elasticsearch 0.90
  481. @member ejs.DateHistogramFacet
  482. @param {String} scope The scope name to calculate facet counts with.
  483. @returns {Object} returns <code>this</code> so that calls can be chained.
  484. */
  485. scope: function (scope) {
  486. return this;
  487. },
  488. /**
  489. <p>Enables caching of the <code>facetFilter</code></p>
  490. @member ejs.DateHistogramFacet
  491. @param {Boolean} trueFalse If the facetFilter should be cached or not
  492. @returns {Object} returns <code>this</code> so that calls can be chained.
  493. */
  494. cacheFilter: function (trueFalse) {
  495. if (trueFalse == null) {
  496. return facet[name].cache_filter;
  497. }
  498. facet[name].cache_filter = trueFalse;
  499. return this;
  500. },
  501. /**
  502. <p>Sets the path to the nested document if faceting against a
  503. nested field.</p>
  504. @member ejs.DateHistogramFacet
  505. @param {String} path The nested path
  506. @returns {Object} returns <code>this</code> so that calls can be chained.
  507. */
  508. nested: function (path) {
  509. if (path == null) {
  510. return facet[name].nested;
  511. }
  512. facet[name].nested = path;
  513. return this;
  514. },
  515. /**
  516. <p>Allows you to serialize this object into a JSON encoded string.</p>
  517. @member ejs.DateHistogramFacet
  518. @returns {String} returns this object as a serialized JSON string.
  519. */
  520. toString: function () {
  521. return JSON.stringify(facet);
  522. },
  523. /**
  524. The type of ejs object. For internal use only.
  525. @member ejs.DateHistogramFacet
  526. @returns {String} the type of object
  527. */
  528. _type: function () {
  529. return 'facet';
  530. },
  531. /**
  532. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  533. internal API functions so use with caution.</p>
  534. @member ejs.DateHistogramFacet
  535. @returns {String} returns this object's internal <code>facet</code> property.
  536. */
  537. _self: function () {
  538. return facet;
  539. }
  540. };
  541. };
  542. /**
  543. @class
  544. <p>The FilterFacet allows you to specify any valid <code>Filter</code> and
  545. have the number of matching hits returned as the value.</p>
  546. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  547. better. You can also construct several <em>"groups"</em> at once by simply
  548. specifying multiple facets.</p>
  549. <div class="alert-message block-message info">
  550. <p>
  551. <strong>Tip: </strong>
  552. For more information on faceted navigation, see
  553. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  554. Wikipedia article on Faceted Classification.
  555. </p>
  556. </div>
  557. @name ejs.FilterFacet
  558. @desc
  559. <p>A facet that return a count of the hits matching the given filter.</p>
  560. @param {String} name The name which be used to refer to this facet. For instance,
  561. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  562. <code>name</code> to <code>Authors</code> would allow you to refer to the
  563. facet by that name, possibly simplifying some of the display logic.
  564. */
  565. ejs.FilterFacet = function (name) {
  566. /**
  567. The internal facet object.
  568. @member ejs.FilterFacet
  569. @property {Object} facet
  570. */
  571. var facet = {};
  572. facet[name] = {};
  573. return {
  574. /**
  575. <p>Sets the filter to be used for this facet.</p>
  576. @member ejs.FilterFacet
  577. @param {Object} oFilter A valid <code>Query</code> object.
  578. @returns {Object} returns <code>this</code> so that calls can be chained.
  579. */
  580. filter: function (oFilter) {
  581. if (oFilter == null) {
  582. return facet[name].filter;
  583. }
  584. if (!isFilter(oFilter)) {
  585. throw new TypeError('Argument must be a Filter');
  586. }
  587. facet[name].filter = oFilter._self();
  588. return this;
  589. },
  590. /**
  591. <p>Allows you to reduce the documents used for computing facet results.</p>
  592. @member ejs.FilterFacet
  593. @param {Object} oFilter A valid <code>Filter</code> object.
  594. @returns {Object} returns <code>this</code> so that calls can be chained.
  595. */
  596. facetFilter: function (oFilter) {
  597. if (oFilter == null) {
  598. return facet[name].facet_filter;
  599. }
  600. if (!isFilter(oFilter)) {
  601. throw new TypeError('Argument must be a Filter');
  602. }
  603. facet[name].facet_filter = oFilter._self();
  604. return this;
  605. },
  606. /**
  607. <p>Computes values across the entire index</p>
  608. @member ejs.FilterFacet
  609. @param {Boolean} trueFalse Calculate facet counts globally or not.
  610. @returns {Object} returns <code>this</code> so that calls can be chained.
  611. */
  612. global: function (trueFalse) {
  613. if (trueFalse == null) {
  614. return facet[name].global;
  615. }
  616. facet[name].global = trueFalse;
  617. return this;
  618. },
  619. /**
  620. <p>Sets the mode the facet will use.<p>
  621. <dl>
  622. <dd><code>collector</code></dd>
  623. <dd><code>post</code></dd>
  624. <dl>
  625. @member ejs.FilterFacet
  626. @param {String} m The mode: collector or post.
  627. @returns {Object} returns <code>this</code> so that calls can be chained.
  628. */
  629. mode: function (m) {
  630. if (m == null) {
  631. return facet[name].mode;
  632. }
  633. m = m.toLowerCase();
  634. if (m === 'collector' || m === 'post') {
  635. facet[name].mode = m;
  636. }
  637. return this;
  638. },
  639. /**
  640. <p>Computes values across the the specified scope</p>
  641. @deprecated since elasticsearch 0.90
  642. @member ejs.FilterFacet
  643. @param {String} scope The scope name to calculate facet counts with.
  644. @returns {Object} returns <code>this</code> so that calls can be chained.
  645. */
  646. scope: function (scope) {
  647. return this;
  648. },
  649. /**
  650. <p>Enables caching of the <code>facetFilter</code></p>
  651. @member ejs.FilterFacet
  652. @param {Boolean} trueFalse If the facetFilter should be cached or not
  653. @returns {Object} returns <code>this</code> so that calls can be chained.
  654. */
  655. cacheFilter: function (trueFalse) {
  656. if (trueFalse == null) {
  657. return facet[name].cache_filter;
  658. }
  659. facet[name].cache_filter = trueFalse;
  660. return this;
  661. },
  662. /**
  663. <p>Sets the path to the nested document if faceting against a
  664. nested field.</p>
  665. @member ejs.FilterFacet
  666. @param {String} path The nested path
  667. @returns {Object} returns <code>this</code> so that calls can be chained.
  668. */
  669. nested: function (path) {
  670. if (path == null) {
  671. return facet[name].nested;
  672. }
  673. facet[name].nested = path;
  674. return this;
  675. },
  676. /**
  677. <p>Allows you to serialize this object into a JSON encoded string.</p>
  678. @member ejs.FilterFacet
  679. @returns {String} returns this object as a serialized JSON string.
  680. */
  681. toString: function () {
  682. return JSON.stringify(facet);
  683. },
  684. /**
  685. The type of ejs object. For internal use only.
  686. @member ejs.FilterFacet
  687. @returns {String} the type of object
  688. */
  689. _type: function () {
  690. return 'facet';
  691. },
  692. /**
  693. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  694. internal API functions so use with caution.</p>
  695. @member ejs.FilterFacet
  696. @returns {String} returns this object's internal <code>facet</code> property.
  697. */
  698. _self: function () {
  699. return facet;
  700. }
  701. };
  702. };
  703. /**
  704. @class
  705. <p>The geoDistanceFacet facet provides information over a range of distances from a
  706. provided point. This includes the number of hits that fall within each range,
  707. along with aggregate information (like total).</p>
  708. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  709. better. You can also construct several <em>"groups"</em> at once by simply
  710. specifying multiple facets.</p>
  711. <div class="alert-message block-message info">
  712. <p>
  713. <strong>Tip: </strong>
  714. For more information on faceted navigation, see
  715. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  716. Wikipedia article on Faceted Classification.
  717. </p>
  718. </div>
  719. @name ejs.GeoDistanceFacet
  720. @desc
  721. <p>A facet which provides information over a range of distances from a provided point.</p>
  722. @param {String} name The name which be used to refer to this facet. For instance,
  723. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  724. <code>name</code> to <code>Authors</code> would allow you to refer to the
  725. facet by that name, possibly simplifying some of the display logic.
  726. */
  727. ejs.GeoDistanceFacet = function (name) {
  728. /**
  729. The internal facet object.
  730. @member ejs.GeoDistanceFacet
  731. @property {Object} facet
  732. */
  733. var facet = {},
  734. point = ejs.GeoPoint([0, 0]),
  735. field = 'location';
  736. facet[name] = {
  737. geo_distance: {
  738. location: point._self(),
  739. ranges: []
  740. }
  741. };
  742. return {
  743. /**
  744. Sets the document field containing the geo-coordinate to be used
  745. to calculate the distance. Defaults to "location".
  746. @member ejs.GeoDistanceFacet
  747. @param {String} fieldName The field name whose data will be used to construct the facet.
  748. @returns {Object} returns <code>this</code> so that calls can be chained.
  749. */
  750. field: function (fieldName) {
  751. var oldValue = facet[name].geo_distance[field];
  752. if (fieldName == null) {
  753. return field;
  754. }
  755. delete facet[name].geo_distance[field];
  756. field = fieldName;
  757. facet[name].geo_distance[fieldName] = oldValue;
  758. return this;
  759. },
  760. /**
  761. Sets the point of origin from where distances will be measured.
  762. @member ejs.GeoDistanceFacet
  763. @param {GeoPoint} p A valid GeoPoint object
  764. @returns {Object} returns <code>this</code> so that calls can be chained.
  765. */
  766. point: function (p) {
  767. if (p == null) {
  768. return point;
  769. }
  770. if (!isGeoPoint(p)) {
  771. throw new TypeError('Argument must be a GeoPoint');
  772. }
  773. point = p;
  774. facet[name].geo_distance[field] = p._self();
  775. return this;
  776. },
  777. /**
  778. Adds a new bounded range.
  779. @member ejs.GeoDistanceFacet
  780. @param {Number} from The lower bound of the range
  781. @param {Number} to The upper bound of the range
  782. @returns {Object} returns <code>this</code> so that calls can be chained.
  783. */
  784. addRange: function (from, to) {
  785. if (arguments.length === 0) {
  786. return facet[name].geo_distance.ranges;
  787. }
  788. facet[name].geo_distance.ranges.push({
  789. from: from,
  790. to: to
  791. });
  792. return this;
  793. },
  794. /**
  795. Adds a new unbounded lower limit.
  796. @member ejs.GeoDistanceFacet
  797. @param {Number} from The lower limit of the unbounded range
  798. @returns {Object} returns <code>this</code> so that calls can be chained.
  799. */
  800. addUnboundedFrom: function (from) {
  801. if (from == null) {
  802. return facet[name].geo_distance.ranges;
  803. }
  804. facet[name].geo_distance.ranges.push({
  805. from: from
  806. });
  807. return this;
  808. },
  809. /**
  810. Adds a new unbounded upper limit.
  811. @member ejs.GeoDistanceFacet
  812. @param {Number} to The upper limit of the unbounded range
  813. @returns {Object} returns <code>this</code> so that calls can be chained.
  814. */
  815. addUnboundedTo: function (to) {
  816. if (to == null) {
  817. return facet[name].geo_distance.ranges;
  818. }
  819. facet[name].geo_distance.ranges.push({
  820. to: to
  821. });
  822. return this;
  823. },
  824. /**
  825. Sets the distance unit. Valid values are "mi" for miles or "km"
  826. for kilometers. Defaults to "km".
  827. @member ejs.GeoDistanceFacet
  828. @param {Number} unit the unit of distance measure.
  829. @returns {Object} returns <code>this</code> so that calls can be chained.
  830. */
  831. unit: function (unit) {
  832. if (unit == null) {
  833. return facet[name].geo_distance.unit;
  834. }
  835. unit = unit.toLowerCase();
  836. if (unit === 'mi' || unit === 'km') {
  837. facet[name].geo_distance.unit = unit;
  838. }
  839. return this;
  840. },
  841. /**
  842. How to compute the distance. Can either be arc (better precision)
  843. or plane (faster). Defaults to arc.
  844. @member ejs.GeoDistanceFacet
  845. @param {String} type The execution type as a string.
  846. @returns {Object} returns <code>this</code> so that calls can be chained.
  847. */
  848. distanceType: function (type) {
  849. if (type == null) {
  850. return facet[name].geo_distance.distance_type;
  851. }
  852. type = type.toLowerCase();
  853. if (type === 'arc' || type === 'plane') {
  854. facet[name].geo_distance.distance_type = type;
  855. }
  856. return this;
  857. },
  858. /**
  859. If the lat/long points should be normalized to lie within their
  860. respective normalized ranges.
  861. Normalized ranges are:
  862. lon = -180 (exclusive) to 180 (inclusive) range
  863. lat = -90 to 90 (both inclusive) range
  864. @member ejs.GeoDistanceFacet
  865. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  866. @returns {Object} returns <code>this</code> so that calls can be chained.
  867. */
  868. normalize: function (trueFalse) {
  869. if (trueFalse == null) {
  870. return facet[name].geo_distance.normalize;
  871. }
  872. facet[name].geo_distance.normalize = trueFalse;
  873. return this;
  874. },
  875. /**
  876. Allows you to specify a different value field to aggrerate over.
  877. @member ejs.GeoDistanceFacet
  878. @param {String} fieldName The name of the field to be used.
  879. @returns {Object} returns <code>this</code> so that calls can be chained.
  880. */
  881. valueField: function (fieldName) {
  882. if (fieldName == null) {
  883. return facet[name].geo_distance.value_field;
  884. }
  885. facet[name].geo_distance.value_field = fieldName;
  886. return this;
  887. },
  888. /**
  889. Allows you modify the <code>value</code> field using a script. The modified value
  890. is then used to compute the statistical data.
  891. @member ejs.GeoDistanceFacet
  892. @param {String} scriptCode A valid script string to execute.
  893. @returns {Object} returns <code>this</code> so that calls can be chained.
  894. */
  895. valueScript: function (scriptCode) {
  896. if (scriptCode == null) {
  897. return facet[name].geo_distance.value_script;
  898. }
  899. facet[name].geo_distance.value_script = scriptCode;
  900. return this;
  901. },
  902. /**
  903. The script language being used. Currently supported values are
  904. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  905. @member ejs.GeoDistanceFacet
  906. @param {String} language The language of the script.
  907. @returns {Object} returns <code>this</code> so that calls can be chained.
  908. */
  909. lang: function (language) {
  910. if (language == null) {
  911. return facet[name].geo_distance.lang;
  912. }
  913. facet[name].geo_distance.lang = language;
  914. return this;
  915. },
  916. /**
  917. Sets parameters that will be applied to the script. Overwrites
  918. any existing params.
  919. @member ejs.GeoDistanceFacet
  920. @param {Object} p An object where the keys are the parameter name and
  921. values are the parameter value.
  922. @returns {Object} returns <code>this</code> so that calls can be chained.
  923. */
  924. params: function (p) {
  925. if (p == null) {
  926. return facet[name].geo_distance.params;
  927. }
  928. facet[name].geo_distance.params = p;
  929. return this;
  930. },
  931. /**
  932. <p>Allows you to reduce the documents used for computing facet results.</p>
  933. @member ejs.GeoDistanceFacet
  934. @param {Object} oFilter A valid <code>Filter</code> object.
  935. @returns {Object} returns <code>this</code> so that calls can be chained.
  936. */
  937. facetFilter: function (oFilter) {
  938. if (oFilter == null) {
  939. return facet[name].facet_filter;
  940. }
  941. if (!isFilter(oFilter)) {
  942. throw new TypeError('Argument must be a Filter');
  943. }
  944. facet[name].facet_filter = oFilter._self();
  945. return this;
  946. },
  947. /**
  948. <p>Computes values across the entire index</p>
  949. @member ejs.GeoDistanceFacet
  950. @param {Boolean} trueFalse Calculate facet counts globally or not.
  951. @returns {Object} returns <code>this</code> so that calls can be chained.
  952. */
  953. global: function (trueFalse) {
  954. if (trueFalse == null) {
  955. return facet[name].global;
  956. }
  957. facet[name].global = trueFalse;
  958. return this;
  959. },
  960. /**
  961. <p>Sets the mode the facet will use.<p>
  962. <dl>
  963. <dd><code>collector</code></dd>
  964. <dd><code>post</code></dd>
  965. <dl>
  966. @member ejs.GeoDistanceFacet
  967. @param {String} m The mode: collector or post.
  968. @returns {Object} returns <code>this</code> so that calls can be chained.
  969. */
  970. mode: function (m) {
  971. if (m == null) {
  972. return facet[name].mode;
  973. }
  974. m = m.toLowerCase();
  975. if (m === 'collector' || m === 'post') {
  976. facet[name].mode = m;
  977. }
  978. return this;
  979. },
  980. /**
  981. <p>Computes values across the the specified scope</p>
  982. @deprecated since elasticsearch 0.90
  983. @member ejs.GeoDistanceFacet
  984. @param {String} scope The scope name to calculate facet counts with.
  985. @returns {Object} returns <code>this</code> so that calls can be chained.
  986. */
  987. scope: function (scope) {
  988. return this;
  989. },
  990. /**
  991. <p>Enables caching of the <code>facetFilter</code></p>
  992. @member ejs.GeoDistanceFacet
  993. @param {Boolean} trueFalse If the facetFilter should be cached or not
  994. @returns {Object} returns <code>this</code> so that calls can be chained.
  995. */
  996. cacheFilter: function (trueFalse) {
  997. if (trueFalse == null) {
  998. return facet[name].cache_filter;
  999. }
  1000. facet[name].cache_filter = trueFalse;
  1001. return this;
  1002. },
  1003. /**
  1004. <p>Sets the path to the nested document if faceting against a
  1005. nested field.</p>
  1006. @member ejs.GeoDistanceFacet
  1007. @param {String} path The nested path
  1008. @returns {Object} returns <code>this</code> so that calls can be chained.
  1009. */
  1010. nested: function (path) {
  1011. if (path == null) {
  1012. return facet[name].nested;
  1013. }
  1014. facet[name].nested = path;
  1015. return this;
  1016. },
  1017. /**
  1018. <p>Allows you to serialize this object into a JSON encoded string.</p>
  1019. @member ejs.GeoDistanceFacet
  1020. @returns {String} returns this object as a serialized JSON string.
  1021. */
  1022. toString: function () {
  1023. return JSON.stringify(facet);
  1024. },
  1025. /**
  1026. The type of ejs object. For internal use only.
  1027. @member ejs.GeoDistanceFacet
  1028. @returns {String} the type of object
  1029. */
  1030. _type: function () {
  1031. return 'facet';
  1032. },
  1033. /**
  1034. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  1035. internal API functions so use with caution.</p>
  1036. @member ejs.GeoDistanceFacet
  1037. @returns {String} returns this object's internal <code>facet</code> property.
  1038. */
  1039. _self: function () {
  1040. return facet;
  1041. }
  1042. };
  1043. };
  1044. /**
  1045. @class
  1046. <p>The histogram facet works with numeric data by building a histogram across intervals
  1047. of the field values. Each value is <em>rounded</em> into an interval (or placed in a
  1048. bucket), and statistics are provided per interval/bucket (count and total).</p>
  1049. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  1050. better. You can also construct several <em>"groups"</em> at once by simply
  1051. specifying multiple facets.</p>
  1052. <div class="alert-message block-message info">
  1053. <p>
  1054. <strong>Tip: </strong>
  1055. For more information on faceted navigation, see
  1056. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  1057. Wikipedia article on Faceted Classification.
  1058. </p>
  1059. </div>
  1060. @name ejs.HistogramFacet
  1061. @desc
  1062. <p>A facet which returns the N most frequent terms within a collection
  1063. or set of collections.</p>
  1064. @param {String} name The name which be used to refer to this facet. For instance,
  1065. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  1066. <code>name</code> to <code>Authors</code> would allow you to refer to the
  1067. facet by that name, possibly simplifying some of the display logic.
  1068. */
  1069. ejs.HistogramFacet = function (name) {
  1070. /**
  1071. The internal facet object.
  1072. @member ejs.HistogramFacet
  1073. @property {Object} facet
  1074. */
  1075. var facet = {};
  1076. facet[name] = {
  1077. histogram: {}
  1078. };
  1079. return {
  1080. /**
  1081. Sets the field to be used to construct the this facet.
  1082. @member ejs.HistogramFacet
  1083. @param {String} fieldName The field name whose data will be used to construct the facet.
  1084. @returns {Object} returns <code>this</code> so that calls can be chained.
  1085. */
  1086. field: function (fieldName) {
  1087. if (fieldName == null) {
  1088. return facet[name].histogram.field;
  1089. }
  1090. facet[name].histogram.field = fieldName;
  1091. return this;
  1092. },
  1093. /**
  1094. Sets the bucket interval used to calculate the distribution.
  1095. @member ejs.HistogramFacet
  1096. @param {Number} numericInterval The bucket interval in which to group values.
  1097. @returns {Object} returns <code>this</code> so that calls can be chained.
  1098. */
  1099. interval: function (numericInterval) {
  1100. if (numericInterval == null) {
  1101. return facet[name].histogram.interval;
  1102. }
  1103. facet[name].histogram.interval = numericInterval;
  1104. return this;
  1105. },
  1106. /**
  1107. Sets the bucket interval used to calculate the distribution based
  1108. on a time value such as "1d", "1w", etc.
  1109. @member ejs.HistogramFacet
  1110. @param {Number} timeInterval The bucket interval in which to group values.
  1111. @returns {Object} returns <code>this</code> so that calls can be chained.
  1112. */
  1113. timeInterval: function (timeInterval) {
  1114. if (timeInterval == null) {
  1115. return facet[name].histogram.time_interval;
  1116. }
  1117. facet[name].histogram.time_interval = timeInterval;
  1118. return this;
  1119. },
  1120. /**
  1121. Sets the "from", "start", or lower bounds bucket. For example if
  1122. you have a value of 1023, an interval of 100, and a from value of
  1123. 1500, it will be placed into the 1500 bucket vs. the normal bucket
  1124. of 1000.
  1125. @member ejs.HistogramFacet
  1126. @param {Number} from the lower bounds bucket value.
  1127. @returns {Object} returns <code>this</code> so that calls can be chained.
  1128. */
  1129. from: function (from) {
  1130. if (from == null) {
  1131. return facet[name].histogram.from;
  1132. }
  1133. facet[name].histogram.from = from;
  1134. return this;
  1135. },
  1136. /**
  1137. Sets the "to", "end", or upper bounds bucket. For example if
  1138. you have a value of 1023, an interval of 100, and a to value of
  1139. 900, it will be placed into the 900 bucket vs. the normal bucket
  1140. of 1000.
  1141. @member ejs.HistogramFacet
  1142. @param {Number} to the upper bounds bucket value.
  1143. @returns {Object} returns <code>this</code> so that calls can be chained.
  1144. */
  1145. to: function (to) {
  1146. if (to == null) {
  1147. return facet[name].histogram.to;
  1148. }
  1149. facet[name].histogram.to = to;
  1150. return this;
  1151. },
  1152. /**
  1153. Allows you to specify a different value field to aggrerate over.
  1154. @member ejs.HistogramFacet
  1155. @param {String} fieldName The name of the field to be used.
  1156. @returns {Object} returns <code>this</code> so that calls can be chained.
  1157. */
  1158. valueField: function (fieldName) {
  1159. if (fieldName == null) {
  1160. return facet[name].histogram.value_field;
  1161. }
  1162. facet[name].histogram.value_field = fieldName;
  1163. return this;
  1164. },
  1165. /**
  1166. Allows you to specify a different key field to be used to group intervals.
  1167. @member ejs.HistogramFacet
  1168. @param {String} fieldName The name of the field to be used.
  1169. @returns {Object} returns <code>this</code> so that calls can be chained.
  1170. */
  1171. keyField: function (fieldName) {
  1172. if (fieldName == null) {
  1173. return facet[name].histogram.key_field;
  1174. }
  1175. facet[name].histogram.key_field = fieldName;
  1176. return this;
  1177. },
  1178. /**
  1179. Allows you modify the <code>value</code> field using a script. The modified value
  1180. is then used to compute the statistical data.
  1181. @member ejs.HistogramFacet
  1182. @param {String} scriptCode A valid script string to execute.
  1183. @returns {Object} returns <code>this</code> so that calls can be chained.
  1184. */
  1185. valueScript: function (scriptCode) {
  1186. if (scriptCode == null) {
  1187. return facet[name].histogram.value_script;
  1188. }
  1189. facet[name].histogram.value_script = scriptCode;
  1190. return this;
  1191. },
  1192. /**
  1193. Allows you modify the <code>key</code> field using a script. The modified value
  1194. is then used to generate the interval.
  1195. @member ejs.HistogramFacet
  1196. @param {String} scriptCode A valid script string to execute.
  1197. @returns {Object} returns <code>this</code> so that calls can be chained.
  1198. */
  1199. keyScript: function (scriptCode) {
  1200. if (scriptCode == null) {
  1201. return facet[name].histogram.key_script;
  1202. }
  1203. facet[name].histogram.key_script = scriptCode;
  1204. return this;
  1205. },
  1206. /**
  1207. The script language being used. Currently supported values are
  1208. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  1209. @member ejs.HistogramFacet
  1210. @param {String} language The language of the script.
  1211. @returns {Object} returns <code>this</code> so that calls can be chained.
  1212. */
  1213. lang: function (language) {
  1214. if (language == null) {
  1215. return facet[name].histogram.lang;
  1216. }
  1217. facet[name].histogram.lang = language;
  1218. return this;
  1219. },
  1220. /**
  1221. Sets parameters that will be applied to the script. Overwrites
  1222. any existing params.
  1223. @member ejs.HistogramFacet
  1224. @param {Object} p An object where the keys are the parameter name and
  1225. values are the parameter value.
  1226. @returns {Object} returns <code>this</code> so that calls can be chained.
  1227. */
  1228. params: function (p) {
  1229. if (p == null) {
  1230. return facet[name].histogram.params;
  1231. }
  1232. facet[name].histogram.params = p;
  1233. return this;
  1234. },
  1235. /**
  1236. Sets the type of ordering that will be performed on the date
  1237. buckets. Valid values are:
  1238. key - the default, sort by the bucket's key value
  1239. count - sort by the number of items in the bucket
  1240. total - sort by the sum/total of the items in the bucket
  1241. @member ejs.HistogramFacet
  1242. @param {String} o The ordering method: key, count, or total.
  1243. @returns {Object} returns <code>this</code> so that calls can be chained.
  1244. */
  1245. order: function (o) {
  1246. if (o == null) {
  1247. return facet[name].histogram.order;
  1248. }
  1249. o = o.toLowerCase();
  1250. if (o === 'key' || o === 'count' || o === 'total') {
  1251. facet[name].histogram.order = o;
  1252. }
  1253. return this;
  1254. },
  1255. /**
  1256. <p>Allows you to reduce the documents used for computing facet results.</p>
  1257. @member ejs.HistogramFacet
  1258. @param {Object} oFilter A valid <code>Filter</code> object.
  1259. @returns {Object} returns <code>this</code> so that calls can be chained.
  1260. */
  1261. facetFilter: function (oFilter) {
  1262. if (oFilter == null) {
  1263. return facet[name].facet_filter;
  1264. }
  1265. if (!isFilter(oFilter)) {
  1266. throw new TypeError('Argument must be a Filter');
  1267. }
  1268. facet[name].facet_filter = oFilter._self();
  1269. return this;
  1270. },
  1271. /**
  1272. <p>Computes values across the entire index</p>
  1273. @member ejs.HistogramFacet
  1274. @param {Boolean} trueFalse Calculate facet counts globally or not.
  1275. @returns {Object} returns <code>this</code> so that calls can be chained.
  1276. */
  1277. global: function (trueFalse) {
  1278. if (trueFalse == null) {
  1279. return facet[name].global;
  1280. }
  1281. facet[name].global = trueFalse;
  1282. return this;
  1283. },
  1284. /**
  1285. <p>Sets the mode the facet will use.<p>
  1286. <dl>
  1287. <dd><code>collector</code></dd>
  1288. <dd><code>post</code></dd>
  1289. <dl>
  1290. @member ejs.HistogramFacet
  1291. @param {String} m The mode: collector or post.
  1292. @returns {Object} returns <code>this</code> so that calls can be chained.
  1293. */
  1294. mode: function (m) {
  1295. if (m == null) {
  1296. return facet[name].mode;
  1297. }
  1298. m = m.toLowerCase();
  1299. if (m === 'collector' || m === 'post') {
  1300. facet[name].mode = m;
  1301. }
  1302. return this;
  1303. },
  1304. /**
  1305. <p>Computes values across the the specified scope</p>
  1306. @deprecated since elasticsearch 0.90
  1307. @member ejs.HistogramFacet
  1308. @param {String} scope The scope name to calculate facet counts with.
  1309. @returns {Object} returns <code>this</code> so that calls can be chained.
  1310. */
  1311. scope: function (scope) {
  1312. return this;
  1313. },
  1314. /**
  1315. <p>Enables caching of the <code>facetFilter</code></p>
  1316. @member ejs.HistogramFacet
  1317. @param {Boolean} trueFalse If the facetFilter should be cached or not
  1318. @returns {Object} returns <code>this</code> so that calls can be chained.
  1319. */
  1320. cacheFilter: function (trueFalse) {
  1321. if (trueFalse == null) {
  1322. return facet[name].cache_filter;
  1323. }
  1324. facet[name].cache_filter = trueFalse;
  1325. return this;
  1326. },
  1327. /**
  1328. <p>Sets the path to the nested document if faceting against a
  1329. nested field.</p>
  1330. @member ejs.HistogramFacet
  1331. @param {String} path The nested path
  1332. @returns {Object} returns <code>this</code> so that calls can be chained.
  1333. */
  1334. nested: function (path) {
  1335. if (path == null) {
  1336. return facet[name].nested;
  1337. }
  1338. facet[name].nested = path;
  1339. return this;
  1340. },
  1341. /**
  1342. <p>Allows you to serialize this object into a JSON encoded string.</p>
  1343. @member ejs.HistogramFacet
  1344. @returns {String} returns this object as a serialized JSON string.
  1345. */
  1346. toString: function () {
  1347. return JSON.stringify(facet);
  1348. },
  1349. /**
  1350. The type of ejs object. For internal use only.
  1351. @member ejs.HistogramFacet
  1352. @returns {String} the type of object
  1353. */
  1354. _type: function () {
  1355. return 'facet';
  1356. },
  1357. /**
  1358. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  1359. internal API functions so use with caution.</p>
  1360. @member ejs.HistogramFacet
  1361. @returns {String} returns this object's internal <code>facet</code> property.
  1362. */
  1363. _self: function () {
  1364. return facet;
  1365. }
  1366. };
  1367. };
  1368. /**
  1369. @class
  1370. <p>The QueryFacet facet allows you to specify any valid <code>Query</code> and
  1371. have the number of matching hits returned as the value.</p>
  1372. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  1373. better. You can also construct several <em>"groups"</em> at once by simply
  1374. specifying multiple facets.</p>
  1375. <div class="alert-message block-message info">
  1376. <p>
  1377. <strong>Tip: </strong>
  1378. For more information on faceted navigation, see
  1379. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  1380. Wikipedia article on Faceted Classification.
  1381. </p>
  1382. </div>
  1383. @name ejs.QueryFacet
  1384. @desc
  1385. <p>A facet that return a count of the hits matching the given query.</p>
  1386. @param {String} name The name which be used to refer to this facet. For instance,
  1387. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  1388. <code>name</code> to <code>Authors</code> would allow you to refer to the
  1389. facet by that name, possibly simplifying some of the display logic.
  1390. */
  1391. ejs.QueryFacet = function (name) {
  1392. /**
  1393. The internal facet object.
  1394. @member ejs.QueryFacet
  1395. @property {Object} facet
  1396. */
  1397. var facet = {};
  1398. facet[name] = {};
  1399. return {
  1400. /**
  1401. <p>Sets the query to be used for this facet.</p>
  1402. @member ejs.QueryFacet
  1403. @param {Object} oQuery A valid <code>Query</code> object.
  1404. @returns {Object} returns <code>this</code> so that calls can be chained.
  1405. */
  1406. query: function (oQuery) {
  1407. if (oQuery == null) {
  1408. return facet[name].query;
  1409. }
  1410. if (!isQuery(oQuery)) {
  1411. throw new TypeError('Argument must be a Query');
  1412. }
  1413. facet[name].query = oQuery._self();
  1414. return this;
  1415. },
  1416. /**
  1417. <p>Allows you to reduce the documents used for computing facet results.</p>
  1418. @member ejs.QueryFacet
  1419. @param {Object} oFilter A valid <code>Filter</code> object.
  1420. @returns {Object} returns <code>this</code> so that calls can be chained.
  1421. */
  1422. facetFilter: function (oFilter) {
  1423. if (oFilter == null) {
  1424. return facet[name].facet_filter;
  1425. }
  1426. if (!isFilter(oFilter)) {
  1427. throw new TypeError('Argumnet must be a Filter');
  1428. }
  1429. facet[name].facet_filter = oFilter._self();
  1430. return this;
  1431. },
  1432. /**
  1433. <p>Computes values across the entire index</p>
  1434. @member ejs.QueryFacet
  1435. @param {Boolean} trueFalse Calculate facet counts globally or not.
  1436. @returns {Object} returns <code>this</code> so that calls can be chained.
  1437. */
  1438. global: function (trueFalse) {
  1439. if (trueFalse == null) {
  1440. return facet[name].global;
  1441. }
  1442. facet[name].global = trueFalse;
  1443. return this;
  1444. },
  1445. /**
  1446. <p>Sets the mode the facet will use.<p>
  1447. <dl>
  1448. <dd><code>collector</code></dd>
  1449. <dd><code>post</code></dd>
  1450. <dl>
  1451. @member ejs.QueryFacet
  1452. @param {String} m The mode: collector or post.
  1453. @returns {Object} returns <code>this</code> so that calls can be chained.
  1454. */
  1455. mode: function (m) {
  1456. if (m == null) {
  1457. return facet[name].mode;
  1458. }
  1459. m = m.toLowerCase();
  1460. if (m === 'collector' || m === 'post') {
  1461. facet[name].mode = m;
  1462. }
  1463. return this;
  1464. },
  1465. /**
  1466. <p>Computes values across the the specified scope</p>
  1467. @deprecated since elasticsearch 0.90
  1468. @member ejs.QueryFacet
  1469. @param {String} scope The scope name to calculate facet counts with.
  1470. @returns {Object} returns <code>this</code> so that calls can be chained.
  1471. */
  1472. scope: function (scope) {
  1473. return this;
  1474. },
  1475. /**
  1476. <p>Enables caching of the <code>facetFilter</code></p>
  1477. @member ejs.QueryFacet
  1478. @param {Boolean} trueFalse If the facetFilter should be cached or not
  1479. @returns {Object} returns <code>this</code> so that calls can be chained.
  1480. */
  1481. cacheFilter: function (trueFalse) {
  1482. if (trueFalse == null) {
  1483. return facet[name].cache_filter;
  1484. }
  1485. facet[name].cache_filter = trueFalse;
  1486. return this;
  1487. },
  1488. /**
  1489. <p>Sets the path to the nested document if faceting against a
  1490. nested field.</p>
  1491. @member ejs.QueryFacet
  1492. @param {String} path The nested path
  1493. @returns {Object} returns <code>this</code> so that calls can be chained.
  1494. */
  1495. nested: function (path) {
  1496. if (path == null) {
  1497. return facet[name].nested;
  1498. }
  1499. facet[name].nested = path;
  1500. return this;
  1501. },
  1502. /**
  1503. <p>Allows you to serialize this object into a JSON encoded string.</p>
  1504. @member ejs.QueryFacet
  1505. @returns {String} returns this object as a serialized JSON string.
  1506. */
  1507. toString: function () {
  1508. return JSON.stringify(facet);
  1509. },
  1510. /**
  1511. The type of ejs object. For internal use only.
  1512. @member ejs.QueryFacet
  1513. @returns {String} the type of object
  1514. */
  1515. _type: function () {
  1516. return 'facet';
  1517. },
  1518. /**
  1519. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  1520. internal API functions so use with caution.</p>
  1521. @member ejs.QueryFacet
  1522. @returns {String} returns this object's internal <code>facet</code> property.
  1523. */
  1524. _self: function () {
  1525. return facet;
  1526. }
  1527. };
  1528. };
  1529. /**
  1530. @class
  1531. <p>A RangeFacet allows you to specify a set of ranges and get both the number of docs (count) that
  1532. fall within each range, and aggregated data based on the field, or another specified field.</p>
  1533. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  1534. better. You can also construct several <em>"groups"</em> at once by simply
  1535. specifying multiple facets.</p>
  1536. <div class="alert-message block-message info">
  1537. <p>
  1538. <strong>Tip: </strong>
  1539. For more information on faceted navigation, see
  1540. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  1541. Wikipedia article on Faceted Classification.
  1542. </p>
  1543. </div>
  1544. @name ejs.RangeFacet
  1545. @desc
  1546. <p>A facet which provides information over a range of numeric intervals.</p>
  1547. @param {String} name The name which be used to refer to this facet. For instance,
  1548. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  1549. <code>name</code> to <code>Authors</code> would allow you to refer to the
  1550. facet by that name, possibly simplifying some of the display logic.
  1551. */
  1552. ejs.RangeFacet = function (name) {
  1553. /**
  1554. The internal facet object.
  1555. @member ejs.RangeFacet
  1556. @property {Object} facet
  1557. */
  1558. var facet = {};
  1559. facet[name] = {
  1560. range: {
  1561. ranges: []
  1562. }
  1563. };
  1564. return {
  1565. /**
  1566. Sets the document field to be used for the facet.
  1567. @member ejs.RangeFacet
  1568. @param {String} fieldName The field name whose data will be used to compute the interval.
  1569. @returns {Object} returns <code>this</code> so that calls can be chained.
  1570. */
  1571. field: function (fieldName) {
  1572. if (fieldName == null) {
  1573. return facet[name].range.field;
  1574. }
  1575. facet[name].range.field = fieldName;
  1576. return this;
  1577. },
  1578. /**
  1579. Allows you to specify an alternate key field to be used to compute the interval.
  1580. @member ejs.RangeFacet
  1581. @param {String} fieldName The field name whose data will be used to compute the interval.
  1582. @returns {Object} returns <code>this</code> so that calls can be chained.
  1583. */
  1584. keyField: function (fieldName) {
  1585. if (fieldName == null) {
  1586. return facet[name].range.key_field;
  1587. }
  1588. facet[name].range.key_field = fieldName;
  1589. return this;
  1590. },
  1591. /**
  1592. Allows you to specify an alternate value field to be used to compute statistical information.
  1593. @member ejs.RangeFacet
  1594. @param {String} fieldName The field name whose data will be used to compute statistics.
  1595. @returns {Object} returns <code>this</code> so that calls can be chained.
  1596. */
  1597. valueField: function (fieldName) {
  1598. if (fieldName == null) {
  1599. return facet[name].range.value_field;
  1600. }
  1601. facet[name].range.value_field = fieldName;
  1602. return this;
  1603. },
  1604. /**
  1605. Allows you modify the <code>value</code> field using a script. The modified value
  1606. is then used to compute the statistical data.
  1607. @member ejs.RangeFacet
  1608. @param {String} scriptCode A valid script string to execute.
  1609. @returns {Object} returns <code>this</code> so that calls can be chained.
  1610. */
  1611. valueScript: function (scriptCode) {
  1612. if (scriptCode == null) {
  1613. return facet[name].range.value_script;
  1614. }
  1615. facet[name].range.value_script = scriptCode;
  1616. return this;
  1617. },
  1618. /**
  1619. Allows you modify the <code>key</code> field using a script. The modified value
  1620. is then used to generate the interval.
  1621. @member ejs.RangeFacet
  1622. @param {String} scriptCode A valid script string to execute.
  1623. @returns {Object} returns <code>this</code> so that calls can be chained.
  1624. */
  1625. keyScript: function (scriptCode) {
  1626. if (scriptCode == null) {
  1627. return facet[name].range.key_script;
  1628. }
  1629. facet[name].range.key_script = scriptCode;
  1630. return this;
  1631. },
  1632. /**
  1633. The script language being used. Currently supported values are
  1634. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  1635. @member ejs.RangeFacet
  1636. @param {String} language The language of the script.
  1637. @returns {Object} returns <code>this</code> so that calls can be chained.
  1638. */
  1639. lang: function (language) {
  1640. if (language == null) {
  1641. return facet[name].range.lang;
  1642. }
  1643. facet[name].range.lang = language;
  1644. return this;
  1645. },
  1646. /**
  1647. Sets parameters that will be applied to the script. Overwrites
  1648. any existing params.
  1649. @member ejs.RangeFacet
  1650. @param {Object} p An object where the keys are the parameter name and
  1651. values are the parameter value.
  1652. @returns {Object} returns <code>this</code> so that calls can be chained.
  1653. */
  1654. params: function (p) {
  1655. if (p == null) {
  1656. return facet[name].range.params;
  1657. }
  1658. facet[name].range.params = p;
  1659. return this;
  1660. },
  1661. /**
  1662. Adds a new bounded range.
  1663. @member ejs.RangeFacet
  1664. @param {Number} from The lower bound of the range (can also be <code>Date</code>).
  1665. @param {Number} to The upper bound of the range (can also be <code>Date</code>).
  1666. @returns {Object} returns <code>this</code> so that calls can be chained.
  1667. */
  1668. addRange: function (from, to) {
  1669. if (arguments.length === 0) {
  1670. return facet[name].range.ranges;
  1671. }
  1672. facet[name].range.ranges.push({
  1673. from: from,
  1674. to: to
  1675. });
  1676. return this;
  1677. },
  1678. /**
  1679. Adds a new unbounded lower limit.
  1680. @member ejs.RangeFacet
  1681. @param {Number} from The lower limit of the unbounded range (can also be <code>Date</code>).
  1682. @returns {Object} returns <code>this</code> so that calls can be chained.
  1683. */
  1684. addUnboundedFrom: function (from) {
  1685. if (from == null) {
  1686. return facet[name].range.ranges;
  1687. }
  1688. facet[name].range.ranges.push({
  1689. from: from
  1690. });
  1691. return this;
  1692. },
  1693. /**
  1694. Adds a new unbounded upper limit.
  1695. @member ejs.RangeFacet
  1696. @param {Number} to The upper limit of the unbounded range (can also be <code>Date</code>).
  1697. @returns {Object} returns <code>this</code> so that calls can be chained.
  1698. */
  1699. addUnboundedTo: function (to) {
  1700. if (to == null) {
  1701. return facet[name].range.ranges;
  1702. }
  1703. facet[name].range.ranges.push({
  1704. to: to
  1705. });
  1706. return this;
  1707. },
  1708. /**
  1709. <p>Allows you to reduce the documents used for computing facet results.</p>
  1710. @member ejs.RangeFacet
  1711. @param {Object} oFilter A valid <code>Filter</code> object.
  1712. @returns {Object} returns <code>this</code> so that calls can be chained.
  1713. */
  1714. facetFilter: function (oFilter) {
  1715. if (oFilter == null) {
  1716. return facet[name].facet_filter;
  1717. }
  1718. if (!isFilter(oFilter)) {
  1719. throw new TypeError('Argument must be a Filter');
  1720. }
  1721. facet[name].facet_filter = oFilter._self();
  1722. return this;
  1723. },
  1724. /**
  1725. <p>Computes values across the entire index</p>
  1726. @member ejs.RangeFacet
  1727. @param {Boolean} trueFalse Calculate facet counts globally or not.
  1728. @returns {Object} returns <code>this</code> so that calls can be chained.
  1729. */
  1730. global: function (trueFalse) {
  1731. if (trueFalse == null) {
  1732. return facet[name].global;
  1733. }
  1734. facet[name].global = trueFalse;
  1735. return this;
  1736. },
  1737. /**
  1738. <p>Sets the mode the facet will use.<p>
  1739. <dl>
  1740. <dd><code>collector</code></dd>
  1741. <dd><code>post</code></dd>
  1742. <dl>
  1743. @member ejs.RangeFacet
  1744. @param {String} m The mode: collector or post.
  1745. @returns {Object} returns <code>this</code> so that calls can be chained.
  1746. */
  1747. mode: function (m) {
  1748. if (m == null) {
  1749. return facet[name].mode;
  1750. }
  1751. m = m.toLowerCase();
  1752. if (m === 'collector' || m === 'post') {
  1753. facet[name].mode = m;
  1754. }
  1755. return this;
  1756. },
  1757. /**
  1758. <p>Computes values across the the specified scope</p>
  1759. @deprecated since elasticsearch 0.90
  1760. @member ejs.RangeFacet
  1761. @param {String} scope The scope name to calculate facet counts with.
  1762. @returns {Object} returns <code>this</code> so that calls can be chained.
  1763. */
  1764. scope: function (scope) {
  1765. return this;
  1766. },
  1767. /**
  1768. <p>Enables caching of the <code>facetFilter</code></p>
  1769. @member ejs.RangeFacet
  1770. @param {Boolean} trueFalse If the facetFilter should be cached or not
  1771. @returns {Object} returns <code>this</code> so that calls can be chained.
  1772. */
  1773. cacheFilter: function (trueFalse) {
  1774. if (trueFalse == null) {
  1775. return facet[name].cache_filter;
  1776. }
  1777. facet[name].cache_filter = trueFalse;
  1778. return this;
  1779. },
  1780. /**
  1781. <p>Sets the path to the nested document if faceting against a
  1782. nested field.</p>
  1783. @member ejs.RangeFacet
  1784. @param {String} path The nested path
  1785. @returns {Object} returns <code>this</code> so that calls can be chained.
  1786. */
  1787. nested: function (path) {
  1788. if (path == null) {
  1789. return facet[name].nested;
  1790. }
  1791. facet[name].nested = path;
  1792. return this;
  1793. },
  1794. /**
  1795. <p>Allows you to serialize this object into a JSON encoded string.</p>
  1796. @member ejs.RangeFacet
  1797. @returns {String} returns this object as a serialized JSON string.
  1798. */
  1799. toString: function () {
  1800. return JSON.stringify(facet);
  1801. },
  1802. /**
  1803. The type of ejs object. For internal use only.
  1804. @member ejs.RangeFacet
  1805. @returns {String} the type of object
  1806. */
  1807. _type: function () {
  1808. return 'facet';
  1809. },
  1810. /**
  1811. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  1812. internal API functions so use with caution.</p>
  1813. @member ejs.RangeFacet
  1814. @returns {String} returns this object's internal <code>facet</code> property.
  1815. */
  1816. _self: function () {
  1817. return facet;
  1818. }
  1819. };
  1820. };
  1821. /**
  1822. @class
  1823. <p>A statistical facet allows you to compute statistical data over a numeric fields. Statistical data includes
  1824. the count, total, sum of squares, mean (average), minimum, maximum, variance, and standard deviation.</p>
  1825. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  1826. better. You can also construct several <em>"groups"</em> at once by simply
  1827. specifying multiple facets.</p>
  1828. <div class="alert-message block-message info">
  1829. <p>
  1830. <strong>Tip: </strong>
  1831. For more information on faceted navigation, see
  1832. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  1833. Wikipedia article on Faceted Classification.
  1834. </p>
  1835. </div>
  1836. @name ejs.StatisticalFacet
  1837. @desc
  1838. <p>A facet which returns statistical information about a numeric field</p>
  1839. @param {String} name The name which be used to refer to this facet. For instance,
  1840. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  1841. <code>name</code> to <code>Authors</code> would allow you to refer to the
  1842. facet by that name, possibly simplifying some of the display logic.
  1843. */
  1844. ejs.StatisticalFacet = function (name) {
  1845. /**
  1846. The internal facet object.
  1847. @member ejs.StatisticalFacet
  1848. @property {Object} facet
  1849. */
  1850. var facet = {};
  1851. facet[name] = {
  1852. statistical: {}
  1853. };
  1854. return {
  1855. /**
  1856. Sets the field to be used to construct the this facet.
  1857. @member ejs.StatisticalFacet
  1858. @param {String} fieldName The field name whose data will be used to construct the facet.
  1859. @returns {Object} returns <code>this</code> so that calls can be chained.
  1860. */
  1861. field: function (fieldName) {
  1862. if (fieldName == null) {
  1863. return facet[name].statistical.field;
  1864. }
  1865. facet[name].statistical.field = fieldName;
  1866. return this;
  1867. },
  1868. /**
  1869. Aggregate statistical info across a set of fields.
  1870. @member ejs.StatisticalFacet
  1871. @param {Array} aFieldName An array of field names.
  1872. @returns {Object} returns <code>this</code> so that calls can be chained.
  1873. */
  1874. fields: function (fields) {
  1875. if (fields == null) {
  1876. return facet[name].statistical.fields;
  1877. }
  1878. if (!isArray(fields)) {
  1879. throw new TypeError('Argument must be an array');
  1880. }
  1881. facet[name].statistical.fields = fields;
  1882. return this;
  1883. },
  1884. /**
  1885. Define a script to evaluate of which the result will be used to generate
  1886. the statistical information.
  1887. @member ejs.StatisticalFacet
  1888. @param {String} code The script code to execute.
  1889. @returns {Object} returns <code>this</code> so that calls can be chained.
  1890. */
  1891. script: function (code) {
  1892. if (code == null) {
  1893. return facet[name].statistical.script;
  1894. }
  1895. facet[name].statistical.script = code;
  1896. return this;
  1897. },
  1898. /**
  1899. The script language being used. Currently supported values are
  1900. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  1901. @member ejs.StatisticalFacet
  1902. @param {String} language The language of the script.
  1903. @returns {Object} returns <code>this</code> so that calls can be chained.
  1904. */
  1905. lang: function (language) {
  1906. if (language == null) {
  1907. return facet[name].statistical.lang;
  1908. }
  1909. facet[name].statistical.lang = language;
  1910. return this;
  1911. },
  1912. /**
  1913. Allows you to set script parameters to be used during the execution of the script.
  1914. @member ejs.StatisticalFacet
  1915. @param {Object} oParams An object containing key/value pairs representing param name/value.
  1916. @returns {Object} returns <code>this</code> so that calls can be chained.
  1917. */
  1918. params: function (oParams) {
  1919. if (oParams == null) {
  1920. return facet[name].statistical.params;
  1921. }
  1922. facet[name].statistical.params = oParams;
  1923. return this;
  1924. },
  1925. /**
  1926. <p>Allows you to reduce the documents used for computing facet results.</p>
  1927. @member ejs.StatisticalFacet
  1928. @param {Object} oFilter A valid <code>Filter</code> object.
  1929. @returns {Object} returns <code>this</code> so that calls can be chained.
  1930. */
  1931. facetFilter: function (oFilter) {
  1932. if (oFilter == null) {
  1933. return facet[name].facet_filter;
  1934. }
  1935. if (!isFilter(oFilter)) {
  1936. throw new TypeError('Argument must be a Filter');
  1937. }
  1938. facet[name].facet_filter = oFilter._self();
  1939. return this;
  1940. },
  1941. /**
  1942. <p>Computes values across the entire index</p>
  1943. @member ejs.StatisticalFacet
  1944. @param {Boolean} trueFalse Calculate facet counts globally or not.
  1945. @returns {Object} returns <code>this</code> so that calls can be chained.
  1946. */
  1947. global: function (trueFalse) {
  1948. if (trueFalse == null) {
  1949. return facet[name].global;
  1950. }
  1951. facet[name].global = trueFalse;
  1952. return this;
  1953. },
  1954. /**
  1955. <p>Sets the mode the facet will use.<p>
  1956. <dl>
  1957. <dd><code>collector</code></dd>
  1958. <dd><code>post</code></dd>
  1959. <dl>
  1960. @member ejs.StatisticalFacet
  1961. @param {String} m The mode: collector or post.
  1962. @returns {Object} returns <code>this</code> so that calls can be chained.
  1963. */
  1964. mode: function (m) {
  1965. if (m == null) {
  1966. return facet[name].mode;
  1967. }
  1968. m = m.toLowerCase();
  1969. if (m === 'collector' || m === 'post') {
  1970. facet[name].mode = m;
  1971. }
  1972. return this;
  1973. },
  1974. /**
  1975. <p>Computes values across the the specified scope</p>
  1976. @deprecated since elasticsearch 0.90
  1977. @member ejs.StatisticalFacet
  1978. @param {String} scope The scope name to calculate facet counts with.
  1979. @returns {Object} returns <code>this</code> so that calls can be chained.
  1980. */
  1981. scope: function (scope) {
  1982. return this;
  1983. },
  1984. /**
  1985. <p>Enables caching of the <code>facetFilter</code></p>
  1986. @member ejs.StatisticalFacet
  1987. @param {Boolean} trueFalse If the facetFilter should be cached or not
  1988. @returns {Object} returns <code>this</code> so that calls can be chained.
  1989. */
  1990. cacheFilter: function (trueFalse) {
  1991. if (trueFalse == null) {
  1992. return facet[name].cache_filter;
  1993. }
  1994. facet[name].cache_filter = trueFalse;
  1995. return this;
  1996. },
  1997. /**
  1998. <p>Sets the path to the nested document if faceting against a
  1999. nested field.</p>
  2000. @member ejs.StatisticalFacet
  2001. @param {String} path The nested path
  2002. @returns {Object} returns <code>this</code> so that calls can be chained.
  2003. */
  2004. nested: function (path) {
  2005. if (path == null) {
  2006. return facet[name].nested;
  2007. }
  2008. facet[name].nested = path;
  2009. return this;
  2010. },
  2011. /**
  2012. <p>Allows you to serialize this object into a JSON encoded string.</p>
  2013. @member ejs.StatisticalFacet
  2014. @returns {String} returns this object as a serialized JSON string.
  2015. */
  2016. toString: function () {
  2017. return JSON.stringify(facet);
  2018. },
  2019. /**
  2020. The type of ejs object. For internal use only.
  2021. @member ejs.StatisticalFacet
  2022. @returns {String} the type of object
  2023. */
  2024. _type: function () {
  2025. return 'facet';
  2026. },
  2027. /**
  2028. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  2029. internal API functions so use with caution.</p>
  2030. @member ejs.StatisticalFacet
  2031. @returns {String} returns this object's internal <code>facet</code> property.
  2032. */
  2033. _self: function () {
  2034. return facet;
  2035. }
  2036. };
  2037. };
  2038. /**
  2039. @class
  2040. <p>A termsStatsFacet allows you to compute statistics over an aggregate key (term). Essentially this
  2041. facet provides the functionality of what is often refered to as a <em>pivot table</em>.</p>
  2042. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  2043. better. You can also construct several <em>"groups"</em> at once by simply
  2044. specifying multiple facets.</p>
  2045. <div class="alert-message block-message info">
  2046. <p>
  2047. <strong>Tip: </strong>
  2048. For more information on faceted navigation, see
  2049. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  2050. Wikipedia article on Faceted Classification.
  2051. </p>
  2052. </div>
  2053. @name ejs.TermStatsFacet
  2054. @desc
  2055. <p>A facet which computes statistical data based on an aggregate key.</p>
  2056. @param {String} name The name which be used to refer to this facet. For instance,
  2057. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  2058. <code>name</code> to <code>Authors</code> would allow you to refer to the
  2059. facet by that name, possibly simplifying some of the display logic.
  2060. */
  2061. ejs.TermStatsFacet = function (name) {
  2062. /**
  2063. The internal facet object.
  2064. @member ejs.TermStatsFacet
  2065. @property {Object} facet
  2066. */
  2067. var facet = {};
  2068. facet[name] = {
  2069. terms_stats: {}
  2070. };
  2071. return {
  2072. /**
  2073. Sets the field for which statistical information will be generated.
  2074. @member ejs.TermStatsFacet
  2075. @param {String} fieldName The field name whose data will be used to construct the facet.
  2076. @returns {Object} returns <code>this</code> so that calls can be chained.
  2077. */
  2078. valueField: function (fieldName) {
  2079. if (fieldName == null) {
  2080. return facet[name].terms_stats.value_field;
  2081. }
  2082. facet[name].terms_stats.value_field = fieldName;
  2083. return this;
  2084. },
  2085. /**
  2086. Sets the field which will be used to pivot on (group-by).
  2087. @member ejs.TermStatsFacet
  2088. @param {String} fieldName The field name whose data will be used to construct the facet.
  2089. @returns {Object} returns <code>this</code> so that calls can be chained.
  2090. */
  2091. keyField: function (fieldName) {
  2092. if (fieldName == null) {
  2093. return facet[name].terms_stats.key_field;
  2094. }
  2095. facet[name].terms_stats.key_field = fieldName;
  2096. return this;
  2097. },
  2098. /**
  2099. Sets a script that will provide the terms for a given document.
  2100. @member ejs.TermStatsFacet
  2101. @param {String} script The script code.
  2102. @returns {Object} returns <code>this</code> so that calls can be chained.
  2103. */
  2104. scriptField: function (script) {
  2105. if (script == null) {
  2106. return facet[name].terms_stats.script_field;
  2107. }
  2108. facet[name].terms_stats.script_field = script;
  2109. return this;
  2110. },
  2111. /**
  2112. Define a script to evaluate of which the result will be used to generate
  2113. the statistical information.
  2114. @member ejs.TermStatsFacet
  2115. @param {String} code The script code to execute.
  2116. @returns {Object} returns <code>this</code> so that calls can be chained.
  2117. */
  2118. valueScript: function (code) {
  2119. if (code == null) {
  2120. return facet[name].terms_stats.value_script;
  2121. }
  2122. facet[name].terms_stats.value_script = code;
  2123. return this;
  2124. },
  2125. /**
  2126. <p>Allows you to return all terms, even if the frequency count is 0. This should not be
  2127. used on fields that contain a large number of unique terms because it could cause
  2128. <em>out-of-memory</em> errors.</p>
  2129. @member ejs.TermStatsFacet
  2130. @param {String} trueFalse <code>true</code> or <code>false</code>
  2131. @returns {Object} returns <code>this</code> so that calls can be chained.
  2132. */
  2133. allTerms: function (trueFalse) {
  2134. if (trueFalse == null) {
  2135. return facet[name].terms_stats.all_terms;
  2136. }
  2137. facet[name].terms_stats.all_terms = trueFalse;
  2138. return this;
  2139. },
  2140. /**
  2141. The script language being used. Currently supported values are
  2142. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  2143. @member ejs.TermStatsFacet
  2144. @param {String} language The language of the script.
  2145. @returns {Object} returns <code>this</code> so that calls can be chained.
  2146. */
  2147. lang: function (language) {
  2148. if (language == null) {
  2149. return facet[name].terms_stats.lang;
  2150. }
  2151. facet[name].terms_stats.lang = language;
  2152. return this;
  2153. },
  2154. /**
  2155. Allows you to set script parameters to be used during the execution of the script.
  2156. @member ejs.TermStatsFacet
  2157. @param {Object} oParams An object containing key/value pairs representing param name/value.
  2158. @returns {Object} returns <code>this</code> so that calls can be chained.
  2159. */
  2160. params: function (oParams) {
  2161. if (oParams == null) {
  2162. return facet[name].terms_stats.params;
  2163. }
  2164. facet[name].terms_stats.params = oParams;
  2165. return this;
  2166. },
  2167. /**
  2168. Sets the number of facet entries that will be returned for this facet. For instance, you
  2169. might ask for only the top 5 aggregate keys although there might be hundreds of
  2170. unique keys. <strong>Higher settings could cause memory strain</strong>.
  2171. @member ejs.TermStatsFacet
  2172. @param {Integer} facetSize The numer of facet entries to be returned.
  2173. @returns {Object} returns <code>this</code> so that calls can be chained.
  2174. */
  2175. size: function (facetSize) {
  2176. if (facetSize == null) {
  2177. return facet[name].terms_stats.size;
  2178. }
  2179. facet[name].terms_stats.size = facetSize;
  2180. return this;
  2181. },
  2182. /**
  2183. Sets the type of ordering that will be performed on the date
  2184. buckets. Valid values are:
  2185. count - default, sort by the number of items in the bucket
  2186. term - sort by term value.
  2187. reverse_count - reverse sort of the number of items in the bucket
  2188. reverse_term - reverse sort of the term value.
  2189. total - sorts by the total value of the bucket contents
  2190. reverse_total - reverse sort of the total value of bucket contents
  2191. min - the minimum value in the bucket
  2192. reverse_min - the reverse sort of the minimum value
  2193. max - the maximum value in the bucket
  2194. reverse_max - the reverse sort of the maximum value
  2195. mean - the mean value of the bucket contents
  2196. reverse_mean - the reverse sort of the mean value of bucket contents.
  2197. @member ejs.TermStatsFacet
  2198. @param {String} o The ordering method
  2199. @returns {Object} returns <code>this</code> so that calls can be chained.
  2200. */
  2201. order: function (o) {
  2202. if (o == null) {
  2203. return facet[name].terms_stats.order;
  2204. }
  2205. o = o.toLowerCase();
  2206. if (o === 'count' || o === 'term' || o === 'reverse_count' ||
  2207. o === 'reverse_term' || o === 'total' || o === 'reverse_total' ||
  2208. o === 'min' || o === 'reverse_min' || o === 'max' ||
  2209. o === 'reverse_max' || o === 'mean' || o === 'reverse_mean') {
  2210. facet[name].terms_stats.order = o;
  2211. }
  2212. return this;
  2213. },
  2214. /**
  2215. <p>Allows you to reduce the documents used for computing facet results.</p>
  2216. @member ejs.TermStatsFacet
  2217. @param {Object} oFilter A valid <code>Filter</code> object.
  2218. @returns {Object} returns <code>this</code> so that calls can be chained.
  2219. */
  2220. facetFilter: function (oFilter) {
  2221. if (oFilter == null) {
  2222. return facet[name].facet_filter;
  2223. }
  2224. if (!isFilter(oFilter)) {
  2225. throw new TypeError('Argument must be a Filter');
  2226. }
  2227. facet[name].facet_filter = oFilter._self();
  2228. return this;
  2229. },
  2230. /**
  2231. <p>Computes values across the entire index</p>
  2232. @member ejs.TermStatsFacet
  2233. @param {Boolean} trueFalse Calculate facet counts globally or not.
  2234. @returns {Object} returns <code>this</code> so that calls can be chained.
  2235. */
  2236. global: function (trueFalse) {
  2237. if (trueFalse == null) {
  2238. return facet[name].global;
  2239. }
  2240. facet[name].global = trueFalse;
  2241. return this;
  2242. },
  2243. /**
  2244. <p>Sets the mode the facet will use.<p>
  2245. <dl>
  2246. <dd><code>collector</code></dd>
  2247. <dd><code>post</code></dd>
  2248. <dl>
  2249. @member ejs.TermStatsFacet
  2250. @param {String} m The mode: collector or post.
  2251. @returns {Object} returns <code>this</code> so that calls can be chained.
  2252. */
  2253. mode: function (m) {
  2254. if (m == null) {
  2255. return facet[name].mode;
  2256. }
  2257. m = m.toLowerCase();
  2258. if (m === 'collector' || m === 'post') {
  2259. facet[name].mode = m;
  2260. }
  2261. return this;
  2262. },
  2263. /**
  2264. <p>Computes values across the the specified scope</p>
  2265. @deprecated since elasticsearch 0.90
  2266. @member ejs.TermStatsFacet
  2267. @param {String} scope The scope name to calculate facet counts with.
  2268. @returns {Object} returns <code>this</code> so that calls can be chained.
  2269. */
  2270. scope: function (scope) {
  2271. return this;
  2272. },
  2273. /**
  2274. <p>Enables caching of the <code>facetFilter</code></p>
  2275. @member ejs.TermStatsFacet
  2276. @param {Boolean} trueFalse If the facetFilter should be cached or not
  2277. @returns {Object} returns <code>this</code> so that calls can be chained.
  2278. */
  2279. cacheFilter: function (trueFalse) {
  2280. if (trueFalse == null) {
  2281. return facet[name].cache_filter;
  2282. }
  2283. facet[name].cache_filter = trueFalse;
  2284. return this;
  2285. },
  2286. /**
  2287. <p>Sets the path to the nested document if faceting against a
  2288. nested field.</p>
  2289. @member ejs.TermStatsFacet
  2290. @param {String} path The nested path
  2291. @returns {Object} returns <code>this</code> so that calls can be chained.
  2292. */
  2293. nested: function (path) {
  2294. if (path == null) {
  2295. return facet[name].nested;
  2296. }
  2297. facet[name].nested = path;
  2298. return this;
  2299. },
  2300. /**
  2301. <p>Allows you to serialize this object into a JSON encoded string.</p>
  2302. @member ejs.TermStatsFacet
  2303. @returns {String} returns this object as a serialized JSON string.
  2304. */
  2305. toString: function () {
  2306. return JSON.stringify(facet);
  2307. },
  2308. /**
  2309. The type of ejs object. For internal use only.
  2310. @member ejs.TermStatsFacet
  2311. @returns {String} the type of object
  2312. */
  2313. _type: function () {
  2314. return 'facet';
  2315. },
  2316. /**
  2317. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  2318. internal API functions so use with caution.</p>
  2319. @member ejs.TermStatsFacet
  2320. @returns {String} returns this object's internal <code>facet</code> property.
  2321. */
  2322. _self: function () {
  2323. return facet;
  2324. }
  2325. };
  2326. };
  2327. /**
  2328. @class
  2329. <p>A facet which returns the N most frequent terms within a collection
  2330. or set of collections. Term facets are useful for building constructs
  2331. which allow users to refine search results by filtering on terms returned
  2332. by the facet.</p>
  2333. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  2334. better. You can also construct several <em>"groups"</em> at once by simply
  2335. specifying multiple facets.</p>
  2336. <p>For more information on faceted navigation, see this Wikipedia article on
  2337. <a href="http://en.wikipedia.org/wiki/Faceted_classification">Faceted Classification</a></p<
  2338. @name ejs.TermsFacet
  2339. @desc
  2340. <p>A facet which returns the N most frequent terms within a collection
  2341. or set of collections.</p>
  2342. @param {String} name The name which be used to refer to this facet. For instance,
  2343. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  2344. <code>name</code> to <code>Authors</code> would allow you to refer to the
  2345. facet by that name, possibly simplifying some of the display logic.
  2346. */
  2347. ejs.TermsFacet = function (name) {
  2348. /**
  2349. The internal facet object.
  2350. @member ejs.TermsFacet
  2351. @property {Object} facet
  2352. */
  2353. var facet = {};
  2354. facet[name] = {
  2355. terms: {}
  2356. };
  2357. return {
  2358. /**
  2359. Sets the field to be used to construct the this facet. Set to
  2360. _index to return a facet count of hits per _index the search was
  2361. executed on.
  2362. @member ejs.TermsFacet
  2363. @param {String} fieldName The field name whose data will be used to construct the facet.
  2364. @returns {Object} returns <code>this</code> so that calls can be chained.
  2365. */
  2366. field: function (fieldName) {
  2367. if (fieldName == null) {
  2368. return facet[name].terms.field;
  2369. }
  2370. facet[name].terms.field = fieldName;
  2371. return this;
  2372. },
  2373. /**
  2374. Aggregate statistical info across a set of fields.
  2375. @member ejs.TermsFacet
  2376. @param {Array} aFieldName An array of field names.
  2377. @returns {Object} returns <code>this</code> so that calls can be chained.
  2378. */
  2379. fields: function (fields) {
  2380. if (fields == null) {
  2381. return facet[name].terms.fields;
  2382. }
  2383. if (!isArray(fields)) {
  2384. throw new TypeError('Argument must be an array');
  2385. }
  2386. facet[name].terms.fields = fields;
  2387. return this;
  2388. },
  2389. /**
  2390. Sets a script that will provide the terms for a given document.
  2391. @member ejs.TermsFacet
  2392. @param {String} script The script code.
  2393. @returns {Object} returns <code>this</code> so that calls can be chained.
  2394. */
  2395. scriptField: function (script) {
  2396. if (script == null) {
  2397. return facet[name].terms.script_field;
  2398. }
  2399. facet[name].terms.script_field = script;
  2400. return this;
  2401. },
  2402. /**
  2403. Sets the number of facet entries that will be returned for this facet. For instance, you
  2404. might ask for only the top 5 <code>authors</code> although there might be hundreds of
  2405. unique authors.
  2406. @member ejs.TermsFacet
  2407. @param {Integer} facetSize The numer of facet entries to be returned.
  2408. @returns {Object} returns <code>this</code> so that calls can be chained.
  2409. */
  2410. size: function (facetSize) {
  2411. if (facetSize == null) {
  2412. return facet[name].terms.size;
  2413. }
  2414. facet[name].terms.size = facetSize;
  2415. return this;
  2416. },
  2417. /**
  2418. Sets the type of ordering that will be performed on the date
  2419. buckets. Valid values are:
  2420. count - default, sort by the number of items in the bucket
  2421. term - sort by term value.
  2422. reverse_count - reverse sort of the number of items in the bucket
  2423. reverse_term - reverse sort of the term value.
  2424. @member ejs.TermsFacet
  2425. @param {String} o The ordering method
  2426. @returns {Object} returns <code>this</code> so that calls can be chained.
  2427. */
  2428. order: function (o) {
  2429. if (o == null) {
  2430. return facet[name].terms.order;
  2431. }
  2432. o = o.toLowerCase();
  2433. if (o === 'count' || o === 'term' ||
  2434. o === 'reverse_count' || o === 'reverse_term') {
  2435. facet[name].terms.order = o;
  2436. }
  2437. return this;
  2438. },
  2439. /**
  2440. <p>Allows you to return all terms, even if the frequency count is 0. This should not be
  2441. used on fields that contain a large number of unique terms because it could cause
  2442. <em>out-of-memory</em> errors.</p>
  2443. @member ejs.TermsFacet
  2444. @param {String} trueFalse <code>true</code> or <code>false</code>
  2445. @returns {Object} returns <code>this</code> so that calls can be chained.
  2446. */
  2447. allTerms: function (trueFalse) {
  2448. if (trueFalse == null) {
  2449. return facet[name].terms.all_terms;
  2450. }
  2451. facet[name].terms.all_terms = trueFalse;
  2452. return this;
  2453. },
  2454. /**
  2455. <p>Allows you to filter out unwanted facet entries. When passed
  2456. a single term, it is appended to the list of currently excluded
  2457. terms. If passed an array, it overwrites all existing values.</p>
  2458. @member ejs.TermsFacet
  2459. @param {String || Array} exclude A single term to exclude or an
  2460. array of terms to exclude.
  2461. @returns {Object} returns <code>this</code> so that calls can be chained.
  2462. */
  2463. exclude: function (exclude) {
  2464. if (facet[name].terms.exclude == null) {
  2465. facet[name].terms.exclude = [];
  2466. }
  2467. if (exclude == null) {
  2468. return facet[name].terms.exclude;
  2469. }
  2470. if (isString(exclude)) {
  2471. facet[name].terms.exclude.push(exclude);
  2472. } else if (isArray(exclude)) {
  2473. facet[name].terms.exclude = exclude;
  2474. } else {
  2475. throw new TypeError('Argument must be string or array');
  2476. }
  2477. return this;
  2478. },
  2479. /**
  2480. <p>Allows you to only include facet entries matching a specified regular expression.</p>
  2481. @member ejs.TermsFacet
  2482. @param {String} exp A valid regular expression.
  2483. @returns {Object} returns <code>this</code> so that calls can be chained.
  2484. */
  2485. regex: function (exp) {
  2486. if (exp == null) {
  2487. return facet[name].terms.regex;
  2488. }
  2489. facet[name].terms.regex = exp;
  2490. return this;
  2491. },
  2492. /**
  2493. <p>Allows you to set the regular expression flags to be used
  2494. with the <code>regex</code></p>
  2495. @member ejs.TermsFacet
  2496. @param {String} flags A valid regex flag - see <a href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#field_summary">Java Pattern API</a>
  2497. @returns {Object} returns <code>this</code> so that calls can be chained.
  2498. */
  2499. regexFlags: function (flags) {
  2500. if (flags == null) {
  2501. return facet[name].terms.regex_flags;
  2502. }
  2503. facet[name].terms.regex_flags = flags;
  2504. return this;
  2505. },
  2506. /**
  2507. Allows you modify the term using a script. The modified value
  2508. is then used in the facet collection.
  2509. @member ejs.TermsFacet
  2510. @param {String} scriptCode A valid script string to execute.
  2511. @returns {Object} returns <code>this</code> so that calls can be chained.
  2512. */
  2513. script: function (scriptCode) {
  2514. if (scriptCode == null) {
  2515. return facet[name].terms.script;
  2516. }
  2517. facet[name].terms.script = scriptCode;
  2518. return this;
  2519. },
  2520. /**
  2521. The script language being used. Currently supported values are
  2522. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  2523. @member ejs.TermsFacet
  2524. @param {String} language The language of the script.
  2525. @returns {Object} returns <code>this</code> so that calls can be chained.
  2526. */
  2527. lang: function (language) {
  2528. if (language == null) {
  2529. return facet[name].terms.lang;
  2530. }
  2531. facet[name].terms.lang = language;
  2532. return this;
  2533. },
  2534. /**
  2535. Sets parameters that will be applied to the script. Overwrites
  2536. any existing params.
  2537. @member ejs.TermsFacet
  2538. @param {Object} p An object where the keys are the parameter name and
  2539. values are the parameter value.
  2540. @returns {Object} returns <code>this</code> so that calls can be chained.
  2541. */
  2542. params: function (p) {
  2543. if (p == null) {
  2544. return facet[name].terms.params;
  2545. }
  2546. facet[name].terms.params = p;
  2547. return this;
  2548. },
  2549. /**
  2550. Sets the execution hint determines how the facet is computed.
  2551. Currently only supported value is "map".
  2552. @member ejs.TermsFacet
  2553. @param {Object} h The hint value as a string.
  2554. @returns {Object} returns <code>this</code> so that calls can be chained.
  2555. */
  2556. executionHint: function (h) {
  2557. if (h == null) {
  2558. return facet[name].terms.execution_hint;
  2559. }
  2560. facet[name].terms.execution_hint = h;
  2561. return this;
  2562. },
  2563. /**
  2564. <p>Allows you to reduce the documents used for computing facet results.</p>
  2565. @member ejs.TermsFacet
  2566. @param {Object} oFilter A valid <code>Filter</code> object.
  2567. @returns {Object} returns <code>this</code> so that calls can be chained.
  2568. */
  2569. facetFilter: function (oFilter) {
  2570. if (oFilter == null) {
  2571. return facet[name].facet_filter;
  2572. }
  2573. if (!isFilter(oFilter)) {
  2574. throw new TypeError('Argument must be a Filter');
  2575. }
  2576. facet[name].facet_filter = oFilter._self();
  2577. return this;
  2578. },
  2579. /**
  2580. <p>Computes values across the entire index</p>
  2581. @member ejs.TermsFacet
  2582. @param {Boolean} trueFalse Calculate facet counts globally or not.
  2583. @returns {Object} returns <code>this</code> so that calls can be chained.
  2584. */
  2585. global: function (trueFalse) {
  2586. if (trueFalse == null) {
  2587. return facet[name].global;
  2588. }
  2589. facet[name].global = trueFalse;
  2590. return this;
  2591. },
  2592. /**
  2593. <p>Sets the mode the facet will use.<p>
  2594. <dl>
  2595. <dd><code>collector</code></dd>
  2596. <dd><code>post</code></dd>
  2597. <dl>
  2598. @member ejs.TermsFacet
  2599. @param {String} m The mode: collector or post.
  2600. @returns {Object} returns <code>this</code> so that calls can be chained.
  2601. */
  2602. mode: function (m) {
  2603. if (m == null) {
  2604. return facet[name].mode;
  2605. }
  2606. m = m.toLowerCase();
  2607. if (m === 'collector' || m === 'post') {
  2608. facet[name].mode = m;
  2609. }
  2610. return this;
  2611. },
  2612. /**
  2613. <p>Computes values across the the specified scope</p>
  2614. @deprecated since elasticsearch 0.90
  2615. @member ejs.TermsFacet
  2616. @param {String} scope The scope name to calculate facet counts with.
  2617. @returns {Object} returns <code>this</code> so that calls can be chained.
  2618. */
  2619. scope: function (scope) {
  2620. return this;
  2621. },
  2622. /**
  2623. <p>Enables caching of the <code>facetFilter</code></p>
  2624. @member ejs.TermsFacet
  2625. @param {Boolean} trueFalse If the facetFilter should be cached or not
  2626. @returns {Object} returns <code>this</code> so that calls can be chained.
  2627. */
  2628. cacheFilter: function (trueFalse) {
  2629. if (trueFalse == null) {
  2630. return facet[name].cache_filter;
  2631. }
  2632. facet[name].cache_filter = trueFalse;
  2633. return this;
  2634. },
  2635. /**
  2636. <p>Sets the path to the nested document if faceting against a
  2637. nested field.</p>
  2638. @member ejs.TermsFacet
  2639. @param {String} path The nested path
  2640. @returns {Object} returns <code>this</code> so that calls can be chained.
  2641. */
  2642. nested: function (path) {
  2643. if (path == null) {
  2644. return facet[name].nested;
  2645. }
  2646. facet[name].nested = path;
  2647. return this;
  2648. },
  2649. /**
  2650. <p>Allows you to serialize this object into a JSON encoded string.</p>
  2651. @member ejs.TermsFacet
  2652. @returns {String} returns this object as a serialized JSON string.
  2653. */
  2654. toString: function () {
  2655. return JSON.stringify(facet);
  2656. },
  2657. /**
  2658. The type of ejs object. For internal use only.
  2659. @member ejs.TermsFacet
  2660. @returns {String} the type of object
  2661. */
  2662. _type: function () {
  2663. return 'facet';
  2664. },
  2665. /**
  2666. <p>Retrieves the internal <code>facet</code> property. This is typically used by
  2667. internal API functions so use with caution.</p>
  2668. @member ejs.TermsFacet
  2669. @returns {String} returns this object's internal <code>facet</code> property.
  2670. */
  2671. _self: function () {
  2672. return facet;
  2673. }
  2674. };
  2675. };
  2676. /**
  2677. @class
  2678. A container Filter that allows Boolean AND composition of Filters.
  2679. @name ejs.AndFilter
  2680. @desc
  2681. A container Filter that allows Boolean AND composition of Filters.
  2682. @param {Filter || Array} f A single Filter object or an array of valid
  2683. Filter objects.
  2684. */
  2685. ejs.AndFilter = function (f) {
  2686. /**
  2687. The internal filter object. Use <code>_self()</code>
  2688. @member ejs.AndFilter
  2689. @property {Object} filter
  2690. */
  2691. var i,
  2692. len,
  2693. filter = {
  2694. and: {
  2695. filters: []
  2696. }
  2697. };
  2698. if (isFilter(f)) {
  2699. filter.and.filters.push(f._self());
  2700. } else if (isArray(f)) {
  2701. for (i = 0, len = f.length; i < len; i++) {
  2702. if (!isFilter(f[i])) {
  2703. throw new TypeError('Array must contain only Filter objects');
  2704. }
  2705. filter.and.filters.push(f[i]._self());
  2706. }
  2707. } else {
  2708. throw new TypeError('Argument must be a Filter or Array of Filters');
  2709. }
  2710. return {
  2711. /**
  2712. Sets the filters for the filter. If fltr is a single
  2713. Filter, it is added to the current filters. If fltr is an array
  2714. of Filters, then they replace all existing filters.
  2715. @member ejs.AndFilter
  2716. @param {Filter || Array} fltr A valid filter object or an array of filters.
  2717. @returns {Object} returns <code>this</code> so that calls can be chained.
  2718. */
  2719. filters: function (fltr) {
  2720. var i,
  2721. len;
  2722. if (fltr == null) {
  2723. return filter.and.filters;
  2724. }
  2725. if (isFilter(fltr)) {
  2726. filter.and.filters.push(fltr._self());
  2727. } else if (isArray(fltr)) {
  2728. filter.and.filters = [];
  2729. for (i = 0, len = fltr.length; i < len; i++) {
  2730. if (!isFilter(fltr[i])) {
  2731. throw new TypeError('Array must contain only Filter objects');
  2732. }
  2733. filter.and.filters.push(fltr[i]._self());
  2734. }
  2735. } else {
  2736. throw new TypeError('Argument must be a Filter or an Array of Filters');
  2737. }
  2738. return this;
  2739. },
  2740. /**
  2741. Sets the filter name.
  2742. @member ejs.AndFilter
  2743. @param {String} name A name for the filter.
  2744. @returns {Object} returns <code>this</code> so that calls can be chained.
  2745. */
  2746. name: function (name) {
  2747. if (name == null) {
  2748. return filter.and._name;
  2749. }
  2750. filter.and._name = name;
  2751. return this;
  2752. },
  2753. /**
  2754. Enable or disable caching of the filter
  2755. @member ejs.AndFilter
  2756. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  2757. @returns {Object} returns <code>this</code> so that calls can be chained.
  2758. */
  2759. cache: function (trueFalse) {
  2760. if (trueFalse == null) {
  2761. return filter.and._cache;
  2762. }
  2763. filter.and._cache = trueFalse;
  2764. return this;
  2765. },
  2766. /**
  2767. Sets the cache key.
  2768. @member ejs.AndFilter
  2769. @param {String} key the cache key as a string.
  2770. @returns {Object} returns <code>this</code> so that calls can be chained.
  2771. */
  2772. cacheKey: function (key) {
  2773. if (key == null) {
  2774. return filter.and._cache_key;
  2775. }
  2776. filter.and._cache_key = key;
  2777. return this;
  2778. },
  2779. /**
  2780. Returns the filter container as a JSON string
  2781. @member ejs.AndFilter
  2782. @returns {String} JSON representation of the andFilter object
  2783. */
  2784. toString: function () {
  2785. return JSON.stringify(filter);
  2786. },
  2787. /**
  2788. The type of ejs object. For internal use only.
  2789. @member ejs.AndFilter
  2790. @returns {String} the type of object
  2791. */
  2792. _type: function () {
  2793. return 'filter';
  2794. },
  2795. /**
  2796. Returns the filter object.
  2797. @member ejs.AndFilter
  2798. @returns {Object} filter object
  2799. */
  2800. _self: function () {
  2801. return filter;
  2802. }
  2803. };
  2804. };
  2805. /**
  2806. @class
  2807. <p>A <code>BoolFilter</code> allows you to build <em>Boolean</em> filter constructs
  2808. from individual filters. Similar in concept to Boolean query, except that
  2809. the clauses are other filters. Can be placed within queries that accept a
  2810. filter.
  2811. @name ejs.BoolFilter
  2812. @desc
  2813. A Filter that matches documents matching boolean combinations of other
  2814. filters.
  2815. */
  2816. ejs.BoolFilter = function () {
  2817. /**
  2818. The internal filter object. <code>Use _self()</code>
  2819. @member ejs.BoolFilter
  2820. @property {Object} filter
  2821. */
  2822. var filter = {
  2823. bool: {}
  2824. };
  2825. return {
  2826. /**
  2827. Adds filter to boolean container. Given filter "must" appear in
  2828. matching documents. If passed a single Filter it is added to the
  2829. list of existing filters. If passed an array of Filters, they
  2830. replace all existing filters.
  2831. @member ejs.BoolFilter
  2832. @param {Filter || Array} oFilter A valid Filter or array of
  2833. Filter objects.
  2834. @returns {Object} returns <code>this</code> so that calls can be chained.
  2835. */
  2836. must: function (oFilter) {
  2837. var i, len;
  2838. if (filter.bool.must == null) {
  2839. filter.bool.must = [];
  2840. }
  2841. if (oFilter == null) {
  2842. return filter.bool.must;
  2843. }
  2844. if (isFilter(oFilter)) {
  2845. filter.bool.must.push(oFilter._self());
  2846. } else if (isArray(oFilter)) {
  2847. filter.bool.must = [];
  2848. for (i = 0, len = oFilter.length; i < len; i++) {
  2849. if (!isFilter(oFilter[i])) {
  2850. throw new TypeError('Argument must be an array of Filters');
  2851. }
  2852. filter.bool.must.push(oFilter[i]._self());
  2853. }
  2854. } else {
  2855. throw new TypeError('Argument must be a Filter or array of Filters');
  2856. }
  2857. return this;
  2858. },
  2859. /**
  2860. Adds filter to boolean container. Given filter "must not" appear
  2861. in matching documents. If passed a single Filter it is added to
  2862. the list of existing filters. If passed an array of Filters,
  2863. they replace all existing filters.
  2864. @member ejs.BoolFilter
  2865. @param {Filter || Array} oFilter A valid Filter or array of
  2866. Filter objects.
  2867. @returns {Object} returns <code>this</code> so that calls can be chained.
  2868. */
  2869. mustNot: function (oFilter) {
  2870. var i, len;
  2871. if (filter.bool.must_not == null) {
  2872. filter.bool.must_not = [];
  2873. }
  2874. if (oFilter == null) {
  2875. return filter.bool.must_not;
  2876. }
  2877. if (isFilter(oFilter)) {
  2878. filter.bool.must_not.push(oFilter._self());
  2879. } else if (isArray(oFilter)) {
  2880. filter.bool.must_not = [];
  2881. for (i = 0, len = oFilter.length; i < len; i++) {
  2882. if (!isFilter(oFilter[i])) {
  2883. throw new TypeError('Argument must be an array of Filters');
  2884. }
  2885. filter.bool.must_not.push(oFilter[i]._self());
  2886. }
  2887. } else {
  2888. throw new TypeError('Argument must be a Filter or array of Filters');
  2889. }
  2890. return this;
  2891. },
  2892. /**
  2893. Adds filter to boolean container. Given filter "should" appear in
  2894. matching documents. If passed a single Filter it is added to
  2895. the list of existing filters. If passed an array of Filters,
  2896. they replace all existing filters.
  2897. @member ejs.BoolFilter
  2898. @param {Filter || Array} oFilter A valid Filter or array of
  2899. Filter objects.
  2900. @returns {Object} returns <code>this</code> so that calls can be chained.
  2901. */
  2902. should: function (oFilter) {
  2903. var i, len;
  2904. if (filter.bool.should == null) {
  2905. filter.bool.should = [];
  2906. }
  2907. if (oFilter == null) {
  2908. return filter.bool.should;
  2909. }
  2910. if (isFilter(oFilter)) {
  2911. filter.bool.should.push(oFilter._self());
  2912. } else if (isArray(oFilter)) {
  2913. filter.bool.should = [];
  2914. for (i = 0, len = oFilter.length; i < len; i++) {
  2915. if (!isFilter(oFilter[i])) {
  2916. throw new TypeError('Argument must be an array of Filters');
  2917. }
  2918. filter.bool.should.push(oFilter[i]._self());
  2919. }
  2920. } else {
  2921. throw new TypeError('Argument must be a Filter or array of Filters');
  2922. }
  2923. return this;
  2924. },
  2925. /**
  2926. Sets the filter name.
  2927. @member ejs.BoolFilter
  2928. @param {String} name A name for the filter.
  2929. @returns {Object} returns <code>this</code> so that calls can be chained.
  2930. */
  2931. name: function (name) {
  2932. if (name == null) {
  2933. return filter.bool._name;
  2934. }
  2935. filter.bool._name = name;
  2936. return this;
  2937. },
  2938. /**
  2939. Enable or disable caching of the filter
  2940. @member ejs.BoolFilter
  2941. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  2942. @returns {Object} returns <code>this</code> so that calls can be chained.
  2943. */
  2944. cache: function (trueFalse) {
  2945. if (trueFalse == null) {
  2946. return filter.bool._cache;
  2947. }
  2948. filter.bool._cache = trueFalse;
  2949. return this;
  2950. },
  2951. /**
  2952. Sets the cache key.
  2953. @member ejs.BoolFilter
  2954. @param {String} key the cache key as a string.
  2955. @returns {Object} returns <code>this</code> so that calls can be chained.
  2956. */
  2957. cacheKey: function (key) {
  2958. if (key == null) {
  2959. return filter.bool._cache_key;
  2960. }
  2961. filter.bool._cache_key = key;
  2962. return this;
  2963. },
  2964. /**
  2965. Allows you to serialize this object into a JSON encoded string.
  2966. @member ejs.BoolFilter
  2967. @returns {String} returns this object as a serialized JSON string.
  2968. */
  2969. toString: function () {
  2970. return JSON.stringify(filter);
  2971. },
  2972. /**
  2973. The type of ejs object. For internal use only.
  2974. @member ejs.BoolFilter
  2975. @returns {String} the type of object
  2976. */
  2977. _type: function () {
  2978. return 'filter';
  2979. },
  2980. /**
  2981. Retrieves the internal <code>filter</code> object. This is typically used by
  2982. internal API functions so use with caution.
  2983. @member ejs.BoolFilter
  2984. @returns {String} returns this object's internal <code>filter</code> property.
  2985. */
  2986. _self: function () {
  2987. return filter;
  2988. }
  2989. };
  2990. };
  2991. /**
  2992. @class
  2993. <p>An existsFilter matches documents where the specified field is present
  2994. and the field contains a legitimate value.</p>
  2995. @name ejs.ExistsFilter
  2996. @desc
  2997. Filters documents where a specified field exists and contains a value.
  2998. @param {String} fieldName the field name that must exists and contain a value.
  2999. */
  3000. ejs.ExistsFilter = function (fieldName) {
  3001. /**
  3002. The internal filter object. Use <code>get()</code>
  3003. @member ejs.ExistsFilter
  3004. @property {Object} filter
  3005. */
  3006. var filter = {
  3007. exists: {
  3008. field: fieldName
  3009. }
  3010. };
  3011. return {
  3012. /**
  3013. Sets the field to check for missing values.
  3014. @member ejs.ExistsFilter
  3015. @param {String} name A name of the field.
  3016. @returns {Object} returns <code>this</code> so that calls can be chained.
  3017. */
  3018. field: function (name) {
  3019. if (name == null) {
  3020. return filter.exists.field;
  3021. }
  3022. filter.exists.field = name;
  3023. return this;
  3024. },
  3025. /**
  3026. Sets the filter name.
  3027. @member ejs.ExistsFilter
  3028. @param {String} name A name for the filter.
  3029. @returns {Object} returns <code>this</code> so that calls can be chained.
  3030. */
  3031. name: function (name) {
  3032. if (name == null) {
  3033. return filter.exists._name;
  3034. }
  3035. filter.exists._name = name;
  3036. return this;
  3037. },
  3038. /**
  3039. Returns the filter container as a JSON string
  3040. @member ejs.ExistsFilter
  3041. @returns {String} JSON representation of the existsFilter object
  3042. */
  3043. toString: function () {
  3044. return JSON.stringify(filter);
  3045. },
  3046. /**
  3047. The type of ejs object. For internal use only.
  3048. @member ejs.ExistsFilter
  3049. @returns {String} the type of object
  3050. */
  3051. _type: function () {
  3052. return 'filter';
  3053. },
  3054. /**
  3055. Returns the filter object.
  3056. @member ejs.ExistsFilter
  3057. @returns {Object} filter object
  3058. */
  3059. _self: function () {
  3060. return filter;
  3061. }
  3062. };
  3063. };
  3064. /**
  3065. @class
  3066. <p>A filter that restricts matched results/docs to a geographic bounding box described by
  3067. the specified lon and lat coordinates. The format conforms with the GeoJSON specification.</p>
  3068. @name ejs.GeoBboxFilter
  3069. @desc
  3070. Filter results to those which are contained within the defined bounding box.
  3071. @param {String} fieldName the document property/field containing the Geo Point (lon/lat).
  3072. */
  3073. ejs.GeoBboxFilter = function (fieldName) {
  3074. /**
  3075. The internal filter object. Use <code>_self()</code>
  3076. @member ejs.GeoBboxFilter
  3077. @property {Object} filter
  3078. */
  3079. var filter = {
  3080. geo_bounding_box: {}
  3081. };
  3082. filter.geo_bounding_box[fieldName] = {};
  3083. return {
  3084. /**
  3085. Sets the fields to filter against.
  3086. @member ejs.GeoBboxFilter
  3087. @param {String} f A valid field name.
  3088. @returns {Object} returns <code>this</code> so that calls can be chained.
  3089. */
  3090. field: function (f) {
  3091. var oldValue = filter.geo_bounding_box[fieldName];
  3092. if (f == null) {
  3093. return fieldName;
  3094. }
  3095. delete filter.geo_bounding_box[fieldName];
  3096. fieldName = f;
  3097. filter.geo_bounding_box[f] = oldValue;
  3098. return this;
  3099. },
  3100. /**
  3101. Sets the top-left coordinate of the bounding box
  3102. @member ejs.GeoBboxFilter
  3103. @param {GeoPoint} p A valid GeoPoint object
  3104. @returns {Object} returns <code>this</code> so that calls can be chained.
  3105. */
  3106. topLeft: function (p) {
  3107. if (p == null) {
  3108. return filter.geo_bounding_box[fieldName].top_left;
  3109. }
  3110. if (isGeoPoint(p)) {
  3111. filter.geo_bounding_box[fieldName].top_left = p._self();
  3112. } else {
  3113. throw new TypeError('Argument must be a GeoPoint');
  3114. }
  3115. return this;
  3116. },
  3117. /**
  3118. Sets the bottom-right coordinate of the bounding box
  3119. @member ejs.GeoBboxFilter
  3120. @param {GeoPoint} p A valid GeoPoint object
  3121. @returns {Object} returns <code>this</code> so that calls can be chained.
  3122. */
  3123. bottomRight: function (p) {
  3124. if (p == null) {
  3125. return filter.geo_bounding_box[fieldName].bottom_right;
  3126. }
  3127. if (isGeoPoint(p)) {
  3128. filter.geo_bounding_box[fieldName].bottom_right = p._self();
  3129. } else {
  3130. throw new TypeError('Argument must be a GeoPoint');
  3131. }
  3132. return this;
  3133. },
  3134. /**
  3135. Sets the type of the bounding box execution. Valid values are
  3136. "memory" and "indexed". Default is memory.
  3137. @member ejs.GeoBboxFilter
  3138. @param {String} type The execution type as a string.
  3139. @returns {Object} returns <code>this</code> so that calls can be chained.
  3140. */
  3141. type: function (type) {
  3142. if (type == null) {
  3143. return filter.geo_bounding_box.type;
  3144. }
  3145. type = type.toLowerCase();
  3146. if (type === 'memory' || type === 'indexed') {
  3147. filter.geo_bounding_box.type = type;
  3148. }
  3149. return this;
  3150. },
  3151. /**
  3152. If the lat/long points should be normalized to lie within their
  3153. respective normalized ranges.
  3154. Normalized ranges are:
  3155. lon = -180 (exclusive) to 180 (inclusive) range
  3156. lat = -90 to 90 (both inclusive) range
  3157. @member ejs.GeoBboxFilter
  3158. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  3159. @returns {Object} returns <code>this</code> so that calls can be chained.
  3160. */
  3161. normalize: function (trueFalse) {
  3162. if (trueFalse == null) {
  3163. return filter.geo_bounding_box.normalize;
  3164. }
  3165. filter.geo_bounding_box.normalize = trueFalse;
  3166. return this;
  3167. },
  3168. /**
  3169. Sets the filter name.
  3170. @member ejs.GeoBboxFilter
  3171. @param {String} name A name for the filter.
  3172. @returns {Object} returns <code>this</code> so that calls can be chained.
  3173. */
  3174. name: function (name) {
  3175. if (name == null) {
  3176. return filter.geo_bounding_box._name;
  3177. }
  3178. filter.geo_bounding_box._name = name;
  3179. return this;
  3180. },
  3181. /**
  3182. Enable or disable caching of the filter
  3183. @member ejs.GeoBboxFilter
  3184. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  3185. @returns {Object} returns <code>this</code> so that calls can be chained.
  3186. */
  3187. cache: function (trueFalse) {
  3188. if (trueFalse == null) {
  3189. return filter.geo_bounding_box._cache;
  3190. }
  3191. filter.geo_bounding_box._cache = trueFalse;
  3192. return this;
  3193. },
  3194. /**
  3195. Sets the cache key.
  3196. @member ejs.GeoBboxFilter
  3197. @param {String} key the cache key as a string.
  3198. @returns {Object} returns <code>this</code> so that calls can be chained.
  3199. */
  3200. cacheKey: function (key) {
  3201. if (key == null) {
  3202. return filter.geo_bounding_box._cache_key;
  3203. }
  3204. filter.geo_bounding_box._cache_key = key;
  3205. return this;
  3206. },
  3207. /**
  3208. Returns the filter container as a JSON string
  3209. @member ejs.GeoBboxFilter
  3210. @returns {String} JSON representation of the notFilter object
  3211. */
  3212. toString: function () {
  3213. return JSON.stringify(filter);
  3214. },
  3215. /**
  3216. The type of ejs object. For internal use only.
  3217. @member ejs.GeoBboxFilter
  3218. @returns {String} the type of object
  3219. */
  3220. _type: function () {
  3221. return 'filter';
  3222. },
  3223. /**
  3224. Returns the filter object.
  3225. @member ejs.GeoBboxFilter
  3226. @returns {Object} filter object
  3227. */
  3228. _self: function () {
  3229. return filter;
  3230. }
  3231. };
  3232. };
  3233. /**
  3234. @class
  3235. <p>A filter that restricts matched results/docs to a given distance from the
  3236. point of origin. The format conforms with the GeoJSON specification.</p>
  3237. @name ejs.GeoDistanceFilter
  3238. @desc
  3239. Filter results to those which fall within the given distance of the point of origin.
  3240. @param {String} fieldName the document property/field containing the Geo Point (lon/lat).
  3241. */
  3242. ejs.GeoDistanceFilter = function (fieldName) {
  3243. /**
  3244. The internal filter object. Use <code>_self()</code>
  3245. @member ejs.GeoDistanceFilter
  3246. @property {Object} filter
  3247. */
  3248. var filter = {
  3249. geo_distance: {
  3250. }
  3251. };
  3252. filter.geo_distance[fieldName] = [0, 0];
  3253. return {
  3254. /**
  3255. Sets the fields to filter against.
  3256. @member ejs.GeoDistanceFilter
  3257. @param {String} f A valid field name.
  3258. @returns {Object} returns <code>this</code> so that calls can be chained.
  3259. */
  3260. field: function (f) {
  3261. var oldValue = filter.geo_distance[fieldName];
  3262. if (f == null) {
  3263. return fieldName;
  3264. }
  3265. delete filter.geo_distance[fieldName];
  3266. fieldName = f;
  3267. filter.geo_distance[f] = oldValue;
  3268. return this;
  3269. },
  3270. /**
  3271. Sets the numeric distance to be used. The distance can be a
  3272. numeric value, and then the unit (either mi or km can be set)
  3273. controlling the unit. Or a single string with the unit as well.
  3274. @member ejs.GeoDistanceFilter
  3275. @param {Number} numericDistance the numeric distance
  3276. @returns {Object} returns <code>this</code> so that calls can be chained.
  3277. */
  3278. distance: function (numericDistance) {
  3279. if (numericDistance == null) {
  3280. return filter.geo_distance.distance;
  3281. }
  3282. if (!isNumber(numericDistance)) {
  3283. throw new TypeError('Argument must be a numeric value');
  3284. }
  3285. filter.geo_distance.distance = numericDistance;
  3286. return this;
  3287. },
  3288. /**
  3289. Sets the distance unit. Valid values are "mi" for miles or "km"
  3290. for kilometers. Defaults to "km".
  3291. @member ejs.GeoDistanceFilter
  3292. @param {Number} unit the unit of distance measure.
  3293. @returns {Object} returns <code>this</code> so that calls can be chained.
  3294. */
  3295. unit: function (unit) {
  3296. if (unit == null) {
  3297. return filter.geo_distance.unit;
  3298. }
  3299. unit = unit.toLowerCase();
  3300. if (unit === 'mi' || unit === 'km') {
  3301. filter.geo_distance.unit = unit;
  3302. }
  3303. return this;
  3304. },
  3305. /**
  3306. Sets the point of origin in which distance will be measured from
  3307. @member ejs.GeoDistanceFilter
  3308. @param {GeoPoint} p A valid GeoPoint object.
  3309. @returns {Object} returns <code>this</code> so that calls can be chained.
  3310. */
  3311. point: function (p) {
  3312. if (p == null) {
  3313. return filter.geo_distance[fieldName];
  3314. }
  3315. if (isGeoPoint(p)) {
  3316. filter.geo_distance[fieldName] = p._self();
  3317. } else {
  3318. throw new TypeError('Argument must be a GeoPoint');
  3319. }
  3320. return this;
  3321. },
  3322. /**
  3323. How to compute the distance. Can either be arc (better precision)
  3324. or plane (faster). Defaults to arc.
  3325. @member ejs.GeoDistanceFilter
  3326. @param {String} type The execution type as a string.
  3327. @returns {Object} returns <code>this</code> so that calls can be chained.
  3328. */
  3329. distanceType: function (type) {
  3330. if (type == null) {
  3331. return filter.geo_distance.distance_type;
  3332. }
  3333. type = type.toLowerCase();
  3334. if (type === 'arc' || type === 'plane') {
  3335. filter.geo_distance.distance_type = type;
  3336. }
  3337. return this;
  3338. },
  3339. /**
  3340. If the lat/long points should be normalized to lie within their
  3341. respective normalized ranges.
  3342. Normalized ranges are:
  3343. lon = -180 (exclusive) to 180 (inclusive) range
  3344. lat = -90 to 90 (both inclusive) range
  3345. @member ejs.GeoDistanceFilter
  3346. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  3347. @returns {Object} returns <code>this</code> so that calls can be chained.
  3348. */
  3349. normalize: function (trueFalse) {
  3350. if (trueFalse == null) {
  3351. return filter.geo_distance.normalize;
  3352. }
  3353. filter.geo_distance.normalize = trueFalse;
  3354. return this;
  3355. },
  3356. /**
  3357. Will an optimization of using first a bounding box check will be
  3358. used. Defaults to memory which will do in memory checks. Can also
  3359. have values of indexed to use indexed value check, or none which
  3360. disables bounding box optimization.
  3361. @member ejs.GeoDistanceFilter
  3362. @param {String} t optimization type of memory, indexed, or none.
  3363. @returns {Object} returns <code>this</code> so that calls can be chained.
  3364. */
  3365. optimizeBbox: function (t) {
  3366. if (t == null) {
  3367. return filter.geo_distance.optimize_bbox;
  3368. }
  3369. t = t.toLowerCase();
  3370. if (t === 'memory' || t === 'indexed' || t === 'none') {
  3371. filter.geo_distance.optimize_bbox = t;
  3372. }
  3373. return this;
  3374. },
  3375. /**
  3376. Sets the filter name.
  3377. @member ejs.GeoDistanceFilter
  3378. @param {String} name A name for the filter.
  3379. @returns {Object} returns <code>this</code> so that calls can be chained.
  3380. */
  3381. name: function (name) {
  3382. if (name == null) {
  3383. return filter.geo_distance._name;
  3384. }
  3385. filter.geo_distance._name = name;
  3386. return this;
  3387. },
  3388. /**
  3389. Enable or disable caching of the filter
  3390. @member ejs.GeoDistanceFilter
  3391. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  3392. @returns {Object} returns <code>this</code> so that calls can be chained.
  3393. */
  3394. cache: function (trueFalse) {
  3395. if (trueFalse == null) {
  3396. return filter.geo_distance._cache;
  3397. }
  3398. filter.geo_distance._cache = trueFalse;
  3399. return this;
  3400. },
  3401. /**
  3402. Sets the cache key.
  3403. @member ejs.GeoDistanceFilter
  3404. @param {String} key the cache key as a string.
  3405. @returns {Object} returns <code>this</code> so that calls can be chained.
  3406. */
  3407. cacheKey: function (key) {
  3408. if (key == null) {
  3409. return filter.geo_distance._cache_key;
  3410. }
  3411. filter.geo_distance._cache_key = key;
  3412. return this;
  3413. },
  3414. /**
  3415. Returns the filter container as a JSON string
  3416. @member ejs.GeoDistanceFilter
  3417. @returns {String} JSON representation of the notFilter object
  3418. */
  3419. toString: function () {
  3420. return JSON.stringify(filter);
  3421. },
  3422. /**
  3423. The type of ejs object. For internal use only.
  3424. @member ejs.GeoDistanceFilter
  3425. @returns {String} the type of object
  3426. */
  3427. _type: function () {
  3428. return 'filter';
  3429. },
  3430. /**
  3431. Returns the filter object.
  3432. @member ejs.GeoDistanceFilter
  3433. @returns {Object} filter object
  3434. */
  3435. _self: function () {
  3436. return filter;
  3437. }
  3438. };
  3439. };
  3440. /**
  3441. @class
  3442. <p>A filter that restricts matched results/docs to a given distance range from the
  3443. point of origin. The format conforms with the GeoJSON specification.</p>
  3444. @name ejs.GeoDistanceRangeFilter
  3445. @desc
  3446. Filter results to those which fall within the given distance range of the point of origin.
  3447. @param {String} fieldName the document property/field containing the Geo Point (lon/lat).
  3448. */
  3449. ejs.GeoDistanceRangeFilter = function (fieldName) {
  3450. /**
  3451. The internal filter object. Use <code>_self()</code>
  3452. @member ejs.GeoDistanceRangeFilter
  3453. @property {Object} filter
  3454. */
  3455. var filter = {
  3456. geo_distance_range: {}
  3457. };
  3458. filter.geo_distance_range[fieldName] = [0, 0];
  3459. return {
  3460. /**
  3461. Sets the fields to filter against.
  3462. @member ejs.GeoDistanceRangeFilter
  3463. @param {String} f A valid field name.
  3464. @returns {Object} returns <code>this</code> so that calls can be chained.
  3465. */
  3466. field: function (f) {
  3467. var oldValue = filter.geo_distance_range[fieldName];
  3468. if (f == null) {
  3469. return fieldName;
  3470. }
  3471. delete filter.geo_distance_range[fieldName];
  3472. fieldName = f;
  3473. filter.geo_distance_range[f] = oldValue;
  3474. return this;
  3475. },
  3476. /**
  3477. * Sets the start point of the distance range
  3478. @member ejs.GeoDistanceRangeFilter
  3479. @param {Number} numericDistance the numeric distance
  3480. @returns {Object} returns <code>this</code> so that calls can be chained.
  3481. */
  3482. from: function (numericDistance) {
  3483. if (numericDistance == null) {
  3484. return filter.geo_distance_range.from;
  3485. }
  3486. if (!isNumber(numericDistance)) {
  3487. throw new TypeError('Argument must be a numeric value');
  3488. }
  3489. filter.geo_distance_range.from = numericDistance;
  3490. return this;
  3491. },
  3492. /**
  3493. * Sets the end point of the distance range
  3494. @member ejs.GeoDistanceRangeFilter
  3495. @param {Number} numericDistance the numeric distance
  3496. @returns {Object} returns <code>this</code> so that calls can be chained.
  3497. */
  3498. to: function (numericDistance) {
  3499. if (numericDistance == null) {
  3500. return filter.geo_distance_range.to;
  3501. }
  3502. if (!isNumber(numericDistance)) {
  3503. throw new TypeError('Argument must be a numeric value');
  3504. }
  3505. filter.geo_distance_range.to = numericDistance;
  3506. return this;
  3507. },
  3508. /**
  3509. Should the first from (if set) be inclusive or not.
  3510. Defaults to true
  3511. @member ejs.GeoDistanceRangeFilter
  3512. @param {Boolean} trueFalse true to include, false to exclude
  3513. @returns {Object} returns <code>this</code> so that calls can be chained.
  3514. */
  3515. includeLower: function (trueFalse) {
  3516. if (trueFalse == null) {
  3517. return filter.geo_distance_range.include_lower;
  3518. }
  3519. filter.geo_distance_range.include_lower = trueFalse;
  3520. return this;
  3521. },
  3522. /**
  3523. Should the last to (if set) be inclusive or not. Defaults to true.
  3524. @member ejs.GeoDistanceRangeFilter
  3525. @param {Boolean} trueFalse true to include, false to exclude
  3526. @returns {Object} returns <code>this</code> so that calls can be chained.
  3527. */
  3528. includeUpper: function (trueFalse) {
  3529. if (trueFalse == null) {
  3530. return filter.geo_distance_range.include_upper;
  3531. }
  3532. filter.geo_distance_range.include_upper = trueFalse;
  3533. return this;
  3534. },
  3535. /**
  3536. Greater than value. Same as setting from to the value, and
  3537. include_lower to false,
  3538. @member ejs.GeoDistanceRangeFilter
  3539. @param {Number} val the numeric distance
  3540. @returns {Object} returns <code>this</code> so that calls can be chained.
  3541. */
  3542. gt: function (val) {
  3543. if (val == null) {
  3544. return filter.geo_distance_range.gt;
  3545. }
  3546. if (!isNumber(val)) {
  3547. throw new TypeError('Argument must be a numeric value');
  3548. }
  3549. filter.geo_distance_range.gt = val;
  3550. return this;
  3551. },
  3552. /**
  3553. Greater than or equal to value. Same as setting from to the value,
  3554. and include_lower to true.
  3555. @member ejs.GeoDistanceRangeFilter
  3556. @param {Number} val the numeric distance
  3557. @returns {Object} returns <code>this</code> so that calls can be chained.
  3558. */
  3559. gte: function (val) {
  3560. if (val == null) {
  3561. return filter.geo_distance_range.gte;
  3562. }
  3563. if (!isNumber(val)) {
  3564. throw new TypeError('Argument must be a numeric value');
  3565. }
  3566. filter.geo_distance_range.gte = val;
  3567. return this;
  3568. },
  3569. /**
  3570. Less than value. Same as setting to to the value, and include_upper
  3571. to false.
  3572. @member ejs.GeoDistanceRangeFilter
  3573. @param {Number} val the numeric distance
  3574. @returns {Object} returns <code>this</code> so that calls can be chained.
  3575. */
  3576. lt: function (val) {
  3577. if (val == null) {
  3578. return filter.geo_distance_range.lt;
  3579. }
  3580. if (!isNumber(val)) {
  3581. throw new TypeError('Argument must be a numeric value');
  3582. }
  3583. filter.geo_distance_range.lt = val;
  3584. return this;
  3585. },
  3586. /**
  3587. Less than or equal to value. Same as setting to to the value,
  3588. and include_upper to true.
  3589. @member ejs.GeoDistanceRangeFilter
  3590. @param {Number} val the numeric distance
  3591. @returns {Object} returns <code>this</code> so that calls can be chained.
  3592. */
  3593. lte: function (val) {
  3594. if (val == null) {
  3595. return filter.geo_distance_range.lte;
  3596. }
  3597. if (!isNumber(val)) {
  3598. throw new TypeError('Argument must be a numeric value');
  3599. }
  3600. filter.geo_distance_range.lte = val;
  3601. return this;
  3602. },
  3603. /**
  3604. Sets the distance unit. Valid values are "mi" for miles or "km"
  3605. for kilometers. Defaults to "km".
  3606. @member ejs.GeoDistanceRangeFilter
  3607. @param {Number} unit the unit of distance measure.
  3608. @returns {Object} returns <code>this</code> so that calls can be chained.
  3609. */
  3610. unit: function (unit) {
  3611. if (unit == null) {
  3612. return filter.geo_distance_range.unit;
  3613. }
  3614. unit = unit.toLowerCase();
  3615. if (unit === 'mi' || unit === 'km') {
  3616. filter.geo_distance_range.unit = unit;
  3617. }
  3618. return this;
  3619. },
  3620. /**
  3621. Sets the point of origin in which distance will be measured from
  3622. @member ejs.GeoDistanceRangeFilter
  3623. @param {GeoPoint} p A valid GeoPoint object.
  3624. @returns {Object} returns <code>this</code> so that calls can be chained.
  3625. */
  3626. point: function (p) {
  3627. if (p == null) {
  3628. return filter.geo_distance_range[fieldName];
  3629. }
  3630. if (isGeoPoint(p)) {
  3631. filter.geo_distance_range[fieldName] = p._self();
  3632. } else {
  3633. throw new TypeError('Argument must be a GeoPoint');
  3634. }
  3635. return this;
  3636. },
  3637. /**
  3638. How to compute the distance. Can either be arc (better precision)
  3639. or plane (faster). Defaults to arc.
  3640. @member ejs.GeoDistanceRangeFilter
  3641. @param {String} type The execution type as a string.
  3642. @returns {Object} returns <code>this</code> so that calls can be chained.
  3643. */
  3644. distanceType: function (type) {
  3645. if (type == null) {
  3646. return filter.geo_distance_range.distance_type;
  3647. }
  3648. type = type.toLowerCase();
  3649. if (type === 'arc' || type === 'plane') {
  3650. filter.geo_distance_range.distance_type = type;
  3651. }
  3652. return this;
  3653. },
  3654. /**
  3655. If the lat/long points should be normalized to lie within their
  3656. respective normalized ranges.
  3657. Normalized ranges are:
  3658. lon = -180 (exclusive) to 180 (inclusive) range
  3659. lat = -90 to 90 (both inclusive) range
  3660. @member ejs.GeoDistanceRangeFilter
  3661. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  3662. @returns {Object} returns <code>this</code> so that calls can be chained.
  3663. */
  3664. normalize: function (trueFalse) {
  3665. if (trueFalse == null) {
  3666. return filter.geo_distance_range.normalize;
  3667. }
  3668. filter.geo_distance_range.normalize = trueFalse;
  3669. return this;
  3670. },
  3671. /**
  3672. Will an optimization of using first a bounding box check will be
  3673. used. Defaults to memory which will do in memory checks. Can also
  3674. have values of indexed to use indexed value check, or none which
  3675. disables bounding box optimization.
  3676. @member ejs.GeoDistanceRangeFilter
  3677. @param {String} t optimization type of memory, indexed, or none.
  3678. @returns {Object} returns <code>this</code> so that calls can be chained.
  3679. */
  3680. optimizeBbox: function (t) {
  3681. if (t == null) {
  3682. return filter.geo_distance_range.optimize_bbox;
  3683. }
  3684. t = t.toLowerCase();
  3685. if (t === 'memory' || t === 'indexed' || t === 'none') {
  3686. filter.geo_distance_range.optimize_bbox = t;
  3687. }
  3688. return this;
  3689. },
  3690. /**
  3691. Sets the filter name.
  3692. @member ejs.GeoDistanceRangeFilter
  3693. @param {String} name A name for the filter.
  3694. @returns {Object} returns <code>this</code> so that calls can be chained.
  3695. */
  3696. name: function (name) {
  3697. if (name == null) {
  3698. return filter.geo_distance_range._name;
  3699. }
  3700. filter.geo_distance_range._name = name;
  3701. return this;
  3702. },
  3703. /**
  3704. Enable or disable caching of the filter
  3705. @member ejs.GeoDistanceRangeFilter
  3706. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  3707. @returns {Object} returns <code>this</code> so that calls can be chained.
  3708. */
  3709. cache: function (trueFalse) {
  3710. if (trueFalse == null) {
  3711. return filter.geo_distance_range._cache;
  3712. }
  3713. filter.geo_distance_range._cache = trueFalse;
  3714. return this;
  3715. },
  3716. /**
  3717. Sets the cache key.
  3718. @member ejs.GeoDistanceRangeFilter
  3719. @param {String} key the cache key as a string.
  3720. @returns {Object} returns <code>this</code> so that calls can be chained.
  3721. */
  3722. cacheKey: function (key) {
  3723. if (key == null) {
  3724. return filter.geo_distance_range._cache_key;
  3725. }
  3726. filter.geo_distance_range._cache_key = key;
  3727. return this;
  3728. },
  3729. /**
  3730. Returns the filter container as a JSON string
  3731. @member ejs.GeoDistanceRangeFilter
  3732. @returns {String} JSON representation of the notFilter object
  3733. */
  3734. toString: function () {
  3735. return JSON.stringify(filter);
  3736. },
  3737. /**
  3738. The type of ejs object. For internal use only.
  3739. @member ejs.GeoDistanceRangeFilter
  3740. @returns {String} the type of object
  3741. */
  3742. _type: function () {
  3743. return 'filter';
  3744. },
  3745. /**
  3746. Returns the filter object.
  3747. @member ejs.GeoDistanceRangeFilter
  3748. @returns {Object} filter object
  3749. */
  3750. _self: function () {
  3751. return filter;
  3752. }
  3753. };
  3754. };
  3755. /**
  3756. @class
  3757. <p>A filter for locating documents that fall within a polygon of points. Simply provide a lon/lat
  3758. for each document as a Geo Point type. The format conforms with the GeoJSON specification.</p>
  3759. @name ejs.GeoPolygonFilter
  3760. @desc
  3761. Filter results to those which are contained within the polygon of points.
  3762. @param {String} fieldName the document property/field containing the Geo Point (lon/lat).
  3763. */
  3764. ejs.GeoPolygonFilter = function (fieldName) {
  3765. /**
  3766. The internal filter object. Use <code>_self()</code>
  3767. @member ejs.GeoPolygonFilter
  3768. @property {Object} filter
  3769. */
  3770. var filter = {
  3771. geo_polygon: {}
  3772. };
  3773. filter.geo_polygon[fieldName] = {
  3774. points: []
  3775. };
  3776. return {
  3777. /**
  3778. Sets the fields to filter against.
  3779. @member ejs.GeoPolygonFilter
  3780. @param {String} f A valid field name.
  3781. @returns {Object} returns <code>this</code> so that calls can be chained.
  3782. */
  3783. field: function (f) {
  3784. var oldValue = filter.geo_polygon[fieldName];
  3785. if (f == null) {
  3786. return fieldName;
  3787. }
  3788. delete filter.geo_polygon[fieldName];
  3789. fieldName = f;
  3790. filter.geo_polygon[f] = oldValue;
  3791. return this;
  3792. },
  3793. /**
  3794. Sets a series of points that represent a polygon. If passed a
  3795. single <code>GeoPoint</code> object, it is added to the current
  3796. list of points. If passed an array of <code>GeoPoint</code>
  3797. objects it replaces all current values.
  3798. @member ejs.GeoPolygonFilter
  3799. @param {Array} pointsArray the array of points that represent the polygon
  3800. @returns {Object} returns <code>this</code> so that calls can be chained.
  3801. */
  3802. points: function (p) {
  3803. var i, len;
  3804. if (p == null) {
  3805. return filter.geo_polygon[fieldName].points;
  3806. }
  3807. if (isGeoPoint(p)) {
  3808. filter.geo_polygon[fieldName].points.push(p._self());
  3809. } else if (isArray(p)) {
  3810. filter.geo_polygon[fieldName].points = [];
  3811. for (i = 0, len = p.length; i < len; i++) {
  3812. if (!isGeoPoint(p[i])) {
  3813. throw new TypeError('Argument must be Array of GeoPoints');
  3814. }
  3815. filter.geo_polygon[fieldName].points.push(p[i]._self());
  3816. }
  3817. } else {
  3818. throw new TypeError('Argument must be a GeoPoint or Array of GeoPoints');
  3819. }
  3820. return this;
  3821. },
  3822. /**
  3823. If the lat/long points should be normalized to lie within their
  3824. respective normalized ranges.
  3825. Normalized ranges are:
  3826. lon = -180 (exclusive) to 180 (inclusive) range
  3827. lat = -90 to 90 (both inclusive) range
  3828. @member ejs.GeoPolygonFilter
  3829. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  3830. @returns {Object} returns <code>this</code> so that calls can be chained.
  3831. */
  3832. normalize: function (trueFalse) {
  3833. if (trueFalse == null) {
  3834. return filter.geo_polygon.normalize;
  3835. }
  3836. filter.geo_polygon.normalize = trueFalse;
  3837. return this;
  3838. },
  3839. /**
  3840. Sets the filter name.
  3841. @member ejs.GeoPolygonFilter
  3842. @param {String} name A name for the filter.
  3843. @returns {Object} returns <code>this</code> so that calls can be chained.
  3844. */
  3845. name: function (name) {
  3846. if (name == null) {
  3847. return filter.geo_polygon._name;
  3848. }
  3849. filter.geo_polygon._name = name;
  3850. return this;
  3851. },
  3852. /**
  3853. Enable or disable caching of the filter
  3854. @member ejs.GeoPolygonFilter
  3855. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  3856. @returns {Object} returns <code>this</code> so that calls can be chained.
  3857. */
  3858. cache: function (trueFalse) {
  3859. if (trueFalse == null) {
  3860. return filter.geo_polygon._cache;
  3861. }
  3862. filter.geo_polygon._cache = trueFalse;
  3863. return this;
  3864. },
  3865. /**
  3866. Sets the cache key.
  3867. @member ejs.GeoPolygonFilter
  3868. @param {String} key the cache key as a string.
  3869. @returns {Object} returns <code>this</code> so that calls can be chained.
  3870. */
  3871. cacheKey: function (key) {
  3872. if (key == null) {
  3873. return filter.geo_polygon._cache_key;
  3874. }
  3875. filter.geo_polygon._cache_key = key;
  3876. return this;
  3877. },
  3878. /**
  3879. Returns the filter container as a JSON string
  3880. @member ejs.GeoPolygonFilter
  3881. @returns {String} JSON representation of the notFilter object
  3882. */
  3883. toString: function () {
  3884. return JSON.stringify(filter);
  3885. },
  3886. /**
  3887. The type of ejs object. For internal use only.
  3888. @member ejs.GeoPolygonFilter
  3889. @returns {String} the type of object
  3890. */
  3891. _type: function () {
  3892. return 'filter';
  3893. },
  3894. /**
  3895. Returns the filter object.
  3896. @member ejs.GeoPolygonFilter
  3897. @returns {Object} filter object
  3898. */
  3899. _self: function () {
  3900. return filter;
  3901. }
  3902. };
  3903. };
  3904. /**
  3905. @class
  3906. <p>Efficient filtering of documents containing shapes indexed using the
  3907. geo_shape type.</p>
  3908. <p>Much like the geo_shape type, the geo_shape filter uses a grid square
  3909. representation of the filter shape to find those documents which have shapes
  3910. that relate to the filter shape in a specified way. In order to do this, the
  3911. field being queried must be of geo_shape type. The filter will use the same
  3912. PrefixTree configuration as defined for the field.</p>
  3913. @name ejs.GeoShapeFilter
  3914. @desc
  3915. A Filter to find documents with a geo_shapes matching a specific shape.
  3916. */
  3917. ejs.GeoShapeFilter = function (field) {
  3918. /**
  3919. The internal filter object. <code>Use _self()</code>
  3920. @member ejs.GeoShapeFilter
  3921. @property {Object} GeoShapeFilter
  3922. */
  3923. var filter = {
  3924. geo_shape: {}
  3925. };
  3926. filter.geo_shape[field] = {};
  3927. return {
  3928. /**
  3929. Sets the field to filter against.
  3930. @member ejs.GeoShapeFilter
  3931. @param {String} f A valid field name.
  3932. @returns {Object} returns <code>this</code> so that calls can be chained.
  3933. */
  3934. field: function (f) {
  3935. var oldValue = filter.geo_shape[field];
  3936. if (f == null) {
  3937. return field;
  3938. }
  3939. delete filter.geo_shape[field];
  3940. field = f;
  3941. filter.geo_shape[f] = oldValue;
  3942. return this;
  3943. },
  3944. /**
  3945. Sets the shape
  3946. @member ejs.GeoShapeFilter
  3947. @param {String} shape A valid <code>Shape</code> object.
  3948. @returns {Object} returns <code>this</code> so that calls can be chained.
  3949. */
  3950. shape: function (shape) {
  3951. if (shape == null) {
  3952. return filter.geo_shape[field].shape;
  3953. }
  3954. if (filter.geo_shape[field].indexed_shape != null) {
  3955. delete filter.geo_shape[field].indexed_shape;
  3956. }
  3957. filter.geo_shape[field].shape = shape._self();
  3958. return this;
  3959. },
  3960. /**
  3961. Sets the indexed shape. Use this if you already have shape definitions
  3962. already indexed.
  3963. @member ejs.GeoShapeFilter
  3964. @param {String} indexedShape A valid <code>IndexedShape</code> object.
  3965. @returns {Object} returns <code>this</code> so that calls can be chained.
  3966. */
  3967. indexedShape: function (indexedShape) {
  3968. if (indexedShape == null) {
  3969. return filter.geo_shape[field].indexed_shape;
  3970. }
  3971. if (filter.geo_shape[field].shape != null) {
  3972. delete filter.geo_shape[field].shape;
  3973. }
  3974. filter.geo_shape[field].indexed_shape = indexedShape._self();
  3975. return this;
  3976. },
  3977. /**
  3978. Sets the shape relation type. A relationship between a Query Shape
  3979. and indexed Shapes that will be used to determine if a Document
  3980. should be matched or not. Valid values are: intersects, disjoint,
  3981. and within.
  3982. @member ejs.GeoShapeFilter
  3983. @param {String} indexedShape A valid <code>IndexedShape</code> object.
  3984. @returns {Object} returns <code>this</code> so that calls can be chained.
  3985. */
  3986. relation: function (relation) {
  3987. if (relation == null) {
  3988. return filter.geo_shape[field].relation;
  3989. }
  3990. relation = relation.toLowerCase();
  3991. if (relation === 'intersects' || relation === 'disjoint' || relation === 'within') {
  3992. filter.geo_shape[field].relation = relation;
  3993. }
  3994. return this;
  3995. },
  3996. /**
  3997. <p>Sets the spatial strategy.</p>
  3998. <p>Valid values are:</p>
  3999. <dl>
  4000. <dd><code>recursive</code> - default, recursively traverse nodes in
  4001. the spatial prefix tree. This strategy has support for
  4002. searching non-point shapes.</dd>
  4003. <dd><code>term</code> - uses a large TermsFilter on each node
  4004. in the spatial prefix tree. It only supports the search of
  4005. indexed Point shapes.</dd>
  4006. </dl>
  4007. <p>This is an advanced setting, use with care.</p>
  4008. @since elasticsearch 0.90
  4009. @member ejs.GeoShapeFilter
  4010. @param {String} strategy The strategy as a string.
  4011. @returns {Object} returns <code>this</code> so that calls can be chained.
  4012. */
  4013. strategy: function (strategy) {
  4014. if (strategy == null) {
  4015. return filter.geo_shape[field].strategy;
  4016. }
  4017. strategy = strategy.toLowerCase();
  4018. if (strategy === 'recursive' || strategy === 'term') {
  4019. filter.geo_shape[field].strategy = strategy;
  4020. }
  4021. return this;
  4022. },
  4023. /**
  4024. Sets the filter name.
  4025. @member ejs.GeoShapeFilter
  4026. @param {String} name A name for the filter.
  4027. @returns {Object} returns <code>this</code> so that calls can be chained.
  4028. */
  4029. name: function (name) {
  4030. if (name == null) {
  4031. return filter.geo_shape._name;
  4032. }
  4033. filter.geo_shape._name = name;
  4034. return this;
  4035. },
  4036. /**
  4037. Enable or disable caching of the filter
  4038. @member ejs.GeoShapeFilter
  4039. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  4040. @returns {Object} returns <code>this</code> so that calls can be chained.
  4041. */
  4042. cache: function (trueFalse) {
  4043. if (trueFalse == null) {
  4044. return filter.geo_shape._cache;
  4045. }
  4046. filter.geo_shape._cache = trueFalse;
  4047. return this;
  4048. },
  4049. /**
  4050. Sets the cache key.
  4051. @member ejs.GeoShapeFilter
  4052. @param {String} key the cache key as a string.
  4053. @returns {Object} returns <code>this</code> so that calls can be chained.
  4054. */
  4055. cacheKey: function (key) {
  4056. if (key == null) {
  4057. return filter.geo_shape._cache_key;
  4058. }
  4059. filter.geo_shape._cache_key = key;
  4060. return this;
  4061. },
  4062. /**
  4063. Allows you to serialize this object into a JSON encoded string.
  4064. @member ejs.GeoShapeFilter
  4065. @returns {String} returns this object as a serialized JSON string.
  4066. */
  4067. toString: function () {
  4068. return JSON.stringify(filter);
  4069. },
  4070. /**
  4071. The type of ejs object. For internal use only.
  4072. @member ejs.GeoShapeFilter
  4073. @returns {String} the type of object
  4074. */
  4075. _type: function () {
  4076. return 'filter';
  4077. },
  4078. /**
  4079. Retrieves the internal <code>filter</code> object. This is typically used by
  4080. internal API functions so use with caution.
  4081. @member ejs.GeoShapeFilter
  4082. @returns {String} returns this object's internal <code>filter</code> property.
  4083. */
  4084. _self: function () {
  4085. return filter;
  4086. }
  4087. };
  4088. };
  4089. /**
  4090. @class
  4091. <p>The has_child filter results in parent documents that have child docs
  4092. matching the query being returned.</p>
  4093. @name ejs.HasChildFilter
  4094. @desc
  4095. Returns results that have child documents matching the filter.
  4096. @param {Object} qry A valid query object.
  4097. @param {String} type The child type
  4098. */
  4099. ejs.HasChildFilter = function (qry, type) {
  4100. if (!isQuery(qry)) {
  4101. throw new TypeError('No Query object found');
  4102. }
  4103. /**
  4104. The internal query object. <code>Use _self()</code>
  4105. @member ejs.HasChildFilter
  4106. @property {Object} query
  4107. */
  4108. var filter = {
  4109. has_child: {
  4110. query: qry._self(),
  4111. type: type
  4112. }
  4113. };
  4114. return {
  4115. /**
  4116. Sets the query
  4117. @member ejs.HasChildFilter
  4118. @param {Query} q A valid Query object
  4119. @returns {Object} returns <code>this</code> so that calls can be chained.
  4120. */
  4121. query: function (q) {
  4122. if (q == null) {
  4123. return filter.has_child.query;
  4124. }
  4125. if (!isQuery(q)) {
  4126. throw new TypeError('Argument must be a Query object');
  4127. }
  4128. filter.has_child.query = q._self();
  4129. return this;
  4130. },
  4131. /**
  4132. Sets the filter
  4133. @since elasticsearch 0.90
  4134. @member ejs.HasChildFilter
  4135. @param {Query} f A valid Filter object
  4136. @returns {Object} returns <code>this</code> so that calls can be chained.
  4137. */
  4138. filter: function (f) {
  4139. if (f == null) {
  4140. return filter.has_child.filter;
  4141. }
  4142. if (!isFilter(f)) {
  4143. throw new TypeError('Argument must be a Filter object');
  4144. }
  4145. filter.has_child.filter = f._self();
  4146. return this;
  4147. },
  4148. /**
  4149. Sets the child document type to search against
  4150. @member ejs.HasChildFilter
  4151. @param {String} t A valid type name
  4152. @returns {Object} returns <code>this</code> so that calls can be chained.
  4153. */
  4154. type: function (t) {
  4155. if (t == null) {
  4156. return filter.has_child.type;
  4157. }
  4158. filter.has_child.type = t;
  4159. return this;
  4160. },
  4161. /**
  4162. Sets the scope of the filter. A scope allows to run facets on the
  4163. same scope name that will work against the child documents.
  4164. @deprecated since elasticsearch 0.90
  4165. @member ejs.HasChildFilter
  4166. @param {String} s The scope name as a string.
  4167. @returns {Object} returns <code>this</code> so that calls can be chained.
  4168. */
  4169. scope: function (s) {
  4170. return this;
  4171. },
  4172. /**
  4173. Sets the filter name.
  4174. @member ejs.HasChildFilter
  4175. @param {String} name A name for the filter.
  4176. @returns {Object} returns <code>this</code> so that calls can be chained.
  4177. */
  4178. name: function (name) {
  4179. if (name == null) {
  4180. return filter.has_child._name;
  4181. }
  4182. filter.has_child._name = name;
  4183. return this;
  4184. },
  4185. /**
  4186. Allows you to serialize this object into a JSON encoded string.
  4187. @member ejs.HasChildFilter
  4188. @returns {String} returns this object as a serialized JSON string.
  4189. */
  4190. toString: function () {
  4191. return JSON.stringify(filter);
  4192. },
  4193. /**
  4194. The type of ejs object. For internal use only.
  4195. @member ejs.HasChildFilter
  4196. @returns {String} the type of object
  4197. */
  4198. _type: function () {
  4199. return 'filter';
  4200. },
  4201. /**
  4202. Retrieves the internal <code>filter</code> object. This is typically used by
  4203. internal API functions so use with caution.
  4204. @member ejs.HasChildFilter
  4205. @returns {String} returns this object's internal <code>filter</code> property.
  4206. */
  4207. _self: function () {
  4208. return filter;
  4209. }
  4210. };
  4211. };
  4212. /**
  4213. @class
  4214. <p>The has_parent results in child documents that have parent docs matching
  4215. the query being returned.</p>
  4216. @name ejs.HasParentFilter
  4217. @desc
  4218. Returns results that have parent documents matching the filter.
  4219. @param {Object} qry A valid query object.
  4220. @param {String} parentType The child type
  4221. */
  4222. ejs.HasParentFilter = function (qry, parentType) {
  4223. if (!isQuery(qry)) {
  4224. throw new TypeError('No Query object found');
  4225. }
  4226. /**
  4227. The internal filter object. <code>Use _self()</code>
  4228. @member ejs.HasParentFilter
  4229. @property {Object} query
  4230. */
  4231. var filter = {
  4232. has_parent: {
  4233. query: qry._self(),
  4234. parent_type: parentType
  4235. }
  4236. };
  4237. return {
  4238. /**
  4239. Sets the query
  4240. @member ejs.HasParentFilter
  4241. @param {Object} q A valid Query object
  4242. @returns {Object} returns <code>this</code> so that calls can be chained.
  4243. */
  4244. query: function (q) {
  4245. if (q == null) {
  4246. return filter.has_parent.query;
  4247. }
  4248. if (!isQuery(q)) {
  4249. throw new TypeError('Argument must be a Query object');
  4250. }
  4251. filter.has_parent.query = q._self();
  4252. return this;
  4253. },
  4254. /**
  4255. Sets the filter
  4256. @since elasticsearch 0.90
  4257. @member ejs.HasParentFilter
  4258. @param {Object} f A valid Filter object
  4259. @returns {Object} returns <code>this</code> so that calls can be chained.
  4260. */
  4261. filter: function (f) {
  4262. if (f == null) {
  4263. return filter.has_parent.filter;
  4264. }
  4265. if (!isFilter(f)) {
  4266. throw new TypeError('Argument must be a Filter object');
  4267. }
  4268. filter.has_parent.filter = f._self();
  4269. return this;
  4270. },
  4271. /**
  4272. Sets the child document type to search against
  4273. @member ejs.HasParentFilter
  4274. @param {String} t A valid type name
  4275. @returns {Object} returns <code>this</code> so that calls can be chained.
  4276. */
  4277. parentType: function (t) {
  4278. if (t == null) {
  4279. return filter.has_parent.parent_type;
  4280. }
  4281. filter.has_parent.parent_type = t;
  4282. return this;
  4283. },
  4284. /**
  4285. Sets the scope of the filter. A scope allows to run facets on the
  4286. same scope name that will work against the parent documents.
  4287. @deprecated since elasticsearch 0.90
  4288. @member ejs.HasParentFilter
  4289. @param {String} s The scope name as a string.
  4290. @returns {Object} returns <code>this</code> so that calls can be chained.
  4291. */
  4292. scope: function (s) {
  4293. return this;
  4294. },
  4295. /**
  4296. Sets the filter name.
  4297. @member ejs.HasParentFilter
  4298. @param {String} name A name for the filter.
  4299. @returns {Object} returns <code>this</code> so that calls can be chained.
  4300. */
  4301. name: function (name) {
  4302. if (name == null) {
  4303. return filter.has_parent._name;
  4304. }
  4305. filter.has_parent._name = name;
  4306. return this;
  4307. },
  4308. /**
  4309. Allows you to serialize this object into a JSON encoded string.
  4310. @member ejs.HasParentFilter
  4311. @returns {String} returns this object as a serialized JSON string.
  4312. */
  4313. toString: function () {
  4314. return JSON.stringify(filter);
  4315. },
  4316. /**
  4317. The type of ejs object. For internal use only.
  4318. @member ejs.HasParentFilter
  4319. @returns {String} the type of object
  4320. */
  4321. _type: function () {
  4322. return 'filter';
  4323. },
  4324. /**
  4325. Retrieves the internal <code>filter</code> object. This is typically used by
  4326. internal API functions so use with caution.
  4327. @member ejs.HasParentFilter
  4328. @returns {String} returns this object's internal <code>filter</code> property.
  4329. */
  4330. _self: function () {
  4331. return filter;
  4332. }
  4333. };
  4334. };
  4335. /**
  4336. @class
  4337. <p>Filters documents that only have the provided ids. Note, this filter
  4338. does not require the _id field to be indexed since it works using the
  4339. _uid field.</p>
  4340. @name ejs.IdsFilter
  4341. @desc
  4342. Matches documents with the specified id(s).
  4343. @param {Array || String} ids A single document id or a list of document ids.
  4344. */
  4345. ejs.IdsFilter = function (ids) {
  4346. /**
  4347. The internal filter object. <code>Use get()</code>
  4348. @member ejs.IdsFilter
  4349. @property {Object} filter
  4350. */
  4351. var filter = {
  4352. ids: {}
  4353. };
  4354. if (isString(ids)) {
  4355. filter.ids.values = [ids];
  4356. } else if (isArray(ids)) {
  4357. filter.ids.values = ids;
  4358. } else {
  4359. throw new TypeError('Argument must be a string or an array');
  4360. }
  4361. return {
  4362. /**
  4363. Sets the values array or adds a new value. if val is a string, it
  4364. is added to the list of existing document ids. If val is an
  4365. array it is set as the document values and replaces any existing values.
  4366. @member ejs.IdsFilter
  4367. @param {Array || String} val An single document id or an array of document ids.
  4368. @returns {Object} returns <code>this</code> so that calls can be chained.
  4369. */
  4370. values: function (val) {
  4371. if (val == null) {
  4372. return filter.ids.values;
  4373. }
  4374. if (isString(val)) {
  4375. filter.ids.values.push(val);
  4376. } else if (isArray(val)) {
  4377. filter.ids.values = val;
  4378. } else {
  4379. throw new TypeError('Argument must be a string or an array');
  4380. }
  4381. return this;
  4382. },
  4383. /**
  4384. Sets the type as a single type or an array of types. If type is a
  4385. string, it is added to the list of existing types. If type is an
  4386. array, it is set as the types and overwrites an existing types. This
  4387. parameter is optional.
  4388. @member ejs.IdsFilter
  4389. @param {Array || String} type A type or a list of types
  4390. @returns {Object} returns <code>this</code> so that calls can be chained.
  4391. */
  4392. type: function (type) {
  4393. if (filter.ids.type == null) {
  4394. filter.ids.type = [];
  4395. }
  4396. if (type == null) {
  4397. return filter.ids.type;
  4398. }
  4399. if (isString(type)) {
  4400. filter.ids.type.push(type);
  4401. } else if (isArray(type)) {
  4402. filter.ids.type = type;
  4403. } else {
  4404. throw new TypeError('Argument must be a string or an array');
  4405. }
  4406. return this;
  4407. },
  4408. /**
  4409. Sets the filter name.
  4410. @member ejs.IdsFilter
  4411. @param {String} name A name for the filter.
  4412. @returns {Object} returns <code>this</code> so that calls can be chained.
  4413. */
  4414. name: function (name) {
  4415. if (name == null) {
  4416. return filter.ids._name;
  4417. }
  4418. filter.ids._name = name;
  4419. return this;
  4420. },
  4421. /**
  4422. Allows you to serialize this object into a JSON encoded string.
  4423. @member ejs.IdsFilter
  4424. @returns {String} returns this object as a serialized JSON string.
  4425. */
  4426. toString: function () {
  4427. return JSON.stringify(filter);
  4428. },
  4429. /**
  4430. The type of ejs object. For internal use only.
  4431. @member ejs.IdsFilter
  4432. @returns {String} the type of object
  4433. */
  4434. _type: function () {
  4435. return 'filter';
  4436. },
  4437. /**
  4438. Retrieves the internal <code>filter</code> object. This is typically used by
  4439. internal API functions so use with caution.
  4440. @member ejs.IdsFilter
  4441. @returns {String} returns this object's internal <code>filter</code> property.
  4442. */
  4443. _self: function () {
  4444. return filter;
  4445. }
  4446. };
  4447. };
  4448. /**
  4449. @class
  4450. <p>The indices filter can be used when executed across multiple indices,
  4451. allowing to have a filter that executes only when executed on an index that
  4452. matches a specific list of indices, and another filter that executes when it
  4453. is executed on an index that does not match the listed indices.</p>
  4454. @name ejs.IndicesFilter
  4455. @desc
  4456. A configurable filter that is dependent on the index name.
  4457. @param {Object} fltr A valid filter object.
  4458. @param {String || Array} indices a single index name or an array of index
  4459. names.
  4460. */
  4461. ejs.IndicesFilter = function (fltr, indices) {
  4462. if (!isFilter(fltr)) {
  4463. throw new TypeError('Argument must be a Filter');
  4464. }
  4465. /**
  4466. The internal filter object. <code>Use _self()</code>
  4467. @member ejs.IndicesFilter
  4468. @property {Object} filter
  4469. */
  4470. var filter = {
  4471. indices: {
  4472. filter: fltr._self()
  4473. }
  4474. };
  4475. if (isString(indices)) {
  4476. filter.indices.indices = [indices];
  4477. } else if (isArray(indices)) {
  4478. filter.indices.indices = indices;
  4479. } else {
  4480. throw new TypeError('Argument must be a string or array');
  4481. }
  4482. return {
  4483. /**
  4484. Sets the indicies the filter should match. When passed a string,
  4485. the index name is added to the current list of indices. When passed
  4486. an array, it overwites all current indices.
  4487. @member ejs.IndicesFilter
  4488. @param {String || Array} i A single index name or an array of index names.
  4489. @returns {Object} returns <code>this</code> so that calls can be chained.
  4490. */
  4491. indices: function (i) {
  4492. if (i == null) {
  4493. return filter.indices.indices;
  4494. }
  4495. if (isString(i)) {
  4496. filter.indices.indices.push(i);
  4497. } else if (isArray(i)) {
  4498. filter.indices.indices = i;
  4499. } else {
  4500. throw new TypeError('Argument must be a string or array');
  4501. }
  4502. return this;
  4503. },
  4504. /**
  4505. Sets the filter to be used when executing on one of the indicies
  4506. specified.
  4507. @member ejs.IndicesFilter
  4508. @param {Object} f A valid Filter object
  4509. @returns {Object} returns <code>this</code> so that calls can be chained.
  4510. */
  4511. filter: function (f) {
  4512. if (f == null) {
  4513. return filter.indices.filter;
  4514. }
  4515. if (!isFilter(f)) {
  4516. throw new TypeError('Argument must be a Filter');
  4517. }
  4518. filter.indices.filter = f._self();
  4519. return this;
  4520. },
  4521. /**
  4522. Sets the filter to be used on an index that does not match an index
  4523. name in the indices list. Can also be set to "none" to not match any
  4524. documents or "all" to match all documents.
  4525. @member ejs.IndicesFilter
  4526. @param {Object || String} f A valid Filter object or "none" or "all"
  4527. @returns {Object} returns <code>this</code> so that calls can be chained.
  4528. */
  4529. noMatchFilter: function (f) {
  4530. if (f == null) {
  4531. return filter.indices.no_match_filter;
  4532. }
  4533. if (isString(f)) {
  4534. f = f.toLowerCase();
  4535. if (f === 'none' || f === 'all') {
  4536. filter.indices.no_match_filter = f;
  4537. }
  4538. } else if (isFilter(f)) {
  4539. filter.indices.no_match_filter = f._self();
  4540. } else {
  4541. throw new TypeError('Argument must be string or Filter');
  4542. }
  4543. return this;
  4544. },
  4545. /**
  4546. Allows you to serialize this object into a JSON encoded string.
  4547. @member ejs.IndicesFilter
  4548. @returns {String} returns this object as a serialized JSON string.
  4549. */
  4550. toString: function () {
  4551. return JSON.stringify(filter);
  4552. },
  4553. /**
  4554. The type of ejs object. For internal use only.
  4555. @member ejs.IndicesFilter
  4556. @returns {String} the type of object
  4557. */
  4558. _type: function () {
  4559. return 'filter';
  4560. },
  4561. /**
  4562. Retrieves the internal <code>filter</code> object. This is typically used by
  4563. internal API functions so use with caution.
  4564. @member ejs.IndicesFilter
  4565. @returns {String} returns this object's internal <code>filter</code> property.
  4566. */
  4567. _self: function () {
  4568. return filter;
  4569. }
  4570. };
  4571. };
  4572. /**
  4573. @class
  4574. <p>A limit filter limits the number of documents (per shard) to execute on.</p>
  4575. @name ejs.LimitFilter
  4576. @desc
  4577. Limits the number of documents to execute on.
  4578. @param {Integer} limit The number of documents to execute on.
  4579. */
  4580. ejs.LimitFilter = function (limit) {
  4581. /**
  4582. The internal filter object. <code>Use get()</code>
  4583. @member ejs.LimitFilter
  4584. @property {Object} filter
  4585. */
  4586. var filter = {
  4587. limit: {
  4588. value: limit
  4589. }
  4590. };
  4591. return {
  4592. /**
  4593. Sets the limit value.
  4594. @member ejs.LimitFilter
  4595. @param {Integer} val An The number of documents to execute on.
  4596. @returns {Object} returns <code>this</code> so that calls can be chained.
  4597. */
  4598. value: function (val) {
  4599. if (val == null) {
  4600. return filter.limit.value;
  4601. }
  4602. if (!isNumber(val)) {
  4603. throw new TypeError('Argument must be a numeric value');
  4604. }
  4605. filter.limit.value = val;
  4606. return this;
  4607. },
  4608. /**
  4609. Allows you to serialize this object into a JSON encoded string.
  4610. @member ejs.LimitFilter
  4611. @returns {String} returns this object as a serialized JSON string.
  4612. */
  4613. toString: function () {
  4614. return JSON.stringify(filter);
  4615. },
  4616. /**
  4617. The type of ejs object. For internal use only.
  4618. @member ejs.LimitFilter
  4619. @returns {String} the type of object
  4620. */
  4621. _type: function () {
  4622. return 'filter';
  4623. },
  4624. /**
  4625. Retrieves the internal <code>filter</code> object. This is typically used by
  4626. internal API functions so use with caution.
  4627. @member ejs.LimitFilter
  4628. @returns {String} returns this object's internal <code>filter</code> property.
  4629. */
  4630. _self: function () {
  4631. return filter;
  4632. }
  4633. };
  4634. };
  4635. /**
  4636. @class
  4637. <p>This filter can be used to match on all the documents
  4638. in a given set of collections and/or types.</p>
  4639. @name ejs.MatchAllFilter
  4640. @desc
  4641. <p>A filter that matches on all documents</p>
  4642. */
  4643. ejs.MatchAllFilter = function () {
  4644. /**
  4645. The internal Query object. Use <code>get()</code>.
  4646. @member ejs.MatchAllFilter
  4647. @property {Object} filter
  4648. */
  4649. var filter = {
  4650. match_all: {}
  4651. };
  4652. return {
  4653. /**
  4654. Serializes the internal <em>filter</em> object as a JSON string.
  4655. @member ejs.MatchAllFilter
  4656. @returns {String} Returns a JSON representation of the object.
  4657. */
  4658. toString: function () {
  4659. return JSON.stringify(filter);
  4660. },
  4661. /**
  4662. The type of ejs object. For internal use only.
  4663. @member ejs.MatchAllFilter
  4664. @returns {String} the type of object
  4665. */
  4666. _type: function () {
  4667. return 'filter';
  4668. },
  4669. /**
  4670. This method is used to retrieve the raw filter object. It's designed
  4671. for internal use when composing and serializing queries.
  4672. @member ejs.MatchAllFilter
  4673. @returns {Object} Returns the object's <em>filter</em> property.
  4674. */
  4675. _self: function () {
  4676. return filter;
  4677. }
  4678. };
  4679. };
  4680. /**
  4681. @class
  4682. <p>An missingFilter matches documents where the specified field contains no legitimate value.</p>
  4683. @name ejs.MissingFilter
  4684. @desc
  4685. Filters documents where a specific field has no value present.
  4686. @param {String} fieldName the field name to check for missing values.
  4687. */
  4688. ejs.MissingFilter = function (fieldName) {
  4689. /**
  4690. The internal filter object. Use <code>get()</code>
  4691. @member ejs.MissingFilter
  4692. @property {Object} filter
  4693. */
  4694. var filter = {
  4695. missing: {
  4696. field: fieldName
  4697. }
  4698. };
  4699. return {
  4700. /**
  4701. Sets the field to check for missing values.
  4702. @member ejs.MissingFilter
  4703. @param {String} name A name of the field.
  4704. @returns {Object} returns <code>this</code> so that calls can be chained.
  4705. */
  4706. field: function (name) {
  4707. if (name == null) {
  4708. return filter.missing.field;
  4709. }
  4710. filter.missing.field = name;
  4711. return this;
  4712. },
  4713. /**
  4714. Checks if the field doesn't exist.
  4715. @member ejs.MissingFilter
  4716. @param {Boolean} trueFalse True to check if the field doesn't exist.
  4717. @returns {Object} returns <code>this</code> so that calls can be chained.
  4718. */
  4719. existence: function (trueFalse) {
  4720. if (trueFalse == null) {
  4721. return filter.missing.existence;
  4722. }
  4723. filter.missing.existence = trueFalse;
  4724. return this;
  4725. },
  4726. /**
  4727. Checks if the field has null values.
  4728. @member ejs.MissingFilter
  4729. @param {Boolean} trueFalse True to check if the field has nulls.
  4730. @returns {Object} returns <code>this</code> so that calls can be chained.
  4731. */
  4732. nullValue: function (trueFalse) {
  4733. if (trueFalse == null) {
  4734. return filter.missing.null_value;
  4735. }
  4736. filter.missing.null_value = trueFalse;
  4737. return this;
  4738. },
  4739. /**
  4740. Sets the filter name.
  4741. @member ejs.MissingFilter
  4742. @param {String} name A name for the filter.
  4743. @returns {Object} returns <code>this</code> so that calls can be chained.
  4744. */
  4745. name: function (name) {
  4746. if (name == null) {
  4747. return filter.missing._name;
  4748. }
  4749. filter.missing._name = name;
  4750. return this;
  4751. },
  4752. /**
  4753. Returns the filter container as a JSON string
  4754. @member ejs.MissingFilter
  4755. @returns {String} JSON representation of the missingFilter object
  4756. */
  4757. toString: function () {
  4758. return JSON.stringify(filter);
  4759. },
  4760. /**
  4761. The type of ejs object. For internal use only.
  4762. @member ejs.MissingFilter
  4763. @returns {String} the type of object
  4764. */
  4765. _type: function () {
  4766. return 'filter';
  4767. },
  4768. /**
  4769. Returns the filter object.
  4770. @member ejs.MissingFilter
  4771. @returns {Object} filter object
  4772. */
  4773. _self: function () {
  4774. return filter;
  4775. }
  4776. };
  4777. };
  4778. /**
  4779. @class
  4780. <p>Nested filters allow you to search against content within objects that are
  4781. embedded inside of other objects. It is similar to <code>XPath</code>
  4782. expressions in <code>XML</code> both conceptually and syntactically.</p>
  4783. <p>
  4784. The filter is executed against the nested objects / docs as if they were
  4785. indexed as separate docs and resulting in the root
  4786. parent doc (or parent nested mapping).</p>
  4787. @name ejs.NestedFilter
  4788. @desc
  4789. <p>Constructs a filter that is capable of executing a filter against objects
  4790. nested within a document.</p>
  4791. @param {String} path The nested object path.
  4792. */
  4793. ejs.NestedFilter = function (path) {
  4794. /**
  4795. The internal Filter object. Use <code>_self()</code>.
  4796. @member ejs.NestedFilter
  4797. @property {Object} filter
  4798. */
  4799. var filter = {
  4800. nested: {
  4801. path: path
  4802. }
  4803. };
  4804. return {
  4805. /**
  4806. Sets the root context for the nested filter.
  4807. @member ejs.NestedFilter
  4808. @param {String} p The path defining the root for the nested filter.
  4809. @returns {Object} returns <code>this</code> so that calls can be chained.
  4810. */
  4811. path: function (p) {
  4812. if (p == null) {
  4813. return filter.nested.path;
  4814. }
  4815. filter.nested.path = p;
  4816. return this;
  4817. },
  4818. /**
  4819. Sets the nested query to be executed.
  4820. @member ejs.NestedFilter
  4821. @param {Query} oQuery A valid Query object
  4822. @returns {Object} returns <code>this</code> so that calls can be chained.
  4823. */
  4824. query: function (oQuery) {
  4825. if (oQuery == null) {
  4826. return filter.nested.query;
  4827. }
  4828. if (!isQuery(oQuery)) {
  4829. throw new TypeError('Argument must be a Query object');
  4830. }
  4831. filter.nested.query = oQuery._self();
  4832. return this;
  4833. },
  4834. /**
  4835. Sets the nested filter to be executed.
  4836. @member ejs.NestedFilter
  4837. @param {Object} oFilter A valid Filter object
  4838. @returns {Object} returns <code>this</code> so that calls can be chained.
  4839. */
  4840. filter: function (oFilter) {
  4841. if (oFilter == null) {
  4842. return filter.nested.filter;
  4843. }
  4844. if (!isFilter(oFilter)) {
  4845. throw new TypeError('Argument must be a Filter object');
  4846. }
  4847. filter.nested.filter = oFilter._self();
  4848. return this;
  4849. },
  4850. /**
  4851. Sets the boost value of the nested <code>Query</code>.
  4852. @member ejs.NestedFilter
  4853. @param {Double} boost A positive <code>double</code> value.
  4854. @returns {Object} returns <code>this</code> so that calls can be chained.
  4855. */
  4856. boost: function (boost) {
  4857. if (boost == null) {
  4858. return filter.nested.boost;
  4859. }
  4860. filter.nested.boost = boost;
  4861. return this;
  4862. },
  4863. /**
  4864. If the nested query should be "joined" with the parent document.
  4865. Defaults to false.
  4866. @member ejs.NestedFilter
  4867. @param {Boolean} trueFalse If the query should be joined or not.
  4868. @returns {Object} returns <code>this</code> so that calls can be chained.
  4869. */
  4870. join: function (trueFalse) {
  4871. if (trueFalse == null) {
  4872. return filter.nested.join;
  4873. }
  4874. filter.nested.join = trueFalse;
  4875. return this;
  4876. },
  4877. /**
  4878. Sets the scope of the filter. A scope allows to run facets on the
  4879. same scope name that will work against the nested documents.
  4880. @deprecated since elasticsearch 0.90
  4881. @member ejs.NestedFilter
  4882. @param {String} s The scope name as a string.
  4883. @returns {Object} returns <code>this</code> so that calls can be chained.
  4884. */
  4885. scope: function (s) {
  4886. return this;
  4887. },
  4888. /**
  4889. Sets the filter name.
  4890. @member ejs.NestedFilter
  4891. @param {String} name A name for the filter.
  4892. @returns {Object} returns <code>this</code> so that calls can be chained.
  4893. */
  4894. name: function (name) {
  4895. if (name == null) {
  4896. return filter.nested._name;
  4897. }
  4898. filter.nested._name = name;
  4899. return this;
  4900. },
  4901. /**
  4902. Enable or disable caching of the filter
  4903. @member ejs.NestedFilter
  4904. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  4905. @returns {Object} returns <code>this</code> so that calls can be chained.
  4906. */
  4907. cache: function (trueFalse) {
  4908. if (trueFalse == null) {
  4909. return filter.nested._cache;
  4910. }
  4911. filter.nested._cache = trueFalse;
  4912. return this;
  4913. },
  4914. /**
  4915. Sets the cache key.
  4916. @member ejs.NestedFilter
  4917. @param {String} key the cache key as a string.
  4918. @returns {Object} returns <code>this</code> so that calls can be chained.
  4919. */
  4920. cacheKey: function (key) {
  4921. if (key == null) {
  4922. return filter.nested._cache_key;
  4923. }
  4924. filter.nested._cache_key = key;
  4925. return this;
  4926. },
  4927. /**
  4928. Serializes the internal <em>filter</em> object as a JSON string.
  4929. @member ejs.NestedFilter
  4930. @returns {String} Returns a JSON representation of the termFilter object.
  4931. */
  4932. toString: function () {
  4933. return JSON.stringify(filter);
  4934. },
  4935. /**
  4936. The type of ejs object. For internal use only.
  4937. @member ejs.NestedFilter
  4938. @returns {String} the type of object
  4939. */
  4940. _type: function () {
  4941. return 'filter';
  4942. },
  4943. /**
  4944. This method is used to retrieve the raw filter object. It's designed
  4945. for internal use when composing and serializing filters.
  4946. @member ejs.NestedFilter
  4947. @returns {Object} Returns the object's <em>filter</em> property.
  4948. */
  4949. _self: function () {
  4950. return filter;
  4951. }
  4952. };
  4953. };
  4954. /**
  4955. @class
  4956. <p>A container Filter that excludes the documents matched by the
  4957. contained filter.</p>
  4958. @name ejs.NotFilter
  4959. @desc
  4960. Container filter that excludes the matched documents of the contained filter.
  4961. @param {Object} oFilter a valid Filter object such as a termFilter, etc.
  4962. */
  4963. ejs.NotFilter = function (oFilter) {
  4964. if (!isFilter(oFilter)) {
  4965. throw new TypeError('Argument must be a Filter');
  4966. }
  4967. /**
  4968. The internal filter object. Use <code>_self()</code>
  4969. @member ejs.NotFilter
  4970. @property {Object} filter
  4971. */
  4972. var filter = {
  4973. not: oFilter._self()
  4974. };
  4975. return {
  4976. /**
  4977. Sets the filter
  4978. @member ejs.NotFilter
  4979. @param {Object} fltr A valid filter object such as a termFilter, etc.
  4980. @returns {Object} returns <code>this</code> so that calls can be chained.
  4981. */
  4982. filter: function (fltr) {
  4983. if (fltr == null) {
  4984. return filter.not;
  4985. }
  4986. if (!isFilter(fltr)) {
  4987. throw new TypeError('Argument must be a Filter');
  4988. }
  4989. filter.not = fltr._self();
  4990. return this;
  4991. },
  4992. /**
  4993. Sets the filter name.
  4994. @member ejs.NotFilter
  4995. @param {String} name A name for the filter.
  4996. @returns {Object} returns <code>this</code> so that calls can be chained.
  4997. */
  4998. name: function (name) {
  4999. if (name == null) {
  5000. return filter.not._name;
  5001. }
  5002. filter.not._name = name;
  5003. return this;
  5004. },
  5005. /**
  5006. Enable or disable caching of the filter
  5007. @member ejs.NotFilter
  5008. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5009. @returns {Object} returns <code>this</code> so that calls can be chained.
  5010. */
  5011. cache: function (trueFalse) {
  5012. if (trueFalse == null) {
  5013. return filter.not._cache;
  5014. }
  5015. filter.not._cache = trueFalse;
  5016. return this;
  5017. },
  5018. /**
  5019. Sets the cache key.
  5020. @member ejs.NotFilter
  5021. @param {String} key the cache key as a string.
  5022. @returns {Object} returns <code>this</code> so that calls can be chained.
  5023. */
  5024. cacheKey: function (key) {
  5025. if (key == null) {
  5026. return filter.not._cache_key;
  5027. }
  5028. filter.not._cache_key = key;
  5029. return this;
  5030. },
  5031. /**
  5032. Returns the filter container as a JSON string
  5033. @member ejs.NotFilter
  5034. @returns {String} JSON representation of the notFilter object
  5035. */
  5036. toString: function () {
  5037. return JSON.stringify(filter);
  5038. },
  5039. /**
  5040. The type of ejs object. For internal use only.
  5041. @member ejs.NotFilter
  5042. @returns {String} the type of object
  5043. */
  5044. _type: function () {
  5045. return 'filter';
  5046. },
  5047. /**
  5048. Returns the filter object.
  5049. @member ejs.NotFilter
  5050. @returns {Object} filter object
  5051. */
  5052. _self: function () {
  5053. return filter;
  5054. }
  5055. };
  5056. };
  5057. /**
  5058. @class
  5059. <p>Filters documents with fields that have values within a certain numeric
  5060. range. Similar to range filter, except that it works only with numeric
  5061. values, and the filter execution works differently.</p>
  5062. <p>The numeric range filter works by loading all the relevant field values
  5063. into memory, and checking for the relevant docs if they satisfy the range
  5064. requirements. This requires more memory since the numeric range data are
  5065. loaded to memory, but can provide a significant increase in performance.</p>
  5066. <p>Note, if the relevant field values have already been loaded to memory,
  5067. for example because it was used in facets or was sorted on, then this
  5068. filter should be used.</p>
  5069. @name ejs.NumericRangeFilter
  5070. @desc
  5071. A Filter that only accepts numeric values within a specified range.
  5072. @param {string} fieldName The name of the field to filter on.
  5073. */
  5074. ejs.NumericRangeFilter = function (fieldName) {
  5075. /**
  5076. The internal filter object. Use <code>get()</code>
  5077. @member ejs.NumericRangeFilter
  5078. @property {Object} filter
  5079. */
  5080. var filter = {
  5081. numeric_range: {}
  5082. };
  5083. filter.numeric_range[fieldName] = {};
  5084. return {
  5085. /**
  5086. Returns the field name used to create this object.
  5087. @member ejs.NumericRangeFilter
  5088. @param {String} field the field name
  5089. @returns {Object} returns <code>this</code> so that calls can be
  5090. chained. Returns {String}, field name when field is not specified.
  5091. */
  5092. field: function (field) {
  5093. var oldValue = filter.numeric_range[fieldName];
  5094. if (field == null) {
  5095. return fieldName;
  5096. }
  5097. delete filter.numeric_range[fieldName];
  5098. fieldName = field;
  5099. filter.numeric_range[fieldName] = oldValue;
  5100. return this;
  5101. },
  5102. /**
  5103. Sets the endpoint for the current range.
  5104. @member ejs.NumericRangeFilter
  5105. @param {Number} startPoint A numeric value representing the start of the range
  5106. @returns {Object} returns <code>this</code> so that calls can be chained.
  5107. */
  5108. from: function (from) {
  5109. if (from == null) {
  5110. return filter.numeric_range[fieldName].from;
  5111. }
  5112. if (!isNumber(from)) {
  5113. throw new TypeError('Argument must be a numeric value');
  5114. }
  5115. filter.numeric_range[fieldName].from = from;
  5116. return this;
  5117. },
  5118. /**
  5119. Sets the endpoint for the current range.
  5120. @member ejs.NumericRangeFilter
  5121. @param {Number} endPoint A numeric value representing the end of the range
  5122. @returns {Object} returns <code>this</code> so that calls can be chained.
  5123. */
  5124. to: function (to) {
  5125. if (to == null) {
  5126. return filter.numeric_range[fieldName].to;
  5127. }
  5128. if (!isNumber(to)) {
  5129. throw new TypeError('Argument must be a numeric value');
  5130. }
  5131. filter.numeric_range[fieldName].to = to;
  5132. return this;
  5133. },
  5134. /**
  5135. Should the first from (if set) be inclusive or not.
  5136. Defaults to true
  5137. @member ejs.NumericRangeFilter
  5138. @param {Boolean} trueFalse true to include, false to exclude
  5139. @returns {Object} returns <code>this</code> so that calls can be chained.
  5140. */
  5141. includeLower: function (trueFalse) {
  5142. if (trueFalse == null) {
  5143. return filter.numeric_range[fieldName].include_lower;
  5144. }
  5145. filter.numeric_range[fieldName].include_lower = trueFalse;
  5146. return this;
  5147. },
  5148. /**
  5149. Should the last to (if set) be inclusive or not. Defaults to true.
  5150. @member ejs.NumericRangeFilter
  5151. @param {Boolean} trueFalse true to include, false to exclude
  5152. @returns {Object} returns <code>this</code> so that calls can be chained.
  5153. */
  5154. includeUpper: function (trueFalse) {
  5155. if (trueFalse == null) {
  5156. return filter.numeric_range[fieldName].include_upper;
  5157. }
  5158. filter.numeric_range[fieldName].include_upper = trueFalse;
  5159. return this;
  5160. },
  5161. /**
  5162. Greater than value. Same as setting from to the value, and
  5163. include_lower to false,
  5164. @member ejs.NumericRangeFilter
  5165. @param {Variable Type} val the value, type depends on field type
  5166. @returns {Object} returns <code>this</code> so that calls can be chained.
  5167. */
  5168. gt: function (val) {
  5169. if (val == null) {
  5170. return filter.numeric_range[fieldName].gt;
  5171. }
  5172. if (!isNumber(val)) {
  5173. throw new TypeError('Argument must be a numeric value');
  5174. }
  5175. filter.numeric_range[fieldName].gt = val;
  5176. return this;
  5177. },
  5178. /**
  5179. Greater than or equal to value. Same as setting from to the value,
  5180. and include_lower to true.
  5181. @member ejs.NumericRangeFilter
  5182. @param {Variable Type} val the value, type depends on field type
  5183. @returns {Object} returns <code>this</code> so that calls can be chained.
  5184. */
  5185. gte: function (val) {
  5186. if (val == null) {
  5187. return filter.numeric_range[fieldName].gte;
  5188. }
  5189. if (!isNumber(val)) {
  5190. throw new TypeError('Argument must be a numeric value');
  5191. }
  5192. filter.numeric_range[fieldName].gte = val;
  5193. return this;
  5194. },
  5195. /**
  5196. Less than value. Same as setting to to the value, and include_upper
  5197. to false.
  5198. @member ejs.NumericRangeFilter
  5199. @param {Variable Type} val the value, type depends on field type
  5200. @returns {Object} returns <code>this</code> so that calls can be chained.
  5201. */
  5202. lt: function (val) {
  5203. if (val == null) {
  5204. return filter.numeric_range[fieldName].lt;
  5205. }
  5206. if (!isNumber(val)) {
  5207. throw new TypeError('Argument must be a numeric value');
  5208. }
  5209. filter.numeric_range[fieldName].lt = val;
  5210. return this;
  5211. },
  5212. /**
  5213. Less than or equal to value. Same as setting to to the value,
  5214. and include_upper to true.
  5215. @member ejs.NumericRangeFilter
  5216. @param {Variable Type} val the value, type depends on field type
  5217. @returns {Object} returns <code>this</code> so that calls can be chained.
  5218. */
  5219. lte: function (val) {
  5220. if (val == null) {
  5221. return filter.numeric_range[fieldName].lte;
  5222. }
  5223. if (!isNumber(val)) {
  5224. throw new TypeError('Argument must be a numeric value');
  5225. }
  5226. filter.numeric_range[fieldName].lte = val;
  5227. return this;
  5228. },
  5229. /**
  5230. Sets the filter name.
  5231. @member ejs.NumericRangeFilter
  5232. @param {String} name A name for the filter.
  5233. @returns {Object} returns <code>this</code> so that calls can be chained.
  5234. */
  5235. name: function (name) {
  5236. if (name == null) {
  5237. return filter.numeric_range._name;
  5238. }
  5239. filter.numeric_range._name = name;
  5240. return this;
  5241. },
  5242. /**
  5243. Enable or disable caching of the filter
  5244. @member ejs.NumericRangeFilter
  5245. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5246. @returns {Object} returns <code>this</code> so that calls can be chained.
  5247. */
  5248. cache: function (trueFalse) {
  5249. if (trueFalse == null) {
  5250. return filter.numeric_range._cache;
  5251. }
  5252. filter.numeric_range._cache = trueFalse;
  5253. return this;
  5254. },
  5255. /**
  5256. Sets the cache key.
  5257. @member ejs.NumericRangeFilter
  5258. @param {String} key the cache key as a string.
  5259. @returns {Object} returns <code>this</code> so that calls can be chained.
  5260. */
  5261. cacheKey: function (key) {
  5262. if (key == null) {
  5263. return filter.numeric_range._cache_key;
  5264. }
  5265. filter.numeric_range._cache_key = key;
  5266. return this;
  5267. },
  5268. /**
  5269. Returns the filter container as a JSON string.
  5270. @member ejs.NumericRangeFilter
  5271. @returns {String} JSON representation of the numericRangeFilter object
  5272. */
  5273. toString: function () {
  5274. return JSON.stringify(filter);
  5275. },
  5276. /**
  5277. The type of ejs object. For internal use only.
  5278. @member ejs.NumericRangeFilter
  5279. @returns {String} the type of object
  5280. */
  5281. _type: function () {
  5282. return 'filter';
  5283. },
  5284. /**
  5285. Returns the filter object.
  5286. @member ejs.NumericRangeFilter
  5287. @returns {Object} filter object
  5288. */
  5289. _self: function () {
  5290. return filter;
  5291. }
  5292. };
  5293. };
  5294. /**
  5295. @class
  5296. A container filter that allows Boolean OR composition of filters.
  5297. @name ejs.OrFilter
  5298. @desc
  5299. A container Filter that allows Boolean OR composition of filters.
  5300. @param {Filter || Array} filters A valid Filter or array of Filters.
  5301. */
  5302. ejs.OrFilter = function (filters) {
  5303. /**
  5304. The internal filter object. Use <code>_self()</code>
  5305. @member ejs.OrFilter
  5306. @property {Object} filter
  5307. */
  5308. var filter, i, len;
  5309. filter = {
  5310. or: {
  5311. filters: []
  5312. }
  5313. };
  5314. if (isFilter(filters)) {
  5315. filter.or.filters.push(filters._self());
  5316. } else if (isArray(filters)) {
  5317. for (i = 0, len = filters.length; i < len; i++) {
  5318. if (!isFilter(filters[i])) {
  5319. throw new TypeError('Argument must be array of Filters');
  5320. }
  5321. filter.or.filters.push(filters[i]._self());
  5322. }
  5323. } else {
  5324. throw new TypeError('Argument must be a Filter or array of Filters');
  5325. }
  5326. return {
  5327. /**
  5328. Updates the filters. If passed a single Filter it is added to
  5329. the existing filters. If passed an array of Filters, they
  5330. replace all existing Filters.
  5331. @member ejs.OrFilter
  5332. @param {Filter || Array} fltr A Filter or array of Filters
  5333. @returns {Object} returns <code>this</code> so that calls can be chained.
  5334. */
  5335. filters: function (fltr) {
  5336. var i, len;
  5337. if (fltr == null) {
  5338. return filter.or.filters;
  5339. }
  5340. if (isFilter(fltr)) {
  5341. filter.or.filters.push(fltr._self());
  5342. } else if (isArray(fltr)) {
  5343. filter.or.filters = [];
  5344. for (i = 0, len = fltr.length; i < len; i++) {
  5345. if (!isFilter(fltr[i])) {
  5346. throw new TypeError('Argument must be an array of Filters');
  5347. }
  5348. filter.or.filters.push(fltr[i]._self());
  5349. }
  5350. } else {
  5351. throw new TypeError('Argument must be a Filter or array of Filters');
  5352. }
  5353. return this;
  5354. },
  5355. /**
  5356. Sets the filter name.
  5357. @member ejs.OrFilter
  5358. @param {String} name A name for the filter.
  5359. @returns {Object} returns <code>this</code> so that calls can be chained.
  5360. */
  5361. name: function (name) {
  5362. if (name == null) {
  5363. return filter.or._name;
  5364. }
  5365. filter.or._name = name;
  5366. return this;
  5367. },
  5368. /**
  5369. Enable or disable caching of the filter
  5370. @member ejs.OrFilter
  5371. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5372. @returns {Object} returns <code>this</code> so that calls can be chained.
  5373. */
  5374. cache: function (trueFalse) {
  5375. if (trueFalse == null) {
  5376. return filter.or._cache;
  5377. }
  5378. filter.or._cache = trueFalse;
  5379. return this;
  5380. },
  5381. /**
  5382. Sets the cache key.
  5383. @member ejs.OrFilter
  5384. @param {String} key the cache key as a string.
  5385. @returns {Object} returns <code>this</code> so that calls can be chained.
  5386. */
  5387. cacheKey: function (key) {
  5388. if (key == null) {
  5389. return filter.or._cache_key;
  5390. }
  5391. filter.or._cache_key = key;
  5392. return this;
  5393. },
  5394. /**
  5395. Returns the filter container as a JSON string
  5396. @member ejs.OrFilter
  5397. @returns {String} JSON representation of the orFilter object
  5398. */
  5399. toString: function () {
  5400. return JSON.stringify(filter);
  5401. },
  5402. /**
  5403. The type of ejs object. For internal use only.
  5404. @member ejs.OrFilter
  5405. @returns {String} the type of object
  5406. */
  5407. _type: function () {
  5408. return 'filter';
  5409. },
  5410. /**
  5411. Returns the filter object.
  5412. @member ejs.OrFilter
  5413. @returns {Object} filter object
  5414. */
  5415. _self: function () {
  5416. return filter;
  5417. }
  5418. };
  5419. };
  5420. /**
  5421. @class
  5422. <p>Filters documents that have fields containing terms with a specified prefix (not analyzed). Similar
  5423. to phrase query, except that it acts as a filter. Can be placed within queries that accept a filter.</p>
  5424. @name ejs.PrefixFilter
  5425. @desc
  5426. Filters documents that have fields containing terms with a specified prefix.
  5427. @param {String} fieldName the field name to be used during matching.
  5428. @param {String} prefix the prefix value.
  5429. */
  5430. ejs.PrefixFilter = function (fieldName, prefix) {
  5431. /**
  5432. The internal filter object. Use <code>get()</code>
  5433. @member ejs.PrefixFilter
  5434. @property {Object} filter
  5435. */
  5436. var filter = {
  5437. prefix: {}
  5438. };
  5439. filter.prefix[fieldName] = prefix;
  5440. return {
  5441. /**
  5442. Returns the field name used to create this object.
  5443. @member ejs.PrefixFilter
  5444. @param {String} field the field name
  5445. @returns {Object} returns <code>this</code> so that calls can be
  5446. chained. Returns {String}, field name when field is not specified.
  5447. */
  5448. field: function (field) {
  5449. var oldValue = filter.prefix[fieldName];
  5450. if (field == null) {
  5451. return fieldName;
  5452. }
  5453. delete filter.prefix[fieldName];
  5454. fieldName = field;
  5455. filter.prefix[fieldName] = oldValue;
  5456. return this;
  5457. },
  5458. /**
  5459. Sets the prefix to search for.
  5460. @member ejs.PrefixFilter
  5461. @param {String} value the prefix value to match
  5462. @returns {Object} returns <code>this</code> so that calls can be chained.
  5463. */
  5464. prefix: function (value) {
  5465. if (value == null) {
  5466. return filter.prefix[fieldName];
  5467. }
  5468. filter.prefix[fieldName] = value;
  5469. return this;
  5470. },
  5471. /**
  5472. Sets the filter name.
  5473. @member ejs.PrefixFilter
  5474. @param {String} name A name for the filter.
  5475. @returns {Object} returns <code>this</code> so that calls can be chained.
  5476. */
  5477. name: function (name) {
  5478. if (name == null) {
  5479. return filter.prefix._name;
  5480. }
  5481. filter.prefix._name = name;
  5482. return this;
  5483. },
  5484. /**
  5485. Enable or disable caching of the filter
  5486. @member ejs.PrefixFilter
  5487. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5488. @returns {Object} returns <code>this</code> so that calls can be chained.
  5489. */
  5490. cache: function (trueFalse) {
  5491. if (trueFalse == null) {
  5492. return filter.prefix._cache;
  5493. }
  5494. filter.prefix._cache = trueFalse;
  5495. return this;
  5496. },
  5497. /**
  5498. Sets the cache key.
  5499. @member ejs.PrefixFilter
  5500. @param {String} key the cache key as a string.
  5501. @returns {Object} returns <code>this</code> so that calls can be chained.
  5502. */
  5503. cacheKey: function (key) {
  5504. if (key == null) {
  5505. return filter.prefix._cache_key;
  5506. }
  5507. filter.prefix._cache_key = key;
  5508. return this;
  5509. },
  5510. /**
  5511. Returns the filter container as a JSON string
  5512. @member ejs.PrefixFilter
  5513. @returns {String} JSON representation of the prefixFilter object
  5514. */
  5515. toString: function () {
  5516. return JSON.stringify(filter);
  5517. },
  5518. /**
  5519. The type of ejs object. For internal use only.
  5520. @member ejs.PrefixFilter
  5521. @returns {String} the type of object
  5522. */
  5523. _type: function () {
  5524. return 'filter';
  5525. },
  5526. /**
  5527. Returns the filter object.
  5528. @member ejs.PrefixFilter
  5529. @returns {Object} filter object
  5530. */
  5531. _self: function () {
  5532. return filter;
  5533. }
  5534. };
  5535. };
  5536. /**
  5537. @class
  5538. <p>Wraps any query to be used as a filter. Can be placed within queries
  5539. that accept a filter.</p>
  5540. <p>The result of the filter is not cached by default. Set the cache
  5541. parameter to true to cache the result of the filter. This is handy when the
  5542. same query is used on several (many) other queries.</p>
  5543. <p>Note, the process of caching the first execution is higher when not
  5544. caching (since it needs to satisfy different queries).</p>
  5545. @name ejs.QueryFilter
  5546. @desc
  5547. Filters documents matching the wrapped query.
  5548. @param {Object} qry A valid query object.
  5549. */
  5550. ejs.QueryFilter = function (qry) {
  5551. if (!isQuery(qry)) {
  5552. throw new TypeError('Argument must be a Query');
  5553. }
  5554. /**
  5555. The internal query object. <code>Use _self()</code>
  5556. @member ejs.QueryFilter
  5557. @property {Object} query
  5558. */
  5559. var filter = {
  5560. fquery: {
  5561. query: qry._self()
  5562. }
  5563. };
  5564. return {
  5565. /**
  5566. Sets the query
  5567. @member ejs.QueryFilter
  5568. @param {Object} q A valid Query object
  5569. @returns {Object} returns <code>this</code> so that calls can be chained.
  5570. */
  5571. query: function (q) {
  5572. if (q == null) {
  5573. return filter.fquery.query;
  5574. }
  5575. if (!isQuery(q)) {
  5576. throw new TypeError('Argument must be a Query');
  5577. }
  5578. filter.fquery.query = q._self();
  5579. return this;
  5580. },
  5581. /**
  5582. Sets the filter name.
  5583. @member ejs.QueryFilter
  5584. @param {String} name A name for the filter.
  5585. @returns {Object} returns <code>this</code> so that calls can be chained.
  5586. */
  5587. name: function (name) {
  5588. if (name == null) {
  5589. return filter.fquery._name;
  5590. }
  5591. filter.fquery._name = name;
  5592. return this;
  5593. },
  5594. /**
  5595. Enable or disable caching of the filter
  5596. @member ejs.QueryFilter
  5597. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5598. @returns {Object} returns <code>this</code> so that calls can be chained.
  5599. */
  5600. cache: function (trueFalse) {
  5601. if (trueFalse == null) {
  5602. return filter.fquery._cache;
  5603. }
  5604. filter.fquery._cache = trueFalse;
  5605. return this;
  5606. },
  5607. /**
  5608. Sets the cache key.
  5609. @member ejs.QueryFilter
  5610. @param {String} key the cache key as a string.
  5611. @returns {Object} returns <code>this</code> so that calls can be chained.
  5612. */
  5613. cacheKey: function (key) {
  5614. if (key == null) {
  5615. return filter.fquery._cache_key;
  5616. }
  5617. filter.fquery._cache_key = key;
  5618. return this;
  5619. },
  5620. /**
  5621. Allows you to serialize this object into a JSON encoded string.
  5622. @member ejs.QueryFilter
  5623. @returns {String} returns this object as a serialized JSON string.
  5624. */
  5625. toString: function () {
  5626. return JSON.stringify(filter);
  5627. },
  5628. /**
  5629. The type of ejs object. For internal use only.
  5630. @member ejs.QueryFilter
  5631. @returns {String} the type of object
  5632. */
  5633. _type: function () {
  5634. return 'filter';
  5635. },
  5636. /**
  5637. Retrieves the internal <code>filter</code> object. This is typically used by
  5638. internal API functions so use with caution.
  5639. @member ejs.QueryFilter
  5640. @returns {String} returns this object's internal <code>filter</code> property.
  5641. */
  5642. _self: function () {
  5643. return filter;
  5644. }
  5645. };
  5646. };
  5647. /**
  5648. @class
  5649. <p>Matches documents with fields that have terms within a certain range.</p>
  5650. @name ejs.RangeFilter
  5651. @desc
  5652. Filters documents with fields that have terms within a certain range.
  5653. @param {String} field A valid field name.
  5654. */
  5655. ejs.RangeFilter = function (field) {
  5656. /**
  5657. The internal filter object. <code>Use get()</code>
  5658. @member ejs.RangeFilter
  5659. @property {Object} filter
  5660. */
  5661. var filter = {
  5662. range: {}
  5663. };
  5664. filter.range[field] = {};
  5665. return {
  5666. /**
  5667. The field to run the filter against.
  5668. @member ejs.RangeFilter
  5669. @param {String} f A single field name.
  5670. @returns {Object} returns <code>this</code> so that calls can be chained.
  5671. */
  5672. field: function (f) {
  5673. var oldValue = filter.range[field];
  5674. if (f == null) {
  5675. return field;
  5676. }
  5677. delete filter.range[field];
  5678. field = f;
  5679. filter.range[f] = oldValue;
  5680. return this;
  5681. },
  5682. /**
  5683. The lower bound. Defaults to start from the first.
  5684. @member ejs.RangeFilter
  5685. @param {Variable Type} f the lower bound value, type depends on field type
  5686. @returns {Object} returns <code>this</code> so that calls can be chained.
  5687. */
  5688. from: function (f) {
  5689. if (f == null) {
  5690. return filter.range[field].from;
  5691. }
  5692. filter.range[field].from = f;
  5693. return this;
  5694. },
  5695. /**
  5696. The upper bound. Defaults to unbounded.
  5697. @member ejs.RangeFilter
  5698. @param {Variable Type} t the upper bound value, type depends on field type
  5699. @returns {Object} returns <code>this</code> so that calls can be chained.
  5700. */
  5701. to: function (t) {
  5702. if (t == null) {
  5703. return filter.range[field].to;
  5704. }
  5705. filter.range[field].to = t;
  5706. return this;
  5707. },
  5708. /**
  5709. Should the first from (if set) be inclusive or not.
  5710. Defaults to true
  5711. @member ejs.RangeFilter
  5712. @param {Boolean} trueFalse true to include, false to exclude
  5713. @returns {Object} returns <code>this</code> so that calls can be chained.
  5714. */
  5715. includeLower: function (trueFalse) {
  5716. if (trueFalse == null) {
  5717. return filter.range[field].include_lower;
  5718. }
  5719. filter.range[field].include_lower = trueFalse;
  5720. return this;
  5721. },
  5722. /**
  5723. Should the last to (if set) be inclusive or not. Defaults to true.
  5724. @member ejs.RangeFilter
  5725. @param {Boolean} trueFalse true to include, false to exclude
  5726. @returns {Object} returns <code>this</code> so that calls can be chained.
  5727. */
  5728. includeUpper: function (trueFalse) {
  5729. if (trueFalse == null) {
  5730. return filter.range[field].include_upper;
  5731. }
  5732. filter.range[field].include_upper = trueFalse;
  5733. return this;
  5734. },
  5735. /**
  5736. Greater than value. Same as setting from to the value, and
  5737. include_lower to false,
  5738. @member ejs.RangeFilter
  5739. @param {Variable Type} val the value, type depends on field type
  5740. @returns {Object} returns <code>this</code> so that calls can be chained.
  5741. */
  5742. gt: function (val) {
  5743. if (val == null) {
  5744. return filter.range[field].gt;
  5745. }
  5746. filter.range[field].gt = val;
  5747. return this;
  5748. },
  5749. /**
  5750. Greater than or equal to value. Same as setting from to the value,
  5751. and include_lower to true.
  5752. @member ejs.RangeFilter
  5753. @param {Variable Type} val the value, type depends on field type
  5754. @returns {Object} returns <code>this</code> so that calls can be chained.
  5755. */
  5756. gte: function (val) {
  5757. if (val == null) {
  5758. return filter.range[field].gte;
  5759. }
  5760. filter.range[field].gte = val;
  5761. return this;
  5762. },
  5763. /**
  5764. Less than value. Same as setting to to the value, and include_upper
  5765. to false.
  5766. @member ejs.RangeFilter
  5767. @param {Variable Type} val the value, type depends on field type
  5768. @returns {Object} returns <code>this</code> so that calls can be chained.
  5769. */
  5770. lt: function (val) {
  5771. if (val == null) {
  5772. return filter.range[field].lt;
  5773. }
  5774. filter.range[field].lt = val;
  5775. return this;
  5776. },
  5777. /**
  5778. Less than or equal to value. Same as setting to to the value,
  5779. and include_upper to true.
  5780. @member ejs.RangeFilter
  5781. @param {Variable Type} val the value, type depends on field type
  5782. @returns {Object} returns <code>this</code> so that calls can be chained.
  5783. */
  5784. lte: function (val) {
  5785. if (val == null) {
  5786. return filter.range[field].lte;
  5787. }
  5788. filter.range[field].lte = val;
  5789. return this;
  5790. },
  5791. /**
  5792. Sets the filter name.
  5793. @member ejs.RangeFilter
  5794. @param {String} name A name for the filter.
  5795. @returns {Object} returns <code>this</code> so that calls can be chained.
  5796. */
  5797. name: function (name) {
  5798. if (name == null) {
  5799. return filter.range._name;
  5800. }
  5801. filter.range._name = name;
  5802. return this;
  5803. },
  5804. /**
  5805. Enable or disable caching of the filter
  5806. @member ejs.RangeFilter
  5807. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5808. @returns {Object} returns <code>this</code> so that calls can be chained.
  5809. */
  5810. cache: function (trueFalse) {
  5811. if (trueFalse == null) {
  5812. return filter.range._cache;
  5813. }
  5814. filter.range._cache = trueFalse;
  5815. return this;
  5816. },
  5817. /**
  5818. Sets the cache key.
  5819. @member ejs.RangeFilter
  5820. @param {String} key the cache key as a string.
  5821. @returns {Object} returns <code>this</code> so that calls can be chained.
  5822. */
  5823. cacheKey: function (key) {
  5824. if (key == null) {
  5825. return filter.range._cache_key;
  5826. }
  5827. filter.range._cache_key = key;
  5828. return this;
  5829. },
  5830. /**
  5831. Allows you to serialize this object into a JSON encoded string.
  5832. @member ejs.RangeFilter
  5833. @returns {String} returns this object as a serialized JSON string.
  5834. */
  5835. toString: function () {
  5836. return JSON.stringify(filter);
  5837. },
  5838. /**
  5839. The type of ejs object. For internal use only.
  5840. @member ejs.RangeFilter
  5841. @returns {String} the type of object
  5842. */
  5843. _type: function () {
  5844. return 'filter';
  5845. },
  5846. /**
  5847. Retrieves the internal <code>filter</code> object. This is typically used by
  5848. internal API functions so use with caution.
  5849. @member ejs.RangeFilter
  5850. @returns {String} returns this object's internal <code>filter</code> property.
  5851. */
  5852. _self: function () {
  5853. return filter;
  5854. }
  5855. };
  5856. };
  5857. /**
  5858. @class
  5859. <p>Filters documents that have a field value matching a regular expression.
  5860. Based on Lucene 4.0 RegexpFilter which uses automaton to efficiently iterate
  5861. over index terms.</p>
  5862. @name ejs.RegexpFilter
  5863. @desc
  5864. Matches documents that have fields matching a regular expression.
  5865. @param {String} field A valid field name.
  5866. @param {String} value A regex pattern.
  5867. */
  5868. ejs.RegexpFilter = function (field, value) {
  5869. /**
  5870. The internal filter object. <code>Use get()</code>
  5871. @member ejs.RegexpFilter
  5872. @property {Object} filter
  5873. */
  5874. var filter = {
  5875. regexp: {}
  5876. };
  5877. filter.regexp[field] = {
  5878. value: value
  5879. };
  5880. return {
  5881. /**
  5882. The field to run the filter against.
  5883. @member ejs.RegexpFilter
  5884. @param {String} f A single field name.
  5885. @returns {Object} returns <code>this</code> so that calls can be chained.
  5886. */
  5887. field: function (f) {
  5888. var oldValue = filter.regexp[field];
  5889. if (f == null) {
  5890. return field;
  5891. }
  5892. delete filter.regexp[field];
  5893. field = f;
  5894. filter.regexp[f] = oldValue;
  5895. return this;
  5896. },
  5897. /**
  5898. The regexp value.
  5899. @member ejs.RegexpFilter
  5900. @param {String} p A string regexp
  5901. @returns {Object} returns <code>this</code> so that calls can be chained.
  5902. */
  5903. value: function (p) {
  5904. if (p == null) {
  5905. return filter.regexp[field].value;
  5906. }
  5907. filter.regexp[field].value = p;
  5908. return this;
  5909. },
  5910. /**
  5911. The regex flags to use. Valid flags are:
  5912. INTERSECTION - Support for intersection notation
  5913. COMPLEMENT - Support for complement notation
  5914. EMPTY - Support for the empty language symbol: #
  5915. ANYSTRING - Support for the any string symbol: @
  5916. INTERVAL - Support for numerical interval notation: <n-m>
  5917. NONE - Disable support for all syntax options
  5918. ALL - Enables support for all syntax options
  5919. Use multiple flags by separating with a "|" character. Example:
  5920. INTERSECTION|COMPLEMENT|EMPTY
  5921. @member ejs.RegexpFilter
  5922. @param {String} f The flags as a string, separate multiple flags with "|".
  5923. @returns {Object} returns <code>this</code> so that calls can be chained.
  5924. */
  5925. flags: function (f) {
  5926. if (f == null) {
  5927. return filter.regexp[field].flags;
  5928. }
  5929. filter.regexp[field].flags = f;
  5930. return this;
  5931. },
  5932. /**
  5933. The regex flags to use as a numeric value. Advanced use only,
  5934. it is probably better to stick with the <code>flags</code> option.
  5935. @member ejs.RegexpFilter
  5936. @param {String} v The flags as a numeric value.
  5937. @returns {Object} returns <code>this</code> so that calls can be chained.
  5938. */
  5939. flagsValue: function (v) {
  5940. if (v == null) {
  5941. return filter.regexp[field].flags_value;
  5942. }
  5943. filter.regexp[field].flags_value = v;
  5944. return this;
  5945. },
  5946. /**
  5947. Sets the filter name.
  5948. @member ejs.RegexpFilter
  5949. @param {String} name A name for the filter.
  5950. @returns {Object} returns <code>this</code> so that calls can be chained.
  5951. */
  5952. name: function (name) {
  5953. if (name == null) {
  5954. return filter.regexp._name;
  5955. }
  5956. filter.regexp._name = name;
  5957. return this;
  5958. },
  5959. /**
  5960. Enable or disable caching of the filter
  5961. @member ejs.RegexpFilter
  5962. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5963. @returns {Object} returns <code>this</code> so that calls can be chained.
  5964. */
  5965. cache: function (trueFalse) {
  5966. if (trueFalse == null) {
  5967. return filter.regexp._cache;
  5968. }
  5969. filter.regexp._cache = trueFalse;
  5970. return this;
  5971. },
  5972. /**
  5973. Sets the cache key.
  5974. @member ejs.RegexpFilter
  5975. @param {String} key the cache key as a string.
  5976. @returns {Object} returns <code>this</code> so that calls can be chained.
  5977. */
  5978. cacheKey: function (key) {
  5979. if (key == null) {
  5980. return filter.regexp._cache_key;
  5981. }
  5982. filter.regexp._cache_key = key;
  5983. return this;
  5984. },
  5985. /**
  5986. Allows you to serialize this object into a JSON encoded string.
  5987. @member ejs.RegexpFilter
  5988. @returns {String} returns this object as a serialized JSON string.
  5989. */
  5990. toString: function () {
  5991. return JSON.stringify(filter);
  5992. },
  5993. /**
  5994. The type of ejs object. For internal use only.
  5995. @member ejs.RegexpFilter
  5996. @returns {String} the type of object
  5997. */
  5998. _type: function () {
  5999. return 'filter';
  6000. },
  6001. /**
  6002. Retrieves the internal <code>filter</code> object. This is typically used by
  6003. internal API functions so use with caution.
  6004. @member ejs.RegexpFilter
  6005. @returns {String} returns this object's internal <code>filter</code> property.
  6006. */
  6007. _self: function () {
  6008. return filter;
  6009. }
  6010. };
  6011. };
  6012. /**
  6013. @class
  6014. <p>A filter allowing to define scripts as filters</p>
  6015. @name ejs.ScriptFilter
  6016. @desc
  6017. A filter allowing to define scripts as filters.
  6018. @param {String} script The script as a string.
  6019. */
  6020. ejs.ScriptFilter = function (script) {
  6021. /**
  6022. The internal filter object. <code>Use get()</code>
  6023. @member ejs.ScriptFilter
  6024. @property {Object} filter
  6025. */
  6026. var filter = {
  6027. script: {
  6028. script: script
  6029. }
  6030. };
  6031. return {
  6032. /**
  6033. Sets the script.
  6034. @member ejs.ScriptFilter
  6035. @param {String} s The script as a string.
  6036. @returns {Object} returns <code>this</code> so that calls can be chained.
  6037. */
  6038. script: function (s) {
  6039. if (s == null) {
  6040. return filter.script.script;
  6041. }
  6042. filter.script.script = s;
  6043. return this;
  6044. },
  6045. /**
  6046. Sets parameters that will be applied to the script. Overwrites
  6047. any existing params.
  6048. @member ejs.ScriptFilter
  6049. @param {Object} p An object where the keys are the parameter name and
  6050. values are the parameter value.
  6051. @returns {Object} returns <code>this</code> so that calls can be chained.
  6052. */
  6053. params: function (p) {
  6054. if (p == null) {
  6055. return filter.script.params;
  6056. }
  6057. filter.script.params = p;
  6058. return this;
  6059. },
  6060. /**
  6061. Sets the script language.
  6062. @member ejs.ScriptFilter
  6063. @param {String} lang The script language, default mvel.
  6064. @returns {Object} returns <code>this</code> so that calls can be chained.
  6065. */
  6066. lang: function (lang) {
  6067. if (lang == null) {
  6068. return filter.script.lang;
  6069. }
  6070. filter.script.lang = lang;
  6071. return this;
  6072. },
  6073. /**
  6074. Sets the filter name.
  6075. @member ejs.ScriptFilter
  6076. @param {String} name A name for the filter.
  6077. @returns {Object} returns <code>this</code> so that calls can be chained.
  6078. */
  6079. name: function (name) {
  6080. if (name == null) {
  6081. return filter.script._name;
  6082. }
  6083. filter.script._name = name;
  6084. return this;
  6085. },
  6086. /**
  6087. Enable or disable caching of the filter
  6088. @member ejs.ScriptFilter
  6089. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  6090. @returns {Object} returns <code>this</code> so that calls can be chained.
  6091. */
  6092. cache: function (trueFalse) {
  6093. if (trueFalse == null) {
  6094. return filter.script._cache;
  6095. }
  6096. filter.script._cache = trueFalse;
  6097. return this;
  6098. },
  6099. /**
  6100. Sets the cache key.
  6101. @member ejs.ScriptFilter
  6102. @param {String} key the cache key as a string.
  6103. @returns {Object} returns <code>this</code> so that calls can be chained.
  6104. */
  6105. cacheKey: function (key) {
  6106. if (key == null) {
  6107. return filter.script._cache_key;
  6108. }
  6109. filter.script._cache_key = key;
  6110. return this;
  6111. },
  6112. /**
  6113. Allows you to serialize this object into a JSON encoded string.
  6114. @member ejs.ScriptFilter
  6115. @returns {String} returns this object as a serialized JSON string.
  6116. */
  6117. toString: function () {
  6118. return JSON.stringify(filter);
  6119. },
  6120. /**
  6121. The type of ejs object. For internal use only.
  6122. @member ejs.ScriptFilter
  6123. @returns {String} the type of object
  6124. */
  6125. _type: function () {
  6126. return 'filter';
  6127. },
  6128. /**
  6129. Retrieves the internal <code>filter</code> object. This is typically used by
  6130. internal API functions so use with caution.
  6131. @member ejs.ScriptFilter
  6132. @returns {String} returns this object's internal <code>filter</code> property.
  6133. */
  6134. _self: function () {
  6135. return filter;
  6136. }
  6137. };
  6138. };
  6139. /**
  6140. @class
  6141. <p>Constructs a filter for docs matching any of the terms added to this
  6142. object. Unlike a RangeFilter this can be used for filtering on multiple
  6143. terms that are not necessarily in a sequence.</p>
  6144. @name ejs.TermFilter
  6145. @desc
  6146. Constructs a filter for docs matching the term added to this object.
  6147. @param {string} fieldName The document field/fieldName to execute the filter against.
  6148. @param {string} term The literal term used to filter the results.
  6149. */
  6150. ejs.TermFilter = function (fieldName, term) {
  6151. /**
  6152. The internal filter object. Use the get() method for access.
  6153. @member ejs.TermFilter
  6154. @property {Object} filter
  6155. */
  6156. var filter = {
  6157. term: {}
  6158. };
  6159. filter.term[fieldName] = term;
  6160. return {
  6161. /**
  6162. Provides access to the filter fieldName used to construct the
  6163. termFilter object.
  6164. @member ejs.TermFilter
  6165. @param {String} f the fieldName term
  6166. @returns {Object} returns <code>this</code> so that calls can be chained.
  6167. When k is not specified, Returns {String}, the filter fieldName used to construct
  6168. the termFilter object.
  6169. */
  6170. field: function (f) {
  6171. var oldValue = filter.term[fieldName];
  6172. if (f == null) {
  6173. return fieldName;
  6174. }
  6175. delete filter.term[fieldName];
  6176. fieldName = f;
  6177. filter.term[fieldName] = oldValue;
  6178. return this;
  6179. },
  6180. /**
  6181. Provides access to the filter term used to construct the
  6182. termFilter object.
  6183. @member ejs.TermFilter
  6184. @returns {Object} returns <code>this</code> so that calls can be chained.
  6185. When k is not specified, Returns {String}, the filter term used
  6186. to construct the termFilter object.
  6187. */
  6188. term: function (v) {
  6189. if (v == null) {
  6190. return filter.term[fieldName];
  6191. }
  6192. filter.term[fieldName] = v;
  6193. return this;
  6194. },
  6195. /**
  6196. Sets the filter name.
  6197. @member ejs.TermFilter
  6198. @param {String} name A name for the filter.
  6199. @returns {Object} returns <code>this</code> so that calls can be chained.
  6200. */
  6201. name: function (name) {
  6202. if (name == null) {
  6203. return filter.term._name;
  6204. }
  6205. filter.term._name = name;
  6206. return this;
  6207. },
  6208. /**
  6209. Enable or disable caching of the filter
  6210. @member ejs.TermFilter
  6211. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  6212. @returns {Object} returns <code>this</code> so that calls can be chained.
  6213. */
  6214. cache: function (trueFalse) {
  6215. if (trueFalse == null) {
  6216. return filter.term._cache;
  6217. }
  6218. filter.term._cache = trueFalse;
  6219. return this;
  6220. },
  6221. /**
  6222. Sets the cache key.
  6223. @member ejs.TermFilter
  6224. @param {String} key the cache key as a string.
  6225. @returns {Object} returns <code>this</code> so that calls can be chained.
  6226. */
  6227. cacheKey: function (key) {
  6228. if (key == null) {
  6229. return filter.term._cache_key;
  6230. }
  6231. filter.term._cache_key = key;
  6232. return this;
  6233. },
  6234. /**
  6235. Serializes the internal filter object as a JSON string.
  6236. @member ejs.TermFilter
  6237. @returns {String} Returns a JSON representation of the termFilter object.
  6238. */
  6239. toString: function () {
  6240. return JSON.stringify(filter);
  6241. },
  6242. /**
  6243. The type of ejs object. For internal use only.
  6244. @member ejs.TermFilter
  6245. @returns {String} the type of object
  6246. */
  6247. _type: function () {
  6248. return 'filter';
  6249. },
  6250. /**
  6251. Returns the filter object. For internal use only.
  6252. @member ejs.TermFilter
  6253. @returns {Object} Returns the object's filter property.
  6254. */
  6255. _self: function () {
  6256. return filter;
  6257. }
  6258. };
  6259. };
  6260. /**
  6261. @class
  6262. <p>Filters documents that have fields that match any of the provided
  6263. terms (not analyzed)</p>
  6264. @name ejs.TermsFilter
  6265. @desc
  6266. A Filter that matches documents containing provided terms.
  6267. @param {String} field the document field/key to filter against
  6268. @param {String || Array} terms a single term or an array of terms.
  6269. */
  6270. ejs.TermsFilter = function (field, terms) {
  6271. /**
  6272. The internal filter object. <code>Use get()</code>
  6273. @member ejs.TermsFilter
  6274. @property {Object} filter
  6275. */
  6276. var filter = {
  6277. terms: {}
  6278. },
  6279. // make sure we are setup for a list of terms
  6280. setupTerms = function () {
  6281. if (!isArray(filter.terms[field])) {
  6282. filter.terms[field] = [];
  6283. }
  6284. },
  6285. // make sure we are setup for a terms lookup
  6286. setupLookup = function () {
  6287. if (isArray(filter.terms[field])) {
  6288. filter.terms[field] = {};
  6289. }
  6290. };
  6291. if (isArray(terms)) {
  6292. filter.terms[field] = terms;
  6293. } else {
  6294. filter.terms[field] = [terms];
  6295. }
  6296. return {
  6297. /**
  6298. Sets the fields to filter against.
  6299. @member ejs.TermsFilter
  6300. @param {String} f A valid field name.
  6301. @returns {Object} returns <code>this</code> so that calls can be chained.
  6302. */
  6303. field: function (f) {
  6304. var oldValue = filter.terms[field];
  6305. if (f == null) {
  6306. return field;
  6307. }
  6308. delete filter.terms[field];
  6309. field = f;
  6310. filter.terms[f] = oldValue;
  6311. return this;
  6312. },
  6313. /**
  6314. Sets the terms. If t is a String, it is added to the existing
  6315. list of terms. If t is an array, the list of terms replaces the
  6316. existing terms.
  6317. @member ejs.TermsFilter
  6318. @param {String || Array} t A single term or an array or terms.
  6319. @returns {Object} returns <code>this</code> so that calls can be chained.
  6320. */
  6321. terms: function (t) {
  6322. setupTerms();
  6323. if (t == null) {
  6324. return filter.terms[field];
  6325. }
  6326. if (isArray(t)) {
  6327. filter.terms[field] = t;
  6328. } else {
  6329. filter.terms[field].push(t);
  6330. }
  6331. return this;
  6332. },
  6333. /**
  6334. Sets the index the document containing the terms is in when
  6335. performing a terms lookup. Defaults to the index currently
  6336. being searched.
  6337. @since elasticsearch 0.90
  6338. @member ejs.TermsFilter
  6339. @param {String} idx A valid index name.
  6340. @returns {Object} returns <code>this</code> so that calls can be chained.
  6341. */
  6342. index: function (idx) {
  6343. setupLookup();
  6344. if (idx == null) {
  6345. return filter.terms[field].index;
  6346. }
  6347. filter.terms[field].index = idx;
  6348. return this;
  6349. },
  6350. /**
  6351. Sets the type the document containing the terms when performing a
  6352. terms lookup.
  6353. @since elasticsearch 0.90
  6354. @member ejs.TermsFilter
  6355. @param {String} type A valid type name.
  6356. @returns {Object} returns <code>this</code> so that calls can be chained.
  6357. */
  6358. type: function (type) {
  6359. setupLookup();
  6360. if (type == null) {
  6361. return filter.terms[field].type;
  6362. }
  6363. filter.terms[field].type = type;
  6364. return this;
  6365. },
  6366. /**
  6367. Sets the document id of the document containing the terms to use
  6368. when performing a terms lookup.
  6369. @since elasticsearch 0.90
  6370. @member ejs.TermsFilter
  6371. @param {String} id A valid index name.
  6372. @returns {Object} returns <code>this</code> so that calls can be chained.
  6373. */
  6374. id: function (id) {
  6375. setupLookup();
  6376. if (id == null) {
  6377. return filter.terms[field].id;
  6378. }
  6379. filter.terms[field].id = id;
  6380. return this;
  6381. },
  6382. /**
  6383. Sets the path/field name where the terms in the source document
  6384. are located when performing a terms lookup.
  6385. @since elasticsearch 0.90
  6386. @member ejs.TermsFilter
  6387. @param {String} path A valid index name.
  6388. @returns {Object} returns <code>this</code> so that calls can be chained.
  6389. */
  6390. path: function (path) {
  6391. setupLookup();
  6392. if (path == null) {
  6393. return filter.terms[field].path;
  6394. }
  6395. filter.terms[field].path = path;
  6396. return this;
  6397. },
  6398. /**
  6399. Sets the way terms filter executes is by iterating over the terms
  6400. provided and finding matches docs (loading into a bitset) and
  6401. caching it. Valid values are: plain, bool, bool_nocache, and,
  6402. and_nocache, or, or_nocache. Defaults to plain.
  6403. @member ejs.TermsFilter
  6404. @param {String} e A valid execution method.
  6405. @returns {Object} returns <code>this</code> so that calls can be chained.
  6406. */
  6407. execution: function (e) {
  6408. if (e == null) {
  6409. return filter.terms.execution;
  6410. }
  6411. e = e.toLowerCase();
  6412. if (e === 'plain' || e === 'bool' || e === 'bool_nocache' ||
  6413. e === 'and' || e === 'and_nocache' || e === 'or' || e === 'or_nocache') {
  6414. filter.terms.execution = e;
  6415. }
  6416. return this;
  6417. },
  6418. /**
  6419. Sets the filter name.
  6420. @member ejs.TermsFilter
  6421. @param {String} name A name for the filter.
  6422. @returns {Object} returns <code>this</code> so that calls can be chained.
  6423. */
  6424. name: function (name) {
  6425. if (name == null) {
  6426. return filter.terms._name;
  6427. }
  6428. filter.terms._name = name;
  6429. return this;
  6430. },
  6431. /**
  6432. Enable or disable caching of the filter
  6433. @member ejs.TermsFilter
  6434. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  6435. @returns {Object} returns <code>this</code> so that calls can be chained.
  6436. */
  6437. cache: function (trueFalse) {
  6438. if (trueFalse == null) {
  6439. return filter.terms._cache;
  6440. }
  6441. filter.terms._cache = trueFalse;
  6442. return this;
  6443. },
  6444. /**
  6445. Sets the cache key.
  6446. @member ejs.TermsFilter
  6447. @param {String} key the cache key as a string.
  6448. @returns {Object} returns <code>this</code> so that calls can be chained.
  6449. */
  6450. cacheKey: function (key) {
  6451. if (key == null) {
  6452. return filter.terms._cache_key;
  6453. }
  6454. filter.terms._cache_key = key;
  6455. return this;
  6456. },
  6457. /**
  6458. Allows you to serialize this object into a JSON encoded string.
  6459. @member ejs.TermsFilter
  6460. @returns {String} returns this object as a serialized JSON string.
  6461. */
  6462. toString: function () {
  6463. return JSON.stringify(filter);
  6464. },
  6465. /**
  6466. The type of ejs object. For internal use only.
  6467. @member ejs.TermsFilter
  6468. @returns {String} the type of object
  6469. */
  6470. _type: function () {
  6471. return 'filter';
  6472. },
  6473. /**
  6474. Retrieves the internal <code>filter</code> object. This is typically used by
  6475. internal API functions so use with caution.
  6476. @member ejs.TermsFilter
  6477. @returns {String} returns this object's internal <code>filter</code> property.
  6478. */
  6479. _self: function () {
  6480. return filter;
  6481. }
  6482. };
  6483. };
  6484. /**
  6485. @class
  6486. <p>A Filter that filters results by a specified index type.</p>
  6487. @name ejs.TypeFilter
  6488. @desc
  6489. Filter results by a specified index type.
  6490. @param {String} type the index type to filter on.
  6491. */
  6492. ejs.TypeFilter = function (type) {
  6493. /**
  6494. The internal filter object. Use <code>get()</code>
  6495. @member ejs.TypeFilter
  6496. @property {Object} filter
  6497. */
  6498. var filter = {
  6499. "type": {
  6500. "value": type
  6501. }
  6502. };
  6503. return {
  6504. /**
  6505. * Sets the type
  6506. @member ejs.TypeFilter
  6507. @param {String} type the index type to filter on
  6508. @returns {Object} returns <code>this</code> so that calls can be chained.
  6509. */
  6510. type: function (type) {
  6511. if (type == null) {
  6512. return filter.type.value;
  6513. }
  6514. filter.type.value = type;
  6515. return this;
  6516. },
  6517. /**
  6518. Returns the filter container as a JSON string
  6519. @member ejs.TypeFilter
  6520. @returns {String} JSON representation of the notFilter object
  6521. */
  6522. toString: function () {
  6523. return JSON.stringify(filter);
  6524. },
  6525. /**
  6526. The type of ejs object. For internal use only.
  6527. @member ejs.TypeFilter
  6528. @returns {String} the type of object
  6529. */
  6530. _type: function () {
  6531. return 'filter';
  6532. },
  6533. /**
  6534. Returns the filter object.
  6535. @member ejs.TypeFilter
  6536. @returns {Object} filter object
  6537. */
  6538. _self: function () {
  6539. return filter;
  6540. }
  6541. };
  6542. };
  6543. /**
  6544. @class
  6545. <p>The <code>Document</code> object provides an interface for working with
  6546. Documents. Some example operations avaiable are storing documents,
  6547. retreiving documents, updating documents, and deleting documents from an
  6548. index.</p>
  6549. @name ejs.Document
  6550. @desc
  6551. Object used to create, replace, update, and delete documents
  6552. <div class="alert-message block-message info">
  6553. <p>
  6554. <strong>Tip: </strong>
  6555. It is not necessary to first create a index or content-type. If either of these
  6556. do not exist, they will be automatically created when you attempt to store the document.
  6557. </p>
  6558. </div>
  6559. @param {String} index The index the document belongs to.
  6560. @param {String} type The type the document belongs to.
  6561. @param {String} id The id of the document. The id is required except
  6562. for indexing. If no id is specified during indexing, one will be
  6563. created for you.
  6564. */
  6565. ejs.Document = function (index, type, id) {
  6566. var params = {},
  6567. // converts client params to a string param1=val1&param2=val1
  6568. genParamStr = function () {
  6569. var clientParams = genClientParams(),
  6570. parts = [];
  6571. for (var p in clientParams) {
  6572. if (!has(clientParams, p)) {
  6573. continue;
  6574. }
  6575. parts.push(p + '=' + encodeURIComponent(clientParams[p]));
  6576. }
  6577. return parts.join('&');
  6578. },
  6579. // Converts the stored params into parameters that will be passed
  6580. // to a client. Certain parameter are skipped, and others require
  6581. // special processing before being sent to the client.
  6582. genClientParams = function () {
  6583. var clientParams = {};
  6584. for (var param in params) {
  6585. if (!has(params, param)) {
  6586. continue;
  6587. }
  6588. // skip params that don't go in the query string
  6589. if (param === 'upsert' || param === 'source' ||
  6590. param === 'script' || param === 'lang' || param === 'params') {
  6591. continue;
  6592. }
  6593. // process all over params
  6594. var paramVal = params[param];
  6595. if (isArray(paramVal)) {
  6596. paramVal = paramVal.join();
  6597. }
  6598. clientParams[param] = paramVal;
  6599. }
  6600. return clientParams;
  6601. };
  6602. return {
  6603. /**
  6604. Sets the index the document belongs to.
  6605. @member ejs.Document
  6606. @param {String} idx The index name
  6607. @returns {Object} returns <code>this</code> so that calls can be chained.
  6608. */
  6609. index: function (idx) {
  6610. if (idx == null) {
  6611. return index;
  6612. }
  6613. index = idx;
  6614. return this;
  6615. },
  6616. /**
  6617. Sets the type of the document.
  6618. @member ejs.Document
  6619. @param {String} t The type name
  6620. @returns {Object} returns <code>this</code> so that calls can be chained.
  6621. */
  6622. type: function (t) {
  6623. if (t == null) {
  6624. return type;
  6625. }
  6626. type = t;
  6627. return this;
  6628. },
  6629. /**
  6630. Sets the id of the document.
  6631. @member ejs.Document
  6632. @param {String} i The document id
  6633. @returns {Object} returns <code>this</code> so that calls can be chained.
  6634. */
  6635. id: function (i) {
  6636. if (i == null) {
  6637. return id;
  6638. }
  6639. id = i;
  6640. return this;
  6641. },
  6642. /**
  6643. <p>Sets the routing value.<p>
  6644. <p>By default, the shard the document is placed on is controlled by using a
  6645. hash of the document’s id value. For more explicit control, this routing value
  6646. will be fed into the hash function used by the router.</p>
  6647. <p>This option is valid during the following operations:
  6648. <code>index, delete, get, and update</code></p>
  6649. @member ejs.Document
  6650. @param {String} route The routing value
  6651. @returns {Object} returns <code>this</code> so that calls can be chained.
  6652. */
  6653. routing: function (route) {
  6654. if (route == null) {
  6655. return params.routing;
  6656. }
  6657. params.routing = route;
  6658. return this;
  6659. },
  6660. /**
  6661. <p>Sets parent value for a child document.</p>
  6662. <p>When indexing a child document, the routing value is automatically set to be
  6663. the same as it’s parent, unless the routing value is explicitly specified
  6664. using the routing parameter.</p>
  6665. <p>This option is valid during the following operations:
  6666. <code>index, delete, get, and update.</code></p>
  6667. @member ejs.Document
  6668. @param {String} parent The parent value
  6669. @returns {Object} returns <code>this</code> so that calls can be chained.
  6670. */
  6671. parent: function (parent) {
  6672. if (parent == null) {
  6673. return params.parent;
  6674. }
  6675. params.parent = parent;
  6676. return this;
  6677. },
  6678. /**
  6679. <p>Sets timestamp of the document.</p>
  6680. <p>By default the timestamp will be set to the time the docuement was indexed.</p>
  6681. <p>This option is valid during the following operations:
  6682. <code>index</code> and <code>update</code></p>
  6683. @member ejs.Document
  6684. @param {String} parent The parent value
  6685. @returns {Object} returns <code>this</code> so that calls can be chained.
  6686. */
  6687. timestamp: function (ts) {
  6688. if (ts == null) {
  6689. return params.timestamp;
  6690. }
  6691. params.timestamp = ts;
  6692. return this;
  6693. },
  6694. /**
  6695. </p>Sets the documents time to live (ttl).</p>
  6696. The expiration date that will be set for a document with a provided ttl is relative
  6697. to the timestamp of the document, meaning it can be based on the time of indexing or
  6698. on any time provided.</p>
  6699. <p>The provided ttl must be strictly positive and can be a number (in milliseconds)
  6700. or any valid time value such as <code>"1d", "2h", "5m",</code> etc.</p>
  6701. <p>This option is valid during the following operations:
  6702. <code>index</code> and <code>update</code></p>
  6703. @member ejs.Document
  6704. @param {String} length The amount of time after which the document
  6705. will expire.
  6706. @returns {Object} returns <code>this</code> so that calls can be chained.
  6707. */
  6708. ttl: function (length) {
  6709. if (length == null) {
  6710. return params.ttl;
  6711. }
  6712. params.ttl = length;
  6713. return this;
  6714. },
  6715. /**
  6716. <p>Set's a timeout for the given operation.</p>
  6717. If the primary shard has not completed the operation before this value, an error will
  6718. occur. The default timeout is 1 minute. The provided timeout must be strictly positive
  6719. and can be a number (in milliseconds) or any valid time value such as
  6720. <code>"1d", "2h", "5m",</code> etc.</p>
  6721. <p>This option is valid during the following operations:
  6722. <code>index, delete,</code> and <code>update</code></p>
  6723. @member ejs.Document
  6724. @param {String} length The amount of time after which the operation
  6725. will timeout.
  6726. @returns {Object} returns <code>this</code> so that calls can be chained.
  6727. */
  6728. timeout: function (length) {
  6729. if (length == null) {
  6730. return params.timeout;
  6731. }
  6732. params.timeout = length;
  6733. return this;
  6734. },
  6735. /**
  6736. <p>Enables the index to be refreshed immediately after the operation
  6737. occurs. This is an advanced setting and can lead to performance
  6738. issues.</p>
  6739. <p>This option is valid during the following operations:
  6740. <code>index, delete, get,</code> and <code>update</code></p>
  6741. @member ejs.Document
  6742. @param {Boolean} trueFalse If the index should be refreshed or not.
  6743. @returns {Object} returns <code>this</code> so that calls can be chained.
  6744. */
  6745. refresh: function (trueFalse) {
  6746. if (trueFalse == null) {
  6747. return params.refresh;
  6748. }
  6749. params.refresh = trueFalse;
  6750. return this;
  6751. },
  6752. /**
  6753. <p>Sets the document version.</p>
  6754. Used for optimistic concurrency control when set. If the version of the currently
  6755. indexed document is less-than or equal to the version specified, an error is produced,
  6756. otherwise the operation is permitted.</p>
  6757. <p>By default, internal versioning is used that starts at <code>1</code> and
  6758. increments with each update.</p>
  6759. <p>This option is valid during the following operations:
  6760. <code>index, delete,</code> and <code>update</code></p>
  6761. @member ejs.Document
  6762. @param {Long} version A positive long value
  6763. @returns {Object} returns <code>this</code> so that calls can be chained.
  6764. */
  6765. version: function (version) {
  6766. if (version == null) {
  6767. return params.version;
  6768. }
  6769. params.version = version;
  6770. return this;
  6771. },
  6772. /**
  6773. <p>Sets the version type.</p>
  6774. </p>Possible values are:</p>
  6775. <dl>
  6776. <dd><code>internal</code> - the default</dd>
  6777. <dd><code>external</code> - to use your own version (ie. version number from a database)</dd>
  6778. </dl>
  6779. <p>This option is valid during the following operations:
  6780. <code>index, delete,</code> and <code>update</code></p>
  6781. @member ejs.Document
  6782. @param {String} vt A version type (internal or external)
  6783. @returns {Object} returns <code>this</code> so that calls can be chained.
  6784. */
  6785. versionType: function (vt) {
  6786. // internal or external
  6787. if (vt == null) {
  6788. return params.version_type;
  6789. }
  6790. vt = vt.toLowerCase();
  6791. if (vt === 'internal' || vt === 'external') {
  6792. params.version_type = vt;
  6793. }
  6794. return this;
  6795. },
  6796. /**
  6797. <p>Perform percolation at index time.</p>
  6798. <p>Set to * to run document against all registered queries. It is also possible
  6799. to set this value to a string in query string format, ie. <code>"color:green"</code>.</p>
  6800. <p>This option is valid during the following operations:
  6801. <code>index</code> and <code>update</code></p>
  6802. @member ejs.Document
  6803. @param {String} qry A percolation query string
  6804. @returns {Object} returns <code>this</code> so that calls can be chained.
  6805. */
  6806. percolate: function (qry) {
  6807. if (qry == null) {
  6808. return params.percolate;
  6809. }
  6810. params.percolate = qry;
  6811. return this;
  6812. },
  6813. /**
  6814. <p>Sets the indexing operation type.</p>
  6815. <p>Valid values are:</p>
  6816. <dl>
  6817. <dd><code>index</code> - the default, create or replace</dd>
  6818. <dd><code>create</code> - create only</dd>
  6819. </dl>
  6820. <p>This option is valid during the following operations:
  6821. <code>index</code></p>
  6822. @member ejs.Document
  6823. @param {String} op The operation type (index or create)
  6824. @returns {Object} returns <code>this</code> so that calls can be chained.
  6825. */
  6826. opType: function (op) {
  6827. if (op == null) {
  6828. return params.op_type;
  6829. }
  6830. op = op.toLowerCase();
  6831. if (op === 'index' || op === 'create') {
  6832. params.op_type = op;
  6833. }
  6834. return this;
  6835. },
  6836. /**
  6837. <p>Sets the replication mode.</p>
  6838. <p>Valid values are:</p>
  6839. <dl>
  6840. <dd><code>async</code> - asynchronous replication to slaves</dd>
  6841. <dd><code>sync</code> - synchronous replication to the slaves</dd>
  6842. <dd><code>default</code> - the currently configured system default.</dd>
  6843. </dl>
  6844. <p>This option is valid during the following operations:
  6845. <code>index, delete,</code> and <code>update</code></p>
  6846. @member ejs.Document
  6847. @param {String} r The replication mode (async, sync, or default)
  6848. @returns {Object} returns <code>this</code> so that calls can be chained.
  6849. */
  6850. replication: function (r) {
  6851. if (r == null) {
  6852. return params.replication;
  6853. }
  6854. r = r.toLowerCase();
  6855. if (r === 'async' || r === 'sync' || r === 'default') {
  6856. params.replication = r;
  6857. }
  6858. return this;
  6859. },
  6860. /**
  6861. <p>Sets the write consistency.</p>
  6862. <p>Valid values are:</p>
  6863. <dl>
  6864. <dd><code>one - only requires write to one shard</dd>
  6865. <dd><code>quorum - requires writes to quorum <code>(N/2 + 1)</code></dd>
  6866. <dd><code>all - requires write to succeed on all shards</dd>
  6867. <dd><code>default - the currently configured system default</dd>
  6868. </dl>
  6869. <p>This option is valid during the following operations:
  6870. <code>index, delete,</code> and <code>update</code></p>
  6871. @member ejs.Document
  6872. @param {String} c The write consistency (one, quorum, all, or default)
  6873. @returns {Object} returns <code>this</code> so that calls can be chained.
  6874. */
  6875. consistency: function (c) {
  6876. if (c == null) {
  6877. return params.consistency;
  6878. }
  6879. c = c.toLowerCase();
  6880. if (c === 'default' || c === 'one' || c === 'quorum' || c === 'all') {
  6881. params.consistency = c;
  6882. }
  6883. return this;
  6884. },
  6885. /**
  6886. <p>Sets the preference of which shard replicas to execute the get
  6887. request on.</p>
  6888. <p>By default, the operation is randomized between the shard replicas.
  6889. This value can be:</p>
  6890. <dl>
  6891. <dd><code>_primary</code> - execute only on the primary shard</dd>
  6892. <dd><code>_local</code> - the local shard if possible</dd>
  6893. <dd><code>any string value</code> - to guarentee the same shards will always be used</dd>
  6894. </dl>
  6895. <p>This option is valid during the following operations:
  6896. <code>get</code></p>
  6897. @member ejs.Document
  6898. @param {String} p The preference value as a string
  6899. @returns {Object} returns <code>this</code> so that calls can be chained.
  6900. */
  6901. preference: function (p) {
  6902. if (p == null) {
  6903. return params.preference;
  6904. }
  6905. params.preference = p;
  6906. return this;
  6907. },
  6908. /**
  6909. <p>Sets if the get request is performed in realtime or waits for
  6910. the indexing operations to complete. By default it is realtime.</p>
  6911. <p>This option is valid during the following operations:
  6912. <code>get</code></p>
  6913. @member ejs.Document
  6914. @param {Boolean} trueFalse If realtime get is used or not.
  6915. @returns {Object} returns <code>this</code> so that calls can be chained.
  6916. */
  6917. realtime: function (trueFalse) {
  6918. if (trueFalse == null) {
  6919. return params.realtime;
  6920. }
  6921. params.realtime = trueFalse;
  6922. return this;
  6923. },
  6924. /**
  6925. <p>Sets the fields of the document to return.</p>
  6926. <p>By default the <code>_source</code> field is returned. Pass a single value
  6927. to append to the current list of fields, pass an array to overwrite the current
  6928. list of fields. The returned fields will either be loaded if they are stored,
  6929. or fetched from the <code>_source</code></p>
  6930. <p>This option is valid during the following operations:
  6931. <code>get</code> and <code>update</code></p>
  6932. @member ejs.Document
  6933. @param {String || Array} fields a single field name or array of field names.
  6934. @returns {Object} returns <code>this</code> so that calls can be chained.
  6935. */
  6936. fields: function (fields) {
  6937. if (params.fields == null) {
  6938. params.fields = [];
  6939. }
  6940. if (fields == null) {
  6941. return params.fields;
  6942. }
  6943. if (isString(fields)) {
  6944. params.fields.push(fields);
  6945. } else if (isArray(fields)) {
  6946. params.fields = fields;
  6947. } else {
  6948. throw new TypeError('Argument must be string or array');
  6949. }
  6950. return this;
  6951. },
  6952. /**
  6953. <p>Sets the update script.</p>
  6954. <p>This option is valid during the following operations:
  6955. <code>update</code></p>
  6956. @member ejs.Document
  6957. @param {String} script a script to use for docuement updates
  6958. @returns {Object} returns <code>this</code> so that calls can be chained.
  6959. */
  6960. script: function (script) {
  6961. if (script == null) {
  6962. return params.script;
  6963. }
  6964. params.script = script;
  6965. return this;
  6966. },
  6967. /**
  6968. <p>Sets the update script lanauge. Defaults to <code>mvel</code></p>.
  6969. <p>This option is valid during the following operations:
  6970. <code>update</code></p>
  6971. @member ejs.Document
  6972. @param {String} lang a valid script lanauge type such as mvel.
  6973. @returns {Object} returns <code>this</code> so that calls can be chained.
  6974. */
  6975. lang: function (lang) {
  6976. if (lang == null) {
  6977. return params.lang;
  6978. }
  6979. params.lang = lang;
  6980. return this;
  6981. },
  6982. /**
  6983. <p>Sets the parameters sent to the update script.</p>
  6984. <p>The params must be an object where the key is the parameter name and
  6985. the value is the parameter value to use in the script.</p>
  6986. <p>This option is valid during the following operations:
  6987. <code>update</code></p>
  6988. @member ejs.Document
  6989. @param {Object} p a object with script parameters.
  6990. @returns {Object} returns <code>this</code> so that calls can be chained.
  6991. */
  6992. params: function (p) {
  6993. // accept object, prefix keys as sp_{key}
  6994. if (p == null) {
  6995. return params.params;
  6996. }
  6997. if (!isObject(p)) {
  6998. throw new TypeError('Argument must be an object');
  6999. }
  7000. params.params = p;
  7001. return this;
  7002. },
  7003. /**
  7004. <p>Sets how many times to retry if there is a version conflict
  7005. between getting the document and indexing / deleting it.</p>
  7006. <p>Defaults to <code>0</code>.<p>
  7007. <p>This option is valid during the following operations:
  7008. <code>update</code></p>
  7009. @member ejs.Document
  7010. @param {Integer} num the number of times to retry operation.
  7011. @returns {Object} returns <code>this</code> so that calls can be chained.
  7012. */
  7013. retryOnConflict: function (num) {
  7014. if (num == null) {
  7015. return params.retry_on_conflict;
  7016. }
  7017. params.retry_on_conflict = num;
  7018. return this;
  7019. },
  7020. /**
  7021. <p>Sets the upsert document.</p>
  7022. <p>The upsert document is used during updates when the specified document
  7023. you are attempting to update does not exist.</p>
  7024. <p>This option is valid during the following operations:
  7025. <code>update</code></p>
  7026. @member ejs.Document
  7027. @param {Object} doc the upset document.
  7028. @returns {Object} returns <code>this</code> so that calls can be chained.
  7029. */
  7030. upsert: function (doc) {
  7031. if (doc == null) {
  7032. return params.upsert;
  7033. }
  7034. if (!isObject(doc)) {
  7035. throw new TypeError('Argument must be an object');
  7036. }
  7037. params.upsert = doc;
  7038. return this;
  7039. },
  7040. /**
  7041. <p>Sets the source document.</p>
  7042. <p>When set during an update operation, it is used as the partial update document.</p>
  7043. <p>This option is valid during the following operations:
  7044. <code>index</code> and <code>update</code></p>
  7045. @member ejs.Document
  7046. @param {Object} doc the source document.
  7047. @returns {Object} returns <code>this</code> so that calls can be chained.
  7048. */
  7049. source: function (doc) {
  7050. if (doc == null) {
  7051. return params.source;
  7052. }
  7053. if (!isObject(doc)) {
  7054. throw new TypeError('Argument must be an object');
  7055. }
  7056. params.source = doc;
  7057. return this;
  7058. },
  7059. /**
  7060. <p>Allows you to serialize this object into a JSON encoded string.</p>
  7061. @member ejs.Document
  7062. @returns {String} returns this object as a serialized JSON string.
  7063. */
  7064. toString: function () {
  7065. return JSON.stringify(params);
  7066. },
  7067. /**
  7068. <p>The type of ejs object. For internal use only.</p>
  7069. @member ejs.Document
  7070. @returns {String} the type of object
  7071. */
  7072. _type: function () {
  7073. return 'document';
  7074. },
  7075. /**
  7076. <p>Retrieves the internal <code>document</code> object. This is
  7077. typically used by internal API functions so use with caution.</p>
  7078. @member ejs.Document
  7079. @returns {Object} returns this object's internal object.
  7080. */
  7081. _self: function () {
  7082. return params;
  7083. },
  7084. /**
  7085. <p>Retrieves a document from the given index and type.</p>
  7086. @member ejs.Document
  7087. @param {Function} successcb A callback function that handles the response.
  7088. @param {Function} errorcb A callback function that handles errors.
  7089. @returns {Object} The return value is dependent on client implementation.
  7090. */
  7091. doGet: function (successcb, errorcb) {
  7092. // make sure the user has set a client
  7093. if (ejs.client == null) {
  7094. throw new Error("No Client Set");
  7095. }
  7096. if (index == null || type == null || id == null) {
  7097. throw new Error('Index, Type, and ID must be set');
  7098. }
  7099. // we don't need to convert the client params to a string
  7100. // on get requests, just create the url and pass the client
  7101. // params as the data
  7102. var url = '/' + index + '/' + type + '/' + id;
  7103. return ejs.client.get(url, genClientParams(), successcb, errorcb);
  7104. },
  7105. /**
  7106. <p>Stores a document in the given index and type. If no id
  7107. is set, one is created during indexing.</p>
  7108. @member ejs.Document
  7109. @param {Function} successcb A callback function that handles the response.
  7110. @param {Function} errorcb A callback function that handles errors.
  7111. @returns {Object} The return value is dependent on client implementation.
  7112. */
  7113. doIndex: function (successcb, errorcb) {
  7114. // make sure the user has set a client
  7115. if (ejs.client == null) {
  7116. throw new Error("No Client Set");
  7117. }
  7118. if (index == null || type == null) {
  7119. throw new Error('Index and Type must be set');
  7120. }
  7121. if (params.source == null) {
  7122. throw new Error('No source document found');
  7123. }
  7124. var url = '/' + index + '/' + type,
  7125. data = JSON.stringify(params.source),
  7126. paramStr = genParamStr(),
  7127. response;
  7128. if (id != null) {
  7129. url = url + '/' + id;
  7130. }
  7131. if (paramStr !== '') {
  7132. url = url + '?' + paramStr;
  7133. }
  7134. // do post if id not set so one is created
  7135. if (id == null) {
  7136. response = ejs.client.post(url, data, successcb, errorcb);
  7137. } else {
  7138. // put when id is specified
  7139. response = ejs.client.put(url, data, successcb, errorcb);
  7140. }
  7141. return response;
  7142. },
  7143. /**
  7144. <p>Updates a document in the given index and type.</p>
  7145. <p>If the document is not found in the index, the "upsert" value is used
  7146. if set. The document is updated via an update script or partial document.</p>
  7147. <p>To use a script, set the script option, to use a
  7148. partial document, set the source with the partial document.</p>
  7149. @member ejs.Document
  7150. @param {Function} successcb A callback function that handles the response.
  7151. @param {Function} errorcb A callback function that handles errors.
  7152. @returns {Object} The return value is dependent on client implementation.
  7153. */
  7154. doUpdate: function (successcb, errorcb) {
  7155. // make sure the user has set a client
  7156. if (ejs.client == null) {
  7157. throw new Error("No Client Set");
  7158. }
  7159. if (index == null || type == null || id == null) {
  7160. throw new Error('Index, Type, and ID must be set');
  7161. }
  7162. if (params.script == null && params.source == null) {
  7163. throw new Error('Update script or document required');
  7164. }
  7165. var url = '/' + index + '/' + type + '/' + id + '/_update',
  7166. data = {},
  7167. paramStr = genParamStr();
  7168. if (paramStr !== '') {
  7169. url = url + '?' + paramStr;
  7170. }
  7171. if (params.script != null) {
  7172. data.script = params.script;
  7173. }
  7174. if (params.lang != null) {
  7175. data.lang = params.lang;
  7176. }
  7177. if (params.params != null) {
  7178. data.params = params.params;
  7179. }
  7180. if (params.upsert != null) {
  7181. data.upsert = params.upsert;
  7182. }
  7183. if (params.source != null) {
  7184. data.doc = params.source;
  7185. }
  7186. return ejs.client.post(url, JSON.stringify(data), successcb, errorcb);
  7187. },
  7188. /**
  7189. <p>Deletes the document from the given index and type using the
  7190. speciifed id.</p>
  7191. @member ejs.Document
  7192. @param {Function} successcb A callback function that handles the response.
  7193. @param {Function} errorcb A callback function that handles errors.
  7194. @returns {void} Returns the value of the callback when executing on the server.
  7195. */
  7196. doDelete: function (successcb, errorcb) {
  7197. // make sure the user has set a client
  7198. if (ejs.client == null) {
  7199. throw new Error("No Client Set");
  7200. }
  7201. if (index == null || type == null || id == null) {
  7202. throw new Error('Index, Type, and ID must be set');
  7203. }
  7204. var url = '/' + index + '/' + type + '/' + id,
  7205. data = '',
  7206. paramStr = genParamStr();
  7207. if (paramStr !== '') {
  7208. url = url + '?' + paramStr;
  7209. }
  7210. return ejs.client.del(url, data, successcb, errorcb);
  7211. }
  7212. };
  7213. };
  7214. /**
  7215. @class
  7216. <p>A <code>boolQuery</code> allows you to build <em>Boolean</em> query constructs
  7217. from individual term or phrase queries. For example you might want to search
  7218. for documents containing the terms <code>javascript</code> and <code>python</code>.</p>
  7219. @name ejs.BoolQuery
  7220. @desc
  7221. A Query that matches documents matching boolean combinations of other
  7222. queries, e.g. <code>termQuerys, phraseQuerys</code> or other <code>boolQuerys</code>.
  7223. */
  7224. ejs.BoolQuery = function () {
  7225. /**
  7226. The internal query object. <code>Use _self()</code>
  7227. @member ejs.BoolQuery
  7228. @property {Object} query
  7229. */
  7230. var query = {
  7231. bool: {}
  7232. };
  7233. return {
  7234. /**
  7235. Adds query to boolean container. Given query "must" appear in matching documents.
  7236. @member ejs.BoolQuery
  7237. @param {Object} oQuery A valid <code>Query</code> object
  7238. @returns {Object} returns <code>this</code> so that calls can be chained.
  7239. */
  7240. must: function (oQuery) {
  7241. var i, len;
  7242. if (query.bool.must == null) {
  7243. query.bool.must = [];
  7244. }
  7245. if (oQuery == null) {
  7246. return query.bool.must;
  7247. }
  7248. if (isQuery(oQuery)) {
  7249. query.bool.must.push(oQuery._self());
  7250. } else if (isArray(oQuery)) {
  7251. query.bool.must = [];
  7252. for (i = 0, len = oQuery.length; i < len; i++) {
  7253. if (!isQuery(oQuery[i])) {
  7254. throw new TypeError('Argument must be an array of Queries');
  7255. }
  7256. query.bool.must.push(oQuery[i]._self());
  7257. }
  7258. } else {
  7259. throw new TypeError('Argument must be a Query or array of Queries');
  7260. }
  7261. return this;
  7262. },
  7263. /**
  7264. Adds query to boolean container. Given query "must not" appear in matching documents.
  7265. @member ejs.BoolQuery
  7266. @param {Object} oQuery A valid query object
  7267. @returns {Object} returns <code>this</code> so that calls can be chained.
  7268. */
  7269. mustNot: function (oQuery) {
  7270. var i, len;
  7271. if (query.bool.must_not == null) {
  7272. query.bool.must_not = [];
  7273. }
  7274. if (oQuery == null) {
  7275. return query.bool.must_not;
  7276. }
  7277. if (isQuery(oQuery)) {
  7278. query.bool.must_not.push(oQuery._self());
  7279. } else if (isArray(oQuery)) {
  7280. query.bool.must_not = [];
  7281. for (i = 0, len = oQuery.length; i < len; i++) {
  7282. if (!isQuery(oQuery[i])) {
  7283. throw new TypeError('Argument must be an array of Queries');
  7284. }
  7285. query.bool.must_not.push(oQuery[i]._self());
  7286. }
  7287. } else {
  7288. throw new TypeError('Argument must be a Query or array of Queries');
  7289. }
  7290. return this;
  7291. },
  7292. /**
  7293. Adds query to boolean container. Given query "should" appear in matching documents.
  7294. @member ejs.BoolQuery
  7295. @param {Object} oQuery A valid query object
  7296. @returns {Object} returns <code>this</code> so that calls can be chained.
  7297. */
  7298. should: function (oQuery) {
  7299. var i, len;
  7300. if (query.bool.should == null) {
  7301. query.bool.should = [];
  7302. }
  7303. if (oQuery == null) {
  7304. return query.bool.should;
  7305. }
  7306. if (isQuery(oQuery)) {
  7307. query.bool.should.push(oQuery._self());
  7308. } else if (isArray(oQuery)) {
  7309. query.bool.should = [];
  7310. for (i = 0, len = oQuery.length; i < len; i++) {
  7311. if (!isQuery(oQuery[i])) {
  7312. throw new TypeError('Argument must be an array of Queries');
  7313. }
  7314. query.bool.should.push(oQuery[i]._self());
  7315. }
  7316. } else {
  7317. throw new TypeError('Argument must be a Query or array of Queries');
  7318. }
  7319. return this;
  7320. },
  7321. /**
  7322. Sets the boost value for documents matching the <code>Query</code>.
  7323. @member ejs.BoolQuery
  7324. @param {Double} boost A positive <code>double</code> value.
  7325. @returns {Object} returns <code>this</code> so that calls can be chained.
  7326. */
  7327. boost: function (boost) {
  7328. if (boost == null) {
  7329. return query.bool.boost;
  7330. }
  7331. query.bool.boost = boost;
  7332. return this;
  7333. },
  7334. /**
  7335. Enables or disables similarity coordinate scoring of documents
  7336. matching the <code>Query</code>. Default: false.
  7337. @member ejs.BoolQuery
  7338. @param {String} trueFalse A <code>true/false</code value.
  7339. @returns {Object} returns <code>this</code> so that calls can be chained.
  7340. */
  7341. disableCoord: function (trueFalse) {
  7342. if (trueFalse == null) {
  7343. return query.bool.disable_coord;
  7344. }
  7345. query.bool.disable_coord = trueFalse;
  7346. return this;
  7347. },
  7348. /**
  7349. <p>Sets the number of optional clauses that must match.</p>
  7350. <p>By default no optional clauses are necessary for a match
  7351. (unless there are no required clauses). If this method is used,
  7352. then the specified number of clauses is required.</p>
  7353. <p>Use of this method is totally independent of specifying that
  7354. any specific clauses are required (or prohibited). This number will
  7355. only be compared against the number of matching optional clauses.</p>
  7356. @member ejs.BoolQuery
  7357. @param {Integer} minMatch A positive <code>integer</code> value.
  7358. @returns {Object} returns <code>this</code> so that calls can be chained.
  7359. */
  7360. minimumNumberShouldMatch: function (minMatch) {
  7361. if (minMatch == null) {
  7362. return query.bool.minimum_number_should_match;
  7363. }
  7364. query.bool.minimum_number_should_match = minMatch;
  7365. return this;
  7366. },
  7367. /**
  7368. Allows you to serialize this object into a JSON encoded string.
  7369. @member ejs.BoolQuery
  7370. @returns {String} returns this object as a serialized JSON string.
  7371. */
  7372. toString: function () {
  7373. return JSON.stringify(query);
  7374. },
  7375. /**
  7376. The type of ejs object. For internal use only.
  7377. @member ejs.BoolQuery
  7378. @returns {String} the type of object
  7379. */
  7380. _type: function () {
  7381. return 'query';
  7382. },
  7383. /**
  7384. Retrieves the internal <code>query</code> object. This is typically used by
  7385. internal API functions so use with caution.
  7386. @member ejs.BoolQuery
  7387. @returns {String} returns this object's internal <code>query</code> property.
  7388. */
  7389. _self: function () {
  7390. return query;
  7391. }
  7392. };
  7393. };
  7394. /**
  7395. @class
  7396. <p>The boosting query can be used to effectively demote results that match
  7397. a given query. Unlike the “NOT” clause in bool query, this still selects
  7398. documents that contain undesirable terms, but reduces their overall
  7399. score.</p>
  7400. @name ejs.BoostingQuery
  7401. @desc
  7402. <p>Constructs a query that can demote search results. A negative boost.</p>
  7403. @param {Object} positiveQry Valid query object used to select all matching docs.
  7404. @param {Object} negativeQry Valid query object to match the undesirable docs
  7405. returned within the positiveQry result set.
  7406. @param {Double} negativeBoost A double value where 0 < n < 1.
  7407. */
  7408. ejs.BoostingQuery = function (positiveQry, negativeQry, negativeBoost) {
  7409. if (!isQuery(positiveQry) || !isQuery(negativeQry)) {
  7410. throw new TypeError('Arguments must be Queries');
  7411. }
  7412. /**
  7413. The internal Query object. Use <code>_self()</code>.
  7414. @member ejs.BoostingQuery
  7415. @property {Object} BoostingQuery
  7416. */
  7417. var query = {
  7418. boosting: {
  7419. positive: positiveQry._self(),
  7420. negative: negativeQry._self(),
  7421. negative_boost: negativeBoost
  7422. }
  7423. };
  7424. return {
  7425. /**
  7426. Sets the "master" query that determines which results are returned.
  7427. @member ejs.BoostingQuery
  7428. @param {Object} oQuery A valid <code>Query</code> object
  7429. @returns {Object} returns <code>this</code> so that calls can be
  7430. chained. Returns {Object} current positive query if oQuery is
  7431. not specified.
  7432. */
  7433. positive: function (oQuery) {
  7434. if (oQuery == null) {
  7435. return query.boosting.positive;
  7436. }
  7437. if (!isQuery(oQuery)) {
  7438. throw new TypeError('Argument must be a Query');
  7439. }
  7440. query.boosting.positive = oQuery._self();
  7441. return this;
  7442. },
  7443. /**
  7444. Sets the query used to match documents in the <code>positive</code>
  7445. query that will be negatively boosted.
  7446. @member ejs.BoostingQuery
  7447. @param {Object} oQuery A valid <code>Query</code> object
  7448. @returns {Object} returns <code>this</code> so that calls can be
  7449. chained. Returns {Object} current negative query if oQuery is
  7450. not specified.
  7451. */
  7452. negative: function (oQuery) {
  7453. if (oQuery == null) {
  7454. return query.boosting.negative;
  7455. }
  7456. if (!isQuery(oQuery)) {
  7457. throw new TypeError('Argument must be a Query');
  7458. }
  7459. query.boosting.negative = oQuery._self();
  7460. return this;
  7461. },
  7462. /**
  7463. Sets the negative boost value.
  7464. @member ejs.BoostingQuery
  7465. @param {Double} boost A positive <code>double</code> value where 0 < n < 1.
  7466. @returns {Object} returns <code>this</code> so that calls can be chained.
  7467. */
  7468. negativeBoost: function (negBoost) {
  7469. if (negBoost == null) {
  7470. return query.boosting.negative_boost;
  7471. }
  7472. query.boosting.negative_boost = negBoost;
  7473. return this;
  7474. },
  7475. /**
  7476. Sets the boost value of the <code>Query</code>.
  7477. @member ejs.BoostingQuery
  7478. @param {Double} boost A positive <code>double</code> value.
  7479. @returns {Object} returns <code>this</code> so that calls can be chained.
  7480. */
  7481. boost: function (boost) {
  7482. if (boost == null) {
  7483. return query.boosting.boost;
  7484. }
  7485. query.boosting.boost = boost;
  7486. return this;
  7487. },
  7488. /**
  7489. Serializes the internal <em>query</em> object as a JSON string.
  7490. @member ejs.BoostingQuery
  7491. @returns {String} Returns a JSON representation of the Query object.
  7492. */
  7493. toString: function () {
  7494. return JSON.stringify(query);
  7495. },
  7496. /**
  7497. The type of ejs object. For internal use only.
  7498. @member ejs.BoostingQuery
  7499. @returns {String} the type of object
  7500. */
  7501. _type: function () {
  7502. return 'query';
  7503. },
  7504. /**
  7505. This method is used to retrieve the raw query object. It's designed
  7506. for internal use when composing and serializing queries.
  7507. @member ejs.BoostingQuery
  7508. @returns {Object} Returns the object's <em>query</em> property.
  7509. */
  7510. _self: function () {
  7511. return query;
  7512. }
  7513. };
  7514. };
  7515. /**
  7516. @class
  7517. <p>A query that executes high-frequency terms in a optional sub-query to
  7518. prevent slow queries due to "common" terms like stopwords.</p>
  7519. <p>This query basically builds two queries out of the terms in the query
  7520. string where low-frequency terms are added to a required boolean clause and
  7521. high-frequency terms are added to an optional boolean clause. The optional
  7522. clause is only executed if the required "low-frequency' clause matches.</p>
  7523. <p><code>CommonTermsQuery</code> has several advantages over stopword
  7524. filtering at index or query time since a term can be "classified" based on
  7525. the actual document frequency in the index and can prevent slow queries even
  7526. across domains without specialized stopword files.</p>
  7527. @name ejs.CommonTermsQuery
  7528. @since elasticsearch 0.90
  7529. @desc
  7530. A query that executes high-frequency terms in a optional sub-query.
  7531. @param {String} field the document field/key to query against
  7532. @param {String} qstr the query string
  7533. */
  7534. ejs.CommonTermsQuery = function (field, qstr) {
  7535. /**
  7536. The internal query object. <code>Use get()</code>
  7537. @member ejs.CommonTermsQuery
  7538. @property {Object} query
  7539. */
  7540. var query = {
  7541. common: {}
  7542. };
  7543. // support for full Builder functionality where no constructor is used
  7544. // use dummy field until one is set
  7545. if (field == null) {
  7546. field = 'no_field_set';
  7547. }
  7548. query.common[field] = {};
  7549. // only set the query is one is passed in
  7550. if (qstr != null) {
  7551. query.common[field].query = qstr;
  7552. }
  7553. return {
  7554. /**
  7555. Sets the field to query against.
  7556. @member ejs.CommonTermsQuery
  7557. @param {String} f A valid field name.
  7558. @returns {Object} returns <code>this</code> so that calls can be chained.
  7559. */
  7560. field: function (f) {
  7561. var oldValue = query.common[field];
  7562. if (f == null) {
  7563. return field;
  7564. }
  7565. delete query.common[field];
  7566. field = f;
  7567. query.common[f] = oldValue;
  7568. return this;
  7569. },
  7570. /**
  7571. Sets the query string.
  7572. @member ejs.CommonTermsQuery
  7573. @param {String} qstr The query string.
  7574. @returns {Object} returns <code>this</code> so that calls can be chained.
  7575. */
  7576. query: function (qstr) {
  7577. if (qstr == null) {
  7578. return query.common[field].query;
  7579. }
  7580. query.common[field].query = qstr;
  7581. return this;
  7582. },
  7583. /**
  7584. Sets the analyzer name used to analyze the <code>Query</code> object.
  7585. @member ejs.CommonTermsQuery
  7586. @param {String} analyzer A valid analyzer name.
  7587. @returns {Object} returns <code>this</code> so that calls can be chained.
  7588. */
  7589. analyzer: function (analyzer) {
  7590. if (analyzer == null) {
  7591. return query.common[field].analyzer;
  7592. }
  7593. query.common[field].analyzer = analyzer;
  7594. return this;
  7595. },
  7596. /**
  7597. Enables or disables similarity coordinate scoring of documents
  7598. commoning the <code>Query</code>. Default: false.
  7599. @member ejs.CommonTermsQuery
  7600. @param {String} trueFalse A <code>true/false</code value.
  7601. @returns {Object} returns <code>this</code> so that calls can be chained.
  7602. */
  7603. disableCoords: function (trueFalse) {
  7604. if (trueFalse == null) {
  7605. return query.common[field].disable_coords;
  7606. }
  7607. query.common[field].disable_coords = trueFalse;
  7608. return this;
  7609. },
  7610. /**
  7611. Sets the maximum threshold/frequency to be considered a low
  7612. frequency term. Set to a value between 0 and 1.
  7613. @member ejs.CommonTermsQuery
  7614. @param {Number} freq A positive <code>double</code> value.
  7615. @returns {Object} returns <code>this</code> so that calls can be chained.
  7616. */
  7617. cutoffFrequency: function (freq) {
  7618. if (freq == null) {
  7619. return query.common[field].cutoff_frequency;
  7620. }
  7621. query.common[field].cutoff_frequency = freq;
  7622. return this;
  7623. },
  7624. /**
  7625. Sets the boolean operator to be used for high frequency terms.
  7626. Default: AND
  7627. @member ejs.CommonTermsQuery
  7628. @param {String} op Any of "and" or "or", no quote characters.
  7629. @returns {Object} returns <code>this</code> so that calls can be chained.
  7630. */
  7631. highFreqOperator: function (op) {
  7632. if (op == null) {
  7633. return query.common[field].high_freq_operator;
  7634. }
  7635. op = op.toLowerCase();
  7636. if (op === 'and' || op === 'or') {
  7637. query.common[field].high_freq_operator = op;
  7638. }
  7639. return this;
  7640. },
  7641. /**
  7642. Sets the boolean operator to be used for low frequency terms.
  7643. Default: AND
  7644. @member ejs.CommonTermsQuery
  7645. @param {String} op Any of "and" or "or", no quote characters.
  7646. @returns {Object} returns <code>this</code> so that calls can be chained.
  7647. */
  7648. lowFreqOperator: function (op) {
  7649. if (op == null) {
  7650. return query.common[field].low_freq_operator;
  7651. }
  7652. op = op.toLowerCase();
  7653. if (op === 'and' || op === 'or') {
  7654. query.common[field].low_freq_operator = op;
  7655. }
  7656. return this;
  7657. },
  7658. /**
  7659. Sets the minimum number of common that need to common in a document
  7660. before that document is returned in the results.
  7661. @member ejs.CommonTermsQuery
  7662. @param {Integer} min A positive integer.
  7663. @returns {Object} returns <code>this</code> so that calls can be chained.
  7664. */
  7665. minimumShouldMatch: function (min) {
  7666. if (min == null) {
  7667. return query.common[field].minimum_should_match;
  7668. }
  7669. query.common[field].minimum_should_match = min;
  7670. return this;
  7671. },
  7672. /**
  7673. Sets the boost value for documents commoning the <code>Query</code>.
  7674. @member ejs.CommonTermsQuery
  7675. @param {Number} boost A positive <code>double</code> value.
  7676. @returns {Object} returns <code>this</code> so that calls can be chained.
  7677. */
  7678. boost: function (boost) {
  7679. if (boost == null) {
  7680. return query.common[field].boost;
  7681. }
  7682. query.common[field].boost = boost;
  7683. return this;
  7684. },
  7685. /**
  7686. Allows you to serialize this object into a JSON encoded string.
  7687. @member ejs.CommonTermsQuery
  7688. @returns {String} returns this object as a serialized JSON string.
  7689. */
  7690. toString: function () {
  7691. return JSON.stringify(query);
  7692. },
  7693. /**
  7694. The type of ejs object. For internal use only.
  7695. @member ejs.CommonTermsQuery
  7696. @returns {String} the type of object
  7697. */
  7698. _type: function () {
  7699. return 'query';
  7700. },
  7701. /**
  7702. Retrieves the internal <code>query</code> object. This is typically used by
  7703. internal API functions so use with caution.
  7704. @member ejs.CommonTermsQuery
  7705. @returns {String} returns this object's internal <code>query</code> property.
  7706. */
  7707. _self: function () {
  7708. return query;
  7709. }
  7710. };
  7711. };
  7712. /**
  7713. @class
  7714. <p>A constant score query wraps another <code>Query</code> or
  7715. <code>Filter</code> and returns a constant score for each
  7716. result that is equal to the query boost.</p>
  7717. <p>Note that lucene's query normalization (queryNorm) attempts
  7718. to make scores between different queries comparable. It does not
  7719. change the relevance of your query, but it might confuse you when
  7720. you look at the score of your documents and they are not equal to
  7721. the query boost value as expected. The scores were normalized by
  7722. queryNorm, but maintain the same relevance.</p>
  7723. @name ejs.ConstantScoreQuery
  7724. @desc
  7725. <p>Constructs a query where each documents returned by the internal
  7726. query or filter have a constant score equal to the boost factor.</p>
  7727. */
  7728. ejs.ConstantScoreQuery = function () {
  7729. /**
  7730. The internal Query object. Use <code>_self()</code>.
  7731. @member ejs.ConstantScoreQuery
  7732. @property {Object} query
  7733. */
  7734. var query = {
  7735. constant_score: {}
  7736. };
  7737. return {
  7738. /**
  7739. Adds the query to apply a constant score to.
  7740. @member ejs.ConstantScoreQuery
  7741. @param {Object} oQuery A valid <code>Query</code> object
  7742. @returns {Object} returns <code>this</code> so that calls can be chained.
  7743. */
  7744. query: function (oQuery) {
  7745. if (oQuery == null) {
  7746. return query.constant_score.query;
  7747. }
  7748. if (!isQuery(oQuery)) {
  7749. throw new TypeError('Argument must be a Query');
  7750. }
  7751. query.constant_score.query = oQuery._self();
  7752. return this;
  7753. },
  7754. /**
  7755. Adds the filter to apply a constant score to.
  7756. @member ejs.ConstantScoreQuery
  7757. @param {Object} oFilter A valid <code>Filter</code> object
  7758. @returns {Object} returns <code>this</code> so that calls can be chained.
  7759. */
  7760. filter: function (oFilter) {
  7761. if (oFilter == null) {
  7762. return query.constant_score.filter;
  7763. }
  7764. if (!isFilter(oFilter)) {
  7765. throw new TypeError('Argument must be a Filter');
  7766. }
  7767. query.constant_score.filter = oFilter._self();
  7768. return this;
  7769. },
  7770. /**
  7771. Enables caching of the filter.
  7772. @member ejs.ConstantScoreQuery
  7773. @param {Boolean} trueFalse A boolean value.
  7774. @returns {Object} returns <code>this</code> so that calls can be chained.
  7775. */
  7776. cache: function (trueFalse) {
  7777. if (trueFalse == null) {
  7778. return query.constant_score._cache;
  7779. }
  7780. query.constant_score._cache = trueFalse;
  7781. return this;
  7782. },
  7783. /**
  7784. Set the cache key.
  7785. @member ejs.ConstantScoreQuery
  7786. @param {String} k A string cache key.
  7787. @returns {Object} returns <code>this</code> so that calls can be chained.
  7788. */
  7789. cacheKey: function (k) {
  7790. if (k == null) {
  7791. return query.constant_score._cache_key;
  7792. }
  7793. query.constant_score._cache_key = k;
  7794. return this;
  7795. },
  7796. /**
  7797. Sets the boost value of the <code>Query</code>.
  7798. @member ejs.ConstantScoreQuery
  7799. @param {Double} boost A positive <code>double</code> value.
  7800. @returns {Object} returns <code>this</code> so that calls can be chained.
  7801. */
  7802. boost: function (boost) {
  7803. if (boost == null) {
  7804. return query.constant_score.boost;
  7805. }
  7806. query.constant_score.boost = boost;
  7807. return this;
  7808. },
  7809. /**
  7810. Serializes the internal <em>query</em> object as a JSON string.
  7811. @member ejs.ConstantScoreQuery
  7812. @returns {String} Returns a JSON representation of the Query object.
  7813. */
  7814. toString: function () {
  7815. return JSON.stringify(query);
  7816. },
  7817. /**
  7818. The type of ejs object. For internal use only.
  7819. @member ejs.ConstantScoreQuery
  7820. @returns {String} the type of object
  7821. */
  7822. _type: function () {
  7823. return 'query';
  7824. },
  7825. /**
  7826. This method is used to retrieve the raw query object. It's designed
  7827. for internal use when composing and serializing queries.
  7828. @member ejs.ConstantScoreQuery
  7829. @returns {Object} Returns the object's <em>query</em> property.
  7830. */
  7831. _self: function () {
  7832. return query;
  7833. }
  7834. };
  7835. };
  7836. /**
  7837. @class
  7838. <p>A query allows to wrap another query and multiply its score by the
  7839. provided boost_factor. This can sometimes be desired since boost value set
  7840. on specific queries gets normalized, while this query boost factor does not.</p>
  7841. @name ejs.CustomBoostFactorQuery
  7842. @desc
  7843. Boosts a queries score without that boost being normalized.
  7844. @param {Object} qry A valid query object.
  7845. */
  7846. ejs.CustomBoostFactorQuery = function (qry) {
  7847. if (!isQuery(qry)) {
  7848. throw new TypeError('Argument must be a Query');
  7849. }
  7850. /**
  7851. The internal query object. <code>Use _self()</code>
  7852. @member ejs.CustomBoostFactorQuery
  7853. @property {Object} query
  7854. */
  7855. var query = {
  7856. custom_boost_factor: {
  7857. query: qry._self()
  7858. }
  7859. };
  7860. return {
  7861. /**
  7862. Sets the query to be apply the custom boost to.
  7863. @member ejs.CustomBoostFactorQuery
  7864. @param {Object} q A valid Query object
  7865. @returns {Object} returns <code>this</code> so that calls can be chained.
  7866. */
  7867. query: function (q) {
  7868. if (q == null) {
  7869. return query.custom_boost_factor.query;
  7870. }
  7871. if (!isQuery(q)) {
  7872. throw new TypeError('Argument must be a Query');
  7873. }
  7874. query.custom_boost_factor.query = q._self();
  7875. return this;
  7876. },
  7877. /**
  7878. Sets the language used in the script.
  7879. @member ejs.CustomBoostFactorQuery
  7880. @param {Double} boost The boost value.
  7881. @returns {Object} returns <code>this</code> so that calls can be chained.
  7882. */
  7883. boostFactor: function (boost) {
  7884. if (boost == null) {
  7885. return query.custom_boost_factor.boost_factor;
  7886. }
  7887. query.custom_boost_factor.boost_factor = boost;
  7888. return this;
  7889. },
  7890. /**
  7891. Sets the boost value of the <code>Query</code>.
  7892. @member ejs.CustomBoostFactorQuery
  7893. @param {Double} boost A positive <code>double</code> value.
  7894. @returns {Object} returns <code>this</code> so that calls can be chained.
  7895. */
  7896. boost: function (boost) {
  7897. if (boost == null) {
  7898. return query.custom_boost_factor.boost;
  7899. }
  7900. query.custom_boost_factor.boost = boost;
  7901. return this;
  7902. },
  7903. /**
  7904. Allows you to serialize this object into a JSON encoded string.
  7905. @member ejs.CustomBoostFactorQuery
  7906. @returns {String} returns this object as a serialized JSON string.
  7907. */
  7908. toString: function () {
  7909. return JSON.stringify(query);
  7910. },
  7911. /**
  7912. The type of ejs object. For internal use only.
  7913. @member ejs.CustomBoostFactorQuery
  7914. @returns {String} the type of object
  7915. */
  7916. _type: function () {
  7917. return 'query';
  7918. },
  7919. /**
  7920. Retrieves the internal <code>query</code> object. This is typically used by
  7921. internal API functions so use with caution.
  7922. @member ejs.CustomBoostFactorQuery
  7923. @returns {String} returns this object's internal <code>query</code> property.
  7924. */
  7925. _self: function () {
  7926. return query;
  7927. }
  7928. };
  7929. };
  7930. /**
  7931. @class
  7932. <p>A custom_filters_score query allows to execute a query, and if the hit
  7933. matches a provided filter (ordered), use either a boost or a script
  7934. associated with it to compute the score.</p>
  7935. <p>This can considerably simplify and increase performance for parameterized
  7936. based scoring since filters are easily cached for faster performance, and
  7937. boosting / script is considerably simpler.</p>
  7938. @name ejs.CustomFiltersScoreQuery
  7939. @desc
  7940. Returned documents matched by the query and scored based on if the document
  7941. matched in a filter.
  7942. @param {Object} qry A valid query object.
  7943. @param {Object || Array} filters A single object or array of objects. Each
  7944. object must have a 'filter' property and either a 'boost' or 'script'
  7945. property.
  7946. */
  7947. ejs.CustomFiltersScoreQuery = function (qry, filters) {
  7948. if (!isQuery(qry)) {
  7949. throw new TypeError('Argument must be a Query');
  7950. }
  7951. /**
  7952. The internal query object. <code>Use _self()</code>
  7953. @member ejs.CustomFiltersScoreQuery
  7954. @property {Object} query
  7955. */
  7956. var query = {
  7957. custom_filters_score: {
  7958. query: qry._self(),
  7959. filters: []
  7960. }
  7961. },
  7962. // generate a valid filter object that can be inserted into the filters
  7963. // array. Returns null when an invalid filter is passed in.
  7964. genFilterObject = function (filter) {
  7965. var obj = null;
  7966. if (filter.filter && isFilter(filter.filter)) {
  7967. obj = {
  7968. filter: filter.filter._self()
  7969. };
  7970. if (filter.boost) {
  7971. obj.boost = filter.boost;
  7972. } else if (filter.script) {
  7973. obj.script = filter.script;
  7974. } else {
  7975. // invalid filter, must boost or script must be specified
  7976. obj = null;
  7977. }
  7978. }
  7979. return obj;
  7980. };
  7981. each((isArray(filters) ? filters : [filters]), function (filter) {
  7982. var fObj = genFilterObject(filter);
  7983. if (fObj !== null) {
  7984. query.custom_filters_score.filters.push(fObj);
  7985. }
  7986. });
  7987. return {
  7988. /**
  7989. Sets the query to be apply the custom boost to.
  7990. @member ejs.CustomFiltersScoreQuery
  7991. @param {Object} q A valid Query object
  7992. @returns {Object} returns <code>this</code> so that calls can be chained.
  7993. */
  7994. query: function (q) {
  7995. if (q == null) {
  7996. return query.custom_filters_score.query;
  7997. }
  7998. if (!isQuery(q)) {
  7999. throw new TypeError('Argument must be a Query');
  8000. }
  8001. query.custom_filters_score.query = q._self();
  8002. return this;
  8003. },
  8004. /**
  8005. <p>Sets the filters and their related boost or script scoring method.</p>
  8006. <p>Takes an array of objects where each object has a 'filter' property
  8007. and either a 'boost' or 'script' property. Pass a single object to
  8008. add to the current list of filters or pass a list of objects to
  8009. overwrite all existing filters.</p>
  8010. <code>
  8011. {filter: someFilter, boost: 2.1}
  8012. </code>
  8013. @member ejs.CustomFiltersScoreQuery
  8014. @param {Object || Array} fltrs An object or array of objects
  8015. contining a filter and either a boost or script property.
  8016. @returns {Object} returns <code>this</code> so that calls can be chained.
  8017. */
  8018. filters: function (fltrs) {
  8019. if (fltrs == null) {
  8020. return query.custom_filters_score.filters;
  8021. }
  8022. if (isArray(fltrs)) {
  8023. query.custom_filters_score.filters = [];
  8024. }
  8025. each((isArray(fltrs) ? fltrs : [fltrs]), function (f) {
  8026. var fObj = genFilterObject(f);
  8027. if (fObj !== null) {
  8028. query.custom_filters_score.filters.push(fObj);
  8029. }
  8030. });
  8031. return this;
  8032. },
  8033. /**
  8034. <p>A score_mode can be defined to control how multiple matching
  8035. filters control the score.<p>
  8036. <p>By default, it is set to first which means the first matching filter
  8037. will control the score of the result. It can also be set to
  8038. <code>min/max/total/avg/multiply</code> which will aggregate the result from all
  8039. matching filters based on the aggregation type.<p>
  8040. @member ejs.CustomFiltersScoreQuery
  8041. @param {String} s The scoring type as a string.
  8042. @returns {Object} returns <code>this</code> so that calls can be chained.
  8043. */
  8044. scoreMode: function (s) {
  8045. if (s == null) {
  8046. return query.custom_filters_score.score_mode;
  8047. }
  8048. s = s.toLowerCase();
  8049. if (s === 'first' || s === 'min' || s === 'max' || s === 'total' || s === 'avg' || s === 'multiply') {
  8050. query.custom_filters_score.score_mode = s;
  8051. }
  8052. return this;
  8053. },
  8054. /**
  8055. Sets parameters that will be applied to the script. Overwrites
  8056. any existing params.
  8057. @member ejs.CustomFiltersScoreQuery
  8058. @param {Object} q An object where the keys are the parameter name and
  8059. values are the parameter value.
  8060. @returns {Object} returns <code>this</code> so that calls can be chained.
  8061. */
  8062. params: function (p) {
  8063. if (p == null) {
  8064. return query.custom_filters_score.params;
  8065. }
  8066. query.custom_filters_score.params = p;
  8067. return this;
  8068. },
  8069. /**
  8070. Sets the language used in the script.
  8071. @member ejs.CustomFiltersScoreQuery
  8072. @param {String} l The script language, defatuls to mvel.
  8073. @returns {Object} returns <code>this</code> so that calls can be chained.
  8074. */
  8075. lang: function (l) {
  8076. if (l == null) {
  8077. return query.custom_filters_score.lang;
  8078. }
  8079. query.custom_filters_score.lang = l;
  8080. return this;
  8081. },
  8082. /**
  8083. Sets the maximum value a computed boost can reach.
  8084. @member ejs.CustomFiltersScoreQuery
  8085. @param {Double} max A positive <code>double</code> value.
  8086. @returns {Object} returns <code>this</code> so that calls can be chained.
  8087. */
  8088. maxBoost: function (max) {
  8089. if (max == null) {
  8090. return query.custom_filters_score.max_boost;
  8091. }
  8092. query.custom_filters_score.max_boost = max;
  8093. return this;
  8094. },
  8095. /**
  8096. Sets the boost value of the <code>Query</code>.
  8097. @member ejs.CustomFiltersScoreQuery
  8098. @param {Double} boost A positive <code>double</code> value.
  8099. @returns {Object} returns <code>this</code> so that calls can be chained.
  8100. */
  8101. boost: function (boost) {
  8102. if (boost == null) {
  8103. return query.custom_filters_score.boost;
  8104. }
  8105. query.custom_filters_score.boost = boost;
  8106. return this;
  8107. },
  8108. /**
  8109. Allows you to serialize this object into a JSON encoded string.
  8110. @member ejs.CustomFiltersScoreQuery
  8111. @returns {String} returns this object as a serialized JSON string.
  8112. */
  8113. toString: function () {
  8114. return JSON.stringify(query);
  8115. },
  8116. /**
  8117. The type of ejs object. For internal use only.
  8118. @member ejs.CustomFiltersScoreQuery
  8119. @returns {String} the type of object
  8120. */
  8121. _type: function () {
  8122. return 'query';
  8123. },
  8124. /**
  8125. Retrieves the internal <code>query</code> object. This is typically used by
  8126. internal API functions so use with caution.
  8127. @member ejs.CustomFiltersScoreQuery
  8128. @returns {String} returns this object's internal <code>query</code> property.
  8129. */
  8130. _self: function () {
  8131. return query;
  8132. }
  8133. };
  8134. };
  8135. /**
  8136. @class
  8137. <p>A query that wraps another query and customize the scoring of it
  8138. optionally with a computation derived from other field values in the
  8139. doc (numeric ones) using script expression.</p>
  8140. @name ejs.CustomScoreQuery
  8141. @desc
  8142. Scores a query based on a script.
  8143. @param {Object} qry A valid query object.
  8144. @param {String} script A valid script expression.
  8145. */
  8146. ejs.CustomScoreQuery = function (qry, script) {
  8147. if (!isQuery(qry)) {
  8148. throw new TypeError('Argument must be a Query');
  8149. }
  8150. /**
  8151. The internal query object. <code>Use _self()</code>
  8152. @member ejs.CustomScoreQuery
  8153. @property {Object} query
  8154. */
  8155. var query = {
  8156. custom_score: {
  8157. query: qry._self(),
  8158. script: script
  8159. }
  8160. };
  8161. return {
  8162. /**
  8163. Sets the query to be apply the custom score to.
  8164. @member ejs.CustomScoreQuery
  8165. @param {Object} q A valid Query object
  8166. @returns {Object} returns <code>this</code> so that calls can be chained.
  8167. */
  8168. query: function (q) {
  8169. if (q == null) {
  8170. return query.custom_score.query;
  8171. }
  8172. if (!isQuery(q)) {
  8173. throw new TypeError('Argument must be a Query');
  8174. }
  8175. query.custom_score.query = q._self();
  8176. return this;
  8177. },
  8178. /**
  8179. Sets the script that calculates the custom score
  8180. @member ejs.CustomScoreQuery
  8181. @param {String} s A valid script expression
  8182. @returns {Object} returns <code>this</code> so that calls can be chained.
  8183. */
  8184. script: function (s) {
  8185. if (s == null) {
  8186. return query.custom_score.script;
  8187. }
  8188. query.custom_score.script = s;
  8189. return this;
  8190. },
  8191. /**
  8192. Sets parameters that will be applied to the script. Overwrites
  8193. any existing params.
  8194. @member ejs.CustomScoreQuery
  8195. @param {Object} p An object where the keys are the parameter name and
  8196. values are the parameter value.
  8197. @returns {Object} returns <code>this</code> so that calls can be chained.
  8198. */
  8199. params: function (p) {
  8200. if (p == null) {
  8201. return query.custom_score.params;
  8202. }
  8203. query.custom_score.params = p;
  8204. return this;
  8205. },
  8206. /**
  8207. Sets the language used in the script.
  8208. @member ejs.CustomScoreQuery
  8209. @param {String} l The script language, defatuls to mvel.
  8210. @returns {Object} returns <code>this</code> so that calls can be chained.
  8211. */
  8212. lang: function (l) {
  8213. if (l == null) {
  8214. return query.custom_score.lang;
  8215. }
  8216. query.custom_score.lang = l;
  8217. return this;
  8218. },
  8219. /**
  8220. Sets the boost value of the <code>Query</code>.
  8221. @member ejs.CustomScoreQuery
  8222. @param {Double} boost A positive <code>double</code> value.
  8223. @returns {Object} returns <code>this</code> so that calls can be chained.
  8224. */
  8225. boost: function (boost) {
  8226. if (boost == null) {
  8227. return query.custom_score.boost;
  8228. }
  8229. query.custom_score.boost = boost;
  8230. return this;
  8231. },
  8232. /**
  8233. Allows you to serialize this object into a JSON encoded string.
  8234. @member ejs.CustomScoreQuery
  8235. @returns {String} returns this object as a serialized JSON string.
  8236. */
  8237. toString: function () {
  8238. return JSON.stringify(query);
  8239. },
  8240. /**
  8241. The type of ejs object. For internal use only.
  8242. @member ejs.CustomScoreQuery
  8243. @returns {String} the type of object
  8244. */
  8245. _type: function () {
  8246. return 'query';
  8247. },
  8248. /**
  8249. Retrieves the internal <code>query</code> object. This is typically used by
  8250. internal API functions so use with caution.
  8251. @member ejs.CustomScoreQuery
  8252. @returns {String} returns this object's internal <code>query</code> property.
  8253. */
  8254. _self: function () {
  8255. return query;
  8256. }
  8257. };
  8258. };
  8259. /**
  8260. @class
  8261. A query that generates the union of documents produced by its subqueries, and
  8262. that scores each document with the maximum score for that document as produced
  8263. by any subquery, plus a tie breaking increment for any additional matching
  8264. subqueries.
  8265. @name ejs.DisMaxQuery
  8266. @desc
  8267. A query that generates the union of documents produced by its subqueries such
  8268. as <code>termQuerys, phraseQuerys</code>, <code>boolQuerys</code>, etc.
  8269. */
  8270. ejs.DisMaxQuery = function () {
  8271. /**
  8272. The internal query object. <code>Use _self()</code>
  8273. @member ejs.DisMaxQuery
  8274. @property {Object} query
  8275. */
  8276. var query = {
  8277. dis_max: {}
  8278. };
  8279. return {
  8280. /**
  8281. Updates the queries. If passed a single Query, it is added to the
  8282. list of existing queries. If passed an array of Queries, it
  8283. replaces all existing values.
  8284. @member ejs.DisMaxQuery
  8285. @param {Query || Array} qs A single Query or an array of Queries
  8286. @returns {Object} returns <code>this</code> so that calls can be chained.
  8287. */
  8288. queries: function (qs) {
  8289. var i, len;
  8290. if (qs == null) {
  8291. return query.dis_max.queries;
  8292. }
  8293. if (query.dis_max.queries == null) {
  8294. query.dis_max.queries = [];
  8295. }
  8296. if (isQuery(qs)) {
  8297. query.dis_max.queries.push(qs._self());
  8298. } else if (isArray(qs)) {
  8299. query.dis_max.queries = [];
  8300. for (i = 0, len = qs.length; i < len; i++) {
  8301. if (!isQuery(qs[i])) {
  8302. throw new TypeError('Argument must be array of Queries');
  8303. }
  8304. query.dis_max.queries.push(qs[i]._self());
  8305. }
  8306. } else {
  8307. throw new TypeError('Argument must be a Query or array of Queries');
  8308. }
  8309. return this;
  8310. },
  8311. /**
  8312. Sets the boost value of the <code>Query</code>. Default: 1.0.
  8313. @member ejs.DisMaxQuery
  8314. @param {Double} boost A positive <code>double</code> value.
  8315. @returns {Object} returns <code>this</code> so that calls can be chained.
  8316. */
  8317. boost: function (boost) {
  8318. if (boost == null) {
  8319. return query.dis_max.boost;
  8320. }
  8321. query.dis_max.boost = boost;
  8322. return this;
  8323. },
  8324. /**
  8325. <p>The tie breaker value.</p>
  8326. <p>The tie breaker capability allows results that include the same term in multiple
  8327. fields to be judged better than results that include this term in only the best of those
  8328. multiple fields, without confusing this with the better case of two different terms in
  8329. the multiple fields.</p>
  8330. <p>Default: 0.0.</p>
  8331. @member ejs.DisMaxQuery
  8332. @param {Double} tieBreaker A positive <code>double</code> value.
  8333. @returns {Object} returns <code>this</code> so that calls can be chained.
  8334. */
  8335. tieBreaker: function (tieBreaker) {
  8336. if (tieBreaker == null) {
  8337. return query.dis_max.tie_breaker;
  8338. }
  8339. query.dis_max.tie_breaker = tieBreaker;
  8340. return this;
  8341. },
  8342. /**
  8343. Allows you to serialize this object into a JSON encoded string.
  8344. @member ejs.DisMaxQuery
  8345. @returns {String} returns this object as a serialized JSON string.
  8346. */
  8347. toString: function () {
  8348. return JSON.stringify(query);
  8349. },
  8350. /**
  8351. The type of ejs object. For internal use only.
  8352. @member ejs.DisMaxQuery
  8353. @returns {String} the type of object
  8354. */
  8355. _type: function () {
  8356. return 'query';
  8357. },
  8358. /**
  8359. Retrieves the internal <code>query</code> object. This is typically used by
  8360. internal API functions so use with caution.
  8361. @member ejs.DisMaxQuery
  8362. @returns {String} returns this object's internal <code>query</code> property.
  8363. */
  8364. _self: function () {
  8365. return query;
  8366. }
  8367. };
  8368. };
  8369. /**
  8370. @class
  8371. <p>Wrapper to allow SpanQuery objects participate in composite single-field
  8372. SpanQueries by 'lying' about their search field. That is, the masked
  8373. SpanQuery will function as normal, but when asked for the field it
  8374. queries against, it will return the value specified as the masked field vs.
  8375. the real field used in the wrapped span query.</p>
  8376. @name ejs.FieldMaskingSpanQuery
  8377. @desc
  8378. Wraps a SpanQuery and hides the real field being searched across.
  8379. @param {Query} spanQry A valid SpanQuery
  8380. @param {Integer} field the maximum field position in a match.
  8381. */
  8382. ejs.FieldMaskingSpanQuery = function (spanQry, field) {
  8383. if (!isQuery(spanQry)) {
  8384. throw new TypeError('Argument must be a SpanQuery');
  8385. }
  8386. /**
  8387. The internal query object. <code>Use _self()</code>
  8388. @member ejs.FieldMaskingSpanQuery
  8389. @property {Object} query
  8390. */
  8391. var query = {
  8392. field_masking_span: {
  8393. query: spanQry._self(),
  8394. field: field
  8395. }
  8396. };
  8397. return {
  8398. /**
  8399. Sets the span query to wrap.
  8400. @member ejs.FieldMaskingSpanQuery
  8401. @param {Query} spanQuery Any valid span type query.
  8402. @returns {Object} returns <code>this</code> so that calls can be chained.
  8403. */
  8404. query: function (spanQuery) {
  8405. if (spanQuery == null) {
  8406. return query.field_masking_span.query;
  8407. }
  8408. if (!isQuery(spanQuery)) {
  8409. throw new TypeError('Argument must be a SpanQuery');
  8410. }
  8411. query.field_masking_span.query = spanQuery._self();
  8412. return this;
  8413. },
  8414. /**
  8415. Sets the value of the "masked" field.
  8416. @member ejs.FieldMaskingSpanQuery
  8417. @param {String} f A field name the wrapped span query should use
  8418. @returns {Object} returns <code>this</code> so that calls can be chained.
  8419. */
  8420. field: function (f) {
  8421. if (f == null) {
  8422. return query.field_masking_span.field;
  8423. }
  8424. query.field_masking_span.field = f;
  8425. return this;
  8426. },
  8427. /**
  8428. Sets the boost value of the <code>Query</code>.
  8429. @member ejs.FieldMaskingSpanQuery
  8430. @param {Double} boost A positive <code>double</code> value.
  8431. @returns {Object} returns <code>this</code> so that calls can be chained.
  8432. */
  8433. boost: function (boost) {
  8434. if (boost == null) {
  8435. return query.field_masking_span.boost;
  8436. }
  8437. query.field_masking_span.boost = boost;
  8438. return this;
  8439. },
  8440. /**
  8441. Allows you to serialize this object into a JSON encoded string.
  8442. @member ejs.FieldMaskingSpanQuery
  8443. @returns {String} returns this object as a serialized JSON string.
  8444. */
  8445. toString: function () {
  8446. return JSON.stringify(query);
  8447. },
  8448. /**
  8449. The type of ejs object. For internal use only.
  8450. @member ejs.FieldMaskingSpanQuery
  8451. @returns {String} the type of object
  8452. */
  8453. _type: function () {
  8454. return 'query';
  8455. },
  8456. /**
  8457. Retrieves the internal <code>query</code> object. This is typically used by
  8458. internal API functions so use with caution.
  8459. @member ejs.FieldMaskingSpanQuery
  8460. @returns {String} returns this object's internal <code>query</code> property.
  8461. */
  8462. _self: function () {
  8463. return query;
  8464. }
  8465. };
  8466. };
  8467. /**
  8468. @class
  8469. A query that executes against a given field or document property. It is a simplified version
  8470. of the <code><a href="/jsdocs/ejs.queryString.html">queryString</a></code> object.
  8471. @name ejs.FieldQuery
  8472. @desc
  8473. A query that executes against a given field or document property.
  8474. @param {String} field The field or document property to search against.
  8475. @param {String} qstr The value to match.
  8476. */
  8477. ejs.FieldQuery = function (field, qstr) {
  8478. /**
  8479. The internal query object. <code>Use get()</code>
  8480. @member ejs.FieldQuery
  8481. @property {Object} query
  8482. */
  8483. var query = {
  8484. field: {}
  8485. };
  8486. query.field[field] = {
  8487. query: qstr
  8488. };
  8489. return {
  8490. /**
  8491. The field to run the query against.
  8492. @member ejs.FieldQuery
  8493. @param {String} f A single field name.
  8494. @returns {Object} returns <code>this</code> so that calls can be chained.
  8495. */
  8496. field: function (f) {
  8497. var oldValue = query.field[field];
  8498. if (f == null) {
  8499. return field;
  8500. }
  8501. delete query.field[field];
  8502. field = f;
  8503. query.field[f] = oldValue;
  8504. return this;
  8505. },
  8506. /**
  8507. <p>Sets the query string.</p>
  8508. @member ejs.FieldQuery
  8509. @param {String} q The lucene query string.
  8510. @returns {Object} returns <code>this</code> so that calls can be chained.
  8511. */
  8512. query: function (q) {
  8513. if (q == null) {
  8514. return query.field[field].query;
  8515. }
  8516. query.field[field].query = q;
  8517. return this;
  8518. },
  8519. /**
  8520. <p>Set the default <code>Boolean</code> operator.</p>
  8521. <p>This operator is used to join individual query terms when no operator is
  8522. explicity used in the query string (i.e., <code>this AND that</code>).
  8523. Defaults to <code>OR</code> (<em>same as Google</em>).</p>
  8524. @member ejs.FieldQuery
  8525. @param {String} op The operator, AND or OR.
  8526. @returns {Object} returns <code>this</code> so that calls can be chained.
  8527. */
  8528. defaultOperator: function (op) {
  8529. if (op == null) {
  8530. return query.field[field].default_operator;
  8531. }
  8532. op = op.toUpperCase();
  8533. if (op === 'AND' || op === 'OR') {
  8534. query.field[field].default_operator = op;
  8535. }
  8536. return this;
  8537. },
  8538. /**
  8539. <p>Sets the analyzer name used to analyze the <code>Query</code> object.</p>
  8540. @member ejs.FieldQuery
  8541. @param {String} analyzer A valid analyzer name.
  8542. @returns {Object} returns <code>this</code> so that calls can be chained.
  8543. */
  8544. analyzer: function (analyzer) {
  8545. if (analyzer == null) {
  8546. return query.field[field].analyzer;
  8547. }
  8548. query.field[field].analyzer = analyzer;
  8549. return this;
  8550. },
  8551. /**
  8552. <p>Sets the quote analyzer name used to analyze the <code>query</code>
  8553. when in quoted text.</p>
  8554. @member ejs.FieldQuery
  8555. @param {String} analyzer A valid analyzer name.
  8556. @returns {Object} returns <code>this</code> so that calls can be chained.
  8557. */
  8558. quoteAnalyzer: function (analyzer) {
  8559. if (analyzer == null) {
  8560. return query.field[field].quote_analyzer;
  8561. }
  8562. query.field[field].quote_analyzer = analyzer;
  8563. return this;
  8564. },
  8565. /**
  8566. <p>Sets whether or not we should auto generate phrase queries *if* the
  8567. analyzer returns more than one term. Default: false.</p>
  8568. @member ejs.FieldQuery
  8569. @param {Boolean} trueFalse A <code>true/false</code> value.
  8570. @returns {Object} returns <code>this</code> so that calls can be chained.
  8571. */
  8572. autoGeneratePhraseQueries: function (trueFalse) {
  8573. if (trueFalse == null) {
  8574. return query.field[field].auto_generate_phrase_queries;
  8575. }
  8576. query.field[field].auto_generate_phrase_queries = trueFalse;
  8577. return this;
  8578. },
  8579. /**
  8580. <p>Sets whether or not wildcard characters (* and ?) are allowed as the
  8581. first character of the <code>Query</code>.</p>
  8582. <p>Default: <code>true</code>.</p>
  8583. @member ejs.FieldQuery
  8584. @param {Boolean} trueFalse A <code>true/false</code> value.
  8585. @returns {Object} returns <code>this</code> so that calls can be chained.
  8586. */
  8587. allowLeadingWildcard: function (trueFalse) {
  8588. if (trueFalse == null) {
  8589. return query.field[field].allow_leading_wildcard;
  8590. }
  8591. query.field[field].allow_leading_wildcard = trueFalse;
  8592. return this;
  8593. },
  8594. /**
  8595. <p>Sets whether or not terms from <code>wildcard, prefix, fuzzy,</code> and
  8596. <code>range</code> queries should automatically be lowercased in the <code>Query</code>
  8597. since they are not analyzed.</p>
  8598. <p>Default: <code>true</code>.</p>
  8599. @member ejs.FieldQuery
  8600. @param {Boolean} trueFalse A <code>true/false</code> value.
  8601. @returns {Object} returns <code>this</code> so that calls can be chained.
  8602. */
  8603. lowercaseExpandedTerms: function (trueFalse) {
  8604. if (trueFalse == null) {
  8605. return query.field[field].lowercase_expanded_terms;
  8606. }
  8607. query.field[field].lowercase_expanded_terms = trueFalse;
  8608. return this;
  8609. },
  8610. /**
  8611. <p>Sets whether or not position increments will be used in the
  8612. <code>Query</code>.</p>
  8613. <p>Default: <code>true</code>.</p>
  8614. @member ejs.FieldQuery
  8615. @param {Boolean} trueFalse A <code>true/false</code> value.
  8616. @returns {Object} returns <code>this</code> so that calls can be chained.
  8617. */
  8618. enablePositionIncrements: function (trueFalse) {
  8619. if (trueFalse == null) {
  8620. return query.field[field].enable_position_increments;
  8621. }
  8622. query.field[field].enable_position_increments = trueFalse;
  8623. return this;
  8624. },
  8625. /**
  8626. <p>Set the minimum similarity for fuzzy queries.</p>
  8627. <p>Default: <code>0.5</code>.</p>
  8628. @member ejs.FieldQuery
  8629. @param {Double} minSim A <code>double</code> value between 0 and 1.
  8630. @returns {Object} returns <code>this</code> so that calls can be chained.
  8631. */
  8632. fuzzyMinSim: function (minSim) {
  8633. if (minSim == null) {
  8634. return query.field[field].fuzzy_min_sim;
  8635. }
  8636. query.field[field].fuzzy_min_sim = minSim;
  8637. return this;
  8638. },
  8639. /**
  8640. <p>Sets the boost value of the <code>Query</code>.</p>
  8641. <p>Default: <code>1.0</code>.</p>
  8642. @member ejs.FieldQuery
  8643. @param {Double} boost A positive <code>double</code> value.
  8644. @returns {Object} returns <code>this</code> so that calls can be chained.
  8645. */
  8646. boost: function (boost) {
  8647. if (boost == null) {
  8648. return query.field[field].boost;
  8649. }
  8650. query.field[field].boost = boost;
  8651. return this;
  8652. },
  8653. /**
  8654. <p>Sets the prefix length for fuzzy queries.</p>
  8655. <p>Default: <code>0</code>.</p>
  8656. @member ejs.FieldQuery
  8657. @param {Integer} fuzzLen A positive <code>integer</code> value.
  8658. @returns {Object} returns <code>this</code> so that calls can be chained.
  8659. */
  8660. fuzzyPrefixLength: function (fuzzLen) {
  8661. if (fuzzLen == null) {
  8662. return query.field[field].fuzzy_prefix_length;
  8663. }
  8664. query.field[field].fuzzy_prefix_length = fuzzLen;
  8665. return this;
  8666. },
  8667. /**
  8668. <p>Sets the max number of term expansions for fuzzy queries.</p>
  8669. @member ejs.FieldQuery
  8670. @param {Integer} max A positive <code>integer</code> value.
  8671. @returns {Object} returns <code>this</code> so that calls can be chained.
  8672. */
  8673. fuzzyMaxExpansions: function (max) {
  8674. if (max == null) {
  8675. return query.field[field].fuzzy_max_expansions;
  8676. }
  8677. query.field[field].fuzzy_max_expansions = max;
  8678. return this;
  8679. },
  8680. /**
  8681. <p>Sets fuzzy rewrite method.<p>
  8682. <p>Valid values are:</p>
  8683. <dl>
  8684. <dd><code>constant_score_auto</code> - tries to pick the best constant-score rewrite
  8685. method based on term and document counts from the query</dd>
  8686. <dd><code>scoring_boolean</code> - translates each term into boolean should and
  8687. keeps the scores as computed by the query</dd>
  8688. <dd><code>constant_score_boolean</code> - same as scoring_boolean, expect no scores
  8689. are computed.</dd>
  8690. <dd><code>constant_score_filter</code> - first creates a private Filter, by visiting
  8691. each term in sequence and marking all docs for that term</dd>
  8692. <dd><code>top_terms_boost_N</code> - first translates each term into boolean should
  8693. and scores are only computed as the boost using the top <code>N</code>
  8694. scoring terms. Replace <code>N</code> with an integer value.</dd>
  8695. <dd><code>top_terms_N</code> - first translates each term into boolean should
  8696. and keeps the scores as computed by the query. Only the top <code>N</code>
  8697. scoring terms are used. Replace <code>N</code> with an integer value.</dd>
  8698. </dl>
  8699. <p>Default is <code>constant_score_auto</code>.</p>
  8700. <p>This is an advanced option, use with care.</p>
  8701. @member ejs.FieldQuery
  8702. @param {String} m The rewrite method as a string.
  8703. @returns {Object} returns <code>this</code> so that calls can be chained.
  8704. */
  8705. fuzzyRewrite: function (m) {
  8706. if (m == null) {
  8707. return query.field[field].fuzzy_rewrite;
  8708. }
  8709. m = m.toLowerCase();
  8710. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  8711. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  8712. m.indexOf('top_terms_boost_') === 0 ||
  8713. m.indexOf('top_terms_') === 0) {
  8714. query.field[field].fuzzy_rewrite = m;
  8715. }
  8716. return this;
  8717. },
  8718. /**
  8719. <p>Sets rewrite method.</p>
  8720. <p>Valid values are:</p>
  8721. <dl>
  8722. <dd><code>constant_score_auto</code> - tries to pick the best constant-score rewrite
  8723. method based on term and document counts from the query</dd>
  8724. <dd><code>scoring_boolean</code> - translates each term into boolean should and
  8725. keeps the scores as computed by the query</dd>
  8726. <dd><code>constant_score_boolean</code> - same as scoring_boolean, expect no scores
  8727. are computed.</p>
  8728. <dd><code>constant_score_filter</code> - first creates a private Filter, by visiting
  8729. each term in sequence and marking all docs for that term</dd>
  8730. <dd><code>top_terms_boost_N</code> - first translates each term into boolean should
  8731. and scores are only computed as the boost using the top <code>N</code>
  8732. scoring terms. Replace <code>N</code> with an integer value.</dd>
  8733. <dd><code>top_terms_N</code> - first translates each term into boolean should
  8734. and keeps the scores as computed by the query. Only the top <code>N</code>
  8735. scoring terms are used. Replace <code>N</code> with an integer value.</dd>
  8736. </dl>
  8737. <p>Default is <code>constant_score_auto</code>.</p>
  8738. This is an advanced option, use with care.
  8739. @member ejs.FieldQuery
  8740. @param {String} m The rewrite method as a string.
  8741. @returns {Object} returns <code>this</code> so that calls can be chained.
  8742. */
  8743. rewrite: function (m) {
  8744. if (m == null) {
  8745. return query.field[field].rewrite;
  8746. }
  8747. m = m.toLowerCase();
  8748. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  8749. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  8750. m.indexOf('top_terms_boost_') === 0 ||
  8751. m.indexOf('top_terms_') === 0) {
  8752. query.field[field].rewrite = m;
  8753. }
  8754. return this;
  8755. },
  8756. /**
  8757. <p>Sets the suffix to automatically add to the field name when
  8758. performing a quoted search.</p>
  8759. @member ejs.FieldQuery
  8760. @param {String} s The suffix as a string.
  8761. @returns {Object} returns <code>this</code> so that calls can be chained.
  8762. */
  8763. quoteFieldSuffix: function (s) {
  8764. if (s == null) {
  8765. return query.field[field].quote_field_suffix;
  8766. }
  8767. query.field[field].quote_field_suffix = s;
  8768. return this;
  8769. },
  8770. /**
  8771. <p>Sets the default slop for phrases. If zero, then exact phrase matches
  8772. are required.</p>
  8773. <p>Default: <code>0</code>.</p>
  8774. @member ejs.FieldQuery
  8775. @param {Integer} slop A positive <code>integer</code> value.
  8776. @returns {Object} returns <code>this</code> so that calls can be chained.
  8777. */
  8778. phraseSlop: function (slop) {
  8779. if (slop == null) {
  8780. return query.field[field].phrase_slop;
  8781. }
  8782. query.field[field].phrase_slop = slop;
  8783. return this;
  8784. },
  8785. /**
  8786. <p>Sets whether or not we should attempt to analyzed wilcard terms in the
  8787. <code>Query</code>.</p>
  8788. <p>By default, wildcard terms are not analyzed. Analysis of wildcard characters is not perfect.</p>
  8789. <p>Default: <code>false</code>.</p>
  8790. @member ejs.FieldQuery
  8791. @param {Boolean} trueFalse A <code>true/false</code> value.
  8792. @returns {Object} returns <code>this</code> so that calls can be chained.
  8793. */
  8794. analyzeWildcard: function (trueFalse) {
  8795. if (trueFalse == null) {
  8796. return query.field[field].analyze_wildcard;
  8797. }
  8798. query.field[field].analyze_wildcard = trueFalse;
  8799. return this;
  8800. },
  8801. /**
  8802. <p>If the query string should be escaped or not.</p>
  8803. @member ejs.FieldQuery
  8804. @param {Boolean} trueFalse A <code>true/false</code> value.
  8805. @returns {Object} returns <code>this</code> so that calls can be chained.
  8806. */
  8807. escape: function (trueFalse) {
  8808. if (trueFalse == null) {
  8809. return query.field[field].escape;
  8810. }
  8811. query.field[field].escape = trueFalse;
  8812. return this;
  8813. },
  8814. /**
  8815. <p>Sets a percent value controlling how many <code>should</code> clauses in the
  8816. resulting <code>Query</code> should match.</p>
  8817. @member ejs.FieldQuery
  8818. @param {Integer} minMatch An <code>integer</code> between 0 and 100.
  8819. @returns {Object} returns <code>this</code> so that calls can be chained.
  8820. */
  8821. minimumShouldMatch: function (minMatch) {
  8822. if (minMatch == null) {
  8823. return query.field[field].minimum_should_match;
  8824. }
  8825. query.field[field].minimum_should_match = minMatch;
  8826. return this;
  8827. },
  8828. /**
  8829. <p>Allows you to serialize this object into a JSON encoded string.</p>
  8830. @member ejs.FieldQuery
  8831. @returns {String} returns this object as a serialized JSON string.
  8832. */
  8833. toString: function () {
  8834. return JSON.stringify(query);
  8835. },
  8836. /**
  8837. <p>The type of ejs object. For internal use only.</p>
  8838. @member ejs.FieldQuery
  8839. @returns {String} the type of object
  8840. */
  8841. _type: function () {
  8842. return 'query';
  8843. },
  8844. /**
  8845. <p>Retrieves the internal <code>query</code> object. This is typically used by
  8846. internal API functions so use with caution.</p>
  8847. @member ejs.FieldQuery
  8848. @returns {String} returns this object's internal <code>query</code> property.
  8849. */
  8850. _self: function () {
  8851. return query;
  8852. }
  8853. };
  8854. };
  8855. /**
  8856. @class
  8857. <p>Filter queries allow you to restrict the results returned by a query. There are
  8858. several different types of filters that can be applied
  8859. (see <a href="/jsdocs/ejs.filter.html">filter</a> module). A <code>filterQuery</code>
  8860. takes a <code>Query</code> and a <code>Filter</code> object as arguments and constructs
  8861. a new <code>Query</code> that is then used for the search.</p>
  8862. @name ejs.FilteredQuery
  8863. @desc
  8864. <p>A query that applies a filter to the results of another query.</p>
  8865. @param {Object} someQuery a valid <code>Query</code> object
  8866. @param {Object} someFilter a valid <code>Filter</code> object. This parameter
  8867. is optional.
  8868. */
  8869. ejs.FilteredQuery = function (someQuery, someFilter) {
  8870. if (!isQuery(someQuery)) {
  8871. throw new TypeError('Argument must be a Query');
  8872. }
  8873. if (someFilter != null && !isFilter(someFilter)) {
  8874. throw new TypeError('Argument must be a Filter');
  8875. }
  8876. /**
  8877. The internal query object. Use <code>_self()</code>
  8878. @member ejs.FilteredQuery
  8879. @property {Object} query
  8880. */
  8881. var query = {
  8882. filtered: {
  8883. query: someQuery._self()
  8884. }
  8885. };
  8886. if (someFilter != null) {
  8887. query.filtered.filter = someFilter._self();
  8888. }
  8889. return {
  8890. /**
  8891. <p>Adds the query to apply a constant score to.</p>
  8892. @member ejs.FilteredQuery
  8893. @param {Object} oQuery A valid <code>Query</code> object
  8894. @returns {Object} returns <code>this</code> so that calls can be chained.
  8895. */
  8896. query: function (oQuery) {
  8897. if (oQuery == null) {
  8898. return query.filtered.query;
  8899. }
  8900. if (!isQuery(oQuery)) {
  8901. throw new TypeError('Argument must be a Query');
  8902. }
  8903. query.filtered.query = oQuery._self();
  8904. return this;
  8905. },
  8906. /**
  8907. <p>Adds the filter to apply a constant score to.</p>
  8908. @member ejs.FilteredQuery
  8909. @param {Object} oFilter A valid <code>Filter</code> object
  8910. @returns {Object} returns <code>this</code> so that calls can be chained.
  8911. */
  8912. filter: function (oFilter) {
  8913. if (oFilter == null) {
  8914. return query.filtered.filter;
  8915. }
  8916. if (!isFilter(oFilter)) {
  8917. throw new TypeError('Argument must be a Filter');
  8918. }
  8919. query.filtered.filter = oFilter._self();
  8920. return this;
  8921. },
  8922. /**
  8923. <p>Sets the filter strategy.</p>
  8924. <p>The strategy defines how the filter is applied during document collection.
  8925. Valid values are:</p>
  8926. <dl>
  8927. <dd><code>query_first</code> - advance query scorer first then filter</dd>
  8928. <dd><code>random_access_random</code> - random access filter</dd>
  8929. <dd><code>leap_frog</code> - query scorer and filter "leap-frog", query goes first</dd>
  8930. <dd><code>leap_frog_filter_first</code> - same as <code>leap_frog</code>, but filter goes first</dd>
  8931. <dd><code>random_access_N</code> - replace <code>N</code> with integer, same as random access
  8932. except you can specify a custom threshold</dd>
  8933. </dl>
  8934. <p>This is an advanced setting, use with care.</p>
  8935. @member ejs.FilteredQuery
  8936. @param {String} strategy The strategy as a string.
  8937. @returns {Object} returns <code>this</code> so that calls can be chained.
  8938. */
  8939. strategy: function (strategy) {
  8940. if (strategy == null) {
  8941. return query.filtered.strategy;
  8942. }
  8943. strategy = strategy.toLowerCase();
  8944. if (strategy === 'query_first' || strategy === 'random_access_always' ||
  8945. strategy === 'leap_frog' || strategy === 'leap_frog_filter_first' ||
  8946. strategy.indexOf('random_access_') === 0) {
  8947. query.filtered.strategy = strategy;
  8948. }
  8949. return this;
  8950. },
  8951. /**
  8952. <p>Enables caching of the filter.</p>
  8953. @member ejs.FilteredQuery
  8954. @param {Boolean} trueFalse A boolean value.
  8955. @returns {Object} returns <code>this</code> so that calls can be chained.
  8956. */
  8957. cache: function (trueFalse) {
  8958. if (trueFalse == null) {
  8959. return query.filtered._cache;
  8960. }
  8961. query.filtered._cache = trueFalse;
  8962. return this;
  8963. },
  8964. /**
  8965. <p>Set the cache key.</p>
  8966. @member ejs.FilteredQuery
  8967. @param {String} k A string cache key.
  8968. @returns {Object} returns <code>this</code> so that calls can be chained.
  8969. */
  8970. cacheKey: function (k) {
  8971. if (k == null) {
  8972. return query.filtered._cache_key;
  8973. }
  8974. query.filtered._cache_key = k;
  8975. return this;
  8976. },
  8977. /**
  8978. <p>Sets the boost value of the <code>Query</code>.</p>
  8979. @member ejs.FilteredQuery
  8980. @param {Double} boost A positive <code>double</code> value.
  8981. @returns {Object} returns <code>this</code> so that calls can be chained.
  8982. */
  8983. boost: function (boost) {
  8984. if (boost == null) {
  8985. return query.filtered.boost;
  8986. }
  8987. query.filtered.boost = boost;
  8988. return this;
  8989. },
  8990. /**
  8991. <p>Converts this object to a json string</p>
  8992. @member ejs.FilteredQuery
  8993. @returns {Object} string
  8994. */
  8995. toString: function () {
  8996. return JSON.stringify(query);
  8997. },
  8998. /**
  8999. <p>The type of ejs object. For internal use only.</p>
  9000. @member ejs.FilteredQuery
  9001. @returns {String} the type of object
  9002. */
  9003. _type: function () {
  9004. return 'query';
  9005. },
  9006. /**
  9007. <p>returns the query object.</p>
  9008. @member ejs.FilteredQuery
  9009. @returns {Object} query object
  9010. */
  9011. _self: function () {
  9012. return query;
  9013. }
  9014. };
  9015. };
  9016. /**
  9017. @class
  9018. <p>The fuzzy_like_this_field query is the same as the fuzzy_like_this
  9019. query, except that it runs against a single field. It provides nicer query
  9020. DSL over the generic fuzzy_like_this query, and support typed fields
  9021. query (automatically wraps typed fields with type filter to match only on
  9022. the specific type).</p>
  9023. <p>Fuzzifies ALL terms provided as strings and then picks the best n
  9024. differentiating terms. In effect this mixes the behaviour of FuzzyQuery and
  9025. MoreLikeThis but with special consideration of fuzzy scoring factors. This
  9026. generally produces good results for queries where users may provide details
  9027. in a number of fields and have no knowledge of boolean query syntax and
  9028. also want a degree of fuzzy matching and a fast query.</p>
  9029. <p>For each source term the fuzzy variants are held in a BooleanQuery with
  9030. no coord factor (because we are not looking for matches on multiple variants
  9031. in any one doc). Additionally, a specialized TermQuery is used for variants
  9032. and does not use that variant term’s IDF because this would favour rarer
  9033. terms eg misspellings. Instead, all variants use the same IDF
  9034. ranking (the one for the source query term) and this is factored into the
  9035. variant’s boost. If the source query term does not exist in the index the
  9036. average IDF of the variants is used.</p>
  9037. @name ejs.FuzzyLikeThisFieldQuery
  9038. @desc
  9039. <p>Constructs a query where each documents returned are “like” provided text</p>
  9040. @param {String} field The field to run the query against.
  9041. @param {String} likeText The text to find documents like it.
  9042. */
  9043. ejs.FuzzyLikeThisFieldQuery = function (field, likeText) {
  9044. /**
  9045. The internal Query object. Use <code>get()</code>.
  9046. @member ejs.FuzzyLikeThisFieldQuery
  9047. @property {Object} query
  9048. */
  9049. var query = {
  9050. flt_field: {}
  9051. };
  9052. query.flt_field[field] = {
  9053. like_text: likeText
  9054. };
  9055. return {
  9056. /**
  9057. The field to run the query against.
  9058. @member ejs.FuzzyLikeThisFieldQuery
  9059. @param {String} f A single field name.
  9060. @returns {Object} returns <code>this</code> so that calls can be chained.
  9061. */
  9062. field: function (f) {
  9063. var oldValue = query.flt_field[field];
  9064. if (f == null) {
  9065. return field;
  9066. }
  9067. delete query.flt_field[field];
  9068. field = f;
  9069. query.flt_field[f] = oldValue;
  9070. return this;
  9071. },
  9072. /**
  9073. The text to find documents like
  9074. @member ejs.FuzzyLikeThisFieldQuery
  9075. @param {String} s A text string.
  9076. @returns {Object} returns <code>this</code> so that calls can be chained.
  9077. */
  9078. likeText: function (txt) {
  9079. if (txt == null) {
  9080. return query.flt_field[field].like_text;
  9081. }
  9082. query.flt_field[field].like_text = txt;
  9083. return this;
  9084. },
  9085. /**
  9086. Should term frequency be ignored. Defaults to false.
  9087. @member ejs.FuzzyLikeThisFieldQuery
  9088. @param {Boolean} trueFalse A boolean value
  9089. @returns {Object} returns <code>this</code> so that calls can be chained.
  9090. */
  9091. ignoreTf: function (trueFalse) {
  9092. if (trueFalse == null) {
  9093. return query.flt_field[field].ignore_tf;
  9094. }
  9095. query.flt_field[field].ignore_tf = trueFalse;
  9096. return this;
  9097. },
  9098. /**
  9099. The maximum number of query terms that will be included in any
  9100. generated query. Defaults to 25.
  9101. @member ejs.FuzzyLikeThisFieldQuery
  9102. @param {Integer} max A positive integer value.
  9103. @returns {Object} returns <code>this</code> so that calls can be chained.
  9104. */
  9105. maxQueryTerms: function (max) {
  9106. if (max == null) {
  9107. return query.flt_field[field].max_query_terms;
  9108. }
  9109. query.flt_field[field].max_query_terms = max;
  9110. return this;
  9111. },
  9112. /**
  9113. The minimum similarity of the term variants. Defaults to 0.5.
  9114. @member ejs.FuzzyLikeThisFieldQuery
  9115. @param {Double} min A positive double value.
  9116. @returns {Object} returns <code>this</code> so that calls can be chained.
  9117. */
  9118. minSimilarity: function (min) {
  9119. if (min == null) {
  9120. return query.flt_field[field].min_similarity;
  9121. }
  9122. query.flt_field[field].min_similarity = min;
  9123. return this;
  9124. },
  9125. /**
  9126. Length of required common prefix on variant terms. Defaults to 0..
  9127. @member ejs.FuzzyLikeThisFieldQuery
  9128. @param {Integer} len A positive integer value.
  9129. @returns {Object} returns <code>this</code> so that calls can be chained.
  9130. */
  9131. prefixLength: function (len) {
  9132. if (len == null) {
  9133. return query.flt_field[field].prefix_length;
  9134. }
  9135. query.flt_field[field].prefix_length = len;
  9136. return this;
  9137. },
  9138. /**
  9139. The analyzer that will be used to analyze the text. Defaults to the
  9140. analyzer associated with the field.
  9141. @member ejs.FuzzyLikeThisFieldQuery
  9142. @param {String} analyzerName The name of the analyzer.
  9143. @returns {Object} returns <code>this</code> so that calls can be chained.
  9144. */
  9145. analyzer: function (analyzerName) {
  9146. if (analyzerName == null) {
  9147. return query.flt_field[field].analyzer;
  9148. }
  9149. query.flt_field[field].analyzer = analyzerName;
  9150. return this;
  9151. },
  9152. /**
  9153. Sets the boost value of the <code>Query</code>.
  9154. @member ejs.FuzzyLikeThisFieldQuery
  9155. @param {Double} boost A positive <code>double</code> value.
  9156. @returns {Object} returns <code>this</code> so that calls can be chained.
  9157. */
  9158. boost: function (boost) {
  9159. if (boost == null) {
  9160. return query.flt_field[field].boost;
  9161. }
  9162. query.flt_field[field].boost = boost;
  9163. return this;
  9164. },
  9165. /**
  9166. Serializes the internal <em>query</em> object as a JSON string.
  9167. @member ejs.FuzzyLikeThisFieldQuery
  9168. @returns {String} Returns a JSON representation of the Query object.
  9169. */
  9170. toString: function () {
  9171. return JSON.stringify(query);
  9172. },
  9173. /**
  9174. The type of ejs object. For internal use only.
  9175. @member ejs.FuzzyLikeThisFieldQuery
  9176. @returns {String} the type of object
  9177. */
  9178. _type: function () {
  9179. return 'query';
  9180. },
  9181. /**
  9182. This method is used to retrieve the raw query object. It's designed
  9183. for internal use when composing and serializing queries.
  9184. @member ejs.FuzzyLikeThisFieldQuery
  9185. @returns {Object} Returns the object's <em>query</em> property.
  9186. */
  9187. _self: function () {
  9188. return query;
  9189. }
  9190. };
  9191. };
  9192. /**
  9193. @class
  9194. <p>Fuzzy like this query find documents that are “like” provided text by
  9195. running it against one or more fields.</p>
  9196. <p>Fuzzifies ALL terms provided as strings and then picks the best n
  9197. differentiating terms. In effect this mixes the behaviour of FuzzyQuery and
  9198. MoreLikeThis but with special consideration of fuzzy scoring factors. This
  9199. generally produces good results for queries where users may provide details
  9200. in a number of fields and have no knowledge of boolean query syntax and
  9201. also want a degree of fuzzy matching and a fast query.</p>
  9202. <p>For each source term the fuzzy variants are held in a BooleanQuery with
  9203. no coord factor (because we are not looking for matches on multiple variants
  9204. in any one doc). Additionally, a specialized TermQuery is used for variants
  9205. and does not use that variant term’s IDF because this would favour rarer
  9206. terms eg misspellings. Instead, all variants use the same IDF
  9207. ranking (the one for the source query term) and this is factored into the
  9208. variant’s boost. If the source query term does not exist in the index the
  9209. average IDF of the variants is used.</p>
  9210. @name ejs.FuzzyLikeThisQuery
  9211. @desc
  9212. <p>Constructs a query where each documents returned are “like” provided text</p>
  9213. @param {String} likeText The text to find documents like it.
  9214. */
  9215. ejs.FuzzyLikeThisQuery = function (likeText) {
  9216. /**
  9217. The internal Query object. Use <code>get()</code>.
  9218. @member ejs.FuzzyLikeThisQuery
  9219. @property {Object} query
  9220. */
  9221. var query = {
  9222. flt: {
  9223. like_text: likeText
  9224. }
  9225. };
  9226. return {
  9227. /**
  9228. The fields to run the query against. If you call with a single field,
  9229. it is added to the existing list of fields. If called with an array
  9230. of field names, it replaces any existing values with the new array.
  9231. @member ejs.FuzzyLikeThisQuery
  9232. @param {String || Array} f A single field name or a list of field names.
  9233. @returns {Object} returns <code>this</code> so that calls can be chained.
  9234. */
  9235. fields: function (f) {
  9236. if (query.flt.fields == null) {
  9237. query.flt.fields = [];
  9238. }
  9239. if (f == null) {
  9240. return query.flt.fields;
  9241. }
  9242. if (isString(f)) {
  9243. query.flt.fields.push(f);
  9244. } else if (isArray(f)) {
  9245. query.flt.fields = f;
  9246. } else {
  9247. throw new TypeError('Argument must be a string or array');
  9248. }
  9249. return this;
  9250. },
  9251. /**
  9252. The text to find documents like
  9253. @member ejs.FuzzyLikeThisQuery
  9254. @param {String} s A text string.
  9255. @returns {Object} returns <code>this</code> so that calls can be chained.
  9256. */
  9257. likeText: function (txt) {
  9258. if (txt == null) {
  9259. return query.flt.like_text;
  9260. }
  9261. query.flt.like_text = txt;
  9262. return this;
  9263. },
  9264. /**
  9265. Should term frequency be ignored. Defaults to false.
  9266. @member ejs.FuzzyLikeThisQuery
  9267. @param {Boolean} trueFalse A boolean value
  9268. @returns {Object} returns <code>this</code> so that calls can be chained.
  9269. */
  9270. ignoreTf: function (trueFalse) {
  9271. if (trueFalse == null) {
  9272. return query.flt.ignore_tf;
  9273. }
  9274. query.flt.ignore_tf = trueFalse;
  9275. return this;
  9276. },
  9277. /**
  9278. The maximum number of query terms that will be included in any
  9279. generated query. Defaults to 25.
  9280. @member ejs.FuzzyLikeThisQuery
  9281. @param {Integer} max A positive integer value.
  9282. @returns {Object} returns <code>this</code> so that calls can be chained.
  9283. */
  9284. maxQueryTerms: function (max) {
  9285. if (max == null) {
  9286. return query.flt.max_query_terms;
  9287. }
  9288. query.flt.max_query_terms = max;
  9289. return this;
  9290. },
  9291. /**
  9292. The minimum similarity of the term variants. Defaults to 0.5.
  9293. @member ejs.FuzzyLikeThisQuery
  9294. @param {Double} min A positive double value.
  9295. @returns {Object} returns <code>this</code> so that calls can be chained.
  9296. */
  9297. minSimilarity: function (min) {
  9298. if (min == null) {
  9299. return query.flt.min_similarity;
  9300. }
  9301. query.flt.min_similarity = min;
  9302. return this;
  9303. },
  9304. /**
  9305. Length of required common prefix on variant terms. Defaults to 0..
  9306. @member ejs.FuzzyLikeThisQuery
  9307. @param {Integer} len A positive integer value.
  9308. @returns {Object} returns <code>this</code> so that calls can be chained.
  9309. */
  9310. prefixLength: function (len) {
  9311. if (len == null) {
  9312. return query.flt.prefix_length;
  9313. }
  9314. query.flt.prefix_length = len;
  9315. return this;
  9316. },
  9317. /**
  9318. The analyzer that will be used to analyze the text. Defaults to the
  9319. analyzer associated with the field.
  9320. @member ejs.FuzzyLikeThisQuery
  9321. @param {String} analyzerName The name of the analyzer.
  9322. @returns {Object} returns <code>this</code> so that calls can be chained.
  9323. */
  9324. analyzer: function (analyzerName) {
  9325. if (analyzerName == null) {
  9326. return query.flt.analyzer;
  9327. }
  9328. query.flt.analyzer = analyzerName;
  9329. return this;
  9330. },
  9331. /**
  9332. Sets the boost value of the <code>Query</code>.
  9333. @member ejs.FuzzyLikeThisQuery
  9334. @param {Double} boost A positive <code>double</code> value.
  9335. @returns {Object} returns <code>this</code> so that calls can be chained.
  9336. */
  9337. boost: function (boost) {
  9338. if (boost == null) {
  9339. return query.flt.boost;
  9340. }
  9341. query.flt.boost = boost;
  9342. return this;
  9343. },
  9344. /**
  9345. Serializes the internal <em>query</em> object as a JSON string.
  9346. @member ejs.FuzzyLikeThisQuery
  9347. @returns {String} Returns a JSON representation of the Query object.
  9348. */
  9349. toString: function () {
  9350. return JSON.stringify(query);
  9351. },
  9352. /**
  9353. The type of ejs object. For internal use only.
  9354. @member ejs.FuzzyLikeThisQuery
  9355. @returns {String} the type of object
  9356. */
  9357. _type: function () {
  9358. return 'query';
  9359. },
  9360. /**
  9361. This method is used to retrieve the raw query object. It's designed
  9362. for internal use when composing and serializing queries.
  9363. @member ejs.FuzzyLikeThisQuery
  9364. @returns {Object} Returns the object's <em>query</em> property.
  9365. */
  9366. _self: function () {
  9367. return query;
  9368. }
  9369. };
  9370. };
  9371. /**
  9372. @class
  9373. <p>A fuzzy search query based on the Damerau-Levenshtein (optimal string
  9374. alignment) algorithm, though you can explicitly choose classic Levenshtein
  9375. by passing false to the transpositions parameter./p>
  9376. <p>fuzzy query on a numeric field will result in a range query “around”
  9377. the value using the min_similarity value. As an example, if you perform a
  9378. fuzzy query against a field value of "12" with a min similarity setting
  9379. of "2", the query will search for values between "10" and "14".</p>
  9380. @name ejs.FuzzyQuery
  9381. @desc
  9382. <p>Constructs a query where each documents returned are “like” provided text</p>
  9383. @param {String} field The field to run the fuzzy query against.
  9384. @param {String} value The value to fuzzify.
  9385. */
  9386. ejs.FuzzyQuery = function (field, value) {
  9387. /**
  9388. The internal Query object. Use <code>get()</code>.
  9389. @member ejs.FuzzyQuery
  9390. @property {Object} query
  9391. */
  9392. var query = {
  9393. fuzzy: {}
  9394. };
  9395. query.fuzzy[field] = {
  9396. value: value
  9397. };
  9398. return {
  9399. /**
  9400. <p>The field to run the query against.</p>
  9401. @member ejs.FuzzyQuery
  9402. @param {String} f A single field name.
  9403. @returns {Object} returns <code>this</code> so that calls can be chained.
  9404. */
  9405. field: function (f) {
  9406. var oldValue = query.fuzzy[field];
  9407. if (f == null) {
  9408. return field;
  9409. }
  9410. delete query.fuzzy[field];
  9411. field = f;
  9412. query.fuzzy[f] = oldValue;
  9413. return this;
  9414. },
  9415. /**
  9416. <p>The query text to fuzzify.</p>
  9417. @member ejs.FuzzyQuery
  9418. @param {String} s A text string.
  9419. @returns {Object} returns <code>this</code> so that calls can be chained.
  9420. */
  9421. value: function (txt) {
  9422. if (txt == null) {
  9423. return query.fuzzy[field].value;
  9424. }
  9425. query.fuzzy[field].value = txt;
  9426. return this;
  9427. },
  9428. /**
  9429. <p>Set to false to use classic Levenshtein edit distance.</p>
  9430. @member ejs.FuzzyQuery
  9431. @param {Boolean} trueFalse A boolean value
  9432. @returns {Object} returns <code>this</code> so that calls can be chained.
  9433. */
  9434. transpositions: function (trueFalse) {
  9435. if (trueFalse == null) {
  9436. return query.fuzzy[field].transpositions;
  9437. }
  9438. query.fuzzy[field].transpositions = trueFalse;
  9439. return this;
  9440. },
  9441. /**
  9442. <p>The maximum number of query terms that will be included in any
  9443. generated query. Defaults to <code>50</code>.<p>
  9444. @member ejs.FuzzyQuery
  9445. @param {Integer} max A positive integer value.
  9446. @returns {Object} returns <code>this</code> so that calls can be chained.
  9447. */
  9448. maxExpansions: function (max) {
  9449. if (max == null) {
  9450. return query.fuzzy[field].max_expansions;
  9451. }
  9452. query.fuzzy[field].max_expansions = max;
  9453. return this;
  9454. },
  9455. /**
  9456. <p>The minimum similarity of the term variants. Defaults to <code>0.5</code>.</p>
  9457. @member ejs.FuzzyQuery
  9458. @param {Double} min A positive double value.
  9459. @returns {Object} returns <code>this</code> so that calls can be chained.
  9460. */
  9461. minSimilarity: function (min) {
  9462. if (min == null) {
  9463. return query.fuzzy[field].min_similarity;
  9464. }
  9465. query.fuzzy[field].min_similarity = min;
  9466. return this;
  9467. },
  9468. /**
  9469. <p>Length of required common prefix on variant terms. Defaults to <code>0</code>.</p>
  9470. @member ejs.FuzzyQuery
  9471. @param {Integer} len A positive integer value.
  9472. @returns {Object} returns <code>this</code> so that calls can be chained.
  9473. */
  9474. prefixLength: function (len) {
  9475. if (len == null) {
  9476. return query.fuzzy[field].prefix_length;
  9477. }
  9478. query.fuzzy[field].prefix_length = len;
  9479. return this;
  9480. },
  9481. /**
  9482. <p>Sets rewrite method. Valid values are:</p>
  9483. <dl>
  9484. <dd><code>constant_score_auto</code> - tries to pick the best constant-score rewrite
  9485. method based on term and document counts from the query</dd>
  9486. <dd><code>scoring_boolean</code> - translates each term into boolean should and
  9487. keeps the scores as computed by the query</dd>
  9488. <dd><code>constant_score_boolean</code> - same as scoring_boolean, expect no scores
  9489. are computed.</dd>
  9490. <dd><code>constant_score_filter</code> - first creates a private Filter, by visiting
  9491. each term in sequence and marking all docs for that term</dd>
  9492. <dd><code>top_terms_boost_N</code> - first translates each term into boolean should
  9493. and scores are only computed as the boost using the top <code>N</code>
  9494. scoring terms. Replace <code>N</code> with an integer value.</dd>
  9495. <dd><code>top_terms_N</code> - first translates each term into boolean should
  9496. and keeps the scores as computed by the query. Only the top <code>N</code>
  9497. scoring terms are used. Replace <code>N</code> with an integer value.</dd>
  9498. </dl>
  9499. <p>Default is <code>constant_score_auto</code>.</p>
  9500. <p>This is an advanced option, use with care.</p>
  9501. @member ejs.FuzzyQuery
  9502. @param {String} m The rewrite method as a string.
  9503. @returns {Object} returns <code>this</code> so that calls can be chained.
  9504. */
  9505. rewrite: function (m) {
  9506. if (m == null) {
  9507. return query.fuzzy[field].rewrite;
  9508. }
  9509. m = m.toLowerCase();
  9510. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  9511. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  9512. m.indexOf('top_terms_boost_') === 0 ||
  9513. m.indexOf('top_terms_') === 0) {
  9514. query.fuzzy[field].rewrite = m;
  9515. }
  9516. return this;
  9517. },
  9518. /**
  9519. <p>Sets the boost value of the <code>Query</code>.</p>
  9520. @member ejs.FuzzyQuery
  9521. @param {Double} boost A positive <code>double</code> value.
  9522. @returns {Object} returns <code>this</code> so that calls can be chained.
  9523. */
  9524. boost: function (boost) {
  9525. if (boost == null) {
  9526. return query.fuzzy[field].boost;
  9527. }
  9528. query.fuzzy[field].boost = boost;
  9529. return this;
  9530. },
  9531. /**
  9532. <p>Serializes the internal <code>query</code> object as a JSON string.</p>
  9533. @member ejs.FuzzyQuery
  9534. @returns {String} Returns a JSON representation of the Query object.
  9535. */
  9536. toString: function () {
  9537. return JSON.stringify(query);
  9538. },
  9539. /**
  9540. <p>The type of ejs object. For internal use only.</p>
  9541. @member ejs.FuzzyQuery
  9542. @returns {String} the type of object
  9543. */
  9544. _type: function () {
  9545. return 'query';
  9546. },
  9547. /**
  9548. <p>This method is used to retrieve the raw query object. It's designed
  9549. for internal use when composing and serializing queries.</p>
  9550. @member ejs.FuzzyQuery
  9551. @returns {Object} Returns the object's <em>query</em> property.
  9552. */
  9553. _self: function () {
  9554. return query;
  9555. }
  9556. };
  9557. };
  9558. /**
  9559. @class
  9560. <p>Efficient querying of documents containing shapes indexed using the
  9561. geo_shape type.</p>
  9562. <p>Much like the geo_shape type, the geo_shape query uses a grid square
  9563. representation of the query shape to find those documents which have shapes
  9564. that relate to the query shape in a specified way. In order to do this, the
  9565. field being queried must be of geo_shape type. The query will use the same
  9566. PrefixTree configuration as defined for the field.</p>
  9567. @name ejs.GeoShapeQuery
  9568. @desc
  9569. A Query to find documents with a geo_shapes matching a specific shape.
  9570. */
  9571. ejs.GeoShapeQuery = function (field) {
  9572. /**
  9573. The internal query object. <code>Use _self()</code>
  9574. @member ejs.GeoShapeQuery
  9575. @property {Object} GeoShapeQuery
  9576. */
  9577. var query = {
  9578. geo_shape: {}
  9579. };
  9580. query.geo_shape[field] = {};
  9581. return {
  9582. /**
  9583. Sets the field to query against.
  9584. @member ejs.GeoShapeQuery
  9585. @param {String} f A valid field name.
  9586. @returns {Object} returns <code>this</code> so that calls can be chained.
  9587. */
  9588. field: function (f) {
  9589. var oldValue = query.geo_shape[field];
  9590. if (f == null) {
  9591. return field;
  9592. }
  9593. delete query.geo_shape[field];
  9594. field = f;
  9595. query.geo_shape[f] = oldValue;
  9596. return this;
  9597. },
  9598. /**
  9599. Sets the shape
  9600. @member ejs.GeoShapeQuery
  9601. @param {String} shape A valid <code>Shape</code> object.
  9602. @returns {Object} returns <code>this</code> so that calls can be chained.
  9603. */
  9604. shape: function (shape) {
  9605. if (shape == null) {
  9606. return query.geo_shape[field].shape;
  9607. }
  9608. if (query.geo_shape[field].indexed_shape != null) {
  9609. delete query.geo_shape[field].indexed_shape;
  9610. }
  9611. query.geo_shape[field].shape = shape._self();
  9612. return this;
  9613. },
  9614. /**
  9615. Sets the indexed shape. Use this if you already have shape definitions
  9616. already indexed.
  9617. @member ejs.GeoShapeQuery
  9618. @param {String} indexedShape A valid <code>IndexedShape</code> object.
  9619. @returns {Object} returns <code>this</code> so that calls can be chained.
  9620. */
  9621. indexedShape: function (indexedShape) {
  9622. if (indexedShape == null) {
  9623. return query.geo_shape[field].indexed_shape;
  9624. }
  9625. if (query.geo_shape[field].shape != null) {
  9626. delete query.geo_shape[field].shape;
  9627. }
  9628. query.geo_shape[field].indexed_shape = indexedShape._self();
  9629. return this;
  9630. },
  9631. /**
  9632. Sets the shape relation type. A relationship between a Query Shape
  9633. and indexed Shapes that will be used to determine if a Document
  9634. should be matched or not. Valid values are: intersects, disjoint,
  9635. and within.
  9636. @member ejs.GeoShapeQuery
  9637. @param {String} indexedShape A valid <code>IndexedShape</code> object.
  9638. @returns {Object} returns <code>this</code> so that calls can be chained.
  9639. */
  9640. relation: function (relation) {
  9641. if (relation == null) {
  9642. return query.geo_shape[field].relation;
  9643. }
  9644. relation = relation.toLowerCase();
  9645. if (relation === 'intersects' || relation === 'disjoint' || relation === 'within') {
  9646. query.geo_shape[field].relation = relation;
  9647. }
  9648. return this;
  9649. },
  9650. /**
  9651. <p>Sets the spatial strategy.</p>
  9652. <p>Valid values are:</p>
  9653. <dl>
  9654. <dd><code>recursive</code> - default, recursively traverse nodes in
  9655. the spatial prefix tree. This strategy has support for
  9656. searching non-point shapes.</dd>
  9657. <dd><code>term</code> - uses a large TermsFilter on each node
  9658. in the spatial prefix tree. It only supports the search of
  9659. indexed Point shapes.</dd>
  9660. </dl>
  9661. <p>This is an advanced setting, use with care.</p>
  9662. @since elasticsearch 0.90
  9663. @member ejs.GeoShapeQuery
  9664. @param {String} strategy The strategy as a string.
  9665. @returns {Object} returns <code>this</code> so that calls can be chained.
  9666. */
  9667. strategy: function (strategy) {
  9668. if (strategy == null) {
  9669. return query.geo_shape[field].strategy;
  9670. }
  9671. strategy = strategy.toLowerCase();
  9672. if (strategy === 'recursive' || strategy === 'term') {
  9673. query.geo_shape[field].strategy = strategy;
  9674. }
  9675. return this;
  9676. },
  9677. /**
  9678. Sets the boost value for documents matching the <code>Query</code>.
  9679. @member ejs.GeoShapeQuery
  9680. @param {Number} boost A positive <code>double</code> value.
  9681. @returns {Object} returns <code>this</code> so that calls can be chained.
  9682. */
  9683. boost: function (boost) {
  9684. if (boost == null) {
  9685. return query.geo_shape[field].boost;
  9686. }
  9687. query.geo_shape[field].boost = boost;
  9688. return this;
  9689. },
  9690. /**
  9691. Allows you to serialize this object into a JSON encoded string.
  9692. @member ejs.GeoShapeQuery
  9693. @returns {String} returns this object as a serialized JSON string.
  9694. */
  9695. toString: function () {
  9696. return JSON.stringify(query);
  9697. },
  9698. /**
  9699. The type of ejs object. For internal use only.
  9700. @member ejs.GeoShapeQuery
  9701. @returns {String} the type of object
  9702. */
  9703. _type: function () {
  9704. return 'query';
  9705. },
  9706. /**
  9707. Retrieves the internal <code>query</code> object. This is typically used by
  9708. internal API functions so use with caution.
  9709. @member ejs.GeoShapeQuery
  9710. @returns {String} returns this object's internal <code>query</code> property.
  9711. */
  9712. _self: function () {
  9713. return query;
  9714. }
  9715. };
  9716. };
  9717. /**
  9718. @class
  9719. <p>The has_child query works the same as the has_child filter,
  9720. by automatically wrapping the filter with a constant_score. Results in
  9721. parent documents that have child docs matching the query being returned.</p>
  9722. @name ejs.HasChildQuery
  9723. @desc
  9724. Returns results that have child documents matching the query.
  9725. @param {Object} qry A valid query object.
  9726. @param {String} type The child type
  9727. */
  9728. ejs.HasChildQuery = function (qry, type) {
  9729. if (!isQuery(qry)) {
  9730. throw new TypeError('Argument must be a valid Query');
  9731. }
  9732. /**
  9733. The internal query object. <code>Use _self()</code>
  9734. @member ejs.HasChildQuery
  9735. @property {Object} query
  9736. */
  9737. var query = {
  9738. has_child: {
  9739. query: qry._self(),
  9740. type: type
  9741. }
  9742. };
  9743. return {
  9744. /**
  9745. Sets the query
  9746. @member ejs.HasChildQuery
  9747. @param {Object} q A valid Query object
  9748. @returns {Object} returns <code>this</code> so that calls can be chained.
  9749. */
  9750. query: function (q) {
  9751. if (q == null) {
  9752. return query.has_child.query;
  9753. }
  9754. if (!isQuery(q)) {
  9755. throw new TypeError('Argument must be a valid Query');
  9756. }
  9757. query.has_child.query = q._self();
  9758. return this;
  9759. },
  9760. /**
  9761. Sets the child document type to search against
  9762. @member ejs.HasChildQuery
  9763. @param {String} t A valid type name
  9764. @returns {Object} returns <code>this</code> so that calls can be chained.
  9765. */
  9766. type: function (t) {
  9767. if (t == null) {
  9768. return query.has_child.type;
  9769. }
  9770. query.has_child.type = t;
  9771. return this;
  9772. },
  9773. /**
  9774. Sets the scope of the query. A scope allows to run facets on the
  9775. same scope name that will work against the child documents.
  9776. @deprecated since elasticsearch 0.90
  9777. @member ejs.HasChildQuery
  9778. @param {String} s The scope name as a string.
  9779. @returns {Object} returns <code>this</code> so that calls can be chained.
  9780. */
  9781. scope: function (s) {
  9782. return this;
  9783. },
  9784. /**
  9785. Sets the scoring method. Valid values are:
  9786. none - the default, no scoring
  9787. max - the highest score of all matched child documents is used
  9788. sum - the sum the all the matched child documents is used
  9789. avg - the average of all matched child documents is used
  9790. @member ejs.HasChildQuery
  9791. @param {String} s The score type as a string.
  9792. @returns {Object} returns <code>this</code> so that calls can be chained.
  9793. */
  9794. scoreType: function (s) {
  9795. if (s == null) {
  9796. return query.has_child.score_type;
  9797. }
  9798. s = s.toLowerCase();
  9799. if (s === 'none' || s === 'max' || s === 'sum' || s === 'avg') {
  9800. query.has_child.score_type = s;
  9801. }
  9802. return this;
  9803. },
  9804. /**
  9805. Sets the boost value of the <code>Query</code>.
  9806. @member ejs.HasChildQuery
  9807. @param {Double} boost A positive <code>double</code> value.
  9808. @returns {Object} returns <code>this</code> so that calls can be chained.
  9809. */
  9810. boost: function (boost) {
  9811. if (boost == null) {
  9812. return query.has_child.boost;
  9813. }
  9814. query.has_child.boost = boost;
  9815. return this;
  9816. },
  9817. /**
  9818. Allows you to serialize this object into a JSON encoded string.
  9819. @member ejs.HasChildQuery
  9820. @returns {String} returns this object as a serialized JSON string.
  9821. */
  9822. toString: function () {
  9823. return JSON.stringify(query);
  9824. },
  9825. /**
  9826. The type of ejs object. For internal use only.
  9827. @member ejs.HasChildQuery
  9828. @returns {String} the type of object
  9829. */
  9830. _type: function () {
  9831. return 'query';
  9832. },
  9833. /**
  9834. Retrieves the internal <code>query</code> object. This is typically used by
  9835. internal API functions so use with caution.
  9836. @member ejs.HasChildQuery
  9837. @returns {String} returns this object's internal <code>query</code> property.
  9838. */
  9839. _self: function () {
  9840. return query;
  9841. }
  9842. };
  9843. };
  9844. /**
  9845. @class
  9846. <p>The has_parent query works the same as the has_parent filter, by
  9847. automatically wrapping the filter with a constant_score. Results in
  9848. child documents that have parent docs matching the query being returned.</p>
  9849. @name ejs.HasParentQuery
  9850. @desc
  9851. Returns results that have parent documents matching the query.
  9852. @param {Object} qry A valid query object.
  9853. @param {String} parentType The child type
  9854. */
  9855. ejs.HasParentQuery = function (qry, parentType) {
  9856. if (!isQuery(qry)) {
  9857. throw new TypeError('Argument must be a Query');
  9858. }
  9859. /**
  9860. The internal query object. <code>Use _self()</code>
  9861. @member ejs.HasParentQuery
  9862. @property {Object} query
  9863. */
  9864. var query = {
  9865. has_parent: {
  9866. query: qry._self(),
  9867. parent_type: parentType
  9868. }
  9869. };
  9870. return {
  9871. /**
  9872. Sets the query
  9873. @member ejs.HasParentQuery
  9874. @param {Object} q A valid Query object
  9875. @returns {Object} returns <code>this</code> so that calls can be chained.
  9876. */
  9877. query: function (q) {
  9878. if (q == null) {
  9879. return query.has_parent.query;
  9880. }
  9881. if (!isQuery(q)) {
  9882. throw new TypeError('Argument must be a Query');
  9883. }
  9884. query.has_parent.query = q._self();
  9885. return this;
  9886. },
  9887. /**
  9888. Sets the child document type to search against
  9889. @member ejs.HasParentQuery
  9890. @param {String} t A valid type name
  9891. @returns {Object} returns <code>this</code> so that calls can be chained.
  9892. */
  9893. parentType: function (t) {
  9894. if (t == null) {
  9895. return query.has_parent.parent_type;
  9896. }
  9897. query.has_parent.parent_type = t;
  9898. return this;
  9899. },
  9900. /**
  9901. Sets the scope of the query. A scope allows to run facets on the
  9902. same scope name that will work against the parent documents.
  9903. @deprecated since elasticsearch 0.90
  9904. @member ejs.HasParentQuery
  9905. @param {String} s The scope name as a string.
  9906. @returns {Object} returns <code>this</code> so that calls can be chained.
  9907. */
  9908. scope: function (s) {
  9909. return this;
  9910. },
  9911. /**
  9912. Sets the scoring method. Valid values are:
  9913. none - the default, no scoring
  9914. score - the score of the parent is used in all child documents.
  9915. @member ejs.HasParentQuery
  9916. @param {String} s The score type as a string.
  9917. @returns {Object} returns <code>this</code> so that calls can be chained.
  9918. */
  9919. scoreType: function (s) {
  9920. if (s == null) {
  9921. return query.has_parent.score_type;
  9922. }
  9923. s = s.toLowerCase();
  9924. if (s === 'none' || s === 'score') {
  9925. query.has_parent.score_type = s;
  9926. }
  9927. return this;
  9928. },
  9929. /**
  9930. Sets the boost value of the <code>Query</code>.
  9931. @member ejs.HasParentQuery
  9932. @param {Double} boost A positive <code>double</code> value.
  9933. @returns {Object} returns <code>this</code> so that calls can be chained.
  9934. */
  9935. boost: function (boost) {
  9936. if (boost == null) {
  9937. return query.has_parent.boost;
  9938. }
  9939. query.has_parent.boost = boost;
  9940. return this;
  9941. },
  9942. /**
  9943. Allows you to serialize this object into a JSON encoded string.
  9944. @member ejs.HasParentQuery
  9945. @returns {String} returns this object as a serialized JSON string.
  9946. */
  9947. toString: function () {
  9948. return JSON.stringify(query);
  9949. },
  9950. /**
  9951. The type of ejs object. For internal use only.
  9952. @member ejs.HasParentQuery
  9953. @returns {String} the type of object
  9954. */
  9955. _type: function () {
  9956. return 'query';
  9957. },
  9958. /**
  9959. Retrieves the internal <code>query</code> object. This is typically used by
  9960. internal API functions so use with caution.
  9961. @member ejs.HasParentQuery
  9962. @returns {String} returns this object's internal <code>query</code> property.
  9963. */
  9964. _self: function () {
  9965. return query;
  9966. }
  9967. };
  9968. };
  9969. /**
  9970. @class
  9971. <p>Filters documents that only have the provided ids. Note, this filter
  9972. does not require the _id field to be indexed since it works using the
  9973. _uid field.</p>
  9974. @name ejs.IdsQuery
  9975. @desc
  9976. Matches documents with the specified id(s).
  9977. @param {Array || String} ids A single document id or a list of document ids.
  9978. */
  9979. ejs.IdsQuery = function (ids) {
  9980. /**
  9981. The internal query object. <code>Use get()</code>
  9982. @member ejs.IdsQuery
  9983. @property {Object} query
  9984. */
  9985. var query = {
  9986. ids: {}
  9987. };
  9988. if (isString(ids)) {
  9989. query.ids.values = [ids];
  9990. } else if (isArray(ids)) {
  9991. query.ids.values = ids;
  9992. } else {
  9993. throw new TypeError('Argument must be string or array');
  9994. }
  9995. return {
  9996. /**
  9997. Sets the values array or adds a new value. if val is a string, it
  9998. is added to the list of existing document ids. If val is an
  9999. array it is set as the document values and replaces any existing values.
  10000. @member ejs.IdsQuery
  10001. @param {Array || String} val An single document id or an array of document ids.
  10002. @returns {Object} returns <code>this</code> so that calls can be chained.
  10003. */
  10004. values: function (val) {
  10005. if (val == null) {
  10006. return query.ids.values;
  10007. }
  10008. if (isString(val)) {
  10009. query.ids.values.push(val);
  10010. } else if (isArray(val)) {
  10011. query.ids.values = val;
  10012. } else {
  10013. throw new TypeError('Argument must be string or array');
  10014. }
  10015. return this;
  10016. },
  10017. /**
  10018. Sets the type as a single type or an array of types. If type is a
  10019. string, it is added to the list of existing types. If type is an
  10020. array, it is set as the types and overwrites an existing types. This
  10021. parameter is optional.
  10022. @member ejs.IdsQuery
  10023. @param {Array || String} type A type or a list of types
  10024. @returns {Object} returns <code>this</code> so that calls can be chained.
  10025. */
  10026. type: function (type) {
  10027. if (query.ids.type == null) {
  10028. query.ids.type = [];
  10029. }
  10030. if (type == null) {
  10031. return query.ids.type;
  10032. }
  10033. if (isString(type)) {
  10034. query.ids.type.push(type);
  10035. } else if (isArray(type)) {
  10036. query.ids.type = type;
  10037. } else {
  10038. throw new TypeError('Argument must be string or array');
  10039. }
  10040. return this;
  10041. },
  10042. /**
  10043. Sets the boost value of the <code>Query</code>.
  10044. @member ejs.IdsQuery
  10045. @param {Double} boost A positive <code>double</code> value.
  10046. @returns {Object} returns <code>this</code> so that calls can be chained.
  10047. */
  10048. boost: function (boost) {
  10049. if (boost == null) {
  10050. return query.ids.boost;
  10051. }
  10052. query.ids.boost = boost;
  10053. return this;
  10054. },
  10055. /**
  10056. Allows you to serialize this object into a JSON encoded string.
  10057. @member ejs.IdsQuery
  10058. @returns {String} returns this object as a serialized JSON string.
  10059. */
  10060. toString: function () {
  10061. return JSON.stringify(query);
  10062. },
  10063. /**
  10064. The type of ejs object. For internal use only.
  10065. @member ejs.IdsQuery
  10066. @returns {String} the type of object
  10067. */
  10068. _type: function () {
  10069. return 'query';
  10070. },
  10071. /**
  10072. Retrieves the internal <code>query</code> object. This is typically used by
  10073. internal API functions so use with caution.
  10074. @member ejs.IdsQuery
  10075. @returns {String} returns this object's internal <code>query</code> property.
  10076. */
  10077. _self: function () {
  10078. return query;
  10079. }
  10080. };
  10081. };
  10082. /**
  10083. @class
  10084. <p>The indices query can be used when executed across multiple indices,
  10085. allowing to have a query that executes only when executed on an index that
  10086. matches a specific list of indices, and another query that executes when it
  10087. is executed on an index that does not match the listed indices.</p>
  10088. @name ejs.IndicesQuery
  10089. @desc
  10090. A configurable query that is dependent on the index name.
  10091. @param {Object} qry A valid query object.
  10092. @param {String || Array} indices a single index name or an array of index
  10093. names.
  10094. */
  10095. ejs.IndicesQuery = function (qry, indices) {
  10096. if (!isQuery(qry)) {
  10097. throw new TypeError('Argument must be a Query');
  10098. }
  10099. /**
  10100. The internal query object. <code>Use _self()</code>
  10101. @member ejs.IndicesQuery
  10102. @property {Object} query
  10103. */
  10104. var query = {
  10105. indices: {
  10106. query: qry._self()
  10107. }
  10108. };
  10109. if (isString(indices)) {
  10110. query.indices.indices = [indices];
  10111. } else if (isArray(indices)) {
  10112. query.indices.indices = indices;
  10113. } else {
  10114. throw new TypeError('Argument must be a string or array');
  10115. }
  10116. return {
  10117. /**
  10118. Sets the indicies the query should match. When passed a string,
  10119. the index name is added to the current list of indices. When passed
  10120. an array, it overwites all current indices.
  10121. @member ejs.IndicesQuery
  10122. @param {String || Array} i A single index name or an array of index names.
  10123. @returns {Object} returns <code>this</code> so that calls can be chained.
  10124. */
  10125. indices: function (i) {
  10126. if (i == null) {
  10127. return query.indices.indices;
  10128. }
  10129. if (isString(i)) {
  10130. query.indices.indices.push(i);
  10131. } else if (isArray(i)) {
  10132. query.indices.indices = i;
  10133. } else {
  10134. throw new TypeError('Argument must be a string or array');
  10135. }
  10136. return this;
  10137. },
  10138. /**
  10139. Sets the query to be executed against the indices specified.
  10140. @member ejs.IndicesQuery
  10141. @param {Object} q A valid Query object
  10142. @returns {Object} returns <code>this</code> so that calls can be chained.
  10143. */
  10144. query: function (q) {
  10145. if (q == null) {
  10146. return query.indices.query;
  10147. }
  10148. if (!isQuery(q)) {
  10149. throw new TypeError('Argument must be a Query');
  10150. }
  10151. query.indices.query = q._self();
  10152. return this;
  10153. },
  10154. /**
  10155. Sets the query to be used on an index that does not match an index
  10156. name in the indices list. Can also be set to "none" to not match any
  10157. documents or "all" to match all documents.
  10158. @member ejs.IndicesQuery
  10159. @param {Object || String} q A valid Query object or "none" or "all"
  10160. @returns {Object} returns <code>this</code> so that calls can be chained.
  10161. */
  10162. noMatchQuery: function (q) {
  10163. if (q == null) {
  10164. return query.indices.no_match_query;
  10165. }
  10166. if (isString(q)) {
  10167. q = q.toLowerCase();
  10168. if (q === 'none' || q === 'all') {
  10169. query.indices.no_match_query = q;
  10170. }
  10171. } else if (isQuery(q)) {
  10172. query.indices.no_match_query = q._self();
  10173. } else {
  10174. throw new TypeError('Argument must be string or Query');
  10175. }
  10176. return this;
  10177. },
  10178. /**
  10179. Sets the boost value of the <code>Query</code>.
  10180. @member ejs.IndicesQuery
  10181. @param {Double} boost A positive <code>double</code> value.
  10182. @returns {Object} returns <code>this</code> so that calls can be chained.
  10183. */
  10184. boost: function (boost) {
  10185. if (boost == null) {
  10186. return query.indices.boost;
  10187. }
  10188. query.indices.boost = boost;
  10189. return this;
  10190. },
  10191. /**
  10192. Allows you to serialize this object into a JSON encoded string.
  10193. @member ejs.IndicesQuery
  10194. @returns {String} returns this object as a serialized JSON string.
  10195. */
  10196. toString: function () {
  10197. return JSON.stringify(query);
  10198. },
  10199. /**
  10200. The type of ejs object. For internal use only.
  10201. @member ejs.IndicesQuery
  10202. @returns {String} the type of object
  10203. */
  10204. _type: function () {
  10205. return 'query';
  10206. },
  10207. /**
  10208. Retrieves the internal <code>query</code> object. This is typically used by
  10209. internal API functions so use with caution.
  10210. @member ejs.IndicesQuery
  10211. @returns {String} returns this object's internal <code>query</code> property.
  10212. */
  10213. _self: function () {
  10214. return query;
  10215. }
  10216. };
  10217. };
  10218. /**
  10219. @class
  10220. <p>This query can be used to match all the documents
  10221. in a given set of collections and/or types.</p>
  10222. @name ejs.MatchAllQuery
  10223. @desc
  10224. <p>A query that returns all documents.</p>
  10225. */
  10226. ejs.MatchAllQuery = function () {
  10227. /**
  10228. The internal Query object. Use <code>get()</code>.
  10229. @member ejs.MatchAllQuery
  10230. @property {Object} query
  10231. */
  10232. var query = {
  10233. match_all: {}
  10234. };
  10235. return {
  10236. /**
  10237. Sets the boost value of the <code>Query</code>.
  10238. @member ejs.MatchAllQuery
  10239. @param {Double} boost A positive <code>double</code> value.
  10240. @returns {Object} returns <code>this</code> so that calls can be chained.
  10241. */
  10242. boost: function (boost) {
  10243. if (boost == null) {
  10244. return query.match_all.boost;
  10245. }
  10246. query.match_all.boost = boost;
  10247. return this;
  10248. },
  10249. /**
  10250. Serializes the internal <em>query</em> object as a JSON string.
  10251. @member ejs.MatchAllQuery
  10252. @returns {String} Returns a JSON representation of the Query object.
  10253. */
  10254. toString: function () {
  10255. return JSON.stringify(query);
  10256. },
  10257. /**
  10258. The type of ejs object. For internal use only.
  10259. @member ejs.MatchAllQuery
  10260. @returns {String} the type of object
  10261. */
  10262. _type: function () {
  10263. return 'query';
  10264. },
  10265. /**
  10266. This method is used to retrieve the raw query object. It's designed
  10267. for internal use when composing and serializing queries.
  10268. @member ejs.MatchAllQuery
  10269. @returns {Object} Returns the object's <em>query</em> property.
  10270. */
  10271. _self: function () {
  10272. return query;
  10273. }
  10274. };
  10275. };
  10276. /**
  10277. @class
  10278. A <code>MatchQuery</code> is a type of <code>Query</code> that accepts
  10279. text/numerics/dates, analyzes it, generates a query based on the
  10280. <code>MatchQuery</code> type.
  10281. @name ejs.MatchQuery
  10282. @desc
  10283. A Query that appects text, analyzes it, generates internal query based
  10284. on the MatchQuery type.
  10285. @param {String} field the document field/field to query against
  10286. @param {String} qstr the query string
  10287. */
  10288. ejs.MatchQuery = function (field, qstr) {
  10289. /**
  10290. The internal query object. <code>Use get()</code>
  10291. @member ejs.MatchQuery
  10292. @property {Object} query
  10293. */
  10294. var query = {
  10295. match: {}
  10296. };
  10297. query.match[field] = {
  10298. query: qstr
  10299. };
  10300. return {
  10301. /**
  10302. Sets the boost value for documents matching the <code>Query</code>.
  10303. @member ejs.MatchQuery
  10304. @param {Number} boost A positive <code>double</code> value.
  10305. @returns {Object} returns <code>this</code> so that calls can be chained.
  10306. */
  10307. boost: function (boost) {
  10308. if (boost == null) {
  10309. return query.match[field].boost;
  10310. }
  10311. query.match[field].boost = boost;
  10312. return this;
  10313. },
  10314. /**
  10315. Sets the query string for the <code>Query</code>.
  10316. @member ejs.MatchQuery
  10317. @param {String} qstr The query string to search for.
  10318. @returns {Object} returns <code>this</code> so that calls can be chained.
  10319. */
  10320. query: function (qstr) {
  10321. if (qstr == null) {
  10322. return query.match[field].query;
  10323. }
  10324. query.match[field].query = qstr;
  10325. return this;
  10326. },
  10327. /**
  10328. Sets the type of the <code>MatchQuery</code>. Valid values are
  10329. boolean, phrase, and phrase_prefix.
  10330. @member ejs.MatchQuery
  10331. @param {String} type Any of boolean, phrase, phrase_prefix.
  10332. @returns {Object} returns <code>this</code> so that calls can be chained.
  10333. */
  10334. type: function (type) {
  10335. if (type == null) {
  10336. return query.match[field].type;
  10337. }
  10338. type = type.toLowerCase();
  10339. if (type === 'boolean' || type === 'phrase' || type === 'phrase_prefix') {
  10340. query.match[field].type = type;
  10341. }
  10342. return this;
  10343. },
  10344. /**
  10345. Sets the fuzziness value for the <code>Query</code>.
  10346. @member ejs.MatchQuery
  10347. @param {Double} fuzz A <code>double</code> value between 0.0 and 1.0.
  10348. @returns {Object} returns <code>this</code> so that calls can be chained.
  10349. */
  10350. fuzziness: function (fuzz) {
  10351. if (fuzz == null) {
  10352. return query.match[field].fuzziness;
  10353. }
  10354. query.match[field].fuzziness = fuzz;
  10355. return this;
  10356. },
  10357. /**
  10358. Sets the maximum threshold/frequency to be considered a low
  10359. frequency term in a <code>CommonTermsQuery</code>.
  10360. Set to a value between 0 and 1.
  10361. @member ejs.MatchQuery
  10362. @param {Number} freq A positive <code>double</code> value.
  10363. @returns {Object} returns <code>this</code> so that calls can be chained.
  10364. */
  10365. cutoffFrequency: function (freq) {
  10366. if (freq == null) {
  10367. return query.match[field].cutoff_frequency;
  10368. }
  10369. query.match[field].cutoff_frequency = freq;
  10370. return this;
  10371. },
  10372. /**
  10373. Sets the prefix length for a fuzzy prefix <code>MatchQuery</code>.
  10374. @member ejs.MatchQuery
  10375. @param {Integer} l A positive <code>integer</code> length value.
  10376. @returns {Object} returns <code>this</code> so that calls can be chained.
  10377. */
  10378. prefixLength: function (l) {
  10379. if (l == null) {
  10380. return query.match[field].prefix_length;
  10381. }
  10382. query.match[field].prefix_length = l;
  10383. return this;
  10384. },
  10385. /**
  10386. Sets the max expansions of a fuzzy <code>MatchQuery</code>.
  10387. @member ejs.MatchQuery
  10388. @param {Integer} e A positive <code>integer</code> value.
  10389. @returns {Object} returns <code>this</code> so that calls can be chained.
  10390. */
  10391. maxExpansions: function (e) {
  10392. if (e == null) {
  10393. return query.match[field].max_expansions;
  10394. }
  10395. query.match[field].max_expansions = e;
  10396. return this;
  10397. },
  10398. /**
  10399. Sets default operator of the <code>Query</code>. Default: or.
  10400. @member ejs.MatchQuery
  10401. @param {String} op Any of "and" or "or", no quote characters.
  10402. @returns {Object} returns <code>this</code> so that calls can be chained.
  10403. */
  10404. operator: function (op) {
  10405. if (op == null) {
  10406. return query.match[field].operator;
  10407. }
  10408. op = op.toLowerCase();
  10409. if (op === 'and' || op === 'or') {
  10410. query.match[field].operator = op;
  10411. }
  10412. return this;
  10413. },
  10414. /**
  10415. Sets the default slop for phrases. If zero, then exact phrase matches
  10416. are required. Default: 0.
  10417. @member ejs.MatchQuery
  10418. @param {Integer} slop A positive <code>integer</code> value.
  10419. @returns {Object} returns <code>this</code> so that calls can be chained.
  10420. */
  10421. slop: function (slop) {
  10422. if (slop == null) {
  10423. return query.match[field].slop;
  10424. }
  10425. query.match[field].slop = slop;
  10426. return this;
  10427. },
  10428. /**
  10429. Sets the analyzer name used to analyze the <code>Query</code> object.
  10430. @member ejs.MatchQuery
  10431. @param {String} analyzer A valid analyzer name.
  10432. @returns {Object} returns <code>this</code> so that calls can be chained.
  10433. */
  10434. analyzer: function (analyzer) {
  10435. if (analyzer == null) {
  10436. return query.match[field].analyzer;
  10437. }
  10438. query.match[field].analyzer = analyzer;
  10439. return this;
  10440. },
  10441. /**
  10442. Sets a percent value controlling how many "should" clauses in the
  10443. resulting <code>Query</code> should match.
  10444. @member ejs.MatchQuery
  10445. @param {Integer} minMatch An <code>integer</code> between 0 and 100.
  10446. @returns {Object} returns <code>this</code> so that calls can be chained.
  10447. */
  10448. minimumShouldMatch: function (minMatch) {
  10449. if (minMatch == null) {
  10450. return query.match[field].minimum_should_match;
  10451. }
  10452. query.match[field].minimum_should_match = minMatch;
  10453. return this;
  10454. },
  10455. /**
  10456. Sets rewrite method. Valid values are:
  10457. constant_score_auto - tries to pick the best constant-score rewrite
  10458. method based on term and document counts from the query
  10459. scoring_boolean - translates each term into boolean should and
  10460. keeps the scores as computed by the query
  10461. constant_score_boolean - same as scoring_boolean, expect no scores
  10462. are computed.
  10463. constant_score_filter - first creates a private Filter, by visiting
  10464. each term in sequence and marking all docs for that term
  10465. top_terms_boost_N - first translates each term into boolean should
  10466. and scores are only computed as the boost using the top N
  10467. scoring terms. Replace N with an integer value.
  10468. top_terms_N - first translates each term into boolean should
  10469. and keeps the scores as computed by the query. Only the top N
  10470. scoring terms are used. Replace N with an integer value.
  10471. Default is constant_score_auto.
  10472. This is an advanced option, use with care.
  10473. @member ejs.MatchQuery
  10474. @param {String} m The rewrite method as a string.
  10475. @returns {Object} returns <code>this</code> so that calls can be chained.
  10476. */
  10477. rewrite: function (m) {
  10478. if (m == null) {
  10479. return query.match[field].rewrite;
  10480. }
  10481. m = m.toLowerCase();
  10482. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  10483. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  10484. m.indexOf('top_terms_boost_') === 0 ||
  10485. m.indexOf('top_terms_') === 0) {
  10486. query.match[field].rewrite = m;
  10487. }
  10488. return this;
  10489. },
  10490. /**
  10491. Sets fuzzy rewrite method. Valid values are:
  10492. constant_score_auto - tries to pick the best constant-score rewrite
  10493. method based on term and document counts from the query
  10494. scoring_boolean - translates each term into boolean should and
  10495. keeps the scores as computed by the query
  10496. constant_score_boolean - same as scoring_boolean, expect no scores
  10497. are computed.
  10498. constant_score_filter - first creates a private Filter, by visiting
  10499. each term in sequence and marking all docs for that term
  10500. top_terms_boost_N - first translates each term into boolean should
  10501. and scores are only computed as the boost using the top N
  10502. scoring terms. Replace N with an integer value.
  10503. top_terms_N - first translates each term into boolean should
  10504. and keeps the scores as computed by the query. Only the top N
  10505. scoring terms are used. Replace N with an integer value.
  10506. Default is constant_score_auto.
  10507. This is an advanced option, use with care.
  10508. @member ejs.MatchQuery
  10509. @param {String} m The rewrite method as a string.
  10510. @returns {Object} returns <code>this</code> so that calls can be chained.
  10511. */
  10512. fuzzyRewrite: function (m) {
  10513. if (m == null) {
  10514. return query.match[field].fuzzy_rewrite;
  10515. }
  10516. m = m.toLowerCase();
  10517. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  10518. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  10519. m.indexOf('top_terms_boost_') === 0 ||
  10520. m.indexOf('top_terms_') === 0) {
  10521. query.match[field].fuzzy_rewrite = m;
  10522. }
  10523. return this;
  10524. },
  10525. /**
  10526. Set to false to use classic Levenshtein edit distance in the
  10527. fuzzy query.
  10528. @member ejs.MatchQuery
  10529. @param {Boolean} trueFalse A boolean value
  10530. @returns {Object} returns <code>this</code> so that calls can be chained.
  10531. */
  10532. fuzzyTranspositions: function (trueFalse) {
  10533. if (trueFalse == null) {
  10534. return query.match[field].fuzzy_transpositions;
  10535. }
  10536. query.match[field].fuzzy_transpositions = trueFalse;
  10537. return this;
  10538. },
  10539. /**
  10540. Enables lenient parsing of the query string.
  10541. @member ejs.MatchQuery
  10542. @param {Boolean} trueFalse A boolean value
  10543. @returns {Object} returns <code>this</code> so that calls can be chained.
  10544. */
  10545. lenient: function (trueFalse) {
  10546. if (trueFalse == null) {
  10547. return query.match[field].lenient;
  10548. }
  10549. query.match[field].lenient = trueFalse;
  10550. return this;
  10551. },
  10552. /**
  10553. Sets what happens when no terms match. Valid values are
  10554. "all" or "none".
  10555. @member ejs.MatchQuery
  10556. @param {String} q A no match action, "all" or "none".
  10557. @returns {Object} returns <code>this</code> so that calls can be chained.
  10558. */
  10559. zeroTermsQuery: function (q) {
  10560. if (q == null) {
  10561. return query.match[field].zero_terms_query;
  10562. }
  10563. q = q.toLowerCase();
  10564. if (q === 'all' || q === 'none') {
  10565. query.match[field].zero_terms_query = q;
  10566. }
  10567. return this;
  10568. },
  10569. /**
  10570. Allows you to serialize this object into a JSON encoded string.
  10571. @member ejs.MatchQuery
  10572. @returns {String} returns this object as a serialized JSON string.
  10573. */
  10574. toString: function () {
  10575. return JSON.stringify(query);
  10576. },
  10577. /**
  10578. The type of ejs object. For internal use only.
  10579. @member ejs.MatchQuery
  10580. @returns {String} the type of object
  10581. */
  10582. _type: function () {
  10583. return 'query';
  10584. },
  10585. /**
  10586. Retrieves the internal <code>query</code> object. This is typically used by
  10587. internal API functions so use with caution.
  10588. @member ejs.MatchQuery
  10589. @returns {String} returns this object's internal <code>query</code> property.
  10590. */
  10591. _self: function () {
  10592. return query;
  10593. }
  10594. };
  10595. };
  10596. /**
  10597. @class
  10598. <p>The more_like_this_field query is the same as the more_like_this query,
  10599. except it runs against a single field.</p>
  10600. @name ejs.MoreLikeThisFieldQuery
  10601. @desc
  10602. <p>Constructs a query where each documents returned are “like” provided text</p>
  10603. @param {String} field The field to run the query against.
  10604. @param {String} likeText The text to find documents like it.
  10605. */
  10606. ejs.MoreLikeThisFieldQuery = function (field, likeText) {
  10607. /**
  10608. The internal Query object. Use <code>get()</code>.
  10609. @member ejs.MoreLikeThisFieldQuery
  10610. @property {Object} query
  10611. */
  10612. var query = {
  10613. mlt_field: {}
  10614. };
  10615. query.mlt_field[field] = {
  10616. like_text: likeText
  10617. };
  10618. return {
  10619. /**
  10620. The field to run the query against.
  10621. @member ejs.MoreLikeThisFieldQuery
  10622. @param {String} f A single field name.
  10623. @returns {Object} returns <code>this</code> so that calls can be chained.
  10624. */
  10625. field: function (f) {
  10626. var oldValue = query.mlt_field[field];
  10627. if (f == null) {
  10628. return field;
  10629. }
  10630. delete query.mlt_field[field];
  10631. field = f;
  10632. query.mlt_field[f] = oldValue;
  10633. return this;
  10634. },
  10635. /**
  10636. The text to find documents like
  10637. @member ejs.MoreLikeThisFieldQuery
  10638. @param {String} s A text string.
  10639. @returns {Object} returns <code>this</code> so that calls can be chained.
  10640. */
  10641. likeText: function (txt) {
  10642. if (txt == null) {
  10643. return query.mlt_field[field].like_text;
  10644. }
  10645. query.mlt_field[field].like_text = txt;
  10646. return this;
  10647. },
  10648. /**
  10649. The percentage of terms to match on (float value).
  10650. Defaults to 0.3 (30 percent).
  10651. @member ejs.MoreLikeThisFieldQuery
  10652. @param {Double} percent A double value between 0 and 1.
  10653. @returns {Object} returns <code>this</code> so that calls can be chained.
  10654. */
  10655. percentTermsToMatch: function (percent) {
  10656. if (percent == null) {
  10657. return query.mlt_field[field].percent_terms_to_match;
  10658. }
  10659. query.mlt_field[field].percent_terms_to_match = percent;
  10660. return this;
  10661. },
  10662. /**
  10663. The frequency below which terms will be ignored in the source doc.
  10664. The default frequency is 2.
  10665. @member ejs.MoreLikeThisFieldQuery
  10666. @param {Integer} freq A positive integer value.
  10667. @returns {Object} returns <code>this</code> so that calls can be chained.
  10668. */
  10669. minTermFreq: function (freq) {
  10670. if (freq == null) {
  10671. return query.mlt_field[field].min_term_freq;
  10672. }
  10673. query.mlt_field[field].min_term_freq = freq;
  10674. return this;
  10675. },
  10676. /**
  10677. The maximum number of query terms that will be included in any
  10678. generated query. Defaults to 25.
  10679. @member ejs.MoreLikeThisFieldQuery
  10680. @param {Integer} max A positive integer value.
  10681. @returns {Object} returns <code>this</code> so that calls can be chained.
  10682. */
  10683. maxQueryTerms: function (max) {
  10684. if (max == null) {
  10685. return query.mlt_field[field].max_query_terms;
  10686. }
  10687. query.mlt_field[field].max_query_terms = max;
  10688. return this;
  10689. },
  10690. /**
  10691. An array of stop words. Any word in this set is considered
  10692. “uninteresting” and ignored. Even if your Analyzer allows stopwords,
  10693. you might want to tell the MoreLikeThis code to ignore them, as for
  10694. the purposes of document similarity it seems reasonable to assume
  10695. that “a stop word is never interesting”.
  10696. @member ejs.MoreLikeThisFieldQuery
  10697. @param {Array} stopWords An array of string stopwords
  10698. @returns {Object} returns <code>this</code> so that calls can be chained.
  10699. */
  10700. stopWords: function (stopWords) {
  10701. if (stopWords == null) {
  10702. return query.mlt_field[field].stop_words;
  10703. }
  10704. query.mlt_field[field].stop_words = stopWords;
  10705. return this;
  10706. },
  10707. /**
  10708. The frequency at which words will be ignored which do not occur in
  10709. at least this many docs. Defaults to 5.
  10710. @member ejs.MoreLikeThisFieldQuery
  10711. @param {Integer} min A positive integer value.
  10712. @returns {Object} returns <code>this</code> so that calls can be chained.
  10713. */
  10714. minDocFreq: function (min) {
  10715. if (min == null) {
  10716. return query.mlt_field[field].min_doc_freq;
  10717. }
  10718. query.mlt_field[field].min_doc_freq = min;
  10719. return this;
  10720. },
  10721. /**
  10722. The maximum frequency in which words may still appear. Words that
  10723. appear in more than this many docs will be ignored.
  10724. Defaults to unbounded.
  10725. @member ejs.MoreLikeThisFieldQuery
  10726. @param {Integer} max A positive integer value.
  10727. @returns {Object} returns <code>this</code> so that calls can be chained.
  10728. */
  10729. maxDocFreq: function (max) {
  10730. if (max == null) {
  10731. return query.mlt_field[field].max_doc_freq;
  10732. }
  10733. query.mlt_field[field].max_doc_freq = max;
  10734. return this;
  10735. },
  10736. /**
  10737. The minimum word length below which words will be ignored.
  10738. Defaults to 0.
  10739. @member ejs.MoreLikeThisFieldQuery
  10740. @param {Integer} len A positive integer value.
  10741. @returns {Object} returns <code>this</code> so that calls can be chained.
  10742. */
  10743. minWordLen: function (len) {
  10744. if (len == null) {
  10745. return query.mlt_field[field].min_word_len;
  10746. }
  10747. query.mlt_field[field].min_word_len = len;
  10748. return this;
  10749. },
  10750. /**
  10751. The maximum word length above which words will be ignored.
  10752. Defaults to unbounded (0).
  10753. @member ejs.MoreLikeThisFieldQuery
  10754. @param {Integer} len A positive integer value.
  10755. @returns {Object} returns <code>this</code> so that calls can be chained.
  10756. */
  10757. maxWordLen: function (len) {
  10758. if (len == null) {
  10759. return query.mlt_field[field].max_word_len;
  10760. }
  10761. query.mlt_field[field].max_word_len = len;
  10762. return this;
  10763. },
  10764. /**
  10765. The analyzer that will be used to analyze the text. Defaults to the
  10766. analyzer associated with the field.
  10767. @member ejs.MoreLikeThisFieldQuery
  10768. @param {String} analyzerName The name of the analyzer.
  10769. @returns {Object} returns <code>this</code> so that calls can be chained.
  10770. */
  10771. analyzer: function (analyzerName) {
  10772. if (analyzerName == null) {
  10773. return query.mlt_field[field].analyzer;
  10774. }
  10775. query.mlt_field[field].analyzer = analyzerName;
  10776. return this;
  10777. },
  10778. /**
  10779. Sets the boost factor to use when boosting terms.
  10780. Defaults to 1.
  10781. @member ejs.MoreLikeThisFieldQuery
  10782. @param {Double} boost A positive <code>double</code> value.
  10783. @returns {Object} returns <code>this</code> so that calls can be chained.
  10784. */
  10785. boostTerms: function (boost) {
  10786. if (boost == null) {
  10787. return query.mlt_field[field].boost_terms;
  10788. }
  10789. query.mlt_field[field].boost_terms = boost;
  10790. return this;
  10791. },
  10792. /**
  10793. Sets the boost value of the <code>Query</code>.
  10794. @member ejs.MoreLikeThisFieldQuery
  10795. @param {Double} boost A positive <code>double</code> value.
  10796. @returns {Object} returns <code>this</code> so that calls can be chained.
  10797. */
  10798. boost: function (boost) {
  10799. if (boost == null) {
  10800. return query.mlt_field[field].boost;
  10801. }
  10802. query.mlt_field[field].boost = boost;
  10803. return this;
  10804. },
  10805. /**
  10806. Serializes the internal <em>query</em> object as a JSON string.
  10807. @member ejs.MoreLikeThisFieldQuery
  10808. @returns {String} Returns a JSON representation of the Query object.
  10809. */
  10810. toString: function () {
  10811. return JSON.stringify(query);
  10812. },
  10813. /**
  10814. The type of ejs object. For internal use only.
  10815. @member ejs.MoreLikeThisFieldQuery
  10816. @returns {String} the type of object
  10817. */
  10818. _type: function () {
  10819. return 'query';
  10820. },
  10821. /**
  10822. This method is used to retrieve the raw query object. It's designed
  10823. for internal use when composing and serializing queries.
  10824. @member ejs.MoreLikeThisFieldQuery
  10825. @returns {Object} Returns the object's <em>query</em> property.
  10826. */
  10827. _self: function () {
  10828. return query;
  10829. }
  10830. };
  10831. };
  10832. /**
  10833. @class
  10834. <p>More like this query find documents that are “like” provided text by
  10835. running it against one or more fields.</p>
  10836. @name ejs.MoreLikeThisQuery
  10837. @desc
  10838. <p>Constructs a query where each documents returned are “like” provided text</p>
  10839. @param {String || Array} fields A single field or array of fields to run against.
  10840. @param {String} likeText The text to find documents like it.
  10841. */
  10842. ejs.MoreLikeThisQuery = function (fields, likeText) {
  10843. /**
  10844. The internal Query object. Use <code>get()</code>.
  10845. @member ejs.MoreLikeThisQuery
  10846. @property {Object} query
  10847. */
  10848. var query = {
  10849. mlt: {
  10850. like_text: likeText,
  10851. fields: []
  10852. }
  10853. };
  10854. if (isString(fields)) {
  10855. query.mlt.fields.push(fields);
  10856. } else if (isArray(fields)) {
  10857. query.mlt.fields = fields;
  10858. } else {
  10859. throw new TypeError('Argument must be string or array');
  10860. }
  10861. return {
  10862. /**
  10863. The fields to run the query against. If you call with a single field,
  10864. it is added to the existing list of fields. If called with an array
  10865. of field names, it replaces any existing values with the new array.
  10866. @member ejs.MoreLikeThisQuery
  10867. @param {String || Array} f A single field name or a list of field names.
  10868. @returns {Object} returns <code>this</code> so that calls can be chained.
  10869. */
  10870. fields: function (f) {
  10871. if (f == null) {
  10872. return query.mlt.fields;
  10873. }
  10874. if (isString(f)) {
  10875. query.mlt.fields.push(f);
  10876. } else if (isArray(f)) {
  10877. query.mlt.fields = f;
  10878. } else {
  10879. throw new TypeError('Argument must be a string or array');
  10880. }
  10881. return this;
  10882. },
  10883. /**
  10884. The text to find documents like
  10885. @member ejs.MoreLikeThisQuery
  10886. @param {String} s A text string.
  10887. @returns {Object} returns <code>this</code> so that calls can be chained.
  10888. */
  10889. likeText: function (txt) {
  10890. if (txt == null) {
  10891. return query.mlt.like_text;
  10892. }
  10893. query.mlt.like_text = txt;
  10894. return this;
  10895. },
  10896. /**
  10897. The percentage of terms to match on (float value).
  10898. Defaults to 0.3 (30 percent).
  10899. @member ejs.MoreLikeThisQuery
  10900. @param {Double} percent A double value between 0 and 1.
  10901. @returns {Object} returns <code>this</code> so that calls can be chained.
  10902. */
  10903. percentTermsToMatch: function (percent) {
  10904. if (percent == null) {
  10905. return query.mlt.percent_terms_to_match;
  10906. }
  10907. query.mlt.percent_terms_to_match = percent;
  10908. return this;
  10909. },
  10910. /**
  10911. The frequency below which terms will be ignored in the source doc.
  10912. The default frequency is 2.
  10913. @member ejs.MoreLikeThisQuery
  10914. @param {Integer} freq A positive integer value.
  10915. @returns {Object} returns <code>this</code> so that calls can be chained.
  10916. */
  10917. minTermFreq: function (freq) {
  10918. if (freq == null) {
  10919. return query.mlt.min_term_freq;
  10920. }
  10921. query.mlt.min_term_freq = freq;
  10922. return this;
  10923. },
  10924. /**
  10925. The maximum number of query terms that will be included in any
  10926. generated query. Defaults to 25.
  10927. @member ejs.MoreLikeThisQuery
  10928. @param {Integer} max A positive integer value.
  10929. @returns {Object} returns <code>this</code> so that calls can be chained.
  10930. */
  10931. maxQueryTerms: function (max) {
  10932. if (max == null) {
  10933. return query.mlt.max_query_terms;
  10934. }
  10935. query.mlt.max_query_terms = max;
  10936. return this;
  10937. },
  10938. /**
  10939. An array of stop words. Any word in this set is considered
  10940. “uninteresting” and ignored. Even if your Analyzer allows stopwords,
  10941. you might want to tell the MoreLikeThis code to ignore them, as for
  10942. the purposes of document similarity it seems reasonable to assume
  10943. that “a stop word is never interesting”.
  10944. @member ejs.MoreLikeThisQuery
  10945. @param {Array} stopWords An array of string stopwords
  10946. @returns {Object} returns <code>this</code> so that calls can be chained.
  10947. */
  10948. stopWords: function (stopWords) {
  10949. if (stopWords == null) {
  10950. return query.mlt.stop_words;
  10951. }
  10952. query.mlt.stop_words = stopWords;
  10953. return this;
  10954. },
  10955. /**
  10956. The frequency at which words will be ignored which do not occur in
  10957. at least this many docs. Defaults to 5.
  10958. @member ejs.MoreLikeThisQuery
  10959. @param {Integer} min A positive integer value.
  10960. @returns {Object} returns <code>this</code> so that calls can be chained.
  10961. */
  10962. minDocFreq: function (min) {
  10963. if (min == null) {
  10964. return query.mlt.min_doc_freq;
  10965. }
  10966. query.mlt.min_doc_freq = min;
  10967. return this;
  10968. },
  10969. /**
  10970. The maximum frequency in which words may still appear. Words that
  10971. appear in more than this many docs will be ignored.
  10972. Defaults to unbounded.
  10973. @member ejs.MoreLikeThisQuery
  10974. @param {Integer} max A positive integer value.
  10975. @returns {Object} returns <code>this</code> so that calls can be chained.
  10976. */
  10977. maxDocFreq: function (max) {
  10978. if (max == null) {
  10979. return query.mlt.max_doc_freq;
  10980. }
  10981. query.mlt.max_doc_freq = max;
  10982. return this;
  10983. },
  10984. /**
  10985. The minimum word length below which words will be ignored.
  10986. Defaults to 0.
  10987. @member ejs.MoreLikeThisQuery
  10988. @param {Integer} len A positive integer value.
  10989. @returns {Object} returns <code>this</code> so that calls can be chained.
  10990. */
  10991. minWordLen: function (len) {
  10992. if (len == null) {
  10993. return query.mlt.min_word_len;
  10994. }
  10995. query.mlt.min_word_len = len;
  10996. return this;
  10997. },
  10998. /**
  10999. The maximum word length above which words will be ignored.
  11000. Defaults to unbounded (0).
  11001. @member ejs.MoreLikeThisQuery
  11002. @param {Integer} len A positive integer value.
  11003. @returns {Object} returns <code>this</code> so that calls can be chained.
  11004. */
  11005. maxWordLen: function (len) {
  11006. if (len == null) {
  11007. return query.mlt.max_word_len;
  11008. }
  11009. query.mlt.max_word_len = len;
  11010. return this;
  11011. },
  11012. /**
  11013. The analyzer that will be used to analyze the text. Defaults to the
  11014. analyzer associated with the field.
  11015. @member ejs.MoreLikeThisQuery
  11016. @param {String} analyzerName The name of the analyzer.
  11017. @returns {Object} returns <code>this</code> so that calls can be chained.
  11018. */
  11019. analyzer: function (analyzerName) {
  11020. if (analyzerName == null) {
  11021. return query.mlt.analyzer;
  11022. }
  11023. query.mlt.analyzer = analyzerName;
  11024. return this;
  11025. },
  11026. /**
  11027. Sets the boost factor to use when boosting terms.
  11028. Defaults to 1.
  11029. @member ejs.MoreLikeThisQuery
  11030. @param {Double} boost A positive <code>double</code> value.
  11031. @returns {Object} returns <code>this</code> so that calls can be chained.
  11032. */
  11033. boostTerms: function (boost) {
  11034. if (boost == null) {
  11035. return query.mlt.boost_terms;
  11036. }
  11037. query.mlt.boost_terms = boost;
  11038. return this;
  11039. },
  11040. /**
  11041. Sets the boost value of the <code>Query</code>.
  11042. @member ejs.MoreLikeThisQuery
  11043. @param {Double} boost A positive <code>double</code> value.
  11044. @returns {Object} returns <code>this</code> so that calls can be chained.
  11045. */
  11046. boost: function (boost) {
  11047. if (boost == null) {
  11048. return query.mlt.boost;
  11049. }
  11050. query.mlt.boost = boost;
  11051. return this;
  11052. },
  11053. /**
  11054. Serializes the internal <em>query</em> object as a JSON string.
  11055. @member ejs.MoreLikeThisQuery
  11056. @returns {String} Returns a JSON representation of the Query object.
  11057. */
  11058. toString: function () {
  11059. return JSON.stringify(query);
  11060. },
  11061. /**
  11062. The type of ejs object. For internal use only.
  11063. @member ejs.MoreLikeThisQuery
  11064. @returns {String} the type of object
  11065. */
  11066. _type: function () {
  11067. return 'query';
  11068. },
  11069. /**
  11070. This method is used to retrieve the raw query object. It's designed
  11071. for internal use when composing and serializing queries.
  11072. @member ejs.MoreLikeThisQuery
  11073. @returns {Object} Returns the object's <em>query</em> property.
  11074. */
  11075. _self: function () {
  11076. return query;
  11077. }
  11078. };
  11079. };
  11080. /**
  11081. @class
  11082. A <code>MultiMatchQuery</code> query builds further on top of the
  11083. <code>MatchQuery</code> by allowing multiple fields to be specified.
  11084. The idea here is to allow to more easily build a concise match type query
  11085. over multiple fields instead of using a relatively more expressive query
  11086. by using multiple match queries within a bool query.
  11087. @name ejs.MultiMatchQuery
  11088. @desc
  11089. A Query that allow to more easily build a MatchQuery
  11090. over multiple fields
  11091. @param {String || Array} fields the single field or array of fields to search across
  11092. @param {String} qstr the query string
  11093. */
  11094. ejs.MultiMatchQuery = function (fields, qstr) {
  11095. /**
  11096. The internal query object. <code>Use get()</code>
  11097. @member ejs.MultiMatchQuery
  11098. @property {Object} query
  11099. */
  11100. var query = {
  11101. multi_match: {
  11102. query: qstr,
  11103. fields: []
  11104. }
  11105. };
  11106. if (isString(fields)) {
  11107. query.multi_match.fields.push(fields);
  11108. } else if (isArray(fields)) {
  11109. query.multi_match.fields = fields;
  11110. } else {
  11111. throw new TypeError('Argument must be string or array');
  11112. }
  11113. return {
  11114. /**
  11115. Sets the fields to search across. If passed a single value it is
  11116. added to the existing list of fields. If passed an array of
  11117. values, they overwite all existing values.
  11118. @member ejs.MultiMatchQuery
  11119. @param {String || Array} f A single field or list of fields names to
  11120. search across.
  11121. @returns {Object} returns <code>this</code> so that calls can be
  11122. chained. Returns {Array} current value if `f` not specified.
  11123. */
  11124. fields: function (f) {
  11125. if (f == null) {
  11126. return query.multi_match.fields;
  11127. }
  11128. if (isString(f)) {
  11129. query.multi_match.fields.push(f);
  11130. } else if (isArray(f)) {
  11131. query.multi_match.fields = f;
  11132. } else {
  11133. throw new TypeError('Argument must be string or array');
  11134. }
  11135. return this;
  11136. },
  11137. /**
  11138. Sets whether or not queries against multiple fields should be combined using Lucene's
  11139. <a href="http://lucene.apache.org/java/3_0_0/api/core/org/apache/lucene/search/DisjunctionMaxQuery.html">
  11140. DisjunctionMaxQuery</a>
  11141. @member ejs.MultiMatchQuery
  11142. @param {String} trueFalse A <code>true/false</code> value.
  11143. @returns {Object} returns <code>this</code> so that calls can be chained.
  11144. */
  11145. useDisMax: function (trueFalse) {
  11146. if (trueFalse == null) {
  11147. return query.multi_match.use_dis_max;
  11148. }
  11149. query.multi_match.use_dis_max = trueFalse;
  11150. return this;
  11151. },
  11152. /**
  11153. The tie breaker value. The tie breaker capability allows results
  11154. that include the same term in multiple fields to be judged better than
  11155. results that include this term in only the best of those multiple
  11156. fields, without confusing this with the better case of two different
  11157. terms in the multiple fields. Default: 0.0.
  11158. @member ejs.MultiMatchQuery
  11159. @param {Double} tieBreaker A positive <code>double</code> value.
  11160. @returns {Object} returns <code>this</code> so that calls can be chained.
  11161. */
  11162. tieBreaker: function (tieBreaker) {
  11163. if (tieBreaker == null) {
  11164. return query.multi_match.tie_breaker;
  11165. }
  11166. query.multi_match.tie_breaker = tieBreaker;
  11167. return this;
  11168. },
  11169. /**
  11170. Sets the maximum threshold/frequency to be considered a low
  11171. frequency term in a <code>CommonTermsQuery</code>.
  11172. Set to a value between 0 and 1.
  11173. @member ejs.MultiMatchQuery
  11174. @param {Number} freq A positive <code>double</code> value.
  11175. @returns {Object} returns <code>this</code> so that calls can be chained.
  11176. */
  11177. cutoffFrequency: function (freq) {
  11178. if (freq == null) {
  11179. return query.multi_match.cutoff_frequency;
  11180. }
  11181. query.multi_match.cutoff_frequency = freq;
  11182. return this;
  11183. },
  11184. /**
  11185. Sets a percent value controlling how many "should" clauses in the
  11186. resulting <code>Query</code> should match.
  11187. @member ejs.MultiMatchQuery
  11188. @param {Integer} minMatch An <code>integer</code> between 0 and 100.
  11189. @returns {Object} returns <code>this</code> so that calls can be chained.
  11190. */
  11191. minimumShouldMatch: function (minMatch) {
  11192. if (minMatch == null) {
  11193. return query.multi_match.minimum_should_match;
  11194. }
  11195. query.multi_match.minimum_should_match = minMatch;
  11196. return this;
  11197. },
  11198. /**
  11199. Sets rewrite method. Valid values are:
  11200. constant_score_auto - tries to pick the best constant-score rewrite
  11201. method based on term and document counts from the query
  11202. scoring_boolean - translates each term into boolean should and
  11203. keeps the scores as computed by the query
  11204. constant_score_boolean - same as scoring_boolean, expect no scores
  11205. are computed.
  11206. constant_score_filter - first creates a private Filter, by visiting
  11207. each term in sequence and marking all docs for that term
  11208. top_terms_boost_N - first translates each term into boolean should
  11209. and scores are only computed as the boost using the top N
  11210. scoring terms. Replace N with an integer value.
  11211. top_terms_N - first translates each term into boolean should
  11212. and keeps the scores as computed by the query. Only the top N
  11213. scoring terms are used. Replace N with an integer value.
  11214. Default is constant_score_auto.
  11215. This is an advanced option, use with care.
  11216. @member ejs.MultiMatchQuery
  11217. @param {String} m The rewrite method as a string.
  11218. @returns {Object} returns <code>this</code> so that calls can be chained.
  11219. */
  11220. rewrite: function (m) {
  11221. if (m == null) {
  11222. return query.multi_match.rewrite;
  11223. }
  11224. m = m.toLowerCase();
  11225. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  11226. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  11227. m.indexOf('top_terms_boost_') === 0 ||
  11228. m.indexOf('top_terms_') === 0) {
  11229. query.multi_match.rewrite = m;
  11230. }
  11231. return this;
  11232. },
  11233. /**
  11234. Sets fuzzy rewrite method. Valid values are:
  11235. constant_score_auto - tries to pick the best constant-score rewrite
  11236. method based on term and document counts from the query
  11237. scoring_boolean - translates each term into boolean should and
  11238. keeps the scores as computed by the query
  11239. constant_score_boolean - same as scoring_boolean, expect no scores
  11240. are computed.
  11241. constant_score_filter - first creates a private Filter, by visiting
  11242. each term in sequence and marking all docs for that term
  11243. top_terms_boost_N - first translates each term into boolean should
  11244. and scores are only computed as the boost using the top N
  11245. scoring terms. Replace N with an integer value.
  11246. top_terms_N - first translates each term into boolean should
  11247. and keeps the scores as computed by the query. Only the top N
  11248. scoring terms are used. Replace N with an integer value.
  11249. Default is constant_score_auto.
  11250. This is an advanced option, use with care.
  11251. @member ejs.MultiMatchQuery
  11252. @param {String} m The rewrite method as a string.
  11253. @returns {Object} returns <code>this</code> so that calls can be chained.
  11254. */
  11255. fuzzyRewrite: function (m) {
  11256. if (m == null) {
  11257. return query.multi_match.fuzzy_rewrite;
  11258. }
  11259. m = m.toLowerCase();
  11260. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  11261. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  11262. m.indexOf('top_terms_boost_') === 0 ||
  11263. m.indexOf('top_terms_') === 0) {
  11264. query.multi_match.fuzzy_rewrite = m;
  11265. }
  11266. return this;
  11267. },
  11268. /**
  11269. Enables lenient parsing of the query string.
  11270. @member ejs.MultiMatchQuery
  11271. @param {Boolean} trueFalse A boolean value
  11272. @returns {Object} returns <code>this</code> so that calls can be chained.
  11273. */
  11274. lenient: function (trueFalse) {
  11275. if (trueFalse == null) {
  11276. return query.multi_match.lenient;
  11277. }
  11278. query.multi_match.lenient = trueFalse;
  11279. return this;
  11280. },
  11281. /**
  11282. Sets the boost value for documents matching the <code>Query</code>.
  11283. @member ejs.MultiMatchQuery
  11284. @param {Number} boost A positive <code>double</code> value.
  11285. @returns {Object} returns <code>this</code> so that calls can be chained.
  11286. */
  11287. boost: function (boost) {
  11288. if (boost == null) {
  11289. return query.multi_match.boost;
  11290. }
  11291. query.multi_match.boost = boost;
  11292. return this;
  11293. },
  11294. /**
  11295. Sets the query string for the <code>Query</code>.
  11296. @member ejs.MultiMatchQuery
  11297. @param {String} qstr The query string to search for.
  11298. @returns {Object} returns <code>this</code> so that calls can be chained.
  11299. */
  11300. query: function (qstr) {
  11301. if (qstr == null) {
  11302. return query.multi_match.query;
  11303. }
  11304. query.multi_match.query = qstr;
  11305. return this;
  11306. },
  11307. /**
  11308. Sets the type of the <code>MultiMatchQuery</code>. Valid values are
  11309. boolean, phrase, and phrase_prefix or phrasePrefix.
  11310. @member ejs.MultiMatchQuery
  11311. @param {String} type Any of boolean, phrase, phrase_prefix or phrasePrefix.
  11312. @returns {Object} returns <code>this</code> so that calls can be chained.
  11313. */
  11314. type: function (type) {
  11315. if (type == null) {
  11316. return query.multi_match.type;
  11317. }
  11318. type = type.toLowerCase();
  11319. if (type === 'boolean' || type === 'phrase' || type === 'phrase_prefix') {
  11320. query.multi_match.type = type;
  11321. }
  11322. return this;
  11323. },
  11324. /**
  11325. Sets the fuzziness value for the <code>Query</code>.
  11326. @member ejs.MultiMatchQuery
  11327. @param {Double} fuzz A <code>double</code> value between 0.0 and 1.0.
  11328. @returns {Object} returns <code>this</code> so that calls can be chained.
  11329. */
  11330. fuzziness: function (fuzz) {
  11331. if (fuzz == null) {
  11332. return query.multi_match.fuzziness;
  11333. }
  11334. query.multi_match.fuzziness = fuzz;
  11335. return this;
  11336. },
  11337. /**
  11338. Sets the prefix length for a fuzzy prefix <code>Query</code>.
  11339. @member ejs.MultiMatchQuery
  11340. @param {Integer} l A positive <code>integer</code> length value.
  11341. @returns {Object} returns <code>this</code> so that calls can be chained.
  11342. */
  11343. prefixLength: function (l) {
  11344. if (l == null) {
  11345. return query.multi_match.prefix_length;
  11346. }
  11347. query.multi_match.prefix_length = l;
  11348. return this;
  11349. },
  11350. /**
  11351. Sets the max expansions of a fuzzy <code>Query</code>.
  11352. @member ejs.MultiMatchQuery
  11353. @param {Integer} e A positive <code>integer</code> value.
  11354. @returns {Object} returns <code>this</code> so that calls can be chained.
  11355. */
  11356. maxExpansions: function (e) {
  11357. if (e == null) {
  11358. return query.multi_match.max_expansions;
  11359. }
  11360. query.multi_match.max_expansions = e;
  11361. return this;
  11362. },
  11363. /**
  11364. Sets default operator of the <code>Query</code>. Default: or.
  11365. @member ejs.MultiMatchQuery
  11366. @param {String} op Any of "and" or "or", no quote characters.
  11367. @returns {Object} returns <code>this</code> so that calls can be chained.
  11368. */
  11369. operator: function (op) {
  11370. if (op == null) {
  11371. return query.multi_match.operator;
  11372. }
  11373. op = op.toLowerCase();
  11374. if (op === 'and' || op === 'or') {
  11375. query.multi_match.operator = op;
  11376. }
  11377. return this;
  11378. },
  11379. /**
  11380. Sets the default slop for phrases. If zero, then exact phrase matches
  11381. are required. Default: 0.
  11382. @member ejs.MultiMatchQuery
  11383. @param {Integer} slop A positive <code>integer</code> value.
  11384. @returns {Object} returns <code>this</code> so that calls can be chained.
  11385. */
  11386. slop: function (slop) {
  11387. if (slop == null) {
  11388. return query.multi_match.slop;
  11389. }
  11390. query.multi_match.slop = slop;
  11391. return this;
  11392. },
  11393. /**
  11394. Sets the analyzer name used to analyze the <code>Query</code> object.
  11395. @member ejs.MultiMatchQuery
  11396. @param {String} analyzer A valid analyzer name.
  11397. @returns {Object} returns <code>this</code> so that calls can be chained.
  11398. */
  11399. analyzer: function (analyzer) {
  11400. if (analyzer == null) {
  11401. return query.multi_match.analyzer;
  11402. }
  11403. query.multi_match.analyzer = analyzer;
  11404. return this;
  11405. },
  11406. /**
  11407. Sets what happens when no terms match. Valid values are
  11408. "all" or "none".
  11409. @member ejs.MultiMatchQuery
  11410. @param {String} q A no match action, "all" or "none".
  11411. @returns {Object} returns <code>this</code> so that calls can be chained.
  11412. */
  11413. zeroTermsQuery: function (q) {
  11414. if (q == null) {
  11415. return query.multi_match.zero_terms_query;
  11416. }
  11417. q = q.toLowerCase();
  11418. if (q === 'all' || q === 'none') {
  11419. query.multi_match.zero_terms_query = q;
  11420. }
  11421. return this;
  11422. },
  11423. /**
  11424. Allows you to serialize this object into a JSON encoded string.
  11425. @member ejs.MultiMatchQuery
  11426. @returns {String} returns this object as a serialized JSON string.
  11427. */
  11428. toString: function () {
  11429. return JSON.stringify(query);
  11430. },
  11431. /**
  11432. The type of ejs object. For internal use only.
  11433. @member ejs.MultiMatchQuery
  11434. @returns {String} the type of object
  11435. */
  11436. _type: function () {
  11437. return 'query';
  11438. },
  11439. /**
  11440. Retrieves the internal <code>Query</code> object. This is typically used by
  11441. internal API functions so use with caution.
  11442. @member ejs.MultiMatchQuery
  11443. @returns {String} returns this object's internal <code>query</code> property.
  11444. */
  11445. _self: function () {
  11446. return query;
  11447. }
  11448. };
  11449. };
  11450. /**
  11451. @class
  11452. <p>Nested queries allow you to search against content within objects that are
  11453. embedded inside of other objects. It is similar to <code>XPath</code> expressions
  11454. in <code>XML</code> both conceptually and syntactically.</p>
  11455. <p>The query is executed against the nested objects / docs as if they were
  11456. indexed as separate docs and resulting in the rootparent doc (or parent
  11457. nested mapping).</p>
  11458. @name ejs.NestedQuery
  11459. @desc
  11460. <p>Constructs a query that is capable of executing a search against objects
  11461. nested within a document.</p>
  11462. @param {String} path The nested object path.
  11463. */
  11464. ejs.NestedQuery = function (path) {
  11465. /**
  11466. The internal Query object. Use <code>_self()</code>.
  11467. @member ejs.NestedQuery
  11468. @property {Object} query
  11469. */
  11470. var query = {
  11471. nested: {
  11472. path: path
  11473. }
  11474. };
  11475. return {
  11476. /**
  11477. Sets the root context for the nested query.
  11478. @member ejs.NestedQuery
  11479. @param {String} path The path defining the root context for the nested query.
  11480. @returns {Object} returns <code>this</code> so that calls can be chained.
  11481. */
  11482. path: function (path) {
  11483. if (path == null) {
  11484. return query.nested.path;
  11485. }
  11486. query.nested.path = path;
  11487. return this;
  11488. },
  11489. /**
  11490. Sets the nested query to be executed.
  11491. @member ejs.NestedQuery
  11492. @param {Object} oQuery A valid Query object
  11493. @returns {Object} returns <code>this</code> so that calls can be chained.
  11494. */
  11495. query: function (oQuery) {
  11496. if (oQuery == null) {
  11497. return query.nested.query;
  11498. }
  11499. if (!isQuery(oQuery)) {
  11500. throw new TypeError('Argument must be a Query');
  11501. }
  11502. query.nested.query = oQuery._self();
  11503. return this;
  11504. },
  11505. /**
  11506. Sets the nested filter to be executed.
  11507. @member ejs.NestedQuery
  11508. @param {Object} oFilter A valid Filter object
  11509. @returns {Object} returns <code>this</code> so that calls can be chained.
  11510. */
  11511. filter: function (oFilter) {
  11512. if (oFilter == null) {
  11513. return query.nested.filter;
  11514. }
  11515. if (!isFilter(oFilter)) {
  11516. throw new TypeError('Argument must be a Filter');
  11517. }
  11518. query.nested.filter = oFilter._self();
  11519. return this;
  11520. },
  11521. /**
  11522. Sets how the inner (nested) matches affect scoring on the parent document.
  11523. @member ejs.NestedQuery
  11524. @param {String} mode The mode of scoring to be used for nested matches.
  11525. Options are avg, total, max, none - defaults to avg
  11526. @returns {Object} returns <code>this</code> so that calls can be chained.
  11527. */
  11528. scoreMode: function (mode) {
  11529. if (mode == null) {
  11530. return query.nested.score_mode;
  11531. }
  11532. mode = mode.toLowerCase();
  11533. if (mode === 'avg' || mode === 'total' || mode === 'max' ||
  11534. mode === 'none') {
  11535. query.nested.score_mode = mode;
  11536. }
  11537. return this;
  11538. },
  11539. /**
  11540. Sets the scope of the query. A scope allows to run facets on the
  11541. same scope name that will work against the nested documents.
  11542. @deprecated since elasticsearch 0.90
  11543. @member ejs.NestedQuery
  11544. @param {String} s The scope name as a string.
  11545. @returns {Object} returns <code>this</code> so that calls can be chained.
  11546. */
  11547. scope: function (s) {
  11548. return this;
  11549. },
  11550. /**
  11551. Sets the boost value of the nested <code>Query</code>.
  11552. @member ejs.NestedQuery
  11553. @param {Double} boost A positive <code>double</code> value.
  11554. @returns {Object} returns <code>this</code> so that calls can be chained.
  11555. */
  11556. boost: function (boost) {
  11557. if (boost == null) {
  11558. return query.nested.boost;
  11559. }
  11560. query.nested.boost = boost;
  11561. return this;
  11562. },
  11563. /**
  11564. Serializes the internal <em>query</em> object as a JSON string.
  11565. @member ejs.NestedQuery
  11566. @returns {String} Returns a JSON representation of the termFilter object.
  11567. */
  11568. toString: function () {
  11569. return JSON.stringify(query);
  11570. },
  11571. /**
  11572. The type of ejs object. For internal use only.
  11573. @member ejs.NestedQuery
  11574. @returns {String} the type of object
  11575. */
  11576. _type: function () {
  11577. return 'query';
  11578. },
  11579. /**
  11580. This method is used to retrieve the raw query object. It's designed
  11581. for internal use when composing and serializing queries.
  11582. @member ejs.NestedQuery
  11583. @returns {Object} Returns the object's <em>query</em> property.
  11584. */
  11585. _self: function () {
  11586. return query;
  11587. }
  11588. };
  11589. };
  11590. /**
  11591. @class
  11592. <p>Matches documents that have fields containing terms with a specified
  11593. prefix (not analyzed). The prefix query maps to Lucene PrefixQuery.</p>
  11594. @name ejs.PrefixQuery
  11595. @desc
  11596. Matches documents containing the specified un-analyzed prefix.
  11597. @param {String} field A valid field name.
  11598. @param {String} value A string prefix.
  11599. */
  11600. ejs.PrefixQuery = function (field, value) {
  11601. /**
  11602. The internal query object. <code>Use get()</code>
  11603. @member ejs.PrefixQuery
  11604. @property {Object} query
  11605. */
  11606. var query = {
  11607. prefix: {}
  11608. };
  11609. query.prefix[field] = {
  11610. value: value
  11611. };
  11612. return {
  11613. /**
  11614. The field to run the query against.
  11615. @member ejs.PrefixQuery
  11616. @param {String} f A single field name.
  11617. @returns {Object} returns <code>this</code> so that calls can be chained.
  11618. */
  11619. field: function (f) {
  11620. var oldValue = query.prefix[field];
  11621. if (f == null) {
  11622. return field;
  11623. }
  11624. delete query.prefix[field];
  11625. field = f;
  11626. query.prefix[f] = oldValue;
  11627. return this;
  11628. },
  11629. /**
  11630. The prefix value.
  11631. @member ejs.PrefixQuery
  11632. @param {String} p A string prefix
  11633. @returns {Object} returns <code>this</code> so that calls can be chained.
  11634. */
  11635. value: function (p) {
  11636. if (p == null) {
  11637. return query.prefix[field].value;
  11638. }
  11639. query.prefix[field].value = p;
  11640. return this;
  11641. },
  11642. /**
  11643. Sets rewrite method. Valid values are:
  11644. constant_score_auto - tries to pick the best constant-score rewrite
  11645. method based on term and document counts from the query
  11646. scoring_boolean - translates each term into boolean should and
  11647. keeps the scores as computed by the query
  11648. constant_score_boolean - same as scoring_boolean, expect no scores
  11649. are computed.
  11650. constant_score_filter - first creates a private Filter, by visiting
  11651. each term in sequence and marking all docs for that term
  11652. top_terms_boost_N - first translates each term into boolean should
  11653. and scores are only computed as the boost using the top N
  11654. scoring terms. Replace N with an integer value.
  11655. top_terms_N - first translates each term into boolean should
  11656. and keeps the scores as computed by the query. Only the top N
  11657. scoring terms are used. Replace N with an integer value.
  11658. Default is constant_score_auto.
  11659. This is an advanced option, use with care.
  11660. @member ejs.PrefixQuery
  11661. @param {String} m The rewrite method as a string.
  11662. @returns {Object} returns <code>this</code> so that calls can be chained.
  11663. */
  11664. rewrite: function (m) {
  11665. if (m == null) {
  11666. return query.prefix[field].rewrite;
  11667. }
  11668. m = m.toLowerCase();
  11669. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  11670. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  11671. m.indexOf('top_terms_boost_') === 0 ||
  11672. m.indexOf('top_terms_') === 0) {
  11673. query.prefix[field].rewrite = m;
  11674. }
  11675. return this;
  11676. },
  11677. /**
  11678. Sets the boost value of the <code>Query</code>.
  11679. @member ejs.PrefixQuery
  11680. @param {Double} boost A positive <code>double</code> value.
  11681. @returns {Object} returns <code>this</code> so that calls can be chained.
  11682. */
  11683. boost: function (boost) {
  11684. if (boost == null) {
  11685. return query.prefix[field].boost;
  11686. }
  11687. query.prefix[field].boost = boost;
  11688. return this;
  11689. },
  11690. /**
  11691. Allows you to serialize this object into a JSON encoded string.
  11692. @member ejs.PrefixQuery
  11693. @returns {String} returns this object as a serialized JSON string.
  11694. */
  11695. toString: function () {
  11696. return JSON.stringify(query);
  11697. },
  11698. /**
  11699. The type of ejs object. For internal use only.
  11700. @member ejs.PrefixQuery
  11701. @returns {String} the type of object
  11702. */
  11703. _type: function () {
  11704. return 'query';
  11705. },
  11706. /**
  11707. Retrieves the internal <code>query</code> object. This is typically used by
  11708. internal API functions so use with caution.
  11709. @member ejs.PrefixQuery
  11710. @returns {String} returns this object's internal <code>query</code> property.
  11711. */
  11712. _self: function () {
  11713. return query;
  11714. }
  11715. };
  11716. };
  11717. /**
  11718. @class
  11719. <p>A query that is parsed using Lucene's default query parser. Although Lucene provides the
  11720. ability to create your own queries through its API, it also provides a rich query language
  11721. through the Query Parser, a lexer which interprets a string into a Lucene Query.</p>
  11722. </p>See the Lucene <a href="http://lucene.apache.org/java/2_9_1/queryparsersyntax.html">Query Parser Syntax</a>
  11723. for more information.</p>
  11724. @name ejs.QueryStringQuery
  11725. @desc
  11726. A query that is parsed using Lucene's default query parser.
  11727. @param {String} qstr A valid Lucene query string.
  11728. */
  11729. ejs.QueryStringQuery = function (qstr) {
  11730. /**
  11731. The internal Query object. Use <code>get()</code>.
  11732. @member ejs.QueryStringQuery
  11733. @property {Object} query
  11734. */
  11735. var query = {
  11736. query_string: {}
  11737. };
  11738. query.query_string.query = qstr;
  11739. return {
  11740. /**
  11741. Sets the query string on this <code>Query</code> object.
  11742. @member ejs.QueryStringQuery
  11743. @param {String} qstr A valid Lucene query string.
  11744. @returns {Object} returns <code>this</code> so that calls can be chained.
  11745. */
  11746. query: function (qstr) {
  11747. if (qstr == null) {
  11748. return query.query_string.query;
  11749. }
  11750. query.query_string.query = qstr;
  11751. return this;
  11752. },
  11753. /**
  11754. Sets the default field/property this query should execute against.
  11755. @member ejs.QueryStringQuery
  11756. @param {String} fieldName The name of document field/property.
  11757. @returns {Object} returns <code>this</code> so that calls can be chained.
  11758. */
  11759. defaultField: function (fieldName) {
  11760. if (fieldName == null) {
  11761. return query.query_string.default_field;
  11762. }
  11763. query.query_string.default_field = fieldName;
  11764. return this;
  11765. },
  11766. /**
  11767. A set of fields/properties this query should execute against.
  11768. Pass a single value to add to the existing list of fields and
  11769. pass an array to overwrite all existing fields. For each field,
  11770. you can apply a field specific boost by appending a ^boost to the
  11771. field name. For example, title^10, to give the title field a
  11772. boost of 10.
  11773. @member ejs.QueryStringQuery
  11774. @param {Array} fieldNames A list of document fields/properties.
  11775. @returns {Object} returns <code>this</code> so that calls can be chained.
  11776. */
  11777. fields: function (fieldNames) {
  11778. if (query.query_string.fields == null) {
  11779. query.query_string.fields = [];
  11780. }
  11781. if (fieldNames == null) {
  11782. return query.query_string.fields;
  11783. }
  11784. if (isString(fieldNames)) {
  11785. query.query_string.fields.push(fieldNames);
  11786. } else if (isArray(fieldNames)) {
  11787. query.query_string.fields = fieldNames;
  11788. } else {
  11789. throw new TypeError('Argument must be a string or array');
  11790. }
  11791. return this;
  11792. },
  11793. /**
  11794. Sets whether or not queries against multiple fields should be combined using Lucene's
  11795. <a href="http://lucene.apache.org/java/3_0_0/api/core/org/apache/lucene/search/DisjunctionMaxQuery.html">
  11796. DisjunctionMaxQuery</a>
  11797. @member ejs.QueryStringQuery
  11798. @param {String} trueFalse A <code>true/false</code> value.
  11799. @returns {Object} returns <code>this</code> so that calls can be chained.
  11800. */
  11801. useDisMax: function (trueFalse) {
  11802. if (trueFalse == null) {
  11803. return query.query_string.use_dis_max;
  11804. }
  11805. query.query_string.use_dis_max = trueFalse;
  11806. return this;
  11807. },
  11808. /**
  11809. Set the default <em>Boolean</em> operator. This operator is used to join individual query
  11810. terms when no operator is explicity used in the query string (i.e., <code>this AND that</code>).
  11811. Defaults to <code>OR</code> (<em>same as Google</em>).
  11812. @member ejs.QueryStringQuery
  11813. @param {String} op The operator to use, AND or OR.
  11814. @returns {Object} returns <code>this</code> so that calls can be chained.
  11815. */
  11816. defaultOperator: function (op) {
  11817. if (op == null) {
  11818. return query.query_string.default_operator;
  11819. }
  11820. op = op.toUpperCase();
  11821. if (op === 'AND' || op === 'OR') {
  11822. query.query_string.default_operator = op;
  11823. }
  11824. return this;
  11825. },
  11826. /**
  11827. Sets the analyzer name used to analyze the <code>Query</code> object.
  11828. @member ejs.QueryStringQuery
  11829. @param {String} analyzer A valid analyzer name.
  11830. @returns {Object} returns <code>this</code> so that calls can be chained.
  11831. */
  11832. analyzer: function (analyzer) {
  11833. if (analyzer == null) {
  11834. return query.query_string.analyzer;
  11835. }
  11836. query.query_string.analyzer = analyzer;
  11837. return this;
  11838. },
  11839. /**
  11840. Sets the quote analyzer name used to analyze the <code>query</code>
  11841. when in quoted text.
  11842. @member ejs.QueryStringQuery
  11843. @param {String} analyzer A valid analyzer name.
  11844. @returns {Object} returns <code>this</code> so that calls can be chained.
  11845. */
  11846. quoteAnalyzer: function (analyzer) {
  11847. if (analyzer == null) {
  11848. return query.query_string.quote_analyzer;
  11849. }
  11850. query.query_string.quote_analyzer = analyzer;
  11851. return this;
  11852. },
  11853. /**
  11854. Sets whether or not wildcard characters (* and ?) are allowed as the
  11855. first character of the <code>Query</code>. Default: true.
  11856. @member ejs.QueryStringQuery
  11857. @param {Boolean} trueFalse A <code>true/false</code> value.
  11858. @returns {Object} returns <code>this</code> so that calls can be chained.
  11859. */
  11860. allowLeadingWildcard: function (trueFalse) {
  11861. if (trueFalse == null) {
  11862. return query.query_string.allow_leading_wildcard;
  11863. }
  11864. query.query_string.allow_leading_wildcard = trueFalse;
  11865. return this;
  11866. },
  11867. /**
  11868. Sets whether or not terms from wildcard, prefix, fuzzy, and
  11869. range queries should automatically be lowercased in the <code>Query</code>
  11870. since they are not analyzed. Default: true.
  11871. @member ejs.QueryStringQuery
  11872. @param {Boolean} trueFalse A <code>true/false</code> value.
  11873. @returns {Object} returns <code>this</code> so that calls can be chained.
  11874. */
  11875. lowercaseExpandedTerms: function (trueFalse) {
  11876. if (trueFalse == null) {
  11877. return query.query_string.lowercase_expanded_terms;
  11878. }
  11879. query.query_string.lowercase_expanded_terms = trueFalse;
  11880. return this;
  11881. },
  11882. /**
  11883. Sets whether or not position increments will be used in the
  11884. <code>Query</code>. Default: true.
  11885. @member ejs.QueryStringQuery
  11886. @param {Boolean} trueFalse A <code>true/false</code> value.
  11887. @returns {Object} returns <code>this</code> so that calls can be chained.
  11888. */
  11889. enablePositionIncrements: function (trueFalse) {
  11890. if (trueFalse == null) {
  11891. return query.query_string.enable_position_increments;
  11892. }
  11893. query.query_string.enable_position_increments = trueFalse;
  11894. return this;
  11895. },
  11896. /**
  11897. Sets the prefix length for fuzzy queries. Default: 0.
  11898. @member ejs.QueryStringQuery
  11899. @param {Integer} fuzzLen A positive <code>integer</code> value.
  11900. @returns {Object} returns <code>this</code> so that calls can be chained.
  11901. */
  11902. fuzzyPrefixLength: function (fuzzLen) {
  11903. if (fuzzLen == null) {
  11904. return query.query_string.fuzzy_prefix_length;
  11905. }
  11906. query.query_string.fuzzy_prefix_length = fuzzLen;
  11907. return this;
  11908. },
  11909. /**
  11910. Set the minimum similarity for fuzzy queries. Default: 0.5.
  11911. @member ejs.QueryStringQuery
  11912. @param {Double} minSim A <code>double</code> value between 0 and 1.
  11913. @returns {Object} returns <code>this</code> so that calls can be chained.
  11914. */
  11915. fuzzyMinSim: function (minSim) {
  11916. if (minSim == null) {
  11917. return query.query_string.fuzzy_min_sim;
  11918. }
  11919. query.query_string.fuzzy_min_sim = minSim;
  11920. return this;
  11921. },
  11922. /**
  11923. Sets the default slop for phrases. If zero, then exact phrase matches
  11924. are required. Default: 0.
  11925. @member ejs.QueryStringQuery
  11926. @param {Integer} slop A positive <code>integer</code> value.
  11927. @returns {Object} returns <code>this</code> so that calls can be chained.
  11928. */
  11929. phraseSlop: function (slop) {
  11930. if (slop == null) {
  11931. return query.query_string.phrase_slop;
  11932. }
  11933. query.query_string.phrase_slop = slop;
  11934. return this;
  11935. },
  11936. /**
  11937. Sets the boost value of the <code>Query</code>. Default: 1.0.
  11938. @member ejs.QueryStringQuery
  11939. @param {Double} boost A positive <code>double</code> value.
  11940. @returns {Object} returns <code>this</code> so that calls can be chained.
  11941. */
  11942. boost: function (boost) {
  11943. if (boost == null) {
  11944. return query.query_string.boost;
  11945. }
  11946. query.query_string.boost = boost;
  11947. return this;
  11948. },
  11949. /**
  11950. Sets whether or not we should attempt to analyzed wilcard terms in the
  11951. <code>Query</code>. By default, wildcard terms are not analyzed.
  11952. Analysis of wildcard characters is not perfect. Default: false.
  11953. @member ejs.QueryStringQuery
  11954. @param {Boolean} trueFalse A <code>true/false</code> value.
  11955. @returns {Object} returns <code>this</code> so that calls can be chained.
  11956. */
  11957. analyzeWildcard: function (trueFalse) {
  11958. if (trueFalse == null) {
  11959. return query.query_string.analyze_wildcard;
  11960. }
  11961. query.query_string.analyze_wildcard = trueFalse;
  11962. return this;
  11963. },
  11964. /**
  11965. Sets whether or not we should auto generate phrase queries *if* the
  11966. analyzer returns more than one term. Default: false.
  11967. @member ejs.QueryStringQuery
  11968. @param {Boolean} trueFalse A <code>true/false</code> value.
  11969. @returns {Object} returns <code>this</code> so that calls can be chained.
  11970. */
  11971. autoGeneratePhraseQueries: function (trueFalse) {
  11972. if (trueFalse == null) {
  11973. return query.query_string.auto_generate_phrase_queries;
  11974. }
  11975. query.query_string.auto_generate_phrase_queries = trueFalse;
  11976. return this;
  11977. },
  11978. /**
  11979. Sets a percent value controlling how many "should" clauses in the
  11980. resulting <code>Query</code> should match.
  11981. @member ejs.QueryStringQuery
  11982. @param {Integer} minMatch An <code>integer</code> between 0 and 100.
  11983. @returns {Object} returns <code>this</code> so that calls can be chained.
  11984. */
  11985. minimumShouldMatch: function (minMatch) {
  11986. if (minMatch == null) {
  11987. return query.query_string.minimum_should_match;
  11988. }
  11989. query.query_string.minimum_should_match = minMatch;
  11990. return this;
  11991. },
  11992. /**
  11993. Sets the tie breaker value for a <code>Query</code> using
  11994. <code>DisMax</code>. The tie breaker capability allows results
  11995. that include the same term in multiple fields to be judged better than
  11996. results that include this term in only the best of those multiple
  11997. fields, without confusing this with the better case of two different
  11998. terms in the multiple fields. Default: 0.0.
  11999. @member ejs.QueryStringQuery
  12000. @param {Double} tieBreaker A positive <code>double</code> value.
  12001. @returns {Object} returns <code>this</code> so that calls can be chained.
  12002. */
  12003. tieBreaker: function (tieBreaker) {
  12004. if (tieBreaker == null) {
  12005. return query.query_string.tie_breaker;
  12006. }
  12007. query.query_string.tie_breaker = tieBreaker;
  12008. return this;
  12009. },
  12010. /**
  12011. If they query string should be escaped or not.
  12012. @member ejs.QueryStringQuery
  12013. @param {Boolean} trueFalse A <code>true/false</code> value.
  12014. @returns {Object} returns <code>this</code> so that calls can be chained.
  12015. */
  12016. escape: function (trueFalse) {
  12017. if (trueFalse == null) {
  12018. return query.query_string.escape;
  12019. }
  12020. query.query_string.escape = trueFalse;
  12021. return this;
  12022. },
  12023. /**
  12024. Sets the max number of term expansions for fuzzy queries.
  12025. @member ejs.QueryStringQuery
  12026. @param {Integer} max A positive <code>integer</code> value.
  12027. @returns {Object} returns <code>this</code> so that calls can be chained.
  12028. */
  12029. fuzzyMaxExpansions: function (max) {
  12030. if (max == null) {
  12031. return query.query_string.fuzzy_max_expansions;
  12032. }
  12033. query.query_string.fuzzy_max_expansions = max;
  12034. return this;
  12035. },
  12036. /**
  12037. Sets fuzzy rewrite method. Valid values are:
  12038. constant_score_auto - tries to pick the best constant-score rewrite
  12039. method based on term and document counts from the query
  12040. scoring_boolean - translates each term into boolean should and
  12041. keeps the scores as computed by the query
  12042. constant_score_boolean - same as scoring_boolean, expect no scores
  12043. are computed.
  12044. constant_score_filter - first creates a private Filter, by visiting
  12045. each term in sequence and marking all docs for that term
  12046. top_terms_boost_N - first translates each term into boolean should
  12047. and scores are only computed as the boost using the top N
  12048. scoring terms. Replace N with an integer value.
  12049. top_terms_N - first translates each term into boolean should
  12050. and keeps the scores as computed by the query. Only the top N
  12051. scoring terms are used. Replace N with an integer value.
  12052. Default is constant_score_auto.
  12053. This is an advanced option, use with care.
  12054. @member ejs.QueryStringQuery
  12055. @param {String} m The rewrite method as a string.
  12056. @returns {Object} returns <code>this</code> so that calls can be chained.
  12057. */
  12058. fuzzyRewrite: function (m) {
  12059. if (m == null) {
  12060. return query.query_string.fuzzy_rewrite;
  12061. }
  12062. m = m.toLowerCase();
  12063. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  12064. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  12065. m.indexOf('top_terms_boost_') === 0 ||
  12066. m.indexOf('top_terms_') === 0) {
  12067. query.query_string.fuzzy_rewrite = m;
  12068. }
  12069. return this;
  12070. },
  12071. /**
  12072. Sets rewrite method. Valid values are:
  12073. constant_score_auto - tries to pick the best constant-score rewrite
  12074. method based on term and document counts from the query
  12075. scoring_boolean - translates each term into boolean should and
  12076. keeps the scores as computed by the query
  12077. constant_score_boolean - same as scoring_boolean, expect no scores
  12078. are computed.
  12079. constant_score_filter - first creates a private Filter, by visiting
  12080. each term in sequence and marking all docs for that term
  12081. top_terms_boost_N - first translates each term into boolean should
  12082. and scores are only computed as the boost using the top N
  12083. scoring terms. Replace N with an integer value.
  12084. top_terms_N - first translates each term into boolean should
  12085. and keeps the scores as computed by the query. Only the top N
  12086. scoring terms are used. Replace N with an integer value.
  12087. Default is constant_score_auto.
  12088. This is an advanced option, use with care.
  12089. @member ejs.QueryStringQuery
  12090. @param {String} m The rewrite method as a string.
  12091. @returns {Object} returns <code>this</code> so that calls can be chained.
  12092. */
  12093. rewrite: function (m) {
  12094. if (m == null) {
  12095. return query.query_string.rewrite;
  12096. }
  12097. m = m.toLowerCase();
  12098. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  12099. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  12100. m.indexOf('top_terms_boost_') === 0 ||
  12101. m.indexOf('top_terms_') === 0) {
  12102. query.query_string.rewrite = m;
  12103. }
  12104. return this;
  12105. },
  12106. /**
  12107. Sets the suffix to automatically add to the field name when
  12108. performing a quoted search.
  12109. @member ejs.QueryStringQuery
  12110. @param {String} s The suffix as a string.
  12111. @returns {Object} returns <code>this</code> so that calls can be chained.
  12112. */
  12113. quoteFieldSuffix: function (s) {
  12114. if (s == null) {
  12115. return query.query_string.quote_field_suffix;
  12116. }
  12117. query.query_string.quote_field_suffix = s;
  12118. return this;
  12119. },
  12120. /**
  12121. Enables lenient parsing of the query string.
  12122. @member ejs.QueryStringQuery
  12123. @param {Boolean} trueFalse A boolean value
  12124. @returns {Object} returns <code>this</code> so that calls can be chained.
  12125. */
  12126. lenient: function (trueFalse) {
  12127. if (trueFalse == null) {
  12128. return query.query_string.lenient;
  12129. }
  12130. query.query_string.lenient = trueFalse;
  12131. return this;
  12132. },
  12133. /**
  12134. Allows you to serialize this object into a JSON encoded string.
  12135. @member ejs.QueryStringQuery
  12136. @returns {String} returns this object as a serialized JSON string.
  12137. */
  12138. toString: function () {
  12139. return JSON.stringify(query);
  12140. },
  12141. /**
  12142. The type of ejs object. For internal use only.
  12143. @member ejs.QueryStringQuery
  12144. @returns {String} the type of object
  12145. */
  12146. _type: function () {
  12147. return 'query';
  12148. },
  12149. /**
  12150. Retrieves the internal <code>query</code> object. This is typically used by
  12151. internal API functions so use with caution.
  12152. @member ejs.QueryStringQuery
  12153. @returns {String} returns this object's internal <code>query</code> property.
  12154. */
  12155. _self: function () {
  12156. return query;
  12157. }
  12158. };
  12159. };
  12160. /**
  12161. @class
  12162. <p>Matches documents with fields that have terms within a certain range.
  12163. The type of the Lucene query depends on the field type, for string fields,
  12164. the TermRangeQuery, while for number/date fields, the query is a
  12165. NumericRangeQuery.</p>
  12166. @name ejs.RangeQuery
  12167. @desc
  12168. Matches documents with fields that have terms within a certain range.
  12169. @param {String} field A valid field name.
  12170. */
  12171. ejs.RangeQuery = function (field) {
  12172. /**
  12173. The internal query object. <code>Use get()</code>
  12174. @member ejs.RangeQuery
  12175. @property {Object} query
  12176. */
  12177. var query = {
  12178. range: {}
  12179. };
  12180. query.range[field] = {};
  12181. return {
  12182. /**
  12183. The field to run the query against.
  12184. @member ejs.RangeQuery
  12185. @param {String} f A single field name.
  12186. @returns {Object} returns <code>this</code> so that calls can be chained.
  12187. */
  12188. field: function (f) {
  12189. var oldValue = query.range[field];
  12190. if (f == null) {
  12191. return field;
  12192. }
  12193. delete query.range[field];
  12194. field = f;
  12195. query.range[f] = oldValue;
  12196. return this;
  12197. },
  12198. /**
  12199. The lower bound. Defaults to start from the first.
  12200. @member ejs.RangeQuery
  12201. @param {Variable Type} f the lower bound value, type depends on field type
  12202. @returns {Object} returns <code>this</code> so that calls can be chained.
  12203. */
  12204. from: function (f) {
  12205. if (f == null) {
  12206. return query.range[field].from;
  12207. }
  12208. query.range[field].from = f;
  12209. return this;
  12210. },
  12211. /**
  12212. The upper bound. Defaults to unbounded.
  12213. @member ejs.RangeQuery
  12214. @param {Variable Type} t the upper bound value, type depends on field type
  12215. @returns {Object} returns <code>this</code> so that calls can be chained.
  12216. */
  12217. to: function (t) {
  12218. if (t == null) {
  12219. return query.range[field].to;
  12220. }
  12221. query.range[field].to = t;
  12222. return this;
  12223. },
  12224. /**
  12225. Should the first from (if set) be inclusive or not.
  12226. Defaults to true
  12227. @member ejs.RangeQuery
  12228. @param {Boolean} trueFalse true to include, false to exclude
  12229. @returns {Object} returns <code>this</code> so that calls can be chained.
  12230. */
  12231. includeLower: function (trueFalse) {
  12232. if (trueFalse == null) {
  12233. return query.range[field].include_lower;
  12234. }
  12235. query.range[field].include_lower = trueFalse;
  12236. return this;
  12237. },
  12238. /**
  12239. Should the last to (if set) be inclusive or not. Defaults to true.
  12240. @member ejs.RangeQuery
  12241. @param {Boolean} trueFalse true to include, false to exclude
  12242. @returns {Object} returns <code>this</code> so that calls can be chained.
  12243. */
  12244. includeUpper: function (trueFalse) {
  12245. if (trueFalse == null) {
  12246. return query.range[field].include_upper;
  12247. }
  12248. query.range[field].include_upper = trueFalse;
  12249. return this;
  12250. },
  12251. /**
  12252. Greater than value. Same as setting from to the value, and
  12253. include_lower to false,
  12254. @member ejs.RangeQuery
  12255. @param {Variable Type} val the value, type depends on field type
  12256. @returns {Object} returns <code>this</code> so that calls can be chained.
  12257. */
  12258. gt: function (val) {
  12259. if (val == null) {
  12260. return query.range[field].gt;
  12261. }
  12262. query.range[field].gt = val;
  12263. return this;
  12264. },
  12265. /**
  12266. Greater than or equal to value. Same as setting from to the value,
  12267. and include_lower to true.
  12268. @member ejs.RangeQuery
  12269. @param {Variable Type} val the value, type depends on field type
  12270. @returns {Object} returns <code>this</code> so that calls can be chained.
  12271. */
  12272. gte: function (val) {
  12273. if (val == null) {
  12274. return query.range[field].gte;
  12275. }
  12276. query.range[field].gte = val;
  12277. return this;
  12278. },
  12279. /**
  12280. Less than value. Same as setting to to the value, and include_upper
  12281. to false.
  12282. @member ejs.RangeQuery
  12283. @param {Variable Type} val the value, type depends on field type
  12284. @returns {Object} returns <code>this</code> so that calls can be chained.
  12285. */
  12286. lt: function (val) {
  12287. if (val == null) {
  12288. return query.range[field].lt;
  12289. }
  12290. query.range[field].lt = val;
  12291. return this;
  12292. },
  12293. /**
  12294. Less than or equal to value. Same as setting to to the value,
  12295. and include_upper to true.
  12296. @member ejs.RangeQuery
  12297. @param {Variable Type} val the value, type depends on field type
  12298. @returns {Object} returns <code>this</code> so that calls can be chained.
  12299. */
  12300. lte: function (val) {
  12301. if (val == null) {
  12302. return query.range[field].lte;
  12303. }
  12304. query.range[field].lte = val;
  12305. return this;
  12306. },
  12307. /**
  12308. Sets the boost value of the <code>Query</code>.
  12309. @member ejs.RangeQuery
  12310. @param {Double} boost A positive <code>double</code> value.
  12311. @returns {Object} returns <code>this</code> so that calls can be chained.
  12312. */
  12313. boost: function (boost) {
  12314. if (boost == null) {
  12315. return query.range[field].boost;
  12316. }
  12317. query.range[field].boost = boost;
  12318. return this;
  12319. },
  12320. /**
  12321. Allows you to serialize this object into a JSON encoded string.
  12322. @member ejs.RangeQuery
  12323. @returns {String} returns this object as a serialized JSON string.
  12324. */
  12325. toString: function () {
  12326. return JSON.stringify(query);
  12327. },
  12328. /**
  12329. The type of ejs object. For internal use only.
  12330. @member ejs.RangeQuery
  12331. @returns {String} the type of object
  12332. */
  12333. _type: function () {
  12334. return 'query';
  12335. },
  12336. /**
  12337. Retrieves the internal <code>query</code> object. This is typically used by
  12338. internal API functions so use with caution.
  12339. @member ejs.RangeQuery
  12340. @returns {String} returns this object's internal <code>query</code> property.
  12341. */
  12342. _self: function () {
  12343. return query;
  12344. }
  12345. };
  12346. };
  12347. /**
  12348. @class
  12349. <p>Matches documents that have fields matching a regular expression. Based
  12350. on Lucene 4.0 RegexpQuery which uses automaton to efficiently iterate over
  12351. index terms.</p>
  12352. @name ejs.RegexpQuery
  12353. @desc
  12354. Matches documents that have fields matching a regular expression.
  12355. @param {String} field A valid field name.
  12356. @param {String} value A regex pattern.
  12357. */
  12358. ejs.RegexpQuery = function (field, value) {
  12359. /**
  12360. The internal query object. <code>Use get()</code>
  12361. @member ejs.RegexpQuery
  12362. @property {Object} query
  12363. */
  12364. var query = {
  12365. regexp: {}
  12366. };
  12367. query.regexp[field] = {
  12368. value: value
  12369. };
  12370. return {
  12371. /**
  12372. The field to run the query against.
  12373. @member ejs.RegexpQuery
  12374. @param {String} f A single field name.
  12375. @returns {Object} returns <code>this</code> so that calls can be chained.
  12376. */
  12377. field: function (f) {
  12378. var oldValue = query.regexp[field];
  12379. if (f == null) {
  12380. return field;
  12381. }
  12382. delete query.regexp[field];
  12383. field = f;
  12384. query.regexp[f] = oldValue;
  12385. return this;
  12386. },
  12387. /**
  12388. The regexp value.
  12389. @member ejs.RegexpQuery
  12390. @param {String} p A string regexp
  12391. @returns {Object} returns <code>this</code> so that calls can be chained.
  12392. */
  12393. value: function (p) {
  12394. if (p == null) {
  12395. return query.regexp[field].value;
  12396. }
  12397. query.regexp[field].value = p;
  12398. return this;
  12399. },
  12400. /**
  12401. The regex flags to use. Valid flags are:
  12402. INTERSECTION - Support for intersection notation
  12403. COMPLEMENT - Support for complement notation
  12404. EMPTY - Support for the empty language symbol: #
  12405. ANYSTRING - Support for the any string symbol: @
  12406. INTERVAL - Support for numerical interval notation: <n-m>
  12407. NONE - Disable support for all syntax options
  12408. ALL - Enables support for all syntax options
  12409. Use multiple flags by separating with a "|" character. Example:
  12410. INTERSECTION|COMPLEMENT|EMPTY
  12411. @member ejs.RegexpQuery
  12412. @param {String} f The flags as a string, separate multiple flags with "|".
  12413. @returns {Object} returns <code>this</code> so that calls can be chained.
  12414. */
  12415. flags: function (f) {
  12416. if (f == null) {
  12417. return query.regexp[field].flags;
  12418. }
  12419. query.regexp[field].flags = f;
  12420. return this;
  12421. },
  12422. /**
  12423. The regex flags to use as a numeric value. Advanced use only,
  12424. it is probably better to stick with the <code>flags</code> option.
  12425. @member ejs.RegexpQuery
  12426. @param {String} v The flags as a numeric value.
  12427. @returns {Object} returns <code>this</code> so that calls can be chained.
  12428. */
  12429. flagsValue: function (v) {
  12430. if (v == null) {
  12431. return query.regexp[field].flags_value;
  12432. }
  12433. query.regexp[field].flags_value = v;
  12434. return this;
  12435. },
  12436. /**
  12437. Sets rewrite method. Valid values are:
  12438. constant_score_auto - tries to pick the best constant-score rewrite
  12439. method based on term and document counts from the query
  12440. scoring_boolean - translates each term into boolean should and
  12441. keeps the scores as computed by the query
  12442. constant_score_boolean - same as scoring_boolean, expect no scores
  12443. are computed.
  12444. constant_score_filter - first creates a private Filter, by visiting
  12445. each term in sequence and marking all docs for that term
  12446. top_terms_boost_N - first translates each term into boolean should
  12447. and scores are only computed as the boost using the top N
  12448. scoring terms. Replace N with an integer value.
  12449. top_terms_N - first translates each term into boolean should
  12450. and keeps the scores as computed by the query. Only the top N
  12451. scoring terms are used. Replace N with an integer value.
  12452. Default is constant_score_auto.
  12453. This is an advanced option, use with care.
  12454. @member ejs.RegexpQuery
  12455. @param {String} m The rewrite method as a string.
  12456. @returns {Object} returns <code>this</code> so that calls can be chained.
  12457. */
  12458. rewrite: function (m) {
  12459. if (m == null) {
  12460. return query.regexp[field].rewrite;
  12461. }
  12462. m = m.toLowerCase();
  12463. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  12464. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  12465. m.indexOf('top_terms_boost_') === 0 ||
  12466. m.indexOf('top_terms_') === 0) {
  12467. query.regexp[field].rewrite = m;
  12468. }
  12469. return this;
  12470. },
  12471. /**
  12472. Sets the boost value of the <code>Query</code>.
  12473. @member ejs.RegexpQuery
  12474. @param {Double} boost A positive <code>double</code> value.
  12475. @returns {Object} returns <code>this</code> so that calls can be chained.
  12476. */
  12477. boost: function (boost) {
  12478. if (boost == null) {
  12479. return query.regexp[field].boost;
  12480. }
  12481. query.regexp[field].boost = boost;
  12482. return this;
  12483. },
  12484. /**
  12485. Allows you to serialize this object into a JSON encoded string.
  12486. @member ejs.RegexpQuery
  12487. @returns {String} returns this object as a serialized JSON string.
  12488. */
  12489. toString: function () {
  12490. return JSON.stringify(query);
  12491. },
  12492. /**
  12493. The type of ejs object. For internal use only.
  12494. @member ejs.RegexpQuery
  12495. @returns {String} the type of object
  12496. */
  12497. _type: function () {
  12498. return 'query';
  12499. },
  12500. /**
  12501. Retrieves the internal <code>query</code> object. This is typically used by
  12502. internal API functions so use with caution.
  12503. @member ejs.RegexpQuery
  12504. @returns {String} returns this object's internal <code>query</code> property.
  12505. */
  12506. _self: function () {
  12507. return query;
  12508. }
  12509. };
  12510. };
  12511. /**
  12512. @class
  12513. <p>Matches spans near the beginning of a field. The spanFirstQuery allows you to search
  12514. for Spans that start and end within the first <code>n</code> positions of the document.
  12515. The span first query maps to Lucene SpanFirstQuery.</p>
  12516. @name ejs.SpanFirstQuery
  12517. @desc
  12518. Matches spans near the beginning of a field.
  12519. @param {Query} spanQry A valid SpanQuery
  12520. @param {Integer} end the maximum end position in a match.
  12521. */
  12522. ejs.SpanFirstQuery = function (spanQry, end) {
  12523. if (!isQuery(spanQry)) {
  12524. throw new TypeError('Argument must be a SpanQuery');
  12525. }
  12526. /**
  12527. The internal query object. <code>Use _self()</code>
  12528. @member ejs.SpanFirstQuery
  12529. @property {Object} query
  12530. */
  12531. var query = {
  12532. span_first: {
  12533. match: spanQry._self(),
  12534. end: end
  12535. }
  12536. };
  12537. return {
  12538. /**
  12539. Sets the span query to match on.
  12540. @member ejs.SpanFirstQuery
  12541. @param {Object} spanQuery Any valid span type query.
  12542. @returns {Object} returns <code>this</code> so that calls can be chained.
  12543. */
  12544. match: function (spanQuery) {
  12545. if (spanQuery == null) {
  12546. return query.span_first.match;
  12547. }
  12548. if (!isQuery(spanQuery)) {
  12549. throw new TypeError('Argument must be a SpanQuery');
  12550. }
  12551. query.span_first.match = spanQuery._self();
  12552. return this;
  12553. },
  12554. /**
  12555. Sets the maximum end position permitted in a match.
  12556. @member ejs.SpanFirstQuery
  12557. @param {Number} position The maximum position length to consider.
  12558. @returns {Object} returns <code>this</code> so that calls can be chained.
  12559. */
  12560. end: function (position) {
  12561. if (position == null) {
  12562. return query.span_first.end;
  12563. }
  12564. query.span_first.end = position;
  12565. return this;
  12566. },
  12567. /**
  12568. Sets the boost value of the <code>Query</code>.
  12569. @member ejs.SpanFirstQuery
  12570. @param {Double} boost A positive <code>double</code> value.
  12571. @returns {Object} returns <code>this</code> so that calls can be chained.
  12572. */
  12573. boost: function (boost) {
  12574. if (boost == null) {
  12575. return query.span_first.boost;
  12576. }
  12577. query.span_first.boost = boost;
  12578. return this;
  12579. },
  12580. /**
  12581. Allows you to serialize this object into a JSON encoded string.
  12582. @member ejs.SpanFirstQuery
  12583. @returns {String} returns this object as a serialized JSON string.
  12584. */
  12585. toString: function () {
  12586. return JSON.stringify(query);
  12587. },
  12588. /**
  12589. The type of ejs object. For internal use only.
  12590. @member ejs.SpanFirstQuery
  12591. @returns {String} the type of object
  12592. */
  12593. _type: function () {
  12594. return 'query';
  12595. },
  12596. /**
  12597. Retrieves the internal <code>query</code> object. This is typically used by
  12598. internal API functions so use with caution.
  12599. @member ejs.SpanFirstQuery
  12600. @returns {String} returns this object's internal <code>query</code> property.
  12601. */
  12602. _self: function () {
  12603. return query;
  12604. }
  12605. };
  12606. };
  12607. /**
  12608. @class
  12609. <p>A spanNearQuery will look to find a number of spanQuerys within a given
  12610. distance from each other.</p>
  12611. @name ejs.SpanNearQuery
  12612. @desc
  12613. Matches spans which are near one another.
  12614. @param {Query || Array} clauses A single SpanQuery or array of SpanQueries
  12615. @param {Integer} slop The number of intervening unmatched positions
  12616. */
  12617. ejs.SpanNearQuery = function (clauses, slop) {
  12618. /**
  12619. The internal query object. <code>Use _self()</code>
  12620. @member ejs.SpanNearQuery
  12621. @property {Object} query
  12622. */
  12623. var i, len,
  12624. query = {
  12625. span_near: {
  12626. clauses: [],
  12627. slop: slop
  12628. }
  12629. };
  12630. if (isQuery(clauses)) {
  12631. query.span_near.clauses.push(clauses._self());
  12632. } else if (isArray(clauses)) {
  12633. for (i = 0, len = clauses.length; i < len; i++) {
  12634. if (!isQuery(clauses[i])) {
  12635. throw new TypeError('Argument must be array of SpanQueries');
  12636. }
  12637. query.span_near.clauses.push(clauses[i]._self());
  12638. }
  12639. } else {
  12640. throw new TypeError('Argument must be SpanQuery or array of SpanQueries');
  12641. }
  12642. return {
  12643. /**
  12644. Sets the clauses used. If passed a single SpanQuery, it is added
  12645. to the existing list of clauses. If passed an array of
  12646. SpanQueries, they replace any existing clauses.
  12647. @member ejs.SpanNearQuery
  12648. @param {Query || Array} clauses A SpanQuery or array of SpanQueries.
  12649. @returns {Object} returns <code>this</code> so that calls can be chained.
  12650. */
  12651. clauses: function (clauses) {
  12652. var i, len;
  12653. if (clauses == null) {
  12654. return query.span_near.clauses;
  12655. }
  12656. if (isQuery(clauses)) {
  12657. query.span_near.clauses.push(clauses._self());
  12658. } else if (isArray(clauses)) {
  12659. query.span_near.clauses = [];
  12660. for (i = 0, len = clauses.length; i < len; i++) {
  12661. if (!isQuery(clauses[i])) {
  12662. throw new TypeError('Argument must be array of SpanQueries');
  12663. }
  12664. query.span_near.clauses.push(clauses[i]._self());
  12665. }
  12666. } else {
  12667. throw new TypeError('Argument must be SpanQuery or array of SpanQueries');
  12668. }
  12669. return this;
  12670. },
  12671. /**
  12672. Sets the maximum number of intervening unmatched positions.
  12673. @member ejs.SpanNearQuery
  12674. @param {Number} distance The number of intervening unmatched positions.
  12675. @returns {Object} returns <code>this</code> so that calls can be chained.
  12676. */
  12677. slop: function (distance) {
  12678. if (distance == null) {
  12679. return query.span_near.slop;
  12680. }
  12681. query.span_near.slop = distance;
  12682. return this;
  12683. },
  12684. /**
  12685. Sets whether or not matches are required to be in-order.
  12686. @member ejs.SpanNearQuery
  12687. @param {Boolean} trueFalse Determines if matches must be in-order.
  12688. @returns {Object} returns <code>this</code> so that calls can be chained.
  12689. */
  12690. inOrder: function (trueFalse) {
  12691. if (trueFalse == null) {
  12692. return query.span_near.in_order;
  12693. }
  12694. query.span_near.in_order = trueFalse;
  12695. return this;
  12696. },
  12697. /**
  12698. Sets whether or not payloads are being used. A payload is an arbitrary
  12699. byte array stored at a specific position (i.e. token/term).
  12700. @member ejs.SpanNearQuery
  12701. @param {Boolean} trueFalse Whether or not to return payloads.
  12702. @returns {Object} returns <code>this</code> so that calls can be chained.
  12703. */
  12704. collectPayloads: function (trueFalse) {
  12705. if (trueFalse == null) {
  12706. return query.span_near.collect_payloads;
  12707. }
  12708. query.span_near.collect_payloads = trueFalse;
  12709. return this;
  12710. },
  12711. /**
  12712. Sets the boost value of the <code>Query</code>.
  12713. @member ejs.SpanNearQuery
  12714. @param {Double} boost A positive <code>double</code> value.
  12715. @returns {Object} returns <code>this</code> so that calls can be chained.
  12716. */
  12717. boost: function (boost) {
  12718. if (boost == null) {
  12719. return query.span_near.boost;
  12720. }
  12721. query.span_near.boost = boost;
  12722. return this;
  12723. },
  12724. /**
  12725. Allows you to serialize this object into a JSON encoded string.
  12726. @member ejs.SpanNearQuery
  12727. @returns {String} returns this object as a serialized JSON string.
  12728. */
  12729. toString: function () {
  12730. return JSON.stringify(query);
  12731. },
  12732. /**
  12733. The type of ejs object. For internal use only.
  12734. @member ejs.SpanNearQuery
  12735. @returns {String} the type of object
  12736. */
  12737. _type: function () {
  12738. return 'query';
  12739. },
  12740. /**
  12741. Retrieves the internal <code>query</code> object. This is typically used by
  12742. internal API functions so use with caution.
  12743. @member ejs.SpanNearQuery
  12744. @returns {String} returns this object's internal <code>query</code> property.
  12745. */
  12746. _self: function () {
  12747. return query;
  12748. }
  12749. };
  12750. };
  12751. /**
  12752. @class
  12753. <p>Removes matches which overlap with another span query.
  12754. The span not query maps to Lucene SpanNotQuery.</p>
  12755. @name ejs.SpanNotQuery
  12756. @desc
  12757. Removes matches which overlap with another span query.
  12758. @param {Query} includeQry a valid SpanQuery whose matching docs will be returned.
  12759. @param {Query} excludeQry a valid SpanQuery whose matching docs will not be returned
  12760. */
  12761. ejs.SpanNotQuery = function (includeQry, excludeQry) {
  12762. if (!isQuery(includeQry) || !isQuery(excludeQry)) {
  12763. throw new TypeError('Argument must be a SpanQuery');
  12764. }
  12765. /**
  12766. The internal query object. <code>Use _self()</code>
  12767. @member ejs.SpanNotQuery
  12768. @property {Object} query
  12769. */
  12770. var query = {
  12771. span_not: {
  12772. include: includeQry._self(),
  12773. exclude: excludeQry._self()
  12774. }
  12775. };
  12776. return {
  12777. /**
  12778. Set the span query whose matches are filtered.
  12779. @member ejs.SpanNotQuery
  12780. @param {Object} spanQuery Any valid span type query.
  12781. @returns {Object} returns <code>this</code> so that calls can be chained.
  12782. */
  12783. include: function (spanQuery) {
  12784. if (spanQuery == null) {
  12785. return query.span_not.include;
  12786. }
  12787. if (!isQuery(spanQuery)) {
  12788. throw new TypeError('Argument must be a SpanQuery');
  12789. }
  12790. query.span_not.include = spanQuery._self();
  12791. return this;
  12792. },
  12793. /**
  12794. Sets the span query whose matches must not overlap those returned.
  12795. @member ejs.SpanNotQuery
  12796. @param {Object} spanQuery Any valid span type query.
  12797. @returns {Object} returns <code>this</code> so that calls can be chained.
  12798. */
  12799. exclude: function (spanQuery) {
  12800. if (spanQuery == null) {
  12801. return query.span_not.exclude;
  12802. }
  12803. if (!isQuery(spanQuery)) {
  12804. throw new TypeError('Argument must be a SpanQuery');
  12805. }
  12806. query.span_not.exclude = spanQuery._self();
  12807. return this;
  12808. },
  12809. /**
  12810. Sets the boost value of the <code>Query</code>.
  12811. @member ejs.SpanNotQuery
  12812. @param {Double} boost A positive <code>double</code> value.
  12813. @returns {Object} returns <code>this</code> so that calls can be chained.
  12814. */
  12815. boost: function (boost) {
  12816. if (boost == null) {
  12817. return query.span_not.boost;
  12818. }
  12819. query.span_not.boost = boost;
  12820. return this;
  12821. },
  12822. /**
  12823. Allows you to serialize this object into a JSON encoded string.
  12824. @member ejs.SpanNotQuery
  12825. @returns {String} returns this object as a serialized JSON string.
  12826. */
  12827. toString: function () {
  12828. return JSON.stringify(query);
  12829. },
  12830. /**
  12831. The type of ejs object. For internal use only.
  12832. @member ejs.SpanNotQuery
  12833. @returns {String} the type of object
  12834. */
  12835. _type: function () {
  12836. return 'query';
  12837. },
  12838. /**
  12839. Retrieves the internal <code>query</code> object. This is typically used by
  12840. internal API functions so use with caution.
  12841. @member ejs.SpanNotQuery
  12842. @returns {String} returns this object's internal <code>query</code> property.
  12843. */
  12844. _self: function () {
  12845. return query;
  12846. }
  12847. };
  12848. };
  12849. /**
  12850. @class
  12851. <p>The spanOrQuery takes an array of SpanQuerys and will match if any of the
  12852. underlying SpanQueries match. The span or query maps to Lucene SpanOrQuery.</p>
  12853. @name ejs.SpanOrQuery
  12854. @desc
  12855. Matches the union of its span clauses.
  12856. @param {Object} clauses A single SpanQuery or array of SpanQueries.
  12857. */
  12858. ejs.SpanOrQuery = function (clauses) {
  12859. /**
  12860. The internal query object. <code>Use _self()</code>
  12861. @member ejs.SpanOrQuery
  12862. @property {Object} query
  12863. */
  12864. var i,
  12865. len,
  12866. query = {
  12867. span_or: {
  12868. clauses: []
  12869. }
  12870. };
  12871. if (isQuery(clauses)) {
  12872. query.span_or.clauses.push(clauses._self());
  12873. } else if (isArray(clauses)) {
  12874. for (i = 0, len = clauses.length; i < len; i++) {
  12875. if (!isQuery(clauses[i])) {
  12876. throw new TypeError('Argument must be array of SpanQueries');
  12877. }
  12878. query.span_or.clauses.push(clauses[i]._self());
  12879. }
  12880. } else {
  12881. throw new TypeError('Argument must be SpanQuery or array of SpanQueries');
  12882. }
  12883. return {
  12884. /**
  12885. Sets the clauses used. If passed a single SpanQuery, it is added
  12886. to the existing list of clauses. If passed an array of
  12887. SpanQueries, they replace any existing clauses.
  12888. @member ejs.SpanOrQuery
  12889. @param {Query || Array} clauses A SpanQuery or array of SpanQueries.
  12890. @returns {Object} returns <code>this</code> so that calls can be chained.
  12891. */
  12892. clauses: function (clauses) {
  12893. var i, len;
  12894. if (clauses == null) {
  12895. return query.span_or.clauses;
  12896. }
  12897. if (isQuery(clauses)) {
  12898. query.span_or.clauses.push(clauses._self());
  12899. } else if (isArray(clauses)) {
  12900. query.span_or.clauses = [];
  12901. for (i = 0, len = clauses.length; i < len; i++) {
  12902. if (!isQuery(clauses[i])) {
  12903. throw new TypeError('Argument must be array of SpanQueries');
  12904. }
  12905. query.span_or.clauses.push(clauses[i]._self());
  12906. }
  12907. } else {
  12908. throw new TypeError('Argument must be SpanQuery or array of SpanQueries');
  12909. }
  12910. return this;
  12911. },
  12912. /**
  12913. Sets the boost value of the <code>Query</code>.
  12914. @member ejs.SpanOrQuery
  12915. @param {Double} boost A positive <code>double</code> value.
  12916. @returns {Object} returns <code>this</code> so that calls can be chained.
  12917. */
  12918. boost: function (boost) {
  12919. if (boost == null) {
  12920. return query.span_or.boost;
  12921. }
  12922. query.span_or.boost = boost;
  12923. return this;
  12924. },
  12925. /**
  12926. Allows you to serialize this object into a JSON encoded string.
  12927. @member ejs.SpanOrQuery
  12928. @returns {String} returns this object as a serialized JSON string.
  12929. */
  12930. toString: function () {
  12931. return JSON.stringify(query);
  12932. },
  12933. /**
  12934. The type of ejs object. For internal use only.
  12935. @member ejs.SpanOrQuery
  12936. @returns {String} the type of object
  12937. */
  12938. _type: function () {
  12939. return 'query';
  12940. },
  12941. /**
  12942. Retrieves the internal <code>query</code> object. This is typically used by
  12943. internal API functions so use with caution.
  12944. @member ejs.SpanOrQuery
  12945. @returns {String} returns this object's internal <code>query</code> property.
  12946. */
  12947. _self: function () {
  12948. return query;
  12949. }
  12950. };
  12951. };
  12952. /**
  12953. @class
  12954. <p>A spanTermQuery is the basic unit of Lucene's Span Query which allows for nested,
  12955. positional restrictions when matching documents. The spanTermQuery simply matches
  12956. spans containing a term. It's essentially a termQuery with positional information asscoaited.</p>
  12957. @name ejs.SpanTermQuery
  12958. @desc
  12959. Matches spans containing a term
  12960. @param {String} field the document field/field to query against
  12961. @param {String} value the literal value to be matched
  12962. */
  12963. ejs.SpanTermQuery = function (field, value) {
  12964. /**
  12965. The internal query object. <code>Use get()</code>
  12966. @member ejs.SpanTermQuery
  12967. @property {Object} query
  12968. */
  12969. var query = {
  12970. span_term: {}
  12971. };
  12972. query.span_term[field] = {
  12973. term: value
  12974. };
  12975. return {
  12976. /**
  12977. Sets the field to query against.
  12978. @member ejs.SpanTermQuery
  12979. @param {String} f A valid field name.
  12980. @returns {Object} returns <code>this</code> so that calls can be chained.
  12981. */
  12982. field: function (f) {
  12983. var oldValue = query.span_term[field];
  12984. if (f == null) {
  12985. return field;
  12986. }
  12987. delete query.span_term[field];
  12988. field = f;
  12989. query.span_term[f] = oldValue;
  12990. return this;
  12991. },
  12992. /**
  12993. Sets the term.
  12994. @member ejs.SpanTermQuery
  12995. @param {String} t A single term.
  12996. @returns {Object} returns <code>this</code> so that calls can be chained.
  12997. */
  12998. term: function (t) {
  12999. if (t == null) {
  13000. return query.span_term[field].term;
  13001. }
  13002. query.span_term[field].term = t;
  13003. return this;
  13004. },
  13005. /**
  13006. Sets the boost value for documents matching the <code>Query</code>.
  13007. @member ejs.SpanTermQuery
  13008. @param {Double} boost A positive <code>double</code> value.
  13009. @returns {Object} returns <code>this</code> so that calls can be chained.
  13010. */
  13011. boost: function (boost) {
  13012. if (boost == null) {
  13013. return query.span_term[field].boost;
  13014. }
  13015. query.span_term[field].boost = boost;
  13016. return this;
  13017. },
  13018. /**
  13019. Allows you to serialize this object into a JSON encoded string.
  13020. @member ejs.SpanTermQuery
  13021. @returns {String} returns this object as a serialized JSON string.
  13022. */
  13023. toString: function () {
  13024. return JSON.stringify(query);
  13025. },
  13026. /**
  13027. The type of ejs object. For internal use only.
  13028. @member ejs.SpanTermQuery
  13029. @returns {String} the type of object
  13030. */
  13031. _type: function () {
  13032. return 'query';
  13033. },
  13034. /**
  13035. Retrieves the internal <code>query</code> object. This is typically used by
  13036. internal API functions so use with caution.
  13037. @member ejs.SpanTermQuery
  13038. @returns {String} returns this object's internal <code>query</code> property.
  13039. */
  13040. _self: function () {
  13041. return query;
  13042. }
  13043. };
  13044. };
  13045. /**
  13046. @class
  13047. <p>A <code>TermQuery</code> can be used to return documents containing a given
  13048. keyword or <em>term</em>. For instance, you might want to retieve all the
  13049. documents/objects that contain the term <code>Javascript</code>. Term filters
  13050. often serve as the basis for more complex queries such as <em>Boolean</em> queries.</p>
  13051. @name ejs.TermQuery
  13052. @desc
  13053. A Query that matches documents containing a term. This may be
  13054. combined with other terms with a BooleanQuery.
  13055. @param {String} field the document field/key to query against
  13056. @param {String} term the literal value to be matched
  13057. */
  13058. ejs.TermQuery = function (field, term) {
  13059. /**
  13060. The internal query object. <code>Use get()</code>
  13061. @member ejs.TermQuery
  13062. @property {Object} query
  13063. */
  13064. var query = {
  13065. term: {}
  13066. };
  13067. query.term[field] = {
  13068. term: term
  13069. };
  13070. return {
  13071. /**
  13072. Sets the fields to query against.
  13073. @member ejs.TermQuery
  13074. @param {String} f A valid field name.
  13075. @returns {Object} returns <code>this</code> so that calls can be chained.
  13076. */
  13077. field: function (f) {
  13078. var oldValue = query.term[field];
  13079. if (f == null) {
  13080. return field;
  13081. }
  13082. delete query.term[field];
  13083. field = f;
  13084. query.term[f] = oldValue;
  13085. return this;
  13086. },
  13087. /**
  13088. Sets the term.
  13089. @member ejs.TermQuery
  13090. @param {String} t A single term.
  13091. @returns {Object} returns <code>this</code> so that calls can be chained.
  13092. */
  13093. term: function (t) {
  13094. if (t == null) {
  13095. return query.term[field].term;
  13096. }
  13097. query.term[field].term = t;
  13098. return this;
  13099. },
  13100. /**
  13101. Sets the boost value for documents matching the <code>Query</code>.
  13102. @member ejs.TermQuery
  13103. @param {Number} boost A positive <code>double</code> value.
  13104. @returns {Object} returns <code>this</code> so that calls can be chained.
  13105. */
  13106. boost: function (boost) {
  13107. if (boost == null) {
  13108. return query.term[field].boost;
  13109. }
  13110. query.term[field].boost = boost;
  13111. return this;
  13112. },
  13113. /**
  13114. Allows you to serialize this object into a JSON encoded string.
  13115. @member ejs.TermQuery
  13116. @returns {String} returns this object as a serialized JSON string.
  13117. */
  13118. toString: function () {
  13119. return JSON.stringify(query);
  13120. },
  13121. /**
  13122. The type of ejs object. For internal use only.
  13123. @member ejs.TermQuery
  13124. @returns {String} the type of object
  13125. */
  13126. _type: function () {
  13127. return 'query';
  13128. },
  13129. /**
  13130. Retrieves the internal <code>query</code> object. This is typically used by
  13131. internal API functions so use with caution.
  13132. @member ejs.TermQuery
  13133. @returns {String} returns this object's internal <code>query</code> property.
  13134. */
  13135. _self: function () {
  13136. return query;
  13137. }
  13138. };
  13139. };
  13140. /**
  13141. @class
  13142. <p>A query that match on any (configurable) of the provided terms. This is
  13143. a simpler syntax query for using a bool query with several term queries
  13144. in the should clauses.</p>
  13145. @name ejs.TermsQuery
  13146. @desc
  13147. A Query that matches documents containing provided terms.
  13148. @param {String} field the document field/key to query against
  13149. @param {String || Array} terms a single term or array of "terms" to match
  13150. */
  13151. ejs.TermsQuery = function (field, terms) {
  13152. /**
  13153. The internal query object. <code>Use get()</code>
  13154. @member ejs.TermsQuery
  13155. @property {Object} query
  13156. */
  13157. var query = {
  13158. terms: {}
  13159. };
  13160. if (isString(terms)) {
  13161. query.terms[field] = [terms];
  13162. } else if (isArray(terms)) {
  13163. query.terms[field] = terms;
  13164. } else {
  13165. throw new TypeError('Argument must be string or array');
  13166. }
  13167. return {
  13168. /**
  13169. Sets the fields to query against.
  13170. @member ejs.TermsQuery
  13171. @param {String} f A valid field name.
  13172. @returns {Object} returns <code>this</code> so that calls can be chained.
  13173. */
  13174. field: function (f) {
  13175. var oldValue = query.terms[field];
  13176. if (f == null) {
  13177. return field;
  13178. }
  13179. delete query.terms[field];
  13180. field = f;
  13181. query.terms[f] = oldValue;
  13182. return this;
  13183. },
  13184. /**
  13185. Sets the terms. If you t is a String, it is added to the existing
  13186. list of terms. If t is an array, the list of terms replaces the
  13187. existing terms.
  13188. @member ejs.TermsQuery
  13189. @param {String || Array} t A single term or an array or terms.
  13190. @returns {Object} returns <code>this</code> so that calls can be chained.
  13191. */
  13192. terms: function (t) {
  13193. if (t == null) {
  13194. return query.terms[field];
  13195. }
  13196. if (isString(t)) {
  13197. query.terms[field].push(t);
  13198. } else if (isArray(t)) {
  13199. query.terms[field] = t;
  13200. } else {
  13201. throw new TypeError('Argument must be string or array');
  13202. }
  13203. return this;
  13204. },
  13205. /**
  13206. Sets the minimum number of terms that need to match in a document
  13207. before that document is returned in the results.
  13208. @member ejs.TermsQuery
  13209. @param {Integer} min A positive integer.
  13210. @returns {Object} returns <code>this</code> so that calls can be chained.
  13211. */
  13212. minimumShouldMatch: function (min) {
  13213. if (min == null) {
  13214. return query.terms.minimum_should_match;
  13215. }
  13216. query.terms.minimum_should_match = min;
  13217. return this;
  13218. },
  13219. /**
  13220. Enables or disables similarity coordinate scoring of documents
  13221. matching the <code>Query</code>. Default: false.
  13222. @member ejs.TermsQuery
  13223. @param {String} trueFalse A <code>true/false</code value.
  13224. @returns {Object} returns <code>this</code> so that calls can be chained.
  13225. */
  13226. disableCoord: function (trueFalse) {
  13227. if (trueFalse == null) {
  13228. return query.terms.disable_coord;
  13229. }
  13230. query.terms.disable_coord = trueFalse;
  13231. return this;
  13232. },
  13233. /**
  13234. Sets the boost value for documents matching the <code>Query</code>.
  13235. @member ejs.TermsQuery
  13236. @param {Number} boost A positive <code>double</code> value.
  13237. @returns {Object} returns <code>this</code> so that calls can be chained.
  13238. */
  13239. boost: function (boost) {
  13240. if (boost == null) {
  13241. return query.terms.boost;
  13242. }
  13243. query.terms.boost = boost;
  13244. return this;
  13245. },
  13246. /**
  13247. Allows you to serialize this object into a JSON encoded string.
  13248. @member ejs.TermsQuery
  13249. @returns {String} returns this object as a serialized JSON string.
  13250. */
  13251. toString: function () {
  13252. return JSON.stringify(query);
  13253. },
  13254. /**
  13255. The type of ejs object. For internal use only.
  13256. @member ejs.TermsQuery
  13257. @returns {String} the type of object
  13258. */
  13259. _type: function () {
  13260. return 'query';
  13261. },
  13262. /**
  13263. Retrieves the internal <code>query</code> object. This is typically used by
  13264. internal API functions so use with caution.
  13265. @member ejs.TermsQuery
  13266. @returns {String} returns this object's internal <code>query</code> property.
  13267. */
  13268. _self: function () {
  13269. return query;
  13270. }
  13271. };
  13272. };
  13273. /**
  13274. @class
  13275. <p>TThe top_children query runs the child query with an estimated hits size,
  13276. and out of the hit docs, aggregates it into parent docs. If there aren’t
  13277. enough parent docs matching the requested from/size search request, then it
  13278. is run again with a wider (more hits) search.</p>
  13279. <p>The top_children also provide scoring capabilities, with the ability to
  13280. specify max, sum or avg as the score type.</p>
  13281. @name ejs.TopChildrenQuery
  13282. @desc
  13283. Returns child documents matching the query aggregated into the parent docs.
  13284. @param {Object} qry A valid query object.
  13285. @param {String} type The child type to execute the query on
  13286. */
  13287. ejs.TopChildrenQuery = function (qry, type) {
  13288. if (!isQuery(qry)) {
  13289. throw new TypeError('Argument must be a Query');
  13290. }
  13291. /**
  13292. The internal query object. <code>Use _self()</code>
  13293. @member ejs.TopChildrenQuery
  13294. @property {Object} query
  13295. */
  13296. var query = {
  13297. top_children: {
  13298. query: qry._self(),
  13299. type: type
  13300. }
  13301. };
  13302. return {
  13303. /**
  13304. Sets the query
  13305. @member ejs.TopChildrenQuery
  13306. @param {Object} q A valid Query object
  13307. @returns {Object} returns <code>this</code> so that calls can be chained.
  13308. */
  13309. query: function (q) {
  13310. if (q == null) {
  13311. return query.top_children.query;
  13312. }
  13313. if (!isQuery(q)) {
  13314. throw new TypeError('Argument must be a Query');
  13315. }
  13316. query.top_children.query = q._self();
  13317. return this;
  13318. },
  13319. /**
  13320. Sets the child document type to search against
  13321. @member ejs.TopChildrenQuery
  13322. @param {String} t A valid type name
  13323. @returns {Object} returns <code>this</code> so that calls can be chained.
  13324. */
  13325. type: function (t) {
  13326. if (t == null) {
  13327. return query.top_children.type;
  13328. }
  13329. query.top_children.type = t;
  13330. return this;
  13331. },
  13332. /**
  13333. Sets the scope of the query. A scope allows to run facets on the
  13334. same scope name that will work against the child documents.
  13335. @deprecated since elasticsearch 0.90
  13336. @member ejs.TopChildrenQuery
  13337. @param {String} s The scope name as a string.
  13338. @returns {Object} returns <code>this</code> so that calls can be chained.
  13339. */
  13340. scope: function (s) {
  13341. return this;
  13342. },
  13343. /**
  13344. Sets the scoring type. Valid values are max, sum, or avg. If
  13345. another value is passed it we silently ignore the value.
  13346. @member ejs.TopChildrenQuery
  13347. @param {String} s The scoring type as a string.
  13348. @returns {Object} returns <code>this</code> so that calls can be chained.
  13349. */
  13350. score: function (s) {
  13351. if (s == null) {
  13352. return query.top_children.score;
  13353. }
  13354. s = s.toLowerCase();
  13355. if (s === 'max' || s === 'sum' || s === 'avg') {
  13356. query.top_children.score = s;
  13357. }
  13358. return this;
  13359. },
  13360. /**
  13361. Sets the factor which is the number of hits that are asked for in
  13362. the child query. Defaults to 5.
  13363. @member ejs.TopChildrenQuery
  13364. @param {Integer} f A positive integer value.
  13365. @returns {Object} returns <code>this</code> so that calls can be chained.
  13366. */
  13367. factor: function (f) {
  13368. if (f == null) {
  13369. return query.top_children.factor;
  13370. }
  13371. query.top_children.factor = f;
  13372. return this;
  13373. },
  13374. /**
  13375. Sets the incremental factor. The incremental factor is used when not
  13376. enough child documents are returned so the factor is multiplied by
  13377. the incremental factor to fetch more results. Defaults to 52
  13378. @member ejs.TopChildrenQuery
  13379. @param {Integer} f A positive integer value.
  13380. @returns {Object} returns <code>this</code> so that calls can be chained.
  13381. */
  13382. incrementalFactor: function (f) {
  13383. if (f == null) {
  13384. return query.top_children.incremental_factor;
  13385. }
  13386. query.top_children.incremental_factor = f;
  13387. return this;
  13388. },
  13389. /**
  13390. Sets the boost value of the <code>Query</code>.
  13391. @member ejs.TopChildrenQuery
  13392. @param {Double} boost A positive <code>double</code> value.
  13393. @returns {Object} returns <code>this</code> so that calls can be chained.
  13394. */
  13395. boost: function (boost) {
  13396. if (boost == null) {
  13397. return query.top_children.boost;
  13398. }
  13399. query.top_children.boost = boost;
  13400. return this;
  13401. },
  13402. /**
  13403. Allows you to serialize this object into a JSON encoded string.
  13404. @member ejs.TopChildrenQuery
  13405. @returns {String} returns this object as a serialized JSON string.
  13406. */
  13407. toString: function () {
  13408. return JSON.stringify(query);
  13409. },
  13410. /**
  13411. The type of ejs object. For internal use only.
  13412. @member ejs.TopChildrenQuery
  13413. @returns {String} the type of object
  13414. */
  13415. _type: function () {
  13416. return 'query';
  13417. },
  13418. /**
  13419. Retrieves the internal <code>query</code> object. This is typically used by
  13420. internal API functions so use with caution.
  13421. @member ejs.TopChildrenQuery
  13422. @returns {String} returns this object's internal <code>query</code> property.
  13423. */
  13424. _self: function () {
  13425. return query;
  13426. }
  13427. };
  13428. };
  13429. /**
  13430. @class
  13431. <p>Matches documents that have fields matching a wildcard expression
  13432. (not analyzed). Supported wildcards are *, which matches any character
  13433. sequence (including the empty one), and ?, which matches any single
  13434. character. Note this query can be slow, as it needs to iterate over many
  13435. wildcards. In order to prevent extremely slow wildcard queries, a wildcard
  13436. wildcard should not start with one of the wildcards * or ?. The wildcard query
  13437. maps to Lucene WildcardQuery.</p>
  13438. @name ejs.WildcardQuery
  13439. @desc
  13440. A Query that matches documents containing a wildcard. This may be
  13441. combined with other wildcards with a BooleanQuery.
  13442. @param {String} field the document field/key to query against
  13443. @param {String} value the literal value to be matched
  13444. */
  13445. ejs.WildcardQuery = function (field, value) {
  13446. /**
  13447. The internal query object. <code>Use get()</code>
  13448. @member ejs.WildcardQuery
  13449. @property {Object} query
  13450. */
  13451. var query = {
  13452. wildcard: {}
  13453. };
  13454. query.wildcard[field] = {
  13455. value: value
  13456. };
  13457. return {
  13458. /**
  13459. Sets the fields to query against.
  13460. @member ejs.WildcardQuery
  13461. @param {String} f A valid field name.
  13462. @returns {Object} returns <code>this</code> so that calls can be chained.
  13463. */
  13464. field: function (f) {
  13465. var oldValue = query.wildcard[field];
  13466. if (f == null) {
  13467. return field;
  13468. }
  13469. delete query.wildcard[field];
  13470. field = f;
  13471. query.wildcard[f] = oldValue;
  13472. return this;
  13473. },
  13474. /**
  13475. Sets the wildcard query value.
  13476. @member ejs.WildcardQuery
  13477. @param {String} v A single term.
  13478. @returns {Object} returns <code>this</code> so that calls can be chained.
  13479. */
  13480. value: function (v) {
  13481. if (v == null) {
  13482. return query.wildcard[field].value;
  13483. }
  13484. query.wildcard[field].value = v;
  13485. return this;
  13486. },
  13487. /**
  13488. Sets rewrite method. Valid values are:
  13489. constant_score_auto - tries to pick the best constant-score rewrite
  13490. method based on term and document counts from the query
  13491. scoring_boolean - translates each term into boolean should and
  13492. keeps the scores as computed by the query
  13493. constant_score_boolean - same as scoring_boolean, expect no scores
  13494. are computed.
  13495. constant_score_filter - first creates a private Filter, by visiting
  13496. each term in sequence and marking all docs for that term
  13497. top_terms_boost_N - first translates each term into boolean should
  13498. and scores are only computed as the boost using the top N
  13499. scoring terms. Replace N with an integer value.
  13500. top_terms_N - first translates each term into boolean should
  13501. and keeps the scores as computed by the query. Only the top N
  13502. scoring terms are used. Replace N with an integer value.
  13503. Default is constant_score_auto.
  13504. This is an advanced option, use with care.
  13505. @member ejs.WildcardQuery
  13506. @param {String} m The rewrite method as a string.
  13507. @returns {Object} returns <code>this</code> so that calls can be chained.
  13508. */
  13509. rewrite: function (m) {
  13510. if (m == null) {
  13511. return query.wildcard[field].rewrite;
  13512. }
  13513. m = m.toLowerCase();
  13514. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  13515. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  13516. m.indexOf('top_terms_boost_') === 0 ||
  13517. m.indexOf('top_terms_') === 0) {
  13518. query.wildcard[field].rewrite = m;
  13519. }
  13520. return this;
  13521. },
  13522. /**
  13523. Sets the boost value for documents matching the <code>Query</code>.
  13524. @member ejs.WildcardQuery
  13525. @param {Number} boost A positive <code>double</code> value.
  13526. @returns {Object} returns <code>this</code> so that calls can be chained.
  13527. */
  13528. boost: function (boost) {
  13529. if (boost == null) {
  13530. return query.wildcard[field].boost;
  13531. }
  13532. query.wildcard[field].boost = boost;
  13533. return this;
  13534. },
  13535. /**
  13536. Allows you to serialize this object into a JSON encoded string.
  13537. @member ejs.WildcardQuery
  13538. @returns {String} returns this object as a serialized JSON string.
  13539. */
  13540. toString: function () {
  13541. return JSON.stringify(query);
  13542. },
  13543. /**
  13544. The type of ejs object. For internal use only.
  13545. @member ejs.WildcardQuery
  13546. @returns {String} the type of object
  13547. */
  13548. _type: function () {
  13549. return 'query';
  13550. },
  13551. /**
  13552. Retrieves the internal <code>query</code> object. This is typically used by
  13553. internal API functions so use with caution.
  13554. @member ejs.WildcardQuery
  13555. @returns {String} returns this object's internal <code>query</code> property.
  13556. */
  13557. _self: function () {
  13558. return query;
  13559. }
  13560. };
  13561. };
  13562. /**
  13563. @class
  13564. <p>A GeoPoint object that can be used in queries and filters that
  13565. take a GeoPoint. GeoPoint supports various input formats.</p>
  13566. <p>See http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html</p>
  13567. @name ejs.GeoPoint
  13568. @desc
  13569. <p>Defines a point</p>
  13570. @param {Array} p An optional point as an array in [lat, lon] format.
  13571. */
  13572. ejs.GeoPoint = function (p) {
  13573. var point = [0, 0];
  13574. // p = [lat, lon], convert it to GeoJSON format of [lon, lat]
  13575. if (p != null && isArray(p) && p.length === 2) {
  13576. point = [p[1], p[0]];
  13577. }
  13578. return {
  13579. /**
  13580. Sets the GeoPoint as properties on an object. The object must have
  13581. a 'lat' and 'lon' property.
  13582. Example:
  13583. {lat: 41.12, lon: -71.34}
  13584. @member ejs.GeoPoint
  13585. @param {Object} obj an object with a lat and lon property.
  13586. @returns {Object} returns <code>this</code> so that calls can be chained.
  13587. */
  13588. properties: function (obj) {
  13589. if (obj == null) {
  13590. return point;
  13591. }
  13592. if (isObject(obj) && has(obj, 'lat') && has(obj, 'lon')) {
  13593. point = {
  13594. lat: obj.lat,
  13595. lon: obj.lon
  13596. };
  13597. }
  13598. return this;
  13599. },
  13600. /**
  13601. Sets the GeoPoint as a string. The format is "lat,lon".
  13602. Example:
  13603. "41.12,-71.34"
  13604. @member ejs.GeoPoint
  13605. @param {String} s a String point in "lat,lon" format.
  13606. @returns {Object} returns <code>this</code> so that calls can be chained.
  13607. */
  13608. string: function (s) {
  13609. if (s == null) {
  13610. return point;
  13611. }
  13612. if (isString(s) && s.indexOf(',') !== -1) {
  13613. point = s;
  13614. }
  13615. return this;
  13616. },
  13617. /**
  13618. Sets the GeoPoint as a GeoHash. The hash is a string of
  13619. alpha-numeric characters with a precision length that defaults to 12.
  13620. Example:
  13621. "drm3btev3e86"
  13622. @member ejs.GeoPoint
  13623. @param {String} hash an GeoHash as a string
  13624. @param {Integer} precision an optional precision length, defaults
  13625. to 12 if not specified.
  13626. @returns {Object} returns <code>this</code> so that calls can be chained.
  13627. */
  13628. geohash: function (hash, precision) {
  13629. // set precision, default to 12
  13630. precision = (precision != null && isNumber(precision)) ? precision : 12;
  13631. if (hash == null) {
  13632. return point;
  13633. }
  13634. if (isString(hash) && hash.length === precision) {
  13635. point = hash;
  13636. }
  13637. return this;
  13638. },
  13639. /**
  13640. Sets the GeoPoint from an array point. The array must contain only
  13641. 2 values. The first value is the lat and the 2nd value is the lon.
  13642. Example:
  13643. [41.12, -71.34]
  13644. @member ejs.GeoPoint
  13645. @param {Array} a an array of length 2.
  13646. @returns {Object} returns <code>this</code> so that calls can be chained.
  13647. */
  13648. array: function (a) {
  13649. if (a == null) {
  13650. return point;
  13651. }
  13652. // convert to GeoJSON format of [lon, lat]
  13653. if (isArray(a) && a.length === 2) {
  13654. point = [a[1], a[0]];
  13655. }
  13656. return this;
  13657. },
  13658. /**
  13659. Allows you to serialize this object into a JSON encoded string.
  13660. @member ejs.GeoPoint
  13661. @returns {String} returns this object as a serialized JSON string.
  13662. */
  13663. toString: function () {
  13664. return JSON.stringify(point);
  13665. },
  13666. /**
  13667. The type of ejs object. For internal use only.
  13668. @member ejs.GeoPoint
  13669. @returns {String} the type of object
  13670. */
  13671. _type: function () {
  13672. return 'geo point';
  13673. },
  13674. /**
  13675. Retrieves the internal <code>script</code> object. This is typically used by
  13676. internal API functions so use with caution.
  13677. @member ejs.GeoPoint
  13678. @returns {String} returns this object's internal object representation.
  13679. */
  13680. _self: function () {
  13681. return point;
  13682. }
  13683. };
  13684. };
  13685. /**
  13686. @class
  13687. <p>Allows to highlight search results on one or more fields. In order to
  13688. perform highlighting, the actual content of the field is required. If the
  13689. field in question is stored (has store set to yes in the mapping), it will
  13690. be used, otherwise, the actual _source will be loaded and the relevant
  13691. field will be extracted from it.</p>
  13692. <p>If no term_vector information is provided (by setting it to
  13693. with_positions_offsets in the mapping), then the plain highlighter will be
  13694. used. If it is provided, then the fast vector highlighter will be used.
  13695. When term vectors are available, highlighting will be performed faster at
  13696. the cost of bigger index size.</p>
  13697. <p>See http://www.elasticsearch.org/guide/reference/api/search/highlighting.html</p>
  13698. @name ejs.Highlight
  13699. @desc
  13700. <p>Allows to highlight search results on one or more fields.</p>
  13701. @param {String || Array} fields An optional field or array of fields to highlight.
  13702. */
  13703. ejs.Highlight = function (fields) {
  13704. var highlight = {
  13705. fields: {}
  13706. },
  13707. addOption = function (field, option, val) {
  13708. if (field == null) {
  13709. highlight[option] = val;
  13710. } else {
  13711. if (!has(highlight.fields, field)) {
  13712. highlight.fields[field] = {};
  13713. }
  13714. highlight.fields[field][option] = val;
  13715. }
  13716. };
  13717. if (fields != null) {
  13718. if (isString(fields)) {
  13719. highlight.fields[fields] = {};
  13720. } else if (isArray(fields)) {
  13721. each(fields, function (field) {
  13722. highlight.fields[field] = {};
  13723. });
  13724. }
  13725. }
  13726. return {
  13727. /**
  13728. Allows you to set the fields that will be highlighted. You can
  13729. specify a single field or an array of fields. All fields are
  13730. added to the current list of fields.
  13731. @member ejs.Highlight
  13732. @param {String || Array} vals A field name or array of field names.
  13733. @returns {Object} returns <code>this</code> so that calls can be chained.
  13734. */
  13735. fields: function (vals) {
  13736. if (vals == null) {
  13737. return highlight.fields;
  13738. }
  13739. if (isString(vals)) {
  13740. if (!has(highlight.fields, vals)) {
  13741. highlight.fields[vals] = {};
  13742. }
  13743. } else if (isArray(vals)) {
  13744. each(vals, function (field) {
  13745. if (!has(highlight.fields, field)) {
  13746. highlight.fields[field] = {};
  13747. }
  13748. });
  13749. }
  13750. },
  13751. /**
  13752. Sets the pre tags for highlighted fragments. You can apply the
  13753. tags to a specific field by passing the field name in to the
  13754. <code>oField</code> parameter.
  13755. @member ejs.Highlight
  13756. @param {String || Array} tags A single tag or an array of tags.
  13757. @param {String} oField An optional field name
  13758. @returns {Object} returns <code>this</code> so that calls can be chained.
  13759. */
  13760. preTags: function (tags, oField) {
  13761. if (tags === null && oField != null) {
  13762. return highlight.fields[oField].pre_tags;
  13763. } else if (tags == null) {
  13764. return highlight.pre_tags;
  13765. }
  13766. if (isString(tags)) {
  13767. addOption(oField, 'pre_tags', [tags]);
  13768. } else if (isArray(tags)) {
  13769. addOption(oField, 'pre_tags', tags);
  13770. }
  13771. return this;
  13772. },
  13773. /**
  13774. Sets the post tags for highlighted fragments. You can apply the
  13775. tags to a specific field by passing the field name in to the
  13776. <code>oField</code> parameter.
  13777. @member ejs.Highlight
  13778. @param {String || Array} tags A single tag or an array of tags.
  13779. @param {String} oField An optional field name
  13780. @returns {Object} returns <code>this</code> so that calls can be chained.
  13781. */
  13782. postTags: function (tags, oField) {
  13783. if (tags === null && oField != null) {
  13784. return highlight.fields[oField].post_tags;
  13785. } else if (tags == null) {
  13786. return highlight.post_tags;
  13787. }
  13788. if (isString(tags)) {
  13789. addOption(oField, 'post_tags', [tags]);
  13790. } else if (isArray(tags)) {
  13791. addOption(oField, 'post_tags', tags);
  13792. }
  13793. return this;
  13794. },
  13795. /**
  13796. Sets the order of highlight fragments. You can apply the option
  13797. to a specific field by passing the field name in to the
  13798. <code>oField</code> parameter. Valid values for order are:
  13799. score - the score calculated by Lucene's highlighting framework.
  13800. @member ejs.Highlight
  13801. @param {String} o The order. Currently only "score".
  13802. @param {String} oField An optional field name
  13803. @returns {Object} returns <code>this</code> so that calls can be chained.
  13804. */
  13805. order: function (o, oField) {
  13806. if (o === null && oField != null) {
  13807. return highlight.fields[oField].order;
  13808. } else if (o == null) {
  13809. return highlight.order;
  13810. }
  13811. o = o.toLowerCase();
  13812. if (o === 'score') {
  13813. addOption(oField, 'order', o);
  13814. }
  13815. return this;
  13816. },
  13817. /**
  13818. Sets the schema to be used for the tags. Valid values are:
  13819. styled - 10 <em> pre tags with css class of hltN, where N is 1-10
  13820. @member ejs.Highlight
  13821. @param {String} s The schema. Currently only "styled".
  13822. @returns {Object} returns <code>this</code> so that calls can be chained.
  13823. */
  13824. tagsSchema: function (s) {
  13825. if (s == null) {
  13826. return highlight.tags_schema;
  13827. }
  13828. s = s.toLowerCase();
  13829. if (s === 'styled') {
  13830. highlight.tags_schema = s;
  13831. }
  13832. return this;
  13833. },
  13834. /**
  13835. Enables highlights in documents matched by a filter.
  13836. You can apply the option to a specific field by passing the field
  13837. name in to the <code>oField</code> parameter. Defaults to false.
  13838. @member ejs.Highlight
  13839. @param {Boolean} trueFalse If filtered docs should be highlighted.
  13840. @param {String} oField An optional field name
  13841. @returns {Object} returns <code>this</code> so that calls can be chained.
  13842. */
  13843. highlightFilter: function (trueFalse, oField) {
  13844. if (trueFalse === null && oField != null) {
  13845. return highlight.fields[oField].highlight_filter;
  13846. } else if (trueFalse == null) {
  13847. return highlight.highlight_filter;
  13848. }
  13849. addOption(oField, 'highlight_filter', trueFalse);
  13850. return this;
  13851. },
  13852. /**
  13853. Sets the size of each highlight fragment in characters.
  13854. You can apply the option to a specific field by passing the field
  13855. name in to the <code>oField</code> parameter. Default: 100
  13856. @member ejs.Highlight
  13857. @param {Integer} size The fragment size in characters.
  13858. @param {String} oField An optional field name
  13859. @returns {Object} returns <code>this</code> so that calls can be chained.
  13860. */
  13861. fragmentSize: function (size, oField) {
  13862. if (size === null && oField != null) {
  13863. return highlight.fields[oField].fragment_size;
  13864. } else if (size == null) {
  13865. return highlight.fragment_size;
  13866. }
  13867. addOption(oField, 'fragment_size', size);
  13868. return this;
  13869. },
  13870. /**
  13871. Sets the number of highlight fragments.
  13872. You can apply the option to a specific field by passing the field
  13873. name in to the <code>oField</code> parameter. Default: 5
  13874. @member ejs.Highlight
  13875. @param {Integer} cnt The fragment size in characters.
  13876. @param {String} oField An optional field name
  13877. @returns {Object} returns <code>this</code> so that calls can be chained.
  13878. */
  13879. numberOfFragments: function (cnt, oField) {
  13880. if (cnt === null && oField != null) {
  13881. return highlight.fields[oField].number_of_fragments;
  13882. } else if (cnt == null) {
  13883. return highlight.number_of_fragments;
  13884. }
  13885. addOption(oField, 'number_of_fragments', cnt);
  13886. return this;
  13887. },
  13888. /**
  13889. Sets highlight encoder. Valid values are:
  13890. default - the default, no encoding
  13891. html - to encode html characters if you use html tags
  13892. @member ejs.Highlight
  13893. @param {String} e The encoder. default or html
  13894. @returns {Object} returns <code>this</code> so that calls can be chained.
  13895. */
  13896. encoder: function (e) {
  13897. if (e == null) {
  13898. return highlight.encoder;
  13899. }
  13900. e = e.toLowerCase();
  13901. if (e === 'default' || e === 'html') {
  13902. highlight.encoder = e;
  13903. }
  13904. return this;
  13905. },
  13906. /**
  13907. When enabled it will cause a field to be highlighted only if a
  13908. query matched that field. false means that terms are highlighted
  13909. on all requested fields regardless if the query matches
  13910. specifically on them. You can apply the option to a specific
  13911. field by passing the field name in to the <code>oField</code>
  13912. parameter. Defaults to false.
  13913. @member ejs.Highlight
  13914. @param {Boolean} trueFalse If filtered docs should be highlighted.
  13915. @param {String} oField An optional field name
  13916. @returns {Object} returns <code>this</code> so that calls can be chained.
  13917. */
  13918. requireFieldMatch: function (trueFalse, oField) {
  13919. if (trueFalse === null && oField != null) {
  13920. return highlight.fields[oField].require_field_match;
  13921. } else if (trueFalse == null) {
  13922. return highlight.require_field_match;
  13923. }
  13924. addOption(oField, 'require_field_match', trueFalse);
  13925. return this;
  13926. },
  13927. /**
  13928. Sets the max number of characters to scan while looking for the
  13929. start of a boundary character. You can apply the option to a
  13930. specific field by passing the field name in to the
  13931. <code>oField</code> parameter. Default: 20
  13932. @member ejs.Highlight
  13933. @param {Integer} cnt The max characters to scan.
  13934. @param {String} oField An optional field name
  13935. @returns {Object} returns <code>this</code> so that calls can be chained.
  13936. */
  13937. boundaryMaxScan: function (cnt, oField) {
  13938. if (cnt === null && oField != null) {
  13939. return highlight.fields[oField].boundary_max_scan;
  13940. } else if (cnt == null) {
  13941. return highlight.boundary_max_scan;
  13942. }
  13943. addOption(oField, 'boundary_max_scan', cnt);
  13944. return this;
  13945. },
  13946. /**
  13947. Set's the boundary characters. When highlighting a field that is
  13948. mapped with term vectors, boundary_chars can be configured to
  13949. define what constitutes a boundary for highlighting. It’s a single
  13950. string with each boundary character defined in it. You can apply
  13951. the option to a specific field by passing the field name in to
  13952. the <code>oField</code> parameter. It defaults to ".,!? \t\n".
  13953. @member ejs.Highlight
  13954. @param {String} charStr The boundary chars in a string.
  13955. @param {String} oField An optional field name
  13956. @returns {Object} returns <code>this</code> so that calls can be chained.
  13957. */
  13958. boundaryChars: function (charStr, oField) {
  13959. if (charStr === null && oField != null) {
  13960. return highlight.fields[oField].boundary_chars;
  13961. } else if (charStr == null) {
  13962. return highlight.boundary_chars;
  13963. }
  13964. addOption(oField, 'boundary_chars', charStr);
  13965. return this;
  13966. },
  13967. /**
  13968. Sets the highligher type. You can apply the option
  13969. to a specific field by passing the field name in to the
  13970. <code>oField</code> parameter. Valid values for order are:
  13971. fast-vector-highlighter - the fast vector based highligher
  13972. highlighter - the slower plain highligher
  13973. @member ejs.Highlight
  13974. @param {String} t The highligher.
  13975. @param {String} oField An optional field name
  13976. @returns {Object} returns <code>this</code> so that calls can be chained.
  13977. */
  13978. type: function (t, oField) {
  13979. if (t === null && oField != null) {
  13980. return highlight.fields[oField].type;
  13981. } else if (t == null) {
  13982. return highlight.type;
  13983. }
  13984. t = t.toLowerCase();
  13985. if (t === 'fast-vector-highlighter' || t === 'highlighter') {
  13986. addOption(oField, 'type', t);
  13987. }
  13988. return this;
  13989. },
  13990. /**
  13991. Sets the fragmenter type. You can apply the option
  13992. to a specific field by passing the field name in to the
  13993. <code>oField</code> parameter. Valid values for order are:
  13994. simple - breaks text up into same-size fragments with no concerns
  13995. over spotting sentence boundaries.
  13996. span - breaks text up into same-size fragments but does not split
  13997. up Spans.
  13998. @member ejs.Highlight
  13999. @param {String} f The fragmenter.
  14000. @param {String} oField An optional field name
  14001. @returns {Object} returns <code>this</code> so that calls can be chained.
  14002. */
  14003. fragmenter: function (f, oField) {
  14004. if (f === null && oField != null) {
  14005. return highlight.fields[oField].fragmenter;
  14006. } else if (f == null) {
  14007. return highlight.fragmenter;
  14008. }
  14009. f = f.toLowerCase();
  14010. if (f === 'simple' || f === 'span') {
  14011. addOption(oField, 'fragmenter', f);
  14012. }
  14013. return this;
  14014. },
  14015. /**
  14016. Allows you to serialize this object into a JSON encoded string.
  14017. @member ejs.Highlight
  14018. @returns {String} returns this object as a serialized JSON string.
  14019. */
  14020. toString: function () {
  14021. return JSON.stringify(highlight);
  14022. },
  14023. /**
  14024. The type of ejs object. For internal use only.
  14025. @member ejs.Highlight
  14026. @returns {String} the type of object
  14027. */
  14028. _type: function () {
  14029. return 'highlight';
  14030. },
  14031. /**
  14032. Retrieves the internal <code>script</code> object. This is typically used by
  14033. internal API functions so use with caution.
  14034. @member ejs.Highlight
  14035. @returns {String} returns this object's internal object representation.
  14036. */
  14037. _self: function () {
  14038. return highlight;
  14039. }
  14040. };
  14041. };
  14042. /**
  14043. @class
  14044. <p>A shape which has already been indexed in another index and/or index
  14045. type. This is particularly useful for when you have a pre-defined list of
  14046. shapes which are useful to your application and you want to reference this
  14047. using a logical name (for example ‘New Zealand’) rather than having to
  14048. provide their coordinates each time.</p>
  14049. @name ejs.IndexedShape
  14050. @desc
  14051. <p>Defines a shape that already exists in an index/type.</p>
  14052. @param {String} type The name of the type where the shape is indexed.
  14053. @param {String} id The document id of the shape.
  14054. */
  14055. ejs.IndexedShape = function (type, id) {
  14056. var indexedShape = {
  14057. type: type,
  14058. id: id
  14059. };
  14060. return {
  14061. /**
  14062. Sets the type which the shape is indexed under.
  14063. @member ejs.IndexedShape
  14064. @param {String} t a valid shape type.
  14065. @returns {Object} returns <code>this</code> so that calls can be chained.
  14066. */
  14067. type: function (t) {
  14068. if (t == null) {
  14069. return indexedShape.type;
  14070. }
  14071. indexedShape.type = t;
  14072. return this;
  14073. },
  14074. /**
  14075. Sets the document id of the indexed shape.
  14076. @member ejs.IndexedShape
  14077. @param {String} id a valid document id.
  14078. @returns {Object} returns <code>this</code> so that calls can be chained.
  14079. */
  14080. id: function (id) {
  14081. if (id == null) {
  14082. return indexedShape.id;
  14083. }
  14084. indexedShape.id = id;
  14085. return this;
  14086. },
  14087. /**
  14088. Sets the index which the shape is indexed under.
  14089. Defaults to "shapes".
  14090. @member ejs.IndexedShape
  14091. @param {String} idx a valid index name.
  14092. @returns {Object} returns <code>this</code> so that calls can be chained.
  14093. */
  14094. index: function (idx) {
  14095. if (idx == null) {
  14096. return indexedShape.index;
  14097. }
  14098. indexedShape.index = idx;
  14099. return this;
  14100. },
  14101. /**
  14102. Sets the field name containing the indexed shape.
  14103. Defaults to "shape".
  14104. @member ejs.IndexedShape
  14105. @param {String} field a valid field name.
  14106. @returns {Object} returns <code>this</code> so that calls can be chained.
  14107. */
  14108. shapeFieldName: function (field) {
  14109. if (field == null) {
  14110. return indexedShape.shape_field_name;
  14111. }
  14112. indexedShape.shape_field_name = field;
  14113. return this;
  14114. },
  14115. /**
  14116. Allows you to serialize this object into a JSON encoded string.
  14117. @member ejs.IndexedShape
  14118. @returns {String} returns this object as a serialized JSON string.
  14119. */
  14120. toString: function () {
  14121. return JSON.stringify(indexedShape);
  14122. },
  14123. /**
  14124. The type of ejs object. For internal use only.
  14125. @member ejs.IndexedShape
  14126. @returns {String} the type of object
  14127. */
  14128. _type: function () {
  14129. return 'indexed shape';
  14130. },
  14131. /**
  14132. Retrieves the internal <code>script</code> object. This is typically used by
  14133. internal API functions so use with caution.
  14134. @member ejs.IndexedShape
  14135. @returns {String} returns this object's internal object representation.
  14136. */
  14137. _self: function () {
  14138. return indexedShape;
  14139. }
  14140. };
  14141. };
  14142. /**
  14143. @class
  14144. <p>The <code>Request</code> object provides methods generating and
  14145. executing search requests.</p>
  14146. @name ejs.Request
  14147. @desc
  14148. <p>Provides methods for executing search requests</p>
  14149. @param {Object} conf A configuration object containing the initilization
  14150. parameters. The following parameters can be set in the conf object:
  14151. indices - single index name or array of index names
  14152. types - single type name or array of types
  14153. routing - the shard routing value
  14154. */
  14155. ejs.Request = function (conf) {
  14156. var query, indices, types, params = {},
  14157. // gernerates the correct url to the specified REST endpoint
  14158. getRestPath = function (endpoint) {
  14159. var searchUrl = '',
  14160. parts = [];
  14161. // join any indices
  14162. if (indices.length > 0) {
  14163. searchUrl = searchUrl + '/' + indices.join();
  14164. }
  14165. // join any types
  14166. if (types.length > 0) {
  14167. searchUrl = searchUrl + '/' + types.join();
  14168. }
  14169. // add the endpoint
  14170. if (endpoint.length > 0 && endpoint[0] !== '/') {
  14171. searchUrl = searchUrl + '/';
  14172. }
  14173. searchUrl = searchUrl + endpoint;
  14174. for (var p in params) {
  14175. if (!has(params, p) || params[p] === '') {
  14176. continue;
  14177. }
  14178. parts.push(p + '=' + encodeURIComponent(params[p]));
  14179. }
  14180. if (parts.length > 0) {
  14181. searchUrl = searchUrl + '?' + parts.join('&');
  14182. }
  14183. return searchUrl;
  14184. };
  14185. /**
  14186. The internal query object.
  14187. @member ejs.Request
  14188. @property {Object} query
  14189. */
  14190. query = {};
  14191. conf = conf || {};
  14192. // check if we are searching across any specific indeices
  14193. if (conf.indices == null) {
  14194. indices = [];
  14195. } else if (isString(conf.indices)) {
  14196. indices = [conf.indices];
  14197. } else {
  14198. indices = conf.indices;
  14199. }
  14200. // check if we are searching across any specific types
  14201. if (conf.types == null) {
  14202. types = [];
  14203. } else if (isString(conf.types)) {
  14204. types = [conf.types];
  14205. } else {
  14206. types = conf.types;
  14207. }
  14208. // check that an index is specified when a type is
  14209. // if not, search across _all indices
  14210. if (indices.length === 0 && types.length > 0) {
  14211. indices = ["_all"];
  14212. }
  14213. if (conf.routing != null) {
  14214. params.routing = conf.routing;
  14215. }
  14216. return {
  14217. /**
  14218. <p>Sets the sorting for the query. This accepts many input formats.</p>
  14219. <dl>
  14220. <dd><code>sort()</code> - The current sorting values are returned.</dd>
  14221. <dd><code>sort(fieldName)</code> - Adds the field to the current list of sorting values.</dd>
  14222. <dd><code>sort(fieldName, order)</code> - Adds the field to the current list of
  14223. sorting with the specified order. Order must be asc or desc.</dd>
  14224. <dd><code>sort(ejs.Sort)</code> - Adds the Sort value to the current list of sorting values.</dd>
  14225. <dd><code>sort(array)</code> - Replaces all current sorting values with values
  14226. from the array. The array must contain only strings and Sort objects.</dd>
  14227. </dl>
  14228. <p>Multi-level sorting is supported so the order in which sort fields
  14229. are added to the query requests is relevant.</p>
  14230. <p>It is recommended to use <code>Sort</code> objects when possible.</p>
  14231. @member ejs.Request
  14232. @param {String} fieldName The field to be sorted by.
  14233. @returns {Object} returns <code>this</code> so that calls can be chained.
  14234. */
  14235. sort: function () {
  14236. var i, len;
  14237. if (!has(query, "sort")) {
  14238. query.sort = [];
  14239. }
  14240. if (arguments.length === 0) {
  14241. return query.sort;
  14242. }
  14243. // if passed a single argument
  14244. if (arguments.length === 1) {
  14245. var sortVal = arguments[0];
  14246. if (isString(sortVal)) {
  14247. // add a single field name
  14248. query.sort.push(sortVal);
  14249. } else if (isSort(sortVal)) {
  14250. // add the Sort object
  14251. query.sort.push(sortVal._self());
  14252. } else if (isArray(sortVal)) {
  14253. // replace with all values in the array
  14254. // the values must be a fieldName (string) or a
  14255. // Sort object. Any other type throws an Error.
  14256. query.sort = [];
  14257. for (i = 0, len = sortVal.length; i < len; i++) {
  14258. if (isString(sortVal[i])) {
  14259. query.sort.push(sortVal[i]);
  14260. } else if (isSort(sortVal[i])) {
  14261. query.sort.push(sortVal[i]._self());
  14262. } else {
  14263. throw new TypeError('Invalid object in array');
  14264. }
  14265. }
  14266. } else {
  14267. // Invalid object type as argument.
  14268. throw new TypeError('Argument must be string, Sort, or array');
  14269. }
  14270. } else if (arguments.length === 2) {
  14271. // handle the case where a single field name and order are passed
  14272. var field = arguments[0],
  14273. order = arguments[1];
  14274. if (isString(field) && isString(order)) {
  14275. order = order.toLowerCase();
  14276. if (order === 'asc' || order === 'desc') {
  14277. var sortObj = {};
  14278. sortObj[field] = {order: order};
  14279. query.sort.push(sortObj);
  14280. }
  14281. }
  14282. }
  14283. return this;
  14284. },
  14285. /**
  14286. Enables score computation and tracking during sorting. Be default,
  14287. when sorting scores are not computed.
  14288. @member ejs.Request
  14289. @param {Boolean} trueFalse If scores should be computed and tracked.
  14290. @returns {Object} returns <code>this</code> so that calls can be chained.
  14291. */
  14292. trackScores: function (trueFalse) {
  14293. if (trueFalse == null) {
  14294. return query.track_scores;
  14295. }
  14296. query.track_scores = trueFalse;
  14297. return this;
  14298. },
  14299. /**
  14300. Sets the number of results/documents to be returned. This is set on a per page basis.
  14301. @member ejs.Request
  14302. @param {Integer} s The number of results that are to be returned by the search.
  14303. @returns {Object} returns <code>this</code> so that calls can be chained.
  14304. */
  14305. size: function (s) {
  14306. if (s == null) {
  14307. return query.size;
  14308. }
  14309. query.size = s;
  14310. return this;
  14311. },
  14312. /**
  14313. A timeout, bounding the request to be executed within the
  14314. specified time value and bail when expired. Defaults to no timeout.
  14315. <p>This option is valid during the following operations:
  14316. <code>search</code> and <code>delete by query</code></p>
  14317. @member ejs.Request
  14318. @param {Long} t The timeout value in milliseconds.
  14319. @returns {Object} returns <code>this</code> so that calls can be chained.
  14320. */
  14321. timeout: function (t) {
  14322. if (t == null) {
  14323. return params.timeout;
  14324. }
  14325. params.timeout = t;
  14326. return this;
  14327. },
  14328. /**
  14329. Sets the shard routing parameter. Only shards matching routing
  14330. values will be searched. Set to an empty string to disable routing.
  14331. Disabled by default.
  14332. <p>This option is valid during the following operations:
  14333. <code>search, count</code> and <code>delete by query</code></p>
  14334. @member ejs.Request
  14335. @param {String} route The routing values as a comma-separated string.
  14336. @returns {Object} returns <code>this</code> so that calls can be chained.
  14337. */
  14338. routing: function (route) {
  14339. if (route == null) {
  14340. return params.routing;
  14341. }
  14342. params.routing = route;
  14343. return this;
  14344. },
  14345. /**
  14346. <p>Sets the replication mode.</p>
  14347. <p>Valid values are:</p>
  14348. <dl>
  14349. <dd><code>async</code> - asynchronous replication to slaves</dd>
  14350. <dd><code>sync</code> - synchronous replication to the slaves</dd>
  14351. <dd><code>default</code> - the currently configured system default.</dd>
  14352. </dl>
  14353. <p>This option is valid during the following operations:
  14354. <code>delete by query</code></p>
  14355. @member ejs.Request
  14356. @param {String} r The replication mode (async, sync, or default)
  14357. @returns {Object} returns <code>this</code> so that calls can be chained.
  14358. */
  14359. replication: function (r) {
  14360. if (r == null) {
  14361. return params.replication;
  14362. }
  14363. r = r.toLowerCase();
  14364. if (r === 'async' || r === 'sync' || r === 'default') {
  14365. params.replication = r;
  14366. }
  14367. return this;
  14368. },
  14369. /**
  14370. <p>Sets the write consistency.</p>
  14371. <p>Valid values are:</p>
  14372. <dl>
  14373. <dd><code>one</code> - only requires write to one shard</dd>
  14374. <dd><code>quorum</code> - requires writes to quorum <code>(N/2 + 1)</code></dd>
  14375. <dd><code>all</code> - requires write to succeed on all shards</dd>
  14376. <dd><code>default</code> - the currently configured system default</dd>
  14377. </dl>
  14378. <p>This option is valid during the following operations:
  14379. <code>delete by query</code></p>
  14380. @member ejs.Request
  14381. @param {String} c The write consistency (one, quorum, all, or default)
  14382. @returns {Object} returns <code>this</code> so that calls can be chained.
  14383. */
  14384. consistency: function (c) {
  14385. if (c == null) {
  14386. return params.consistency;
  14387. }
  14388. c = c.toLowerCase();
  14389. if (c === 'default' || c === 'one' || c === 'quorum' || c === 'all') {
  14390. params.consistency = c;
  14391. }
  14392. return this;
  14393. },
  14394. /**
  14395. <p>Sets the search execution type for the request.</p>
  14396. <p>Valid values are:</p>
  14397. <dl>
  14398. <dd><code>dfs_query_then_fetch</code> - same as query_then_fetch,
  14399. except distributed term frequencies are calculated first.</dd>
  14400. <dd><code>dfs_query_and_fetch</code> - same as query_and_fetch,
  14401. except distributed term frequencies are calculated first.</dd>
  14402. <dd><code>query_then_fetch</code> - executed against all
  14403. shards, but only enough information is returned. When ready,
  14404. only the relevant shards are asked for the actual document
  14405. content</dd>
  14406. <dd><code>query_and_fetch</code> - execute the query on all
  14407. relevant shards and return the results, including content.</dd>
  14408. <dd><code>scan</code> - efficiently scroll a large result set</dd>
  14409. <dd><code>count</code> - special search type that returns the
  14410. count that matched the search request without any docs </dd>
  14411. </dl>
  14412. <p>This option is valid during the following operations:
  14413. <code>search</code></p>
  14414. @member ejs.Request
  14415. @param {String} t The search execution type
  14416. @returns {Object} returns <code>this</code> so that calls can be chained.
  14417. */
  14418. searchType: function (t) {
  14419. if (t == null) {
  14420. return params.search_type;
  14421. }
  14422. t = t.toLowerCase();
  14423. if (t === 'dfs_query_then_fetch' || t === 'dfs_query_and_fetch' ||
  14424. t === 'query_then_fetch' || t === 'query_and_fetch' ||
  14425. t === 'scan' || t === 'count') {
  14426. params.search_type = t;
  14427. }
  14428. return this;
  14429. },
  14430. /**
  14431. By default, searches return full documents, meaning every property or field.
  14432. This method allows you to specify which fields you want returned.
  14433. Pass a single field name and it is appended to the current list of
  14434. fields. Pass an array of fields and it replaces all existing
  14435. fields.
  14436. @member ejs.Request
  14437. @param {String || Array} s The field as a string or fields as array
  14438. @returns {Object} returns <code>this</code> so that calls can be chained.
  14439. */
  14440. fields: function (fieldList) {
  14441. if (fieldList == null) {
  14442. return query.fields;
  14443. }
  14444. if (query.fields == null) {
  14445. query.fields = [];
  14446. }
  14447. if (isString(fieldList)) {
  14448. query.fields.push(fieldList);
  14449. } else if (isArray(fieldList)) {
  14450. query.fields = fieldList;
  14451. } else {
  14452. throw new TypeError('Argument must be string or array');
  14453. }
  14454. return this;
  14455. },
  14456. /**
  14457. A search result set could be very large (think Google). Setting the
  14458. <code>from</code> parameter allows you to page through the result set
  14459. by making multiple request. This parameters specifies the starting
  14460. result/document number point. Combine with <code>size()</code> to achieve paging.
  14461. @member ejs.Request
  14462. @param {Array} f The offset at which to start fetching results/documents from the result set.
  14463. @returns {Object} returns <code>this</code> so that calls can be chained.
  14464. */
  14465. from: function (f) {
  14466. if (f == null) {
  14467. return query.from;
  14468. }
  14469. query.from = f;
  14470. return this;
  14471. },
  14472. /**
  14473. Allows you to set the specified query on this search object. This is the
  14474. query that will be used when the search is executed.
  14475. @member ejs.Request
  14476. @param {Query} someQuery Any valid <code>Query</code> object.
  14477. @returns {Object} returns <code>this</code> so that calls can be chained.
  14478. */
  14479. query: function (someQuery) {
  14480. if (someQuery == null) {
  14481. return query.query;
  14482. }
  14483. if (!isQuery(someQuery)) {
  14484. throw new TypeError('Argument must be a Query');
  14485. }
  14486. query.query = someQuery._self();
  14487. return this;
  14488. },
  14489. /**
  14490. Allows you to set the specified indices on this request object. This is the
  14491. set of indices that will be used when the search is executed.
  14492. @member ejs.Request
  14493. @param {Array} indexArray An array of collection names.
  14494. @returns {Object} returns <code>this</code> so that calls can be chained.
  14495. */
  14496. indices: function (indexArray) {
  14497. if (indexArray == null) {
  14498. return indices;
  14499. } else if (isString(indexArray)) {
  14500. indices = [indexArray];
  14501. } else if (isArray(indexArray)) {
  14502. indices = indexArray;
  14503. } else {
  14504. throw new TypeError('Argument must be a string or array');
  14505. }
  14506. // check that an index is specified when a type is
  14507. // if not, search across _all indices
  14508. if (indices.length === 0 && types.length > 0) {
  14509. indices = ["_all"];
  14510. }
  14511. return this;
  14512. },
  14513. /**
  14514. Allows you to set the specified content-types on this request object. This is the
  14515. set of indices that will be used when the search is executed.
  14516. @member ejs.Request
  14517. @param {Array} typeArray An array of content-type names.
  14518. @returns {Object} returns <code>this</code> so that calls can be chained.
  14519. */
  14520. types: function (typeArray) {
  14521. if (typeArray == null) {
  14522. return types;
  14523. } else if (isString(typeArray)) {
  14524. types = [typeArray];
  14525. } else if (isArray(typeArray)) {
  14526. types = typeArray;
  14527. } else {
  14528. throw new TypeError('Argument must be a string or array');
  14529. }
  14530. // check that an index is specified when a type is
  14531. // if not, search across _all indices
  14532. if (indices.length === 0 && types.length > 0) {
  14533. indices = ["_all"];
  14534. }
  14535. return this;
  14536. },
  14537. /**
  14538. Allows you to set the specified facet on this request object. Multiple facets can
  14539. be set, all of which will be returned when the search is executed.
  14540. @member ejs.Request
  14541. @param {Facet} facet Any valid <code>Facet</code> object.
  14542. @returns {Object} returns <code>this</code> so that calls can be chained.
  14543. */
  14544. facet: function (facet) {
  14545. if (facet == null) {
  14546. return query.facets;
  14547. }
  14548. if (query.facets == null) {
  14549. query.facets = {};
  14550. }
  14551. if (!isFacet(facet)) {
  14552. throw new TypeError('Argument must be a Facet');
  14553. }
  14554. extend(query.facets, facet._self());
  14555. return this;
  14556. },
  14557. /**
  14558. Allows you to set a specified filter on this request object.
  14559. @member ejs.Request
  14560. @param {Object} filter Any valid <code>Filter</code> object.
  14561. @returns {Object} returns <code>this</code> so that calls can be chained.
  14562. */
  14563. filter: function (filter) {
  14564. if (filter == null) {
  14565. return query.filter;
  14566. }
  14567. if (!isFilter(filter)) {
  14568. throw new TypeError('Argument must be a Filter');
  14569. }
  14570. query.filter = filter._self();
  14571. return this;
  14572. },
  14573. /**
  14574. Performs highlighting based on the <code>Highlight</code>
  14575. settings.
  14576. @member ejs.Request
  14577. @param {Highlight} h A valid Highlight object
  14578. @returns {Object} returns <code>this</code> so that calls can be chained.
  14579. */
  14580. highlight: function (h) {
  14581. if (h == null) {
  14582. return query.highlight;
  14583. }
  14584. if (!isHighlight(h)) {
  14585. throw new TypeError('Argument must be a Highlight object');
  14586. }
  14587. query.highlight = h._self();
  14588. return this;
  14589. },
  14590. /**
  14591. Allows you to set the specified suggester on this request object.
  14592. Multiple suggesters can be set, all of which will be returned when
  14593. the search is executed. Global suggestion text can be set by
  14594. passing in a string vs. a <code>Suggest</code> object.
  14595. @since elasticsearch 0.90
  14596. @member ejs.Request
  14597. @param {String || Suggest} s A valid Suggest object or a String to
  14598. set as the global suggest text.
  14599. @returns {Object} returns <code>this</code> so that calls can be chained.
  14600. */
  14601. suggest: function (s) {
  14602. if (s == null) {
  14603. return query.suggest;
  14604. }
  14605. if (query.suggest == null) {
  14606. query.suggest = {};
  14607. }
  14608. if (isString(s)) {
  14609. query.suggest.text = s;
  14610. } else if (isSuggest(s)) {
  14611. extend(query.suggest, s._self());
  14612. } else {
  14613. throw new TypeError('Argument must be a string or Suggest object');
  14614. }
  14615. return this;
  14616. },
  14617. /**
  14618. Computes a document property dynamically based on the supplied <code>ScriptField</code>.
  14619. @member ejs.Request
  14620. @param {ScriptField} oScriptField A valid <code>ScriptField</code>.
  14621. @returns {Object} returns <code>this</code> so that calls can be chained.
  14622. */
  14623. scriptField: function (oScriptField) {
  14624. if (oScriptField == null) {
  14625. return query.script_fields;
  14626. }
  14627. if (query.script_fields == null) {
  14628. query.script_fields = {};
  14629. }
  14630. if (!isScriptField(oScriptField)) {
  14631. throw new TypeError('Argument must be a ScriptField');
  14632. }
  14633. extend(query.script_fields, oScriptField._self());
  14634. return this;
  14635. },
  14636. /**
  14637. <p>Controls the preference of which shard replicas to execute the search request on.
  14638. By default, the operation is randomized between the each shard replicas. The
  14639. preference can be one of the following:</p>
  14640. <dl>
  14641. <dd><code>_primary</code> - the operation will only be executed on primary shards</dd>
  14642. <dd><code>_local</code> - the operation will prefer to be executed on local shards</dd>
  14643. <dd><code>_only_node:$nodeid</code> - the search will only be executed on node with id $nodeid</dd>
  14644. <dd><code>custom</code> - any string, will guarentee searches always happen on same node.</dd>
  14645. </dl>
  14646. <p>This option is valid during the following operations:
  14647. <code>search</code> and <code>count</code></p>
  14648. @member ejs.Request
  14649. @param {String} perf the preference, any of <code>_primary</code>, <code>_local</code>,
  14650. <code>_only_:$nodeid</code>, or a custom string value.
  14651. @returns {Object} returns <code>this</code> so that calls can be chained.
  14652. */
  14653. preference: function (perf) {
  14654. if (perf == null) {
  14655. return params.preference;
  14656. }
  14657. params.preference = perf;
  14658. return this;
  14659. },
  14660. /**
  14661. <p>Determines what type of indices to exclude from a request. The
  14662. value can be one of the following:</p>
  14663. <dl>
  14664. <dd><code>none</code> - No indices / aliases will be excluded from a request</dd>
  14665. <dd><code>missing</code> - Indices / aliases that are missing will be excluded from a request</dd>
  14666. </dl>
  14667. <p>This option is valid during the following operations:
  14668. <code>search, count</code> and <code>delete by query</code></p>
  14669. @member ejs.Request
  14670. @param {String} ignoreType the type of ignore (none or missing).
  14671. @returns {Object} returns <code>this</code> so that calls can be chained.
  14672. */
  14673. ignoreIndices: function (ignoreType) {
  14674. if (ignoreType == null) {
  14675. return params.ignore_indices;
  14676. }
  14677. ignoreType = ignoreType.toLowerCase();
  14678. if (ignoreType === 'none' || ignoreType === 'missing') {
  14679. params.ignore_indices = ignoreType;
  14680. }
  14681. return this;
  14682. },
  14683. /**
  14684. Boosts hits in the specified index by the given boost value.
  14685. @member ejs.Request
  14686. @param {String} index the index to boost
  14687. @param {Double} boost the boost value
  14688. @returns {Object} returns <code>this</code> so that calls can be chained.
  14689. */
  14690. indexBoost: function (index, boost) {
  14691. if (query.indices_boost == null) {
  14692. query.indices_boost = {};
  14693. }
  14694. if (arguments.length === 0) {
  14695. return query.indices_boost;
  14696. }
  14697. query.indices_boost[index] = boost;
  14698. return this;
  14699. },
  14700. /**
  14701. Enable/Disable explanation of score for each search result.
  14702. @member ejs.Request
  14703. @param {Boolean} trueFalse true to enable, false to disable
  14704. @returns {Object} returns <code>this</code> so that calls can be chained.
  14705. */
  14706. explain: function (trueFalse) {
  14707. if (trueFalse == null) {
  14708. return query.explain;
  14709. }
  14710. query.explain = trueFalse;
  14711. return this;
  14712. },
  14713. /**
  14714. Enable/Disable returning version number for each search result.
  14715. @member ejs.Request
  14716. @param {Boolean} trueFalse true to enable, false to disable
  14717. @returns {Object} returns <code>this</code> so that calls can be chained.
  14718. */
  14719. version: function (trueFalse) {
  14720. if (trueFalse == null) {
  14721. return query.version;
  14722. }
  14723. query.version = trueFalse;
  14724. return this;
  14725. },
  14726. /**
  14727. Filters out search results will scores less than the specified minimum score.
  14728. @member ejs.Request
  14729. @param {Double} min a positive <code>double</code> value.
  14730. @returns {Object} returns <code>this</code> so that calls can be chained.
  14731. */
  14732. minScore: function (min) {
  14733. if (min == null) {
  14734. return query.min_score;
  14735. }
  14736. query.min_score = min;
  14737. return this;
  14738. },
  14739. /**
  14740. Allows you to serialize this object into a JSON encoded string.
  14741. @member ejs.Request
  14742. @returns {String} returns this object as a serialized JSON string.
  14743. */
  14744. toString: function () {
  14745. return JSON.stringify(query);
  14746. },
  14747. /**
  14748. The type of ejs object. For internal use only.
  14749. @member ejs.Request
  14750. @returns {String} the type of object
  14751. */
  14752. _type: function () {
  14753. return 'request';
  14754. },
  14755. /**
  14756. Retrieves the internal <code>query</code> object. This is typically used by
  14757. internal API functions so use with caution.
  14758. @member ejs.Request
  14759. @returns {String} returns this object's internal object representation.
  14760. */
  14761. _self: function () {
  14762. return query;
  14763. },
  14764. /**
  14765. Executes a delete by query request using the current query.
  14766. @member ejs.Request
  14767. @param {Function} successcb A callback function that handles the response.
  14768. @param {Function} errorcb A callback function that handles errors.
  14769. @returns {Object} Returns a client specific object.
  14770. */
  14771. doDeleteByQuery: function (successcb, errorcb) {
  14772. var queryData = JSON.stringify(query.query);
  14773. // make sure the user has set a client
  14774. if (ejs.client == null) {
  14775. throw new Error("No Client Set");
  14776. }
  14777. return ejs.client.del(getRestPath('_query'), queryData, successcb, errorcb);
  14778. },
  14779. /**
  14780. Executes a count request using the current query.
  14781. @member ejs.Request
  14782. @param {Function} successcb A callback function that handles the count response.
  14783. @param {Function} errorcb A callback function that handles errors.
  14784. @returns {Object} Returns a client specific object.
  14785. */
  14786. doCount: function (successcb, errorcb) {
  14787. var queryData = JSON.stringify(query.query);
  14788. // make sure the user has set a client
  14789. if (ejs.client == null) {
  14790. throw new Error("No Client Set");
  14791. }
  14792. return ejs.client.post(getRestPath('_count'), queryData, successcb, errorcb);
  14793. },
  14794. /**
  14795. Executes the search.
  14796. @member ejs.Request
  14797. @param {Function} successcb A callback function that handles the search response.
  14798. @param {Function} errorcb A callback function that handles errors.
  14799. @returns {Object} Returns a client specific object.
  14800. */
  14801. doSearch: function (successcb, errorcb) {
  14802. var queryData = JSON.stringify(query);
  14803. // make sure the user has set a client
  14804. if (ejs.client == null) {
  14805. throw new Error("No Client Set");
  14806. }
  14807. return ejs.client.post(getRestPath('_search'), queryData, successcb, errorcb);
  14808. }
  14809. };
  14810. };
  14811. /**
  14812. @class
  14813. <p>ScriptField's allow you create dynamic fields on stored documents at query
  14814. time. For example, you might have a set of document thats containsthe fields
  14815. <code>price</code> and <code>quantity</code>. At query time, you could define a computed
  14816. property that dynamically creates a new field called <code>total</code>in each document
  14817. based on the calculation <code>price * quantity</code>.</p>
  14818. @name ejs.ScriptField
  14819. @desc
  14820. <p>Computes dynamic document properties based on information from other fields.</p>
  14821. @param {String} fieldName A name of the script field to create.
  14822. */
  14823. ejs.ScriptField = function (fieldName) {
  14824. var script = {};
  14825. script[fieldName] = {};
  14826. return {
  14827. /**
  14828. The script language being used. Currently supported values are
  14829. <code>javascript</code> and <code>mvel</code>.
  14830. @member ejs.ScriptField
  14831. @param {String} language The language of the script.
  14832. @returns {Object} returns <code>this</code> so that calls can be chained.
  14833. */
  14834. lang: function (language) {
  14835. if (language == null) {
  14836. return script[fieldName].lang;
  14837. }
  14838. script[fieldName].lang = language;
  14839. return this;
  14840. },
  14841. /**
  14842. Sets the script/code that will be used to perform the calculation.
  14843. @member ejs.ScriptField
  14844. @param {String} expression The script/code to use.
  14845. @returns {Object} returns <code>this</code> so that calls can be chained.
  14846. */
  14847. script: function (expression) {
  14848. if (expression == null) {
  14849. return script[fieldName].script;
  14850. }
  14851. script[fieldName].script = expression;
  14852. return this;
  14853. },
  14854. /**
  14855. Allows you to set script parameters to be used during the execution of the script.
  14856. @member ejs.ScriptField
  14857. @param {Object} oParams An object containing key/value pairs representing param name/value.
  14858. @returns {Object} returns <code>this</code> so that calls can be chained.
  14859. */
  14860. params: function (oParams) {
  14861. if (oParams == null) {
  14862. return script[fieldName].params;
  14863. }
  14864. script[fieldName].params = oParams;
  14865. return this;
  14866. },
  14867. /**
  14868. If execeptions thrown from the script should be ignored or not.
  14869. Default: false
  14870. @member ejs.ScriptField
  14871. @param {Boolean} trueFalse if execptions should be ignored
  14872. @returns {Object} returns <code>this</code> so that calls can be chained.
  14873. */
  14874. ignoreFailure: function (trueFalse) {
  14875. if (trueFalse == null) {
  14876. return script[fieldName].ignore_failure;
  14877. }
  14878. script[fieldName].ignore_failure = trueFalse;
  14879. return this;
  14880. },
  14881. /**
  14882. Allows you to serialize this object into a JSON encoded string.
  14883. @member ejs.ScriptField
  14884. @returns {String} returns this object as a serialized JSON string.
  14885. */
  14886. toString: function () {
  14887. return JSON.stringify(script);
  14888. },
  14889. /**
  14890. The type of ejs object. For internal use only.
  14891. @member ejs.ScriptField
  14892. @returns {String} the type of object
  14893. */
  14894. _type: function () {
  14895. return 'script field';
  14896. },
  14897. /**
  14898. Retrieves the internal <code>script</code> object. This is typically used by
  14899. internal API functions so use with caution.
  14900. @member ejs.ScriptField
  14901. @returns {String} returns this object's internal <code>facet</code> property.
  14902. */
  14903. _self: function () {
  14904. return script;
  14905. }
  14906. };
  14907. };
  14908. /**
  14909. @class
  14910. <p>A Shape object that can be used in queries and filters that
  14911. take a Shape. Shape uses the GeoJSON format.</p>
  14912. <p>See http://www.geojson.org/</p>
  14913. @name ejs.Shape
  14914. @desc
  14915. <p>Defines a shape</p>
  14916. @param {String} type A valid shape type.
  14917. @param {Array} coords An valid coordinat definition for the given shape.
  14918. */
  14919. ejs.Shape = function (type, coords) {
  14920. var
  14921. shape = {},
  14922. validType = function (t) {
  14923. var valid = false;
  14924. if (t === 'point' || t === 'linestring' || t === 'polygon' ||
  14925. t === 'multipoint' || t === 'envelope' || t === 'multipolygon') {
  14926. valid = true;
  14927. }
  14928. return valid;
  14929. };
  14930. type = type.toLowerCase();
  14931. if (validType(type)) {
  14932. shape.type = type;
  14933. shape.coordinates = coords;
  14934. }
  14935. return {
  14936. /**
  14937. Sets the shape type. Can be set to one of: point, linestring, polygon,
  14938. multipoint, envelope, or multipolygon.
  14939. @member ejs.Shape
  14940. @param {String} t a valid shape type.
  14941. @returns {Object} returns <code>this</code> so that calls can be chained.
  14942. */
  14943. type: function (t) {
  14944. if (t == null) {
  14945. return shape.type;
  14946. }
  14947. t = t.toLowerCase();
  14948. if (validType(t)) {
  14949. shape.type = t;
  14950. }
  14951. return this;
  14952. },
  14953. /**
  14954. Sets the coordinates for the shape definition. Note, the coordinates
  14955. are not validated in this api. Please see GeoJSON and ElasticSearch
  14956. documentation for correct coordinate definitions.
  14957. @member ejs.Shape
  14958. @param {Array} c a valid coordinates definition for the shape.
  14959. @returns {Object} returns <code>this</code> so that calls can be chained.
  14960. */
  14961. coordinates: function (c) {
  14962. if (c == null) {
  14963. return shape.coordinates;
  14964. }
  14965. shape.coordinates = c;
  14966. return this;
  14967. },
  14968. /**
  14969. Allows you to serialize this object into a JSON encoded string.
  14970. @member ejs.Shape
  14971. @returns {String} returns this object as a serialized JSON string.
  14972. */
  14973. toString: function () {
  14974. return JSON.stringify(shape);
  14975. },
  14976. /**
  14977. The type of ejs object. For internal use only.
  14978. @member ejs.Shape
  14979. @returns {String} the type of object
  14980. */
  14981. _type: function () {
  14982. return 'shape';
  14983. },
  14984. /**
  14985. Retrieves the internal <code>script</code> object. This is typically used by
  14986. internal API functions so use with caution.
  14987. @member ejs.Shape
  14988. @returns {String} returns this object's internal object representation.
  14989. */
  14990. _self: function () {
  14991. return shape;
  14992. }
  14993. };
  14994. };
  14995. /**
  14996. @class
  14997. <p>A Sort object that can be used in on the Request object to specify
  14998. various types of sorting.</p>
  14999. <p>See http://www.elasticsearch.org/guide/reference/api/search/sort.html</p>
  15000. @name ejs.Sort
  15001. @desc
  15002. <p>Defines a sort value</p>
  15003. @param {String} fieldName The fieldName to sort against. Defaults to _score
  15004. if not specified.
  15005. */
  15006. ejs.Sort = function (fieldName) {
  15007. // default to sorting against the documents score.
  15008. if (fieldName == null) {
  15009. fieldName = '_score';
  15010. }
  15011. var sort = {},
  15012. key = fieldName, // defaults to field search
  15013. geo_key = '_geo_distance', // used when doing geo distance sort
  15014. script_key = '_script'; // used when doing script sort
  15015. // defaults to a field sort
  15016. sort[key] = {};
  15017. return {
  15018. /**
  15019. Set's the field to sort on
  15020. @member ejs.Sort
  15021. @param {String} f The name of a field
  15022. @returns {Object} returns <code>this</code> so that calls can be chained.
  15023. */
  15024. field: function (f) {
  15025. var oldValue = sort[key];
  15026. if (f == null) {
  15027. return fieldName;
  15028. }
  15029. delete sort[key];
  15030. fieldName = f;
  15031. key = f;
  15032. sort[key] = oldValue;
  15033. return this;
  15034. },
  15035. /**
  15036. Enables sorting based on a distance from a GeoPoint
  15037. @member ejs.Sort
  15038. @param {GeoPoint} point A valid GeoPoint object
  15039. @returns {Object} returns <code>this</code> so that calls can be chained.
  15040. */
  15041. geoDistance: function (point) {
  15042. var oldValue = sort[key];
  15043. if (point == null) {
  15044. return sort[key][fieldName];
  15045. }
  15046. if (!isGeoPoint(point)) {
  15047. throw new TypeError('Argument must be a GeoPoint');
  15048. }
  15049. delete sort[key];
  15050. key = geo_key;
  15051. sort[key] = oldValue;
  15052. sort[key][fieldName] = point._self();
  15053. return this;
  15054. },
  15055. /**
  15056. Enables sorting based on a script.
  15057. @member ejs.Sort
  15058. @param {String} scriptCode The script code as a string
  15059. @returns {Object} returns <code>this</code> so that calls can be chained.
  15060. */
  15061. script: function (scriptCode) {
  15062. var oldValue = sort[key];
  15063. if (scriptCode == null) {
  15064. return sort[key].script;
  15065. }
  15066. delete sort[key];
  15067. key = script_key;
  15068. sort[key] = oldValue;
  15069. sort[key].script = scriptCode;
  15070. return this;
  15071. },
  15072. /**
  15073. Sets the sort order. Valid values are:
  15074. asc - for ascending order
  15075. desc - for descending order
  15076. Valid during sort types: field, geo distance, and script
  15077. @member ejs.Sort
  15078. @param {String} o The sort order as a string, asc or desc.
  15079. @returns {Object} returns <code>this</code> so that calls can be chained.
  15080. */
  15081. order: function (o) {
  15082. if (o == null) {
  15083. return sort[key].order;
  15084. }
  15085. o = o.toLowerCase();
  15086. if (o === 'asc' || o === 'desc') {
  15087. sort[key].order = o;
  15088. }
  15089. return this;
  15090. },
  15091. /**
  15092. Sets the sort order to ascending (asc). Same as calling
  15093. <code>order('asc')</code>.
  15094. @member ejs.Sort
  15095. @returns {Object} returns <code>this</code> so that calls can be chained.
  15096. */
  15097. asc: function () {
  15098. sort[key].order = 'asc';
  15099. return this;
  15100. },
  15101. /**
  15102. Sets the sort order to descending (desc). Same as calling
  15103. <code>order('desc')</code>.
  15104. @member ejs.Sort
  15105. @returns {Object} returns <code>this</code> so that calls can be chained.
  15106. */
  15107. desc: function () {
  15108. sort[key].order = 'desc';
  15109. return this;
  15110. },
  15111. /**
  15112. Sets the order with a boolean value.
  15113. true = descending sort order
  15114. false = ascending sort order
  15115. Valid during sort types: field, geo distance, and script
  15116. @member ejs.Sort
  15117. @param {Boolean} trueFalse If sort should be in reverse order.
  15118. @returns {Object} returns <code>this</code> so that calls can be chained.
  15119. */
  15120. reverse: function (trueFalse) {
  15121. if (trueFalse == null) {
  15122. return sort[key].reverse;
  15123. }
  15124. sort[key].reverse = trueFalse;
  15125. return this;
  15126. },
  15127. /**
  15128. Sets the value to use for missing fields. Valid values are:
  15129. _last - to put documents with the field missing last
  15130. _first - to put documents with the field missing first
  15131. {String} - any string value to use as the sort value.
  15132. Valid during sort types: field
  15133. @member ejs.Sort
  15134. @param {String} m The value to use for documents with the field missing.
  15135. @returns {Object} returns <code>this</code> so that calls can be chained.
  15136. */
  15137. missing: function (m) {
  15138. if (m == null) {
  15139. return sort[key].missing;
  15140. }
  15141. sort[key].missing = m;
  15142. return this;
  15143. },
  15144. /**
  15145. Sets if the sort should ignore unmapped fields vs throwing an error.
  15146. Valid during sort types: field
  15147. @member ejs.Sort
  15148. @param {Boolean} trueFalse If sort should ignore unmapped fields.
  15149. @returns {Object} returns <code>this</code> so that calls can be chained.
  15150. */
  15151. ignoreUnmapped: function (trueFalse) {
  15152. if (trueFalse == null) {
  15153. return sort[key].ignore_unmapped;
  15154. }
  15155. sort[key].ignore_unmapped = trueFalse;
  15156. return this;
  15157. },
  15158. /**
  15159. Sets the distance unit. Valid values are "mi" for miles or "km"
  15160. for kilometers. Defaults to "km".
  15161. Valid during sort types: geo distance
  15162. @member ejs.Sort
  15163. @param {Number} unit the unit of distance measure.
  15164. @returns {Object} returns <code>this</code> so that calls can be chained.
  15165. */
  15166. unit: function (unit) {
  15167. if (unit == null) {
  15168. return sort[key].unit;
  15169. }
  15170. unit = unit.toLowerCase();
  15171. if (unit === 'mi' || unit === 'km') {
  15172. sort[key].unit = unit;
  15173. }
  15174. return this;
  15175. },
  15176. /**
  15177. If the lat/long points should be normalized to lie within their
  15178. respective normalized ranges.
  15179. Normalized ranges are:
  15180. lon = -180 (exclusive) to 180 (inclusive) range
  15181. lat = -90 to 90 (both inclusive) range
  15182. Valid during sort types: geo distance
  15183. @member ejs.Sort
  15184. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  15185. @returns {Object} returns <code>this</code> so that calls can be chained.
  15186. */
  15187. normalize: function (trueFalse) {
  15188. if (trueFalse == null) {
  15189. return sort[key].normalize;
  15190. }
  15191. sort[key].normalize = trueFalse;
  15192. return this;
  15193. },
  15194. /**
  15195. How to compute the distance. Can either be arc (better precision)
  15196. or plane (faster). Defaults to arc.
  15197. Valid during sort types: geo distance
  15198. @member ejs.Sort
  15199. @param {String} type The execution type as a string.
  15200. @returns {Object} returns <code>this</code> so that calls can be chained.
  15201. */
  15202. distanceType: function (type) {
  15203. if (type == null) {
  15204. return sort[key].distance_type;
  15205. }
  15206. type = type.toLowerCase();
  15207. if (type === 'arc' || type === 'plane') {
  15208. sort[key].distance_type = type;
  15209. }
  15210. return this;
  15211. },
  15212. /**
  15213. Sets parameters that will be applied to the script. Overwrites
  15214. any existing params.
  15215. Valid during sort types: script
  15216. @member ejs.Sort
  15217. @param {Object} p An object where the keys are the parameter name and
  15218. values are the parameter value.
  15219. @returns {Object} returns <code>this</code> so that calls can be chained.
  15220. */
  15221. params: function (p) {
  15222. if (p == null) {
  15223. return sort[key].params;
  15224. }
  15225. sort[key].params = p;
  15226. return this;
  15227. },
  15228. /**
  15229. Sets the script language.
  15230. Valid during sort types: script
  15231. @member ejs.Sort
  15232. @param {String} lang The script language, default mvel.
  15233. @returns {Object} returns <code>this</code> so that calls can be chained.
  15234. */
  15235. lang: function (lang) {
  15236. if (lang == null) {
  15237. return sort[key].lang;
  15238. }
  15239. sort[key].lang = lang;
  15240. return this;
  15241. },
  15242. /**
  15243. Sets the script sort type. Valid values are:
  15244. <dl>
  15245. <dd><code>string</code> - script return value is sorted as a string</dd>
  15246. <dd><code>number</code> - script return value is sorted as a number</dd>
  15247. <dl>
  15248. Valid during sort types: script
  15249. @member ejs.Sort
  15250. @param {String} type The sort type. Either string or number.
  15251. @returns {Object} returns <code>this</code> so that calls can be chained.
  15252. */
  15253. type: function (type) {
  15254. if (type == null) {
  15255. return sort[key].type;
  15256. }
  15257. type = type.toLowerCase();
  15258. if (type === 'string' || type === 'number') {
  15259. sort[key].type = type;
  15260. }
  15261. return this;
  15262. },
  15263. /**
  15264. Sets the sort mode. Valid values are:
  15265. <dl>
  15266. <dd><code>min</code> - sort by lowest value</dd>
  15267. <dd><code>max</code> - sort by highest value</dd>
  15268. <dd><code>sum</code> - sort by the sum of all values</dd>
  15269. <dd><code>avg</code> - sort by the average of all values</dd>
  15270. <dl>
  15271. Valid during sort types: field
  15272. @since elasticsearch 0.90
  15273. @member ejs.Sort
  15274. @param {String} m The sort mode. Either min, max, sum, or avg.
  15275. @returns {Object} returns <code>this</code> so that calls can be chained.
  15276. */
  15277. mode: function (m) {
  15278. if (m == null) {
  15279. return sort[key].mode;
  15280. }
  15281. m = m.toLowerCase();
  15282. if (m === 'min' || m === 'max' || m === 'sum' || m === 'avg') {
  15283. sort[key].mode = m;
  15284. }
  15285. return this;
  15286. },
  15287. /**
  15288. Sets the path of the nested object.
  15289. Valid during sort types: field
  15290. @since elasticsearch 0.90
  15291. @member ejs.Sort
  15292. @param {String} path The nested path value.
  15293. @returns {Object} returns <code>this</code> so that calls can be chained.
  15294. */
  15295. nestedPath: function (path) {
  15296. if (path == null) {
  15297. return sort[key].nested_path;
  15298. }
  15299. sort[key].nested_path = path;
  15300. return this;
  15301. },
  15302. /**
  15303. <p>Allows you to set a filter that nested objects must match
  15304. in order to be considered during sorting.</p>
  15305. @since elasticsearch 0.90
  15306. @member ejs.Sort
  15307. @param {Object} oFilter A valid <code>Filter</code> object.
  15308. @returns {Object} returns <code>this</code> so that calls can be chained.
  15309. */
  15310. nestedFilter: function (oFilter) {
  15311. if (oFilter == null) {
  15312. return sort[key].nested_filter;
  15313. }
  15314. if (!isFilter(oFilter)) {
  15315. throw new TypeError('Argument must be a Filter');
  15316. }
  15317. sort[key].nested_filter = oFilter._self();
  15318. return this;
  15319. },
  15320. /**
  15321. Allows you to serialize this object into a JSON encoded string.
  15322. @member ejs.Sort
  15323. @returns {String} returns this object as a serialized JSON string.
  15324. */
  15325. toString: function () {
  15326. return JSON.stringify(sort);
  15327. },
  15328. /**
  15329. The type of ejs object. For internal use only.
  15330. @member ejs.Sort
  15331. @returns {String} the type of object
  15332. */
  15333. _type: function () {
  15334. return 'sort';
  15335. },
  15336. /**
  15337. Retrieves the internal <code>script</code> object. This is typically used by
  15338. internal API functions so use with caution.
  15339. @member ejs.Sort
  15340. @returns {String} returns this object's internal object representation.
  15341. */
  15342. _self: function () {
  15343. return sort;
  15344. }
  15345. };
  15346. };
  15347. /**
  15348. @class
  15349. <p>DirectGenerator is a candidate generator for <code>PhraseSuggester</code>.
  15350. It generates terms based on edit distance and operators much like the
  15351. <code>TermSuggester</code>.</p>
  15352. @name ejs.DirectGenerator
  15353. @since elasticsearch 0.90
  15354. @desc
  15355. <p>A candidate generator that generates terms based on edit distance.</p>
  15356. @borrows ejs.DirectSettingsMixin.accuracy as accuracy
  15357. @borrows ejs.DirectSettingsMixin.suggestMode as suggestMode
  15358. @borrows ejs.DirectSettingsMixin.sort as sort
  15359. @borrows ejs.DirectSettingsMixin.stringDistance as stringDistance
  15360. @borrows ejs.DirectSettingsMixin.maxEdits as maxEdits
  15361. @borrows ejs.DirectSettingsMixin.maxInspections as maxInspections
  15362. @borrows ejs.DirectSettingsMixin.maxTermFreq as maxTermFreq
  15363. @borrows ejs.DirectSettingsMixin.prefixLength as prefixLength
  15364. @borrows ejs.DirectSettingsMixin.minWordLen as minWordLen
  15365. @borrows ejs.DirectSettingsMixin.minDocFreq as minDocFreq
  15366. */
  15367. ejs.DirectGenerator = function () {
  15368. var
  15369. // common suggester options used in this generator
  15370. _common = ejs.DirectSettingsMixin(),
  15371. /**
  15372. The internal generator object.
  15373. @member ejs.DirectGenerator
  15374. @property {Object} suggest
  15375. */
  15376. generator = _common._self();
  15377. return extend(_common, {
  15378. /**
  15379. <p>Sets an analyzer that is applied to each of the tokens passed to
  15380. this generator. The analyzer is applied to the original tokens,
  15381. not the generated tokens.</p>
  15382. @member ejs.DirectGenerator
  15383. @param {String} analyzer A valid analyzer name.
  15384. @returns {Object} returns <code>this</code> so that calls can be chained.
  15385. */
  15386. preFilter: function (analyzer) {
  15387. if (analyzer == null) {
  15388. return generator.pre_filter;
  15389. }
  15390. generator.pre_filter = analyzer;
  15391. return this;
  15392. },
  15393. /**
  15394. <p>Sets an analyzer that is applied to each of the generated tokens
  15395. before they are passed to the actual phrase scorer.</p>
  15396. @member ejs.DirectGenerator
  15397. @param {String} analyzer A valid analyzer name.
  15398. @returns {Object} returns <code>this</code> so that calls can be chained.
  15399. */
  15400. postFilter: function (analyzer) {
  15401. if (analyzer == null) {
  15402. return generator.post_filter;
  15403. }
  15404. generator.post_filter = analyzer;
  15405. return this;
  15406. },
  15407. /**
  15408. <p>Sets the field used to generate suggestions from.</p>
  15409. @member ejs.DirectGenerator
  15410. @param {String} field A valid field name.
  15411. @returns {Object} returns <code>this</code> so that calls can be chained.
  15412. */
  15413. field: function (field) {
  15414. if (field == null) {
  15415. return generator.field;
  15416. }
  15417. generator.field = field;
  15418. return this;
  15419. },
  15420. /**
  15421. <p>Sets the number of suggestions returned for each token.</p>
  15422. @member ejs.DirectGenerator
  15423. @param {Integer} s A positive integer value.
  15424. @returns {Object} returns <code>this</code> so that calls can be chained.
  15425. */
  15426. size: function (s) {
  15427. if (s == null) {
  15428. return generator.size;
  15429. }
  15430. generator.size = s;
  15431. return this;
  15432. },
  15433. /**
  15434. <p>Allows you to serialize this object into a JSON encoded string.</p>
  15435. @member ejs.DirectGenerator
  15436. @returns {String} returns this object as a serialized JSON string.
  15437. */
  15438. toString: function () {
  15439. return JSON.stringify(generator);
  15440. },
  15441. /**
  15442. The type of ejs object. For internal use only.
  15443. @member ejs.DirectGenerator
  15444. @returns {String} the type of object
  15445. */
  15446. _type: function () {
  15447. return 'generator';
  15448. },
  15449. /**
  15450. <p>Retrieves the internal <code>generator</code> object. This is typically used by
  15451. internal API functions so use with caution.</p>
  15452. @member ejs.DirectGenerator
  15453. @returns {String} returns this object's internal <code>generator</code> property.
  15454. */
  15455. _self: function () {
  15456. return generator;
  15457. }
  15458. });
  15459. };
  15460. /**
  15461. @mixin
  15462. <p>The DirectSettingsMixin provides support for common options used across
  15463. various <code>Suggester</code> implementations. This object should not be
  15464. used directly.</p>
  15465. @name ejs.DirectSettingsMixin
  15466. */
  15467. ejs.DirectSettingsMixin = function () {
  15468. /**
  15469. The internal settings object.
  15470. @member ejs.DirectSettingsMixin
  15471. @property {Object} settings
  15472. */
  15473. var settings = {};
  15474. return {
  15475. /**
  15476. <p>Sets the accuracy. How similar the suggested terms at least
  15477. need to be compared to the original suggest text.</p>
  15478. @member ejs.DirectSettingsMixin
  15479. @param {Double} a A positive double value between 0 and 1.
  15480. @returns {Object} returns <code>this</code> so that calls can be chained.
  15481. */
  15482. accuracy: function (a) {
  15483. if (a == null) {
  15484. return settings.accuracy;
  15485. }
  15486. settings.accuracy = a;
  15487. return this;
  15488. },
  15489. /**
  15490. <p>Sets the suggest mode. Valid values are:</p>
  15491. <dl>
  15492. <dd><code>missing</code> - Only suggest terms in the suggest text that aren't in the index</dd>
  15493. <dd><code>popular</code> - Only suggest suggestions that occur in more docs then the original suggest text term</dd>
  15494. <dd><code>always</code> - Suggest any matching suggestions based on terms in the suggest text</dd>
  15495. </dl>
  15496. @member ejs.DirectSettingsMixin
  15497. @param {String} m The mode of missing, popular, or always.
  15498. @returns {Object} returns <code>this</code> so that calls can be chained.
  15499. */
  15500. suggestMode: function (m) {
  15501. if (m == null) {
  15502. return settings.suggest_mode;
  15503. }
  15504. m = m.toLowerCase();
  15505. if (m === 'missing' || m === 'popular' || m === 'always') {
  15506. settings.suggest_mode = m;
  15507. }
  15508. return this;
  15509. },
  15510. /**
  15511. <p>Sets the sort mode. Valid values are:</p>
  15512. <dl>
  15513. <dd><code>score</code> - Sort by score first, then document frequency, and then the term itself</dd>
  15514. <dd><code>frequency</code> - Sort by document frequency first, then simlarity score and then the term itself</dd>
  15515. </dl>
  15516. @member ejs.DirectSettingsMixin
  15517. @param {String} s The score type of score or frequency.
  15518. @returns {Object} returns <code>this</code> so that calls can be chained.
  15519. */
  15520. sort: function (s) {
  15521. if (s == null) {
  15522. return settings.sort;
  15523. }
  15524. s = s.toLowerCase();
  15525. if (s === 'score' || s === 'frequency') {
  15526. settings.sort = s;
  15527. }
  15528. return this;
  15529. },
  15530. /**
  15531. <p>Sets what string distance implementation to use for comparing
  15532. how similar suggested terms are. Valid values are:</p>
  15533. <dl>
  15534. <dd><code>internal</code> - based on damerau_levenshtein but but highly optimized for comparing string distance for terms inside the index</dd>
  15535. <dd><code>damerau_levenshtein</code> - String distance algorithm based on Damerau-Levenshtein algorithm</dd>
  15536. <dd><code>levenstein</code> - String distance algorithm based on Levenstein edit distance algorithm</dd>
  15537. <dd><code>jarowinkler</code> - String distance algorithm based on Jaro-Winkler algorithm</dd>
  15538. <dd><code>ngram</code> - String distance algorithm based on character n-grams</dd>
  15539. </dl>
  15540. @member ejs.DirectSettingsMixin
  15541. @param {String} s The string distance algorithm name.
  15542. @returns {Object} returns <code>this</code> so that calls can be chained.
  15543. */
  15544. stringDistance: function (s) {
  15545. if (s == null) {
  15546. return settings.string_distance;
  15547. }
  15548. s = s.toLowerCase();
  15549. if (s === 'internal' || s === 'damerau_levenshtein' ||
  15550. s === 'levenstein' || s === 'jarowinkler' || s === 'ngram') {
  15551. settings.string_distance = s;
  15552. }
  15553. return this;
  15554. },
  15555. /**
  15556. <p>Sets the maximum edit distance candidate suggestions can have
  15557. in order to be considered as a suggestion.</p>
  15558. @member ejs.DirectSettingsMixin
  15559. @param {Integer} max An integer value greater than 0.
  15560. @returns {Object} returns <code>this</code> so that calls can be chained.
  15561. */
  15562. maxEdits: function (max) {
  15563. if (max == null) {
  15564. return settings.max_edits;
  15565. }
  15566. settings.max_edits = max;
  15567. return this;
  15568. },
  15569. /**
  15570. <p>The factor that is used to multiply with the size in order
  15571. to inspect more candidate suggestions.</p>
  15572. @member ejs.DirectSettingsMixin
  15573. @param {Integer} max A positive integer value.
  15574. @returns {Object} returns <code>this</code> so that calls can be chained.
  15575. */
  15576. maxInspections: function (max) {
  15577. if (max == null) {
  15578. return settings.max_inspections;
  15579. }
  15580. settings.max_inspections = max;
  15581. return this;
  15582. },
  15583. /**
  15584. <p>Sets a maximum threshold in number of documents a suggest text
  15585. token can exist in order to be corrected.</p>
  15586. @member ejs.DirectSettingsMixin
  15587. @param {Double} max A positive double value.
  15588. @returns {Object} returns <code>this</code> so that calls can be chained.
  15589. */
  15590. maxTermFreq: function (max) {
  15591. if (max == null) {
  15592. return settings.max_term_freq;
  15593. }
  15594. settings.max_term_freq = max;
  15595. return this;
  15596. },
  15597. /**
  15598. <p>Sets the number of minimal prefix characters that must match in
  15599. order be a candidate suggestion.</p>
  15600. @member ejs.DirectSettingsMixin
  15601. @param {Integer} len A positive integer value.
  15602. @returns {Object} returns <code>this</code> so that calls can be chained.
  15603. */
  15604. prefixLength: function (len) {
  15605. if (len == null) {
  15606. return settings.prefix_length;
  15607. }
  15608. settings.prefix_length = len;
  15609. return this;
  15610. },
  15611. /**
  15612. <p>Sets the minimum length a suggest text term must have in order
  15613. to be corrected.</p>
  15614. @member ejs.DirectSettingsMixin
  15615. @param {Integer} len A positive integer value.
  15616. @returns {Object} returns <code>this</code> so that calls can be chained.
  15617. */
  15618. minWordLen: function (len) {
  15619. if (len == null) {
  15620. return settings.min_word_len;
  15621. }
  15622. settings.min_word_len = len;
  15623. return this;
  15624. },
  15625. /**
  15626. <p>Sets a minimal threshold of the number of documents a suggested
  15627. term should appear in.</p>
  15628. @member ejs.DirectSettingsMixin
  15629. @param {Double} min A positive double value.
  15630. @returns {Object} returns <code>this</code> so that calls can be chained.
  15631. */
  15632. minDocFreq: function (min) {
  15633. if (min == null) {
  15634. return settings.min_doc_freq;
  15635. }
  15636. settings.min_doc_freq = min;
  15637. return this;
  15638. },
  15639. /**
  15640. <p>Retrieves the internal <code>settings</code> object. This is typically used by
  15641. internal API functions so use with caution.</p>
  15642. @member ejs.DirectSettingsMixin
  15643. @returns {String} returns this object's internal <code>settings</code> property.
  15644. */
  15645. _self: function () {
  15646. return settings;
  15647. }
  15648. };
  15649. };
  15650. /**
  15651. @class
  15652. <p>PhraseSuggester extends the <code>PhraseSuggester</code> and suggests
  15653. entire corrected phrases instead of individual tokens. The individual
  15654. phrase suggestions are weighted based on ngram-langugage models. In practice
  15655. it will be able to make better decision about which tokens to pick based on
  15656. co-occurence and frequencies.</p>
  15657. @name ejs.PhraseSuggester
  15658. @since elasticsearch 0.90
  15659. @desc
  15660. <p>A suggester that suggests entire corrected phrases.</p>
  15661. @param {String} name The name which be used to refer to this suggester.
  15662. */
  15663. ejs.PhraseSuggester = function (name) {
  15664. /**
  15665. The internal suggest object.
  15666. @member ejs.PhraseSuggester
  15667. @property {Object} suggest
  15668. */
  15669. var suggest = {};
  15670. suggest[name] = {phrase: {}};
  15671. return {
  15672. /**
  15673. <p>Sets the text to get suggestions for. If not set, the global
  15674. suggestion text will be used.</p>
  15675. @member ejs.PhraseSuggester
  15676. @param {String} txt A string to get suggestions for.
  15677. @returns {Object} returns <code>this</code> so that calls can be chained.
  15678. */
  15679. text: function (txt) {
  15680. if (txt == null) {
  15681. return suggest[name].text;
  15682. }
  15683. suggest[name].text = txt;
  15684. return this;
  15685. },
  15686. /**
  15687. <p>Sets analyzer used to analyze the suggest text.</p>
  15688. @member ejs.PhraseSuggester
  15689. @param {String} analyzer A valid analyzer name.
  15690. @returns {Object} returns <code>this</code> so that calls can be chained.
  15691. */
  15692. analyzer: function (analyzer) {
  15693. if (analyzer == null) {
  15694. return suggest[name].phrase.analyzer;
  15695. }
  15696. suggest[name].phrase.analyzer = analyzer;
  15697. return this;
  15698. },
  15699. /**
  15700. <p>Sets the field used to generate suggestions from.</p>
  15701. @member ejs.PhraseSuggester
  15702. @param {String} field A valid field name.
  15703. @returns {Object} returns <code>this</code> so that calls can be chained.
  15704. */
  15705. field: function (field) {
  15706. if (field == null) {
  15707. return suggest[name].phrase.field;
  15708. }
  15709. suggest[name].phrase.field = field;
  15710. return this;
  15711. },
  15712. /**
  15713. <p>Sets the number of suggestions returned for each token.</p>
  15714. @member ejs.PhraseSuggester
  15715. @param {Integer} s A positive integer value.
  15716. @returns {Object} returns <code>this</code> so that calls can be chained.
  15717. */
  15718. size: function (s) {
  15719. if (s == null) {
  15720. return suggest[name].phrase.size;
  15721. }
  15722. suggest[name].phrase.size = s;
  15723. return this;
  15724. },
  15725. /**
  15726. <p>Sets the maximum number of suggestions to be retrieved from
  15727. each individual shard.</p>
  15728. @member ejs.PhraseSuggester
  15729. @param {Integer} s A positive integer value.
  15730. @returns {Object} returns <code>this</code> so that calls can be chained.
  15731. */
  15732. shardSize: function (s) {
  15733. if (s == null) {
  15734. return suggest[name].phrase.shard_size;
  15735. }
  15736. suggest[name].phrase.shard_size = s;
  15737. return this;
  15738. },
  15739. /**
  15740. <p>Sets the likelihood of a term being a misspelled even if the
  15741. term exists in the dictionary. The default it 0.95 corresponding
  15742. to 5% or the real words are misspelled.</p>
  15743. @member ejs.PhraseSuggester
  15744. @param {Double} l A positive double value greater than 0.0.
  15745. @returns {Object} returns <code>this</code> so that calls can be chained.
  15746. */
  15747. realWorldErrorLikelihood: function (l) {
  15748. if (l == null) {
  15749. return suggest[name].phrase.real_world_error_likelihood;
  15750. }
  15751. suggest[name].phrase.real_world_error_likelihood = l;
  15752. return this;
  15753. },
  15754. /**
  15755. <p>Sets the confidence level defines a factor applied to the input
  15756. phrases score which is used as a threshold for other suggest
  15757. candidates. Only candidates that score higher than the threshold
  15758. will be included in the result.</p>
  15759. @member ejs.PhraseSuggester
  15760. @param {Double} c A positive double value.
  15761. @returns {Object} returns <code>this</code> so that calls can be chained.
  15762. */
  15763. confidence: function (c) {
  15764. if (c == null) {
  15765. return suggest[name].phrase.confidence;
  15766. }
  15767. suggest[name].phrase.confidence = c;
  15768. return this;
  15769. },
  15770. /**
  15771. <p>Sets the separator that is used to separate terms in the bigram
  15772. field. If not set the whitespce character is used as a
  15773. separator.</p>
  15774. @member ejs.PhraseSuggester
  15775. @param {String} sep A string separator.
  15776. @returns {Object} returns <code>this</code> so that calls can be chained.
  15777. */
  15778. separator: function (sep) {
  15779. if (sep == null) {
  15780. return suggest[name].phrase.separator;
  15781. }
  15782. suggest[name].phrase.separator = sep;
  15783. return this;
  15784. },
  15785. /**
  15786. <p>Sets the maximum percentage of the terms that at most
  15787. considered to be misspellings in order to form a correction.</p>
  15788. @member ejs.PhraseSuggester
  15789. @param {Double} c A positive double value greater between 0 and 1.
  15790. @returns {Object} returns <code>this</code> so that calls can be chained.
  15791. */
  15792. maxErrors: function (max) {
  15793. if (max == null) {
  15794. return suggest[name].phrase.max_errors;
  15795. }
  15796. suggest[name].phrase.max_errors = max;
  15797. return this;
  15798. },
  15799. /**
  15800. <p>Sets the max size of the n-grams (shingles) in the field. If
  15801. the field doesn't contain n-grams (shingles) this should be
  15802. omitted or set to 1.</p>
  15803. @member ejs.PhraseSuggester
  15804. @param {Integer} s A positive integer value.
  15805. @returns {Object} returns <code>this</code> so that calls can be chained.
  15806. */
  15807. gramSize: function (s) {
  15808. if (s == null) {
  15809. return suggest[name].phrase.gram_size;
  15810. }
  15811. suggest[name].phrase.gram_size = s;
  15812. return this;
  15813. },
  15814. /**
  15815. <p>Forces the use of unigrams.</p>
  15816. @member ejs.PhraseSuggester
  15817. @param {Boolean} trueFalse True to force unigrams, false otherwise.
  15818. @returns {Object} returns <code>this</code> so that calls can be chained.
  15819. */
  15820. forceUnigrams: function (trueFalse) {
  15821. if (trueFalse == null) {
  15822. return suggest[name].phrase.force_unigrams;
  15823. }
  15824. suggest[name].phrase.force_unigrams = trueFalse;
  15825. return this;
  15826. },
  15827. /**
  15828. <p>A smoothing model that takes the weighted mean of the unigrams,
  15829. bigrams and trigrams based on user supplied weights (lambdas). The
  15830. sum of tl, bl, and ul must equal 1.</p>
  15831. @member ejs.PhraseSuggester
  15832. @param {Double} tl A positive double value used for trigram weight.
  15833. @param {Double} bl A positive double value used for bigram weight.
  15834. @param {Double} ul A positive double value used for unigram weight.
  15835. @returns {Object} returns <code>this</code> so that calls can be chained.
  15836. */
  15837. linearSmoothing: function (tl, bl, ul) {
  15838. if (arguments.length === 0) {
  15839. return suggest[name].phrase.smoothing;
  15840. }
  15841. suggest[name].phrase.smoothing = {
  15842. linear: {
  15843. trigram_lambda: tl,
  15844. bigram_lambda: bl,
  15845. unigram_lambda: ul
  15846. }
  15847. };
  15848. return this;
  15849. },
  15850. /**
  15851. <p>A smoothing model that uses an additive smoothing model where a
  15852. constant (typically 1.0 or smaller) is added to all counts to
  15853. balance weights, The default alpha is 0.5.</p>
  15854. @member ejs.PhraseSuggester
  15855. @param {Double} alpha A double value.
  15856. @returns {Object} returns <code>this</code> so that calls can be chained.
  15857. */
  15858. laplaceSmoothing: function (alpha) {
  15859. if (alpha == null) {
  15860. return suggest[name].phrase.smoothing;
  15861. }
  15862. suggest[name].phrase.smoothing = {
  15863. laplace: {
  15864. alpha: alpha
  15865. }
  15866. };
  15867. return this;
  15868. },
  15869. /**
  15870. <p>A simple backoff model that backs off to lower order n-gram
  15871. models if the higher order count is 0 and discounts the lower
  15872. order n-gram model by a constant factor. The default discount is
  15873. 0.4.</p>
  15874. @member ejs.PhraseSuggester
  15875. @param {Double} discount A double value.
  15876. @returns {Object} returns <code>this</code> so that calls can be chained.
  15877. */
  15878. stupidBackoffSmoothing: function (discount) {
  15879. if (discount == null) {
  15880. return suggest[name].phrase.smoothing;
  15881. }
  15882. suggest[name].phrase.smoothing = {
  15883. stupid_backoff: {
  15884. discount: discount
  15885. }
  15886. };
  15887. return this;
  15888. },
  15889. /**
  15890. Adds a direct generator. If passed a single <code>Generator</code>
  15891. it is added to the list of existing generators. If passed an
  15892. array of Generators, they replace all existing generators.
  15893. @member ejs.PhraseSuggester
  15894. @param {Generator || Array} oGenerator A valid Generator or
  15895. array of Generator objects.
  15896. @returns {Object} returns <code>this</code> so that calls can be chained.
  15897. */
  15898. directGenerator: function (oGenerator) {
  15899. var i, len;
  15900. if (suggest[name].phrase.direct_generator == null) {
  15901. suggest[name].phrase.direct_generator = [];
  15902. }
  15903. if (oGenerator == null) {
  15904. return suggest[name].phrase.direct_generator;
  15905. }
  15906. if (isGenerator(oGenerator)) {
  15907. suggest[name].phrase.direct_generator.push(oGenerator._self());
  15908. } else if (isArray(oGenerator)) {
  15909. suggest[name].phrase.direct_generator = [];
  15910. for (i = 0, len = oGenerator.length; i < len; i++) {
  15911. if (!isGenerator(oGenerator[i])) {
  15912. throw new TypeError('Argument must be an array of Generators');
  15913. }
  15914. suggest[name].phrase.direct_generator.push(oGenerator[i]._self());
  15915. }
  15916. } else {
  15917. throw new TypeError('Argument must be a Generator or array of Generators');
  15918. }
  15919. return this;
  15920. },
  15921. /**
  15922. <p>Allows you to serialize this object into a JSON encoded string.</p>
  15923. @member ejs.PhraseSuggester
  15924. @returns {String} returns this object as a serialized JSON string.
  15925. */
  15926. toString: function () {
  15927. return JSON.stringify(suggest);
  15928. },
  15929. /**
  15930. The type of ejs object. For internal use only.
  15931. @member ejs.PhraseSuggester
  15932. @returns {String} the type of object
  15933. */
  15934. _type: function () {
  15935. return 'suggest';
  15936. },
  15937. /**
  15938. <p>Retrieves the internal <code>suggest</code> object. This is typically used by
  15939. internal API functions so use with caution.</p>
  15940. @member ejs.PhraseSuggester
  15941. @returns {String} returns this object's internal <code>suggest</code> property.
  15942. */
  15943. _self: function () {
  15944. return suggest;
  15945. }
  15946. };
  15947. };
  15948. /**
  15949. @class
  15950. <p>TermSuggester suggests terms based on edit distance. The provided suggest
  15951. text is analyzed before terms are suggested. The suggested terms are
  15952. provided per analyzed suggest text token. This leaves the suggest-selection
  15953. to the API consumer. For a higher level suggester, please use the
  15954. <code>PhraseSuggester</code>.</p>
  15955. @name ejs.TermSuggester
  15956. @since elasticsearch 0.90
  15957. @desc
  15958. <p>A suggester that suggests terms based on edit distance.</p>
  15959. @borrows ejs.DirectSettingsMixin.accuracy as accuracy
  15960. @borrows ejs.DirectSettingsMixin.suggestMode as suggestMode
  15961. @borrows ejs.DirectSettingsMixin.sort as sort
  15962. @borrows ejs.DirectSettingsMixin.stringDistance as stringDistance
  15963. @borrows ejs.DirectSettingsMixin.maxEdits as maxEdits
  15964. @borrows ejs.DirectSettingsMixin.maxInspections as maxInspections
  15965. @borrows ejs.DirectSettingsMixin.maxTermFreq as maxTermFreq
  15966. @borrows ejs.DirectSettingsMixin.prefixLength as prefixLength
  15967. @borrows ejs.DirectSettingsMixin.minWordLen as minWordLen
  15968. @borrows ejs.DirectSettingsMixin.minDocFreq as minDocFreq
  15969. @param {String} name The name which be used to refer to this suggester.
  15970. */
  15971. ejs.TermSuggester = function (name) {
  15972. /**
  15973. The internal suggest object.
  15974. @member ejs.TermSuggester
  15975. @property {Object} suggest
  15976. */
  15977. var suggest = {},
  15978. // common suggester options
  15979. _common = ejs.DirectSettingsMixin();
  15980. // setup correct term suggestor format
  15981. suggest[name] = {term: _common._self()};
  15982. return extend(_common, {
  15983. /**
  15984. <p>Sets the text to get suggestions for. If not set, the global
  15985. suggestion text will be used.</p>
  15986. @member ejs.TermSuggester
  15987. @param {String} txt A string to get suggestions for.
  15988. @returns {Object} returns <code>this</code> so that calls can be chained.
  15989. */
  15990. text: function (txt) {
  15991. if (txt == null) {
  15992. return suggest[name].text;
  15993. }
  15994. suggest[name].text = txt;
  15995. return this;
  15996. },
  15997. /**
  15998. <p>Sets analyzer used to analyze the suggest text.</p>
  15999. @member ejs.TermSuggester
  16000. @param {String} analyzer A valid analyzer name.
  16001. @returns {Object} returns <code>this</code> so that calls can be chained.
  16002. */
  16003. analyzer: function (analyzer) {
  16004. if (analyzer == null) {
  16005. return suggest[name].term.analyzer;
  16006. }
  16007. suggest[name].term.analyzer = analyzer;
  16008. return this;
  16009. },
  16010. /**
  16011. <p>Sets the field used to generate suggestions from.</p>
  16012. @member ejs.TermSuggester
  16013. @param {String} field A valid field name.
  16014. @returns {Object} returns <code>this</code> so that calls can be chained.
  16015. */
  16016. field: function (field) {
  16017. if (field == null) {
  16018. return suggest[name].term.field;
  16019. }
  16020. suggest[name].term.field = field;
  16021. return this;
  16022. },
  16023. /**
  16024. <p>Sets the number of suggestions returned for each token.</p>
  16025. @member ejs.TermSuggester
  16026. @param {Integer} s A positive integer value.
  16027. @returns {Object} returns <code>this</code> so that calls can be chained.
  16028. */
  16029. size: function (s) {
  16030. if (s == null) {
  16031. return suggest[name].term.size;
  16032. }
  16033. suggest[name].term.size = s;
  16034. return this;
  16035. },
  16036. /**
  16037. <p>Sets the maximum number of suggestions to be retrieved from
  16038. each individual shard.</p>
  16039. @member ejs.TermSuggester
  16040. @param {Integer} s A positive integer value.
  16041. @returns {Object} returns <code>this</code> so that calls can be chained.
  16042. */
  16043. shardSize: function (s) {
  16044. if (s == null) {
  16045. return suggest[name].term.shard_size;
  16046. }
  16047. suggest[name].term.shard_size = s;
  16048. return this;
  16049. },
  16050. /**
  16051. <p>Allows you to serialize this object into a JSON encoded string.</p>
  16052. @member ejs.TermSuggester
  16053. @returns {String} returns this object as a serialized JSON string.
  16054. */
  16055. toString: function () {
  16056. return JSON.stringify(suggest);
  16057. },
  16058. /**
  16059. The type of ejs object. For internal use only.
  16060. @member ejs.TermSuggester
  16061. @returns {String} the type of object
  16062. */
  16063. _type: function () {
  16064. return 'suggest';
  16065. },
  16066. /**
  16067. <p>Retrieves the internal <code>suggest</code> object. This is typically used by
  16068. internal API functions so use with caution.</p>
  16069. @member ejs.TermSuggester
  16070. @returns {String} returns this object's internal <code>suggest</code> property.
  16071. */
  16072. _self: function () {
  16073. return suggest;
  16074. }
  16075. });
  16076. };
  16077. // run in noConflict mode
  16078. ejs.noConflict = function () {
  16079. root.ejs = _ejs;
  16080. return this;
  16081. };
  16082. }).call(this);