elastic.js 537 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990
  1. /*! elastic.js - v1.0.0 - 2013-01-15
  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. // create ejs object
  46. ejs;
  47. if (typeof exports !== 'undefined') {
  48. ejs = exports;
  49. } else {
  50. ejs = root.ejs = {};
  51. }
  52. /* Utility methods, most of which are pulled from underscore.js. */
  53. // Shortcut function for checking if an object has a given property directly
  54. // on itself (in other words, not on a prototype).
  55. has = function (obj, key) {
  56. return hasOwnProp.call(obj, key);
  57. };
  58. // The cornerstone, an `each` implementation, aka `forEach`.
  59. // Handles objects with the built-in `forEach`, arrays, and raw objects.
  60. // Delegates to **ECMAScript 5**'s native `forEach` if available.
  61. each = function (obj, iterator, context) {
  62. if (obj == null) {
  63. return;
  64. }
  65. if (nativeForEach && obj.forEach === nativeForEach) {
  66. obj.forEach(iterator, context);
  67. } else if (obj.length === +obj.length) {
  68. for (var i = 0, l = obj.length; i < l; i++) {
  69. if (iterator.call(context, obj[i], i, obj) === breaker) {
  70. return;
  71. }
  72. }
  73. } else {
  74. for (var key in obj) {
  75. if (has(obj, key)) {
  76. if (iterator.call(context, obj[key], key, obj) === breaker) {
  77. return;
  78. }
  79. }
  80. }
  81. }
  82. };
  83. // Extend a given object with all the properties in passed-in object(s).
  84. extend = function (obj) {
  85. each(slice.call(arguments, 1), function (source) {
  86. for (var prop in source) {
  87. obj[prop] = source[prop];
  88. }
  89. });
  90. return obj;
  91. };
  92. // Is a given value an array?
  93. // Delegates to ECMA5's native Array.isArray
  94. // switched to ===, not sure why underscore used ==
  95. isArray = nativeIsArray || function (obj) {
  96. return toString.call(obj) === '[object Array]';
  97. };
  98. // Is a given variable an object?
  99. isObject = function (obj) {
  100. return obj === Object(obj);
  101. };
  102. // switched to ===, not sure why underscore used ==
  103. isString = function (obj) {
  104. return toString.call(obj) === '[object String]';
  105. };
  106. // switched to ===, not sure why underscore used ==
  107. isNumber = function (obj) {
  108. return toString.call(obj) === '[object Number]';
  109. };
  110. // switched to ===, not sure why underscore used ==
  111. if (typeof (/./) !== 'function') {
  112. isFunction = function (obj) {
  113. return typeof obj === 'function';
  114. };
  115. } else {
  116. isFunction = function (obj) {
  117. return toString.call(obj) === '[object Function]';
  118. };
  119. }
  120. // Is a given value an ejs object?
  121. // Yes if object and has "_type", "_self", and "toString" properties
  122. isEJSObject = function (obj) {
  123. return (isObject(obj) &&
  124. has(obj, '_type') &&
  125. has(obj, '_self') &&
  126. has(obj, 'toString'));
  127. };
  128. isQuery = function (obj) {
  129. return (isEJSObject(obj) && obj._type() === 'query');
  130. };
  131. isFilter = function (obj) {
  132. return (isEJSObject(obj) && obj._type() === 'filter');
  133. };
  134. isFacet = function (obj) {
  135. return (isEJSObject(obj) && obj._type() === 'facet');
  136. };
  137. isScriptField = function (obj) {
  138. return (isEJSObject(obj) && obj._type() === 'script field');
  139. };
  140. isGeoPoint = function (obj) {
  141. return (isEJSObject(obj) && obj._type() === 'geo point');
  142. };
  143. isIndexedShape = function (obj) {
  144. return (isEJSObject(obj) && obj._type() === 'indexed shape');
  145. };
  146. isShape = function (obj) {
  147. return (isEJSObject(obj) && obj._type() === 'shape');
  148. };
  149. isSort = function (obj) {
  150. return (isEJSObject(obj) && obj._type() === 'sort');
  151. };
  152. isHighlight = function (obj) {
  153. return (isEJSObject(obj) && obj._type() === 'highlight');
  154. };
  155. /**
  156. @class
  157. <p>The DateHistogram facet works with time-based values by building a histogram across time
  158. intervals of the <code>value</code> field. Each value is <em>rounded</em> into an interval (or
  159. placed in a bucket), and statistics are provided per interval/bucket (count and total).</p>
  160. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  161. better. You can also construct several <em>"groups"</em> at once by simply
  162. specifying multiple facets.</p>
  163. <div class="alert-message block-message info">
  164. <p>
  165. <strong>Tip: </strong>
  166. For more information on faceted navigation, see
  167. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  168. Wikipedia article on Faceted Classification.
  169. </p>
  170. </div>
  171. @name ejs.DateHistogramFacet
  172. @desc
  173. <p>A facet which returns the N most frequent terms within a collection
  174. or set of collections.</p>
  175. @param {String} name The name which be used to refer to this facet. For instance,
  176. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  177. <code>name</code> to <code>Authors</code> would allow you to refer to the
  178. facet by that name, possibly simplifying some of the display logic.
  179. */
  180. ejs.DateHistogramFacet = function (name) {
  181. /**
  182. The internal facet object.
  183. @member ejs.DateHistogramFacet
  184. @property {Object} facet
  185. */
  186. var facet = {};
  187. facet[name] = {
  188. date_histogram: {}
  189. };
  190. return {
  191. /**
  192. Sets the field to be used to construct the this facet.
  193. @member ejs.DateHistogramFacet
  194. @param {String} fieldName The field name whose data will be used to construct the facet.
  195. @returns {Object} returns <code>this</code> so that calls can be chained.
  196. */
  197. field: function (fieldName) {
  198. if (fieldName == null) {
  199. return facet[name].date_histogram.field;
  200. }
  201. facet[name].date_histogram.field = fieldName;
  202. return this;
  203. },
  204. /**
  205. Allows you to specify a different key field to be used to group intervals.
  206. @member ejs.DateHistogramFacet
  207. @param {String} fieldName The name of the field to be used.
  208. @returns {Object} returns <code>this</code> so that calls can be chained.
  209. */
  210. keyField: function (fieldName) {
  211. if (fieldName == null) {
  212. return facet[name].date_histogram.key_field;
  213. }
  214. facet[name].date_histogram.key_field = fieldName;
  215. return this;
  216. },
  217. /**
  218. Allows you to specify a different value field to aggrerate over.
  219. @member ejs.DateHistogramFacet
  220. @param {String} fieldName The name of the field to be used.
  221. @returns {Object} returns <code>this</code> so that calls can be chained.
  222. */
  223. valueField: function (fieldName) {
  224. if (fieldName == null) {
  225. return facet[name].date_histogram.value_field;
  226. }
  227. facet[name].date_histogram.value_field = fieldName;
  228. return this;
  229. },
  230. /**
  231. Sets the bucket interval used to calculate the distribution.
  232. @member ejs.DateHistogramFacet
  233. @param {String} timeInterval The bucket interval. Valid values are <code>year, month, week, day, hour,</code> and <code>minute</code>.
  234. @returns {Object} returns <code>this</code> so that calls can be chained.
  235. */
  236. interval: function (timeInterval) {
  237. if (timeInterval == null) {
  238. return facet[name].date_histogram.interval;
  239. }
  240. facet[name].date_histogram.interval = timeInterval;
  241. return this;
  242. },
  243. /**
  244. By default, time values are stored in UTC format. This method allows users
  245. to set a time zone value that is then used to compute intervals
  246. before rounding on the interval value. Equalivent to
  247. <coe>preZone</code>. Use <code>preZone</code> if possible. The
  248. value is an offset from UTC.
  249. For example, to use EST you would set the value to <code>-5</code>.
  250. @member ejs.DateHistogramFacet
  251. @param {Integer} tz An offset value from UTC.
  252. @returns {Object} returns <code>this</code> so that calls can be chained.
  253. */
  254. timeZone: function (tz) {
  255. if (tz == null) {
  256. return facet[name].date_histogram.time_zone;
  257. }
  258. facet[name].date_histogram.time_zone = tz;
  259. return this;
  260. },
  261. /**
  262. By default, time values are stored in UTC format. This method allows users
  263. to set a time zone value that is then used to compute intervals
  264. before rounding on the interval value. The value is an offset
  265. from UTC.
  266. For example, to use EST you would set the value to <code>-5</code>.
  267. @member ejs.DateHistogramFacet
  268. @param {Integer} tz An offset value from UTC.
  269. @returns {Object} returns <code>this</code> so that calls can be chained.
  270. */
  271. preZone: function (tz) {
  272. if (tz == null) {
  273. return facet[name].date_histogram.pre_zone;
  274. }
  275. facet[name].date_histogram.pre_zone = tz;
  276. return this;
  277. },
  278. /**
  279. Enables large date interval conversions (day and up). Set to
  280. true to enable and then set the <code>interval</code> to an
  281. interval greater than a day.
  282. @member ejs.DateHistogramFacet
  283. @param {Boolean} trueFalse A valid boolean value.
  284. @returns {Object} returns <code>this</code> so that calls can be chained.
  285. */
  286. preZoneAdjustLargeInterval: function (trueFalse) {
  287. if (trueFalse == null) {
  288. return facet[name].date_histogram.pre_zone_adjust_large_interval;
  289. }
  290. facet[name].date_histogram.pre_zone_adjust_large_interval = trueFalse;
  291. return this;
  292. },
  293. /**
  294. By default, time values are stored in UTC format. This method allows users
  295. to set a time zone value that is then used to compute intervals
  296. after rounding on the interval value. The value is an offset
  297. from UTC. The tz offset value is simply added to the resulting
  298. bucket's date value.
  299. For example, to use EST you would set the value to <code>-5</code>.
  300. @member ejs.DateHistogramFacet
  301. @param {Integer} tz An offset value from UTC.
  302. @returns {Object} returns <code>this</code> so that calls can be chained.
  303. */
  304. postZone: function (tz) {
  305. if (tz == null) {
  306. return facet[name].date_histogram.post_zone;
  307. }
  308. facet[name].date_histogram.post_zone = tz;
  309. return this;
  310. },
  311. /**
  312. Set's a specific pre-rounding offset. Format is 1d, 1h, etc.
  313. @member ejs.DateHistogramFacet
  314. @param {String} offset The offset as a string (1d, 1h, etc)
  315. @returns {Object} returns <code>this</code> so that calls can be chained.
  316. */
  317. preOffset: function (offset) {
  318. if (offset == null) {
  319. return facet[name].date_histogram.pre_offset;
  320. }
  321. facet[name].date_histogram.pre_offset = offset;
  322. return this;
  323. },
  324. /**
  325. Set's a specific post-rounding offset. Format is 1d, 1h, etc.
  326. @member ejs.DateHistogramFacet
  327. @param {String} offset The offset as a string (1d, 1h, etc)
  328. @returns {Object} returns <code>this</code> so that calls can be chained.
  329. */
  330. postOffset: function (offset) {
  331. if (offset == null) {
  332. return facet[name].date_histogram.post_offset;
  333. }
  334. facet[name].date_histogram.post_offset = offset;
  335. return this;
  336. },
  337. /**
  338. The date histogram works on numeric values (since time is stored
  339. in milliseconds since the epoch in UTC). But, sometimes, systems
  340. will store a different resolution (like seconds since UTC) in a
  341. numeric field. The factor parameter can be used to change the
  342. value in the field to milliseconds to actual do the relevant
  343. rounding, and then be applied again to get to the original unit.
  344. For example, when storing in a numeric field seconds resolution,
  345. the factor can be set to 1000.
  346. @member ejs.DateHistogramFacet
  347. @param {Integer} f The conversion factor.
  348. @returns {Object} returns <code>this</code> so that calls can be chained.
  349. */
  350. factor: function (f) {
  351. if (f == null) {
  352. return facet[name].date_histogram.factor;
  353. }
  354. facet[name].date_histogram.factor = f;
  355. return this;
  356. },
  357. /**
  358. Allows you modify the <code>value</code> field using a script. The modified value
  359. is then used to compute the statistical data.
  360. @member ejs.DateHistogramFacet
  361. @param {String} scriptCode A valid script string to execute.
  362. @returns {Object} returns <code>this</code> so that calls can be chained.
  363. */
  364. valueScript: function (scriptCode) {
  365. if (scriptCode == null) {
  366. return facet[name].date_histogram.value_script;
  367. }
  368. facet[name].date_histogram.value_script = scriptCode;
  369. return this;
  370. },
  371. /**
  372. Sets the type of ordering that will be performed on the date
  373. buckets. Valid values are:
  374. time - the default, sort by the buckets start time in milliseconds.
  375. count - sort by the number of items in the bucket
  376. total - sort by the sum/total of the items in the bucket
  377. @member ejs.DateHistogramFacet
  378. @param {String} o The ordering method: time, count, or total.
  379. @returns {Object} returns <code>this</code> so that calls can be chained.
  380. */
  381. order: function (o) {
  382. if (o == null) {
  383. return facet[name].date_histogram.order;
  384. }
  385. o = o.toLowerCase();
  386. if (o === 'time' || o === 'count' || o === 'total') {
  387. facet[name].date_histogram.order = o;
  388. }
  389. return this;
  390. },
  391. /**
  392. The script language being used. Currently supported values are
  393. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  394. @member ejs.DateHistogramFacet
  395. @param {String} language The language of the script.
  396. @returns {Object} returns <code>this</code> so that calls can be chained.
  397. */
  398. lang: function (language) {
  399. if (language == null) {
  400. return facet[name].date_histogram.lang;
  401. }
  402. facet[name].date_histogram.lang = language;
  403. return this;
  404. },
  405. /**
  406. Sets parameters that will be applied to the script. Overwrites
  407. any existing params.
  408. @member ejs.DateHistogramFacet
  409. @param {Object} p An object where the keys are the parameter name and
  410. values are the parameter value.
  411. @returns {Object} returns <code>this</code> so that calls can be chained.
  412. */
  413. params: function (p) {
  414. if (p == null) {
  415. return facet[name].date_histogram.params;
  416. }
  417. facet[name].date_histogram.params = p;
  418. return this;
  419. },
  420. /**
  421. <p>Allows you to reduce the documents used for computing facet results.</p>
  422. @member ejs.DateHistogramFacet
  423. @param {Object} oFilter A valid <code>Filter</code> object.
  424. @returns {Object} returns <code>this</code> so that calls can be chained.
  425. */
  426. facetFilter: function (oFilter) {
  427. if (oFilter == null) {
  428. return facet[name].facet_filter;
  429. }
  430. if (!isFilter(oFilter)) {
  431. throw new TypeError('Argument must be a Filter');
  432. }
  433. facet[name].facet_filter = oFilter._self();
  434. return this;
  435. },
  436. /**
  437. <p>Computes values across the entire index</p>
  438. @member ejs.DateHistogramFacet
  439. @param {Boolean} trueFalse Calculate facet counts globally or not.
  440. @returns {Object} returns <code>this</code> so that calls can be chained.
  441. */
  442. global: function (trueFalse) {
  443. if (trueFalse == null) {
  444. return facet[name].global;
  445. }
  446. facet[name].global = trueFalse;
  447. return this;
  448. },
  449. /**
  450. <p>Computes values across the the specified scope</p>
  451. @member ejs.DateHistogramFacet
  452. @param {String} scope The scope name to calculate facet counts with.
  453. @returns {Object} returns <code>this</code> so that calls can be chained.
  454. */
  455. scope: function (scope) {
  456. if (scope == null) {
  457. return facet[name].scope;
  458. }
  459. facet[name].scope = scope;
  460. return this;
  461. },
  462. /**
  463. <p>Enables caching of the <code>facetFilter</code></p>
  464. @member ejs.DateHistogramFacet
  465. @param {Boolean} trueFalse If the facetFilter should be cached or not
  466. @returns {Object} returns <code>this</code> so that calls can be chained.
  467. */
  468. cacheFilter: function (trueFalse) {
  469. if (trueFalse == null) {
  470. return facet[name].cache_filter;
  471. }
  472. facet[name].cache_filter = trueFalse;
  473. return this;
  474. },
  475. /**
  476. <p>Sets the path to the nested document if faceting against a
  477. nested field.</p>
  478. @member ejs.DateHistogramFacet
  479. @param {String} path The nested path
  480. @returns {Object} returns <code>this</code> so that calls can be chained.
  481. */
  482. nested: function (path) {
  483. if (path == null) {
  484. return facet[name].nested;
  485. }
  486. facet[name].nested = path;
  487. return this;
  488. },
  489. /**
  490. <p>Allows you to serialize this object into a JSON encoded string.</p>
  491. @member ejs.DateHistogramFacet
  492. @returns {String} returns this object as a serialized JSON string.
  493. */
  494. toString: function () {
  495. return JSON.stringify(facet);
  496. },
  497. /**
  498. The type of ejs object. For internal use only.
  499. @member ejs.DateHistogramFacet
  500. @returns {String} the type of object
  501. */
  502. _type: function () {
  503. return 'facet';
  504. },
  505. /**
  506. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  507. internal API functions so use with caution.</p>
  508. @member ejs.DateHistogramFacet
  509. @returns {String} returns this object's internal <code>facet</code> property.
  510. */
  511. _self: function () {
  512. return facet;
  513. }
  514. };
  515. };
  516. /**
  517. @class
  518. <p>The FilterFacet allows you to specify any valid <code>Filter</code> and
  519. have the number of matching hits returned as the value.</p>
  520. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  521. better. You can also construct several <em>"groups"</em> at once by simply
  522. specifying multiple facets.</p>
  523. <div class="alert-message block-message info">
  524. <p>
  525. <strong>Tip: </strong>
  526. For more information on faceted navigation, see
  527. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  528. Wikipedia article on Faceted Classification.
  529. </p>
  530. </div>
  531. @name ejs.FilterFacet
  532. @desc
  533. <p>A facet that return a count of the hits matching the given filter.</p>
  534. @param {String} name The name which be used to refer to this facet. For instance,
  535. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  536. <code>name</code> to <code>Authors</code> would allow you to refer to the
  537. facet by that name, possibly simplifying some of the display logic.
  538. */
  539. ejs.FilterFacet = function (name) {
  540. /**
  541. The internal facet object.
  542. @member ejs.FilterFacet
  543. @property {Object} facet
  544. */
  545. var facet = {};
  546. facet[name] = {};
  547. return {
  548. /**
  549. <p>Sets the filter to be used for this facet.</p>
  550. @member ejs.FilterFacet
  551. @param {Object} oFilter A valid <code>Query</code> object.
  552. @returns {Object} returns <code>this</code> so that calls can be chained.
  553. */
  554. filter: function (oFilter) {
  555. if (oFilter == null) {
  556. return facet[name].filter;
  557. }
  558. if (!isFilter(oFilter)) {
  559. throw new TypeError('Argument must be a Filter');
  560. }
  561. facet[name].filter = oFilter._self();
  562. return this;
  563. },
  564. /**
  565. <p>Allows you to reduce the documents used for computing facet results.</p>
  566. @member ejs.FilterFacet
  567. @param {Object} oFilter A valid <code>Filter</code> object.
  568. @returns {Object} returns <code>this</code> so that calls can be chained.
  569. */
  570. facetFilter: function (oFilter) {
  571. if (oFilter == null) {
  572. return facet[name].facet_filter;
  573. }
  574. if (!isFilter(oFilter)) {
  575. throw new TypeError('Argument must be a Filter');
  576. }
  577. facet[name].facet_filter = oFilter._self();
  578. return this;
  579. },
  580. /**
  581. <p>Computes values across the entire index</p>
  582. @member ejs.FilterFacet
  583. @param {Boolean} trueFalse Calculate facet counts globally or not.
  584. @returns {Object} returns <code>this</code> so that calls can be chained.
  585. */
  586. global: function (trueFalse) {
  587. if (trueFalse == null) {
  588. return facet[name].global;
  589. }
  590. facet[name].global = trueFalse;
  591. return this;
  592. },
  593. /**
  594. <p>Computes values across the the specified scope</p>
  595. @member ejs.FilterFacet
  596. @param {String} scope The scope name to calculate facet counts with.
  597. @returns {Object} returns <code>this</code> so that calls can be chained.
  598. */
  599. scope: function (scope) {
  600. if (scope == null) {
  601. return facet[name].scope;
  602. }
  603. facet[name].scope = scope;
  604. return this;
  605. },
  606. /**
  607. <p>Enables caching of the <code>facetFilter</code></p>
  608. @member ejs.FilterFacet
  609. @param {Boolean} trueFalse If the facetFilter should be cached or not
  610. @returns {Object} returns <code>this</code> so that calls can be chained.
  611. */
  612. cacheFilter: function (trueFalse) {
  613. if (trueFalse == null) {
  614. return facet[name].cache_filter;
  615. }
  616. facet[name].cache_filter = trueFalse;
  617. return this;
  618. },
  619. /**
  620. <p>Sets the path to the nested document if faceting against a
  621. nested field.</p>
  622. @member ejs.FilterFacet
  623. @param {String} path The nested path
  624. @returns {Object} returns <code>this</code> so that calls can be chained.
  625. */
  626. nested: function (path) {
  627. if (path == null) {
  628. return facet[name].nested;
  629. }
  630. facet[name].nested = path;
  631. return this;
  632. },
  633. /**
  634. <p>Allows you to serialize this object into a JSON encoded string.</p>
  635. @member ejs.FilterFacet
  636. @returns {String} returns this object as a serialized JSON string.
  637. */
  638. toString: function () {
  639. return JSON.stringify(facet);
  640. },
  641. /**
  642. The type of ejs object. For internal use only.
  643. @member ejs.FilterFacet
  644. @returns {String} the type of object
  645. */
  646. _type: function () {
  647. return 'facet';
  648. },
  649. /**
  650. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  651. internal API functions so use with caution.</p>
  652. @member ejs.FilterFacet
  653. @returns {String} returns this object's internal <code>facet</code> property.
  654. */
  655. _self: function () {
  656. return facet;
  657. }
  658. };
  659. };
  660. /**
  661. @class
  662. <p>The geoDistanceFacet facet provides information over a range of distances from a
  663. provided point. This includes the number of hits that fall within each range,
  664. along with aggregate information (like total).</p>
  665. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  666. better. You can also construct several <em>"groups"</em> at once by simply
  667. specifying multiple facets.</p>
  668. <div class="alert-message block-message info">
  669. <p>
  670. <strong>Tip: </strong>
  671. For more information on faceted navigation, see
  672. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  673. Wikipedia article on Faceted Classification.
  674. </p>
  675. </div>
  676. @name ejs.GeoDistanceFacet
  677. @desc
  678. <p>A facet which provides information over a range of distances from a provided point.</p>
  679. @param {String} name The name which be used to refer to this facet. For instance,
  680. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  681. <code>name</code> to <code>Authors</code> would allow you to refer to the
  682. facet by that name, possibly simplifying some of the display logic.
  683. */
  684. ejs.GeoDistanceFacet = function (name) {
  685. /**
  686. The internal facet object.
  687. @member ejs.GeoDistanceFacet
  688. @property {Object} facet
  689. */
  690. var facet = {},
  691. point = ejs.GeoPoint([0, 0]),
  692. field = 'location';
  693. facet[name] = {
  694. geo_distance: {
  695. location: point._self(),
  696. ranges: []
  697. }
  698. };
  699. return {
  700. /**
  701. Sets the document field containing the geo-coordinate to be used
  702. to calculate the distance. Defaults to "location".
  703. @member ejs.GeoDistanceFacet
  704. @param {String} fieldName The field name whose data will be used to construct the facet.
  705. @returns {Object} returns <code>this</code> so that calls can be chained.
  706. */
  707. field: function (fieldName) {
  708. var oldValue = facet[name].geo_distance[field];
  709. if (fieldName == null) {
  710. return field;
  711. }
  712. delete facet[name].geo_distance[field];
  713. field = fieldName;
  714. facet[name].geo_distance[fieldName] = oldValue;
  715. return this;
  716. },
  717. /**
  718. Sets the point of origin from where distances will be measured.
  719. @member ejs.GeoDistanceFacet
  720. @param {GeoPoint} p A valid GeoPoint object
  721. @returns {Object} returns <code>this</code> so that calls can be chained.
  722. */
  723. point: function (p) {
  724. if (p == null) {
  725. return point;
  726. }
  727. if (!isGeoPoint(p)) {
  728. throw new TypeError('Argument must be a GeoPoint');
  729. }
  730. point = p;
  731. facet[name].geo_distance[field] = p._self();
  732. return this;
  733. },
  734. /**
  735. Adds a new bounded range.
  736. @member ejs.GeoDistanceFacet
  737. @param {Number} from The lower bound of the range
  738. @param {Number} to The upper bound of the range
  739. @returns {Object} returns <code>this</code> so that calls can be chained.
  740. */
  741. addRange: function (from, to) {
  742. if (arguments.length === 0) {
  743. return facet[name].geo_distance.ranges;
  744. }
  745. facet[name].geo_distance.ranges.push({
  746. from: from,
  747. to: to
  748. });
  749. return this;
  750. },
  751. /**
  752. Adds a new unbounded lower limit.
  753. @member ejs.GeoDistanceFacet
  754. @param {Number} from The lower limit of the unbounded range
  755. @returns {Object} returns <code>this</code> so that calls can be chained.
  756. */
  757. addUnboundedFrom: function (from) {
  758. if (from == null) {
  759. return facet[name].geo_distance.ranges;
  760. }
  761. facet[name].geo_distance.ranges.push({
  762. from: from
  763. });
  764. return this;
  765. },
  766. /**
  767. Adds a new unbounded upper limit.
  768. @member ejs.GeoDistanceFacet
  769. @param {Number} to The upper limit of the unbounded range
  770. @returns {Object} returns <code>this</code> so that calls can be chained.
  771. */
  772. addUnboundedTo: function (to) {
  773. if (to == null) {
  774. return facet[name].geo_distance.ranges;
  775. }
  776. facet[name].geo_distance.ranges.push({
  777. to: to
  778. });
  779. return this;
  780. },
  781. /**
  782. Sets the distance unit. Valid values are "mi" for miles or "km"
  783. for kilometers. Defaults to "km".
  784. @member ejs.GeoDistanceFacet
  785. @param {Number} unit the unit of distance measure.
  786. @returns {Object} returns <code>this</code> so that calls can be chained.
  787. */
  788. unit: function (unit) {
  789. if (unit == null) {
  790. return facet[name].geo_distance.unit;
  791. }
  792. unit = unit.toLowerCase();
  793. if (unit === 'mi' || unit === 'km') {
  794. facet[name].geo_distance.unit = unit;
  795. }
  796. return this;
  797. },
  798. /**
  799. How to compute the distance. Can either be arc (better precision)
  800. or plane (faster). Defaults to arc.
  801. @member ejs.GeoDistanceFacet
  802. @param {String} type The execution type as a string.
  803. @returns {Object} returns <code>this</code> so that calls can be chained.
  804. */
  805. distanceType: function (type) {
  806. if (type == null) {
  807. return facet[name].geo_distance.distance_type;
  808. }
  809. type = type.toLowerCase();
  810. if (type === 'arc' || type === 'plane') {
  811. facet[name].geo_distance.distance_type = type;
  812. }
  813. return this;
  814. },
  815. /**
  816. If the lat/long points should be normalized to lie within their
  817. respective normalized ranges.
  818. Normalized ranges are:
  819. lon = -180 (exclusive) to 180 (inclusive) range
  820. lat = -90 to 90 (both inclusive) range
  821. @member ejs.GeoDistanceFacet
  822. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  823. @returns {Object} returns <code>this</code> so that calls can be chained.
  824. */
  825. normalize: function (trueFalse) {
  826. if (trueFalse == null) {
  827. return facet[name].geo_distance.normalize;
  828. }
  829. facet[name].geo_distance.normalize = trueFalse;
  830. return this;
  831. },
  832. /**
  833. Allows you to specify a different value field to aggrerate over.
  834. @member ejs.GeoDistanceFacet
  835. @param {String} fieldName The name of the field to be used.
  836. @returns {Object} returns <code>this</code> so that calls can be chained.
  837. */
  838. valueField: function (fieldName) {
  839. if (fieldName == null) {
  840. return facet[name].geo_distance.value_field;
  841. }
  842. facet[name].geo_distance.value_field = fieldName;
  843. return this;
  844. },
  845. /**
  846. Allows you modify the <code>value</code> field using a script. The modified value
  847. is then used to compute the statistical data.
  848. @member ejs.GeoDistanceFacet
  849. @param {String} scriptCode A valid script string to execute.
  850. @returns {Object} returns <code>this</code> so that calls can be chained.
  851. */
  852. valueScript: function (scriptCode) {
  853. if (scriptCode == null) {
  854. return facet[name].geo_distance.value_script;
  855. }
  856. facet[name].geo_distance.value_script = scriptCode;
  857. return this;
  858. },
  859. /**
  860. The script language being used. Currently supported values are
  861. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  862. @member ejs.GeoDistanceFacet
  863. @param {String} language The language of the script.
  864. @returns {Object} returns <code>this</code> so that calls can be chained.
  865. */
  866. lang: function (language) {
  867. if (language == null) {
  868. return facet[name].geo_distance.lang;
  869. }
  870. facet[name].geo_distance.lang = language;
  871. return this;
  872. },
  873. /**
  874. Sets parameters that will be applied to the script. Overwrites
  875. any existing params.
  876. @member ejs.GeoDistanceFacet
  877. @param {Object} p An object where the keys are the parameter name and
  878. values are the parameter value.
  879. @returns {Object} returns <code>this</code> so that calls can be chained.
  880. */
  881. params: function (p) {
  882. if (p == null) {
  883. return facet[name].geo_distance.params;
  884. }
  885. facet[name].geo_distance.params = p;
  886. return this;
  887. },
  888. /**
  889. <p>Allows you to reduce the documents used for computing facet results.</p>
  890. @member ejs.GeoDistanceFacet
  891. @param {Object} oFilter A valid <code>Filter</code> object.
  892. @returns {Object} returns <code>this</code> so that calls can be chained.
  893. */
  894. facetFilter: function (oFilter) {
  895. if (oFilter == null) {
  896. return facet[name].facet_filter;
  897. }
  898. if (!isFilter(oFilter)) {
  899. throw new TypeError('Argument must be a Filter');
  900. }
  901. facet[name].facet_filter = oFilter._self();
  902. return this;
  903. },
  904. /**
  905. <p>Computes values across the entire index</p>
  906. @member ejs.GeoDistanceFacet
  907. @param {Boolean} trueFalse Calculate facet counts globally or not.
  908. @returns {Object} returns <code>this</code> so that calls can be chained.
  909. */
  910. global: function (trueFalse) {
  911. if (trueFalse == null) {
  912. return facet[name].global;
  913. }
  914. facet[name].global = trueFalse;
  915. return this;
  916. },
  917. /**
  918. <p>Computes values across the the specified scope</p>
  919. @member ejs.GeoDistanceFacet
  920. @param {String} scope The scope name to calculate facet counts with.
  921. @returns {Object} returns <code>this</code> so that calls can be chained.
  922. */
  923. scope: function (scope) {
  924. if (scope == null) {
  925. return facet[name].scope;
  926. }
  927. facet[name].scope = scope;
  928. return this;
  929. },
  930. /**
  931. <p>Enables caching of the <code>facetFilter</code></p>
  932. @member ejs.GeoDistanceFacet
  933. @param {Boolean} trueFalse If the facetFilter should be cached or not
  934. @returns {Object} returns <code>this</code> so that calls can be chained.
  935. */
  936. cacheFilter: function (trueFalse) {
  937. if (trueFalse == null) {
  938. return facet[name].cache_filter;
  939. }
  940. facet[name].cache_filter = trueFalse;
  941. return this;
  942. },
  943. /**
  944. <p>Sets the path to the nested document if faceting against a
  945. nested field.</p>
  946. @member ejs.GeoDistanceFacet
  947. @param {String} path The nested path
  948. @returns {Object} returns <code>this</code> so that calls can be chained.
  949. */
  950. nested: function (path) {
  951. if (path == null) {
  952. return facet[name].nested;
  953. }
  954. facet[name].nested = path;
  955. return this;
  956. },
  957. /**
  958. <p>Allows you to serialize this object into a JSON encoded string.</p>
  959. @member ejs.GeoDistanceFacet
  960. @returns {String} returns this object as a serialized JSON string.
  961. */
  962. toString: function () {
  963. return JSON.stringify(facet);
  964. },
  965. /**
  966. The type of ejs object. For internal use only.
  967. @member ejs.GeoDistanceFacet
  968. @returns {String} the type of object
  969. */
  970. _type: function () {
  971. return 'facet';
  972. },
  973. /**
  974. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  975. internal API functions so use with caution.</p>
  976. @member ejs.GeoDistanceFacet
  977. @returns {String} returns this object's internal <code>facet</code> property.
  978. */
  979. _self: function () {
  980. return facet;
  981. }
  982. };
  983. };
  984. /**
  985. @class
  986. <p>The histogram facet works with numeric data by building a histogram across intervals
  987. of the field values. Each value is <em>rounded</em> into an interval (or placed in a
  988. bucket), and statistics are provided per interval/bucket (count and total).</p>
  989. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  990. better. You can also construct several <em>"groups"</em> at once by simply
  991. specifying multiple facets.</p>
  992. <div class="alert-message block-message info">
  993. <p>
  994. <strong>Tip: </strong>
  995. For more information on faceted navigation, see
  996. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  997. Wikipedia article on Faceted Classification.
  998. </p>
  999. </div>
  1000. @name ejs.HistogramFacet
  1001. @desc
  1002. <p>A facet which returns the N most frequent terms within a collection
  1003. or set of collections.</p>
  1004. @param {String} name The name which be used to refer to this facet. For instance,
  1005. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  1006. <code>name</code> to <code>Authors</code> would allow you to refer to the
  1007. facet by that name, possibly simplifying some of the display logic.
  1008. */
  1009. ejs.HistogramFacet = function (name) {
  1010. /**
  1011. The internal facet object.
  1012. @member ejs.HistogramFacet
  1013. @property {Object} facet
  1014. */
  1015. var facet = {};
  1016. facet[name] = {
  1017. histogram: {}
  1018. };
  1019. return {
  1020. /**
  1021. Sets the field to be used to construct the this facet.
  1022. @member ejs.HistogramFacet
  1023. @param {String} fieldName The field name whose data will be used to construct the facet.
  1024. @returns {Object} returns <code>this</code> so that calls can be chained.
  1025. */
  1026. field: function (fieldName) {
  1027. if (fieldName == null) {
  1028. return facet[name].histogram.field;
  1029. }
  1030. facet[name].histogram.field = fieldName;
  1031. return this;
  1032. },
  1033. /**
  1034. Sets the bucket interval used to calculate the distribution.
  1035. @member ejs.HistogramFacet
  1036. @param {Number} numericInterval The bucket interval in which to group values.
  1037. @returns {Object} returns <code>this</code> so that calls can be chained.
  1038. */
  1039. interval: function (numericInterval) {
  1040. if (numericInterval == null) {
  1041. return facet[name].histogram.interval;
  1042. }
  1043. facet[name].histogram.interval = numericInterval;
  1044. return this;
  1045. },
  1046. /**
  1047. Sets the bucket interval used to calculate the distribution based
  1048. on a time value such as "1d", "1w", etc.
  1049. @member ejs.HistogramFacet
  1050. @param {Number} timeInterval The bucket interval in which to group values.
  1051. @returns {Object} returns <code>this</code> so that calls can be chained.
  1052. */
  1053. timeInterval: function (timeInterval) {
  1054. if (timeInterval == null) {
  1055. return facet[name].histogram.time_interval;
  1056. }
  1057. facet[name].histogram.time_interval = timeInterval;
  1058. return this;
  1059. },
  1060. /**
  1061. Sets the "from", "start", or lower bounds bucket. For example if
  1062. you have a value of 1023, an interval of 100, and a from value of
  1063. 1500, it will be placed into the 1500 bucket vs. the normal bucket
  1064. of 1000.
  1065. @member ejs.HistogramFacet
  1066. @param {Number} from the lower bounds bucket value.
  1067. @returns {Object} returns <code>this</code> so that calls can be chained.
  1068. */
  1069. from: function (from) {
  1070. if (from == null) {
  1071. return facet[name].histogram.from;
  1072. }
  1073. facet[name].histogram.from = from;
  1074. return this;
  1075. },
  1076. /**
  1077. Sets the "to", "end", or upper bounds bucket. For example if
  1078. you have a value of 1023, an interval of 100, and a to value of
  1079. 900, it will be placed into the 900 bucket vs. the normal bucket
  1080. of 1000.
  1081. @member ejs.HistogramFacet
  1082. @param {Number} to the upper bounds bucket value.
  1083. @returns {Object} returns <code>this</code> so that calls can be chained.
  1084. */
  1085. to: function (to) {
  1086. if (to == null) {
  1087. return facet[name].histogram.to;
  1088. }
  1089. facet[name].histogram.to = to;
  1090. return this;
  1091. },
  1092. /**
  1093. Allows you to specify a different value field to aggrerate over.
  1094. @member ejs.HistogramFacet
  1095. @param {String} fieldName The name of the field to be used.
  1096. @returns {Object} returns <code>this</code> so that calls can be chained.
  1097. */
  1098. valueField: function (fieldName) {
  1099. if (fieldName == null) {
  1100. return facet[name].histogram.value_field;
  1101. }
  1102. facet[name].histogram.value_field = fieldName;
  1103. return this;
  1104. },
  1105. /**
  1106. Allows you to specify a different key field to be used to group intervals.
  1107. @member ejs.HistogramFacet
  1108. @param {String} fieldName The name of the field to be used.
  1109. @returns {Object} returns <code>this</code> so that calls can be chained.
  1110. */
  1111. keyField: function (fieldName) {
  1112. if (fieldName == null) {
  1113. return facet[name].histogram.key_field;
  1114. }
  1115. facet[name].histogram.key_field = fieldName;
  1116. return this;
  1117. },
  1118. /**
  1119. Allows you modify the <code>value</code> field using a script. The modified value
  1120. is then used to compute the statistical data.
  1121. @member ejs.HistogramFacet
  1122. @param {String} scriptCode A valid script string to execute.
  1123. @returns {Object} returns <code>this</code> so that calls can be chained.
  1124. */
  1125. valueScript: function (scriptCode) {
  1126. if (scriptCode == null) {
  1127. return facet[name].histogram.value_script;
  1128. }
  1129. facet[name].histogram.value_script = scriptCode;
  1130. return this;
  1131. },
  1132. /**
  1133. Allows you modify the <code>key</code> field using a script. The modified value
  1134. is then used to generate the interval.
  1135. @member ejs.HistogramFacet
  1136. @param {String} scriptCode A valid script string to execute.
  1137. @returns {Object} returns <code>this</code> so that calls can be chained.
  1138. */
  1139. keyScript: function (scriptCode) {
  1140. if (scriptCode == null) {
  1141. return facet[name].histogram.key_script;
  1142. }
  1143. facet[name].histogram.key_script = scriptCode;
  1144. return this;
  1145. },
  1146. /**
  1147. The script language being used. Currently supported values are
  1148. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  1149. @member ejs.HistogramFacet
  1150. @param {String} language The language of the script.
  1151. @returns {Object} returns <code>this</code> so that calls can be chained.
  1152. */
  1153. lang: function (language) {
  1154. if (language == null) {
  1155. return facet[name].histogram.lang;
  1156. }
  1157. facet[name].histogram.lang = language;
  1158. return this;
  1159. },
  1160. /**
  1161. Sets parameters that will be applied to the script. Overwrites
  1162. any existing params.
  1163. @member ejs.HistogramFacet
  1164. @param {Object} p An object where the keys are the parameter name and
  1165. values are the parameter value.
  1166. @returns {Object} returns <code>this</code> so that calls can be chained.
  1167. */
  1168. params: function (p) {
  1169. if (p == null) {
  1170. return facet[name].histogram.params;
  1171. }
  1172. facet[name].histogram.params = p;
  1173. return this;
  1174. },
  1175. /**
  1176. Sets the type of ordering that will be performed on the date
  1177. buckets. Valid values are:
  1178. key - the default, sort by the bucket's key value
  1179. count - sort by the number of items in the bucket
  1180. total - sort by the sum/total of the items in the bucket
  1181. @member ejs.HistogramFacet
  1182. @param {String} o The ordering method: key, count, or total.
  1183. @returns {Object} returns <code>this</code> so that calls can be chained.
  1184. */
  1185. order: function (o) {
  1186. if (o == null) {
  1187. return facet[name].histogram.order;
  1188. }
  1189. o = o.toLowerCase();
  1190. if (o === 'key' || o === 'count' || o === 'total') {
  1191. facet[name].histogram.order = o;
  1192. }
  1193. return this;
  1194. },
  1195. /**
  1196. <p>Allows you to reduce the documents used for computing facet results.</p>
  1197. @member ejs.HistogramFacet
  1198. @param {Object} oFilter A valid <code>Filter</code> object.
  1199. @returns {Object} returns <code>this</code> so that calls can be chained.
  1200. */
  1201. facetFilter: function (oFilter) {
  1202. if (oFilter == null) {
  1203. return facet[name].facet_filter;
  1204. }
  1205. if (!isFilter(oFilter)) {
  1206. throw new TypeError('Argument must be a Filter');
  1207. }
  1208. facet[name].facet_filter = oFilter._self();
  1209. return this;
  1210. },
  1211. /**
  1212. <p>Computes values across the entire index</p>
  1213. @member ejs.HistogramFacet
  1214. @param {Boolean} trueFalse Calculate facet counts globally or not.
  1215. @returns {Object} returns <code>this</code> so that calls can be chained.
  1216. */
  1217. global: function (trueFalse) {
  1218. if (trueFalse == null) {
  1219. return facet[name].global;
  1220. }
  1221. facet[name].global = trueFalse;
  1222. return this;
  1223. },
  1224. /**
  1225. <p>Computes values across the the specified scope</p>
  1226. @member ejs.HistogramFacet
  1227. @param {String} scope The scope name to calculate facet counts with.
  1228. @returns {Object} returns <code>this</code> so that calls can be chained.
  1229. */
  1230. scope: function (scope) {
  1231. if (scope == null) {
  1232. return facet[name].scope;
  1233. }
  1234. facet[name].scope = scope;
  1235. return this;
  1236. },
  1237. /**
  1238. <p>Enables caching of the <code>facetFilter</code></p>
  1239. @member ejs.HistogramFacet
  1240. @param {Boolean} trueFalse If the facetFilter should be cached or not
  1241. @returns {Object} returns <code>this</code> so that calls can be chained.
  1242. */
  1243. cacheFilter: function (trueFalse) {
  1244. if (trueFalse == null) {
  1245. return facet[name].cache_filter;
  1246. }
  1247. facet[name].cache_filter = trueFalse;
  1248. return this;
  1249. },
  1250. /**
  1251. <p>Sets the path to the nested document if faceting against a
  1252. nested field.</p>
  1253. @member ejs.HistogramFacet
  1254. @param {String} path The nested path
  1255. @returns {Object} returns <code>this</code> so that calls can be chained.
  1256. */
  1257. nested: function (path) {
  1258. if (path == null) {
  1259. return facet[name].nested;
  1260. }
  1261. facet[name].nested = path;
  1262. return this;
  1263. },
  1264. /**
  1265. <p>Allows you to serialize this object into a JSON encoded string.</p>
  1266. @member ejs.HistogramFacet
  1267. @returns {String} returns this object as a serialized JSON string.
  1268. */
  1269. toString: function () {
  1270. return JSON.stringify(facet);
  1271. },
  1272. /**
  1273. The type of ejs object. For internal use only.
  1274. @member ejs.HistogramFacet
  1275. @returns {String} the type of object
  1276. */
  1277. _type: function () {
  1278. return 'facet';
  1279. },
  1280. /**
  1281. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  1282. internal API functions so use with caution.</p>
  1283. @member ejs.HistogramFacet
  1284. @returns {String} returns this object's internal <code>facet</code> property.
  1285. */
  1286. _self: function () {
  1287. return facet;
  1288. }
  1289. };
  1290. };
  1291. /**
  1292. @class
  1293. <p>The QueryFacet facet allows you to specify any valid <code>Query</code> and
  1294. have the number of matching hits returned as the value.</p>
  1295. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  1296. better. You can also construct several <em>"groups"</em> at once by simply
  1297. specifying multiple facets.</p>
  1298. <div class="alert-message block-message info">
  1299. <p>
  1300. <strong>Tip: </strong>
  1301. For more information on faceted navigation, see
  1302. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  1303. Wikipedia article on Faceted Classification.
  1304. </p>
  1305. </div>
  1306. @name ejs.QueryFacet
  1307. @desc
  1308. <p>A facet that return a count of the hits matching the given query.</p>
  1309. @param {String} name The name which be used to refer to this facet. For instance,
  1310. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  1311. <code>name</code> to <code>Authors</code> would allow you to refer to the
  1312. facet by that name, possibly simplifying some of the display logic.
  1313. */
  1314. ejs.QueryFacet = function (name) {
  1315. /**
  1316. The internal facet object.
  1317. @member ejs.QueryFacet
  1318. @property {Object} facet
  1319. */
  1320. var facet = {};
  1321. facet[name] = {};
  1322. return {
  1323. /**
  1324. <p>Sets the query to be used for this facet.</p>
  1325. @member ejs.QueryFacet
  1326. @param {Object} oQuery A valid <code>Query</code> object.
  1327. @returns {Object} returns <code>this</code> so that calls can be chained.
  1328. */
  1329. query: function (oQuery) {
  1330. if (oQuery == null) {
  1331. return facet[name].query;
  1332. }
  1333. if (!isQuery(oQuery)) {
  1334. throw new TypeError('Argument must be a Query');
  1335. }
  1336. facet[name].query = oQuery._self();
  1337. return this;
  1338. },
  1339. /**
  1340. <p>Allows you to reduce the documents used for computing facet results.</p>
  1341. @member ejs.QueryFacet
  1342. @param {Object} oFilter A valid <code>Filter</code> object.
  1343. @returns {Object} returns <code>this</code> so that calls can be chained.
  1344. */
  1345. facetFilter: function (oFilter) {
  1346. if (oFilter == null) {
  1347. return facet[name].facet_filter;
  1348. }
  1349. if (!isFilter(oFilter)) {
  1350. throw new TypeError('Argumnet must be a Filter');
  1351. }
  1352. facet[name].facet_filter = oFilter._self();
  1353. return this;
  1354. },
  1355. /**
  1356. <p>Computes values across the entire index</p>
  1357. @member ejs.QueryFacet
  1358. @param {Boolean} trueFalse Calculate facet counts globally or not.
  1359. @returns {Object} returns <code>this</code> so that calls can be chained.
  1360. */
  1361. global: function (trueFalse) {
  1362. if (trueFalse == null) {
  1363. return facet[name].global;
  1364. }
  1365. facet[name].global = trueFalse;
  1366. return this;
  1367. },
  1368. /**
  1369. <p>Computes values across the the specified scope</p>
  1370. @member ejs.QueryFacet
  1371. @param {String} scope The scope name to calculate facet counts with.
  1372. @returns {Object} returns <code>this</code> so that calls can be chained.
  1373. */
  1374. scope: function (scope) {
  1375. if (scope == null) {
  1376. return facet[name].scope;
  1377. }
  1378. facet[name].scope = scope;
  1379. return this;
  1380. },
  1381. /**
  1382. <p>Enables caching of the <code>facetFilter</code></p>
  1383. @member ejs.QueryFacet
  1384. @param {Boolean} trueFalse If the facetFilter should be cached or not
  1385. @returns {Object} returns <code>this</code> so that calls can be chained.
  1386. */
  1387. cacheFilter: function (trueFalse) {
  1388. if (trueFalse == null) {
  1389. return facet[name].cache_filter;
  1390. }
  1391. facet[name].cache_filter = trueFalse;
  1392. return this;
  1393. },
  1394. /**
  1395. <p>Sets the path to the nested document if faceting against a
  1396. nested field.</p>
  1397. @member ejs.QueryFacet
  1398. @param {String} path The nested path
  1399. @returns {Object} returns <code>this</code> so that calls can be chained.
  1400. */
  1401. nested: function (path) {
  1402. if (path == null) {
  1403. return facet[name].nested;
  1404. }
  1405. facet[name].nested = path;
  1406. return this;
  1407. },
  1408. /**
  1409. <p>Allows you to serialize this object into a JSON encoded string.</p>
  1410. @member ejs.QueryFacet
  1411. @returns {String} returns this object as a serialized JSON string.
  1412. */
  1413. toString: function () {
  1414. return JSON.stringify(facet);
  1415. },
  1416. /**
  1417. The type of ejs object. For internal use only.
  1418. @member ejs.QueryFacet
  1419. @returns {String} the type of object
  1420. */
  1421. _type: function () {
  1422. return 'facet';
  1423. },
  1424. /**
  1425. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  1426. internal API functions so use with caution.</p>
  1427. @member ejs.QueryFacet
  1428. @returns {String} returns this object's internal <code>facet</code> property.
  1429. */
  1430. _self: function () {
  1431. return facet;
  1432. }
  1433. };
  1434. };
  1435. /**
  1436. @class
  1437. <p>A RangeFacet allows you to specify a set of ranges and get both the number of docs (count) that
  1438. fall within each range, and aggregated data based on the field, or another specified field.</p>
  1439. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  1440. better. You can also construct several <em>"groups"</em> at once by simply
  1441. specifying multiple facets.</p>
  1442. <div class="alert-message block-message info">
  1443. <p>
  1444. <strong>Tip: </strong>
  1445. For more information on faceted navigation, see
  1446. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  1447. Wikipedia article on Faceted Classification.
  1448. </p>
  1449. </div>
  1450. @name ejs.RangeFacet
  1451. @desc
  1452. <p>A facet which provides information over a range of numeric intervals.</p>
  1453. @param {String} name The name which be used to refer to this facet. For instance,
  1454. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  1455. <code>name</code> to <code>Authors</code> would allow you to refer to the
  1456. facet by that name, possibly simplifying some of the display logic.
  1457. */
  1458. ejs.RangeFacet = function (name) {
  1459. /**
  1460. The internal facet object.
  1461. @member ejs.RangeFacet
  1462. @property {Object} facet
  1463. */
  1464. var facet = {};
  1465. facet[name] = {
  1466. range: {
  1467. ranges: []
  1468. }
  1469. };
  1470. return {
  1471. /**
  1472. Sets the document field to be used for the facet.
  1473. @member ejs.RangeFacet
  1474. @param {String} fieldName The field name whose data will be used to compute the interval.
  1475. @returns {Object} returns <code>this</code> so that calls can be chained.
  1476. */
  1477. field: function (fieldName) {
  1478. if (fieldName == null) {
  1479. return facet[name].range.field;
  1480. }
  1481. facet[name].range.field = fieldName;
  1482. return this;
  1483. },
  1484. /**
  1485. Allows you to specify an alternate key field to be used to compute the interval.
  1486. @member ejs.RangeFacet
  1487. @param {String} fieldName The field name whose data will be used to compute the interval.
  1488. @returns {Object} returns <code>this</code> so that calls can be chained.
  1489. */
  1490. keyField: function (fieldName) {
  1491. if (fieldName == null) {
  1492. return facet[name].range.key_field;
  1493. }
  1494. facet[name].range.key_field = fieldName;
  1495. return this;
  1496. },
  1497. /**
  1498. Allows you to specify an alternate value field to be used to compute statistical information.
  1499. @member ejs.RangeFacet
  1500. @param {String} fieldName The field name whose data will be used to compute statistics.
  1501. @returns {Object} returns <code>this</code> so that calls can be chained.
  1502. */
  1503. valueField: function (fieldName) {
  1504. if (fieldName == null) {
  1505. return facet[name].range.value_field;
  1506. }
  1507. facet[name].range.value_field = fieldName;
  1508. return this;
  1509. },
  1510. /**
  1511. Allows you modify the <code>value</code> field using a script. The modified value
  1512. is then used to compute the statistical data.
  1513. @member ejs.RangeFacet
  1514. @param {String} scriptCode A valid script string to execute.
  1515. @returns {Object} returns <code>this</code> so that calls can be chained.
  1516. */
  1517. valueScript: function (scriptCode) {
  1518. if (scriptCode == null) {
  1519. return facet[name].range.value_script;
  1520. }
  1521. facet[name].range.value_script = scriptCode;
  1522. return this;
  1523. },
  1524. /**
  1525. Allows you modify the <code>key</code> field using a script. The modified value
  1526. is then used to generate the interval.
  1527. @member ejs.RangeFacet
  1528. @param {String} scriptCode A valid script string to execute.
  1529. @returns {Object} returns <code>this</code> so that calls can be chained.
  1530. */
  1531. keyScript: function (scriptCode) {
  1532. if (scriptCode == null) {
  1533. return facet[name].range.key_script;
  1534. }
  1535. facet[name].range.key_script = scriptCode;
  1536. return this;
  1537. },
  1538. /**
  1539. The script language being used. Currently supported values are
  1540. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  1541. @member ejs.RangeFacet
  1542. @param {String} language The language of the script.
  1543. @returns {Object} returns <code>this</code> so that calls can be chained.
  1544. */
  1545. lang: function (language) {
  1546. if (language == null) {
  1547. return facet[name].range.lang;
  1548. }
  1549. facet[name].range.lang = language;
  1550. return this;
  1551. },
  1552. /**
  1553. Sets parameters that will be applied to the script. Overwrites
  1554. any existing params.
  1555. @member ejs.RangeFacet
  1556. @param {Object} p An object where the keys are the parameter name and
  1557. values are the parameter value.
  1558. @returns {Object} returns <code>this</code> so that calls can be chained.
  1559. */
  1560. params: function (p) {
  1561. if (p == null) {
  1562. return facet[name].range.params;
  1563. }
  1564. facet[name].range.params = p;
  1565. return this;
  1566. },
  1567. /**
  1568. Adds a new bounded range.
  1569. @member ejs.RangeFacet
  1570. @param {Number} from The lower bound of the range (can also be <code>Date</code>).
  1571. @param {Number} to The upper bound of the range (can also be <code>Date</code>).
  1572. @returns {Object} returns <code>this</code> so that calls can be chained.
  1573. */
  1574. addRange: function (from, to) {
  1575. if (arguments.length === 0) {
  1576. return facet[name].range.ranges;
  1577. }
  1578. facet[name].range.ranges.push({
  1579. from: from,
  1580. to: to
  1581. });
  1582. return this;
  1583. },
  1584. /**
  1585. Adds a new unbounded lower limit.
  1586. @member ejs.RangeFacet
  1587. @param {Number} from The lower limit of the unbounded range (can also be <code>Date</code>).
  1588. @returns {Object} returns <code>this</code> so that calls can be chained.
  1589. */
  1590. addUnboundedFrom: function (from) {
  1591. if (from == null) {
  1592. return facet[name].range.ranges;
  1593. }
  1594. facet[name].range.ranges.push({
  1595. from: from
  1596. });
  1597. return this;
  1598. },
  1599. /**
  1600. Adds a new unbounded upper limit.
  1601. @member ejs.RangeFacet
  1602. @param {Number} to The upper limit of the unbounded range (can also be <code>Date</code>).
  1603. @returns {Object} returns <code>this</code> so that calls can be chained.
  1604. */
  1605. addUnboundedTo: function (to) {
  1606. if (to == null) {
  1607. return facet[name].range.ranges;
  1608. }
  1609. facet[name].range.ranges.push({
  1610. to: to
  1611. });
  1612. return this;
  1613. },
  1614. /**
  1615. <p>Allows you to reduce the documents used for computing facet results.</p>
  1616. @member ejs.RangeFacet
  1617. @param {Object} oFilter A valid <code>Filter</code> object.
  1618. @returns {Object} returns <code>this</code> so that calls can be chained.
  1619. */
  1620. facetFilter: function (oFilter) {
  1621. if (oFilter == null) {
  1622. return facet[name].facet_filter;
  1623. }
  1624. if (!isFilter(oFilter)) {
  1625. throw new TypeError('Argument must be a Filter');
  1626. }
  1627. facet[name].facet_filter = oFilter._self();
  1628. return this;
  1629. },
  1630. /**
  1631. <p>Computes values across the entire index</p>
  1632. @member ejs.RangeFacet
  1633. @param {Boolean} trueFalse Calculate facet counts globally or not.
  1634. @returns {Object} returns <code>this</code> so that calls can be chained.
  1635. */
  1636. global: function (trueFalse) {
  1637. if (trueFalse == null) {
  1638. return facet[name].global;
  1639. }
  1640. facet[name].global = trueFalse;
  1641. return this;
  1642. },
  1643. /**
  1644. <p>Computes values across the the specified scope</p>
  1645. @member ejs.RangeFacet
  1646. @param {String} scope The scope name to calculate facet counts with.
  1647. @returns {Object} returns <code>this</code> so that calls can be chained.
  1648. */
  1649. scope: function (scope) {
  1650. if (scope == null) {
  1651. return facet[name].scope;
  1652. }
  1653. facet[name].scope = scope;
  1654. return this;
  1655. },
  1656. /**
  1657. <p>Enables caching of the <code>facetFilter</code></p>
  1658. @member ejs.RangeFacet
  1659. @param {Boolean} trueFalse If the facetFilter should be cached or not
  1660. @returns {Object} returns <code>this</code> so that calls can be chained.
  1661. */
  1662. cacheFilter: function (trueFalse) {
  1663. if (trueFalse == null) {
  1664. return facet[name].cache_filter;
  1665. }
  1666. facet[name].cache_filter = trueFalse;
  1667. return this;
  1668. },
  1669. /**
  1670. <p>Sets the path to the nested document if faceting against a
  1671. nested field.</p>
  1672. @member ejs.RangeFacet
  1673. @param {String} path The nested path
  1674. @returns {Object} returns <code>this</code> so that calls can be chained.
  1675. */
  1676. nested: function (path) {
  1677. if (path == null) {
  1678. return facet[name].nested;
  1679. }
  1680. facet[name].nested = path;
  1681. return this;
  1682. },
  1683. /**
  1684. <p>Allows you to serialize this object into a JSON encoded string.</p>
  1685. @member ejs.RangeFacet
  1686. @returns {String} returns this object as a serialized JSON string.
  1687. */
  1688. toString: function () {
  1689. return JSON.stringify(facet);
  1690. },
  1691. /**
  1692. The type of ejs object. For internal use only.
  1693. @member ejs.RangeFacet
  1694. @returns {String} the type of object
  1695. */
  1696. _type: function () {
  1697. return 'facet';
  1698. },
  1699. /**
  1700. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  1701. internal API functions so use with caution.</p>
  1702. @member ejs.RangeFacet
  1703. @returns {String} returns this object's internal <code>facet</code> property.
  1704. */
  1705. _self: function () {
  1706. return facet;
  1707. }
  1708. };
  1709. };
  1710. /**
  1711. @class
  1712. <p>A statistical facet allows you to compute statistical data over a numeric fields. Statistical data includes
  1713. the count, total, sum of squares, mean (average), minimum, maximum, variance, and standard deviation.</p>
  1714. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  1715. better. You can also construct several <em>"groups"</em> at once by simply
  1716. specifying multiple facets.</p>
  1717. <div class="alert-message block-message info">
  1718. <p>
  1719. <strong>Tip: </strong>
  1720. For more information on faceted navigation, see
  1721. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  1722. Wikipedia article on Faceted Classification.
  1723. </p>
  1724. </div>
  1725. @name ejs.StatisticalFacet
  1726. @desc
  1727. <p>A facet which returns statistical information about a numeric field</p>
  1728. @param {String} name The name which be used to refer to this facet. For instance,
  1729. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  1730. <code>name</code> to <code>Authors</code> would allow you to refer to the
  1731. facet by that name, possibly simplifying some of the display logic.
  1732. */
  1733. ejs.StatisticalFacet = function (name) {
  1734. /**
  1735. The internal facet object.
  1736. @member ejs.StatisticalFacet
  1737. @property {Object} facet
  1738. */
  1739. var facet = {};
  1740. facet[name] = {
  1741. statistical: {}
  1742. };
  1743. return {
  1744. /**
  1745. Sets the field to be used to construct the this facet.
  1746. @member ejs.StatisticalFacet
  1747. @param {String} fieldName The field name whose data will be used to construct the facet.
  1748. @returns {Object} returns <code>this</code> so that calls can be chained.
  1749. */
  1750. field: function (fieldName) {
  1751. if (fieldName == null) {
  1752. return facet[name].statistical.field;
  1753. }
  1754. facet[name].statistical.field = fieldName;
  1755. return this;
  1756. },
  1757. /**
  1758. Aggregate statistical info across a set of fields.
  1759. @member ejs.StatisticalFacet
  1760. @param {Array} aFieldName An array of field names.
  1761. @returns {Object} returns <code>this</code> so that calls can be chained.
  1762. */
  1763. fields: function (fields) {
  1764. if (fields == null) {
  1765. return facet[name].statistical.fields;
  1766. }
  1767. if (!isArray(fields)) {
  1768. throw new TypeError('Argument must be an array');
  1769. }
  1770. facet[name].statistical.fields = fields;
  1771. return this;
  1772. },
  1773. /**
  1774. Define a script to evaluate of which the result will be used to generate
  1775. the statistical information.
  1776. @member ejs.StatisticalFacet
  1777. @param {String} code The script code to execute.
  1778. @returns {Object} returns <code>this</code> so that calls can be chained.
  1779. */
  1780. script: function (code) {
  1781. if (code == null) {
  1782. return facet[name].statistical.script;
  1783. }
  1784. facet[name].statistical.script = code;
  1785. return this;
  1786. },
  1787. /**
  1788. The script language being used. Currently supported values are
  1789. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  1790. @member ejs.StatisticalFacet
  1791. @param {String} language The language of the script.
  1792. @returns {Object} returns <code>this</code> so that calls can be chained.
  1793. */
  1794. lang: function (language) {
  1795. if (language == null) {
  1796. return facet[name].statistical.lang;
  1797. }
  1798. facet[name].statistical.lang = language;
  1799. return this;
  1800. },
  1801. /**
  1802. Allows you to set script parameters to be used during the execution of the script.
  1803. @member ejs.StatisticalFacet
  1804. @param {Object} oParams An object containing key/value pairs representing param name/value.
  1805. @returns {Object} returns <code>this</code> so that calls can be chained.
  1806. */
  1807. params: function (oParams) {
  1808. if (oParams == null) {
  1809. return facet[name].statistical.params;
  1810. }
  1811. facet[name].statistical.params = oParams;
  1812. return this;
  1813. },
  1814. /**
  1815. <p>Allows you to reduce the documents used for computing facet results.</p>
  1816. @member ejs.StatisticalFacet
  1817. @param {Object} oFilter A valid <code>Filter</code> object.
  1818. @returns {Object} returns <code>this</code> so that calls can be chained.
  1819. */
  1820. facetFilter: function (oFilter) {
  1821. if (oFilter == null) {
  1822. return facet[name].facet_filter;
  1823. }
  1824. if (!isFilter(oFilter)) {
  1825. throw new TypeError('Argument must be a Filter');
  1826. }
  1827. facet[name].facet_filter = oFilter._self();
  1828. return this;
  1829. },
  1830. /**
  1831. <p>Computes values across the entire index</p>
  1832. @member ejs.StatisticalFacet
  1833. @param {Boolean} trueFalse Calculate facet counts globally or not.
  1834. @returns {Object} returns <code>this</code> so that calls can be chained.
  1835. */
  1836. global: function (trueFalse) {
  1837. if (trueFalse == null) {
  1838. return facet[name].global;
  1839. }
  1840. facet[name].global = trueFalse;
  1841. return this;
  1842. },
  1843. /**
  1844. <p>Computes values across the the specified scope</p>
  1845. @member ejs.StatisticalFacet
  1846. @param {String} scope The scope name to calculate facet counts with.
  1847. @returns {Object} returns <code>this</code> so that calls can be chained.
  1848. */
  1849. scope: function (scope) {
  1850. if (scope == null) {
  1851. return facet[name].scope;
  1852. }
  1853. facet[name].scope = scope;
  1854. return this;
  1855. },
  1856. /**
  1857. <p>Enables caching of the <code>facetFilter</code></p>
  1858. @member ejs.StatisticalFacet
  1859. @param {Boolean} trueFalse If the facetFilter should be cached or not
  1860. @returns {Object} returns <code>this</code> so that calls can be chained.
  1861. */
  1862. cacheFilter: function (trueFalse) {
  1863. if (trueFalse == null) {
  1864. return facet[name].cache_filter;
  1865. }
  1866. facet[name].cache_filter = trueFalse;
  1867. return this;
  1868. },
  1869. /**
  1870. <p>Sets the path to the nested document if faceting against a
  1871. nested field.</p>
  1872. @member ejs.StatisticalFacet
  1873. @param {String} path The nested path
  1874. @returns {Object} returns <code>this</code> so that calls can be chained.
  1875. */
  1876. nested: function (path) {
  1877. if (path == null) {
  1878. return facet[name].nested;
  1879. }
  1880. facet[name].nested = path;
  1881. return this;
  1882. },
  1883. /**
  1884. <p>Allows you to serialize this object into a JSON encoded string.</p>
  1885. @member ejs.StatisticalFacet
  1886. @returns {String} returns this object as a serialized JSON string.
  1887. */
  1888. toString: function () {
  1889. return JSON.stringify(facet);
  1890. },
  1891. /**
  1892. The type of ejs object. For internal use only.
  1893. @member ejs.StatisticalFacet
  1894. @returns {String} the type of object
  1895. */
  1896. _type: function () {
  1897. return 'facet';
  1898. },
  1899. /**
  1900. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  1901. internal API functions so use with caution.</p>
  1902. @member ejs.StatisticalFacet
  1903. @returns {String} returns this object's internal <code>facet</code> property.
  1904. */
  1905. _self: function () {
  1906. return facet;
  1907. }
  1908. };
  1909. };
  1910. /**
  1911. @class
  1912. <p>A facet which returns the N most frequent terms within a collection
  1913. or set of collections. Term facets are useful for building constructs
  1914. which allow users to refine search results by filtering on terms returned
  1915. by the facet.</p>
  1916. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  1917. better. You can also construct several <em>"groups"</em> at once by simply
  1918. specifying multiple facets.</p>
  1919. <p>For more information on faceted navigation, see this Wikipedia article on
  1920. <a href="http://en.wikipedia.org/wiki/Faceted_classification">Faceted Classification</a></p<
  1921. @name ejs.TermsFacet
  1922. @desc
  1923. <p>A facet which returns the N most frequent terms within a collection
  1924. or set of collections.</p>
  1925. @param {String} name The name which be used to refer to this facet. For instance,
  1926. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  1927. <code>name</code> to <code>Authors</code> would allow you to refer to the
  1928. facet by that name, possibly simplifying some of the display logic.
  1929. */
  1930. ejs.TermsFacet = function (name) {
  1931. /**
  1932. The internal facet object.
  1933. @member ejs.TermsFacet
  1934. @property {Object} facet
  1935. */
  1936. var facet = {};
  1937. facet[name] = {
  1938. terms: {}
  1939. };
  1940. return {
  1941. /**
  1942. Sets the field to be used to construct the this facet. Set to
  1943. _index to return a facet count of hits per _index the search was
  1944. executed on.
  1945. @member ejs.TermsFacet
  1946. @param {String} fieldName The field name whose data will be used to construct the facet.
  1947. @returns {Object} returns <code>this</code> so that calls can be chained.
  1948. */
  1949. field: function (fieldName) {
  1950. if (fieldName == null) {
  1951. return facet[name].terms.field;
  1952. }
  1953. facet[name].terms.field = fieldName;
  1954. return this;
  1955. },
  1956. /**
  1957. Aggregate statistical info across a set of fields.
  1958. @member ejs.TermsFacet
  1959. @param {Array} aFieldName An array of field names.
  1960. @returns {Object} returns <code>this</code> so that calls can be chained.
  1961. */
  1962. fields: function (fields) {
  1963. if (fields == null) {
  1964. return facet[name].terms.fields;
  1965. }
  1966. if (!isArray(fields)) {
  1967. throw new TypeError('Argument must be an array');
  1968. }
  1969. facet[name].terms.fields = fields;
  1970. return this;
  1971. },
  1972. /**
  1973. Sets a script that will provide the terms for a given document.
  1974. @member ejs.TermsFacet
  1975. @param {String} script The script code.
  1976. @returns {Object} returns <code>this</code> so that calls can be chained.
  1977. */
  1978. scriptField: function (script) {
  1979. if (script == null) {
  1980. return facet[name].terms.script_field;
  1981. }
  1982. facet[name].terms.script_field = script;
  1983. return this;
  1984. },
  1985. /**
  1986. Sets the number of facet entries that will be returned for this facet. For instance, you
  1987. might ask for only the top 5 <code>authors</code> although there might be hundreds of
  1988. unique authors.
  1989. @member ejs.TermsFacet
  1990. @param {Integer} facetSize The numer of facet entries to be returned.
  1991. @returns {Object} returns <code>this</code> so that calls can be chained.
  1992. */
  1993. size: function (facetSize) {
  1994. if (facetSize == null) {
  1995. return facet[name].terms.size;
  1996. }
  1997. facet[name].terms.size = facetSize;
  1998. return this;
  1999. },
  2000. /**
  2001. Sets the type of ordering that will be performed on the date
  2002. buckets. Valid values are:
  2003. count - default, sort by the number of items in the bucket
  2004. term - sort by term value.
  2005. reverse_count - reverse sort of the number of items in the bucket
  2006. reverse_term - reverse sort of the term value.
  2007. @member ejs.TermsFacet
  2008. @param {String} o The ordering method
  2009. @returns {Object} returns <code>this</code> so that calls can be chained.
  2010. */
  2011. order: function (o) {
  2012. if (o == null) {
  2013. return facet[name].terms.order;
  2014. }
  2015. o = o.toLowerCase();
  2016. if (o === 'count' || o === 'term' ||
  2017. o === 'reverse_count' || o === 'reverse_term') {
  2018. facet[name].terms.order = o;
  2019. }
  2020. return this;
  2021. },
  2022. /**
  2023. <p>Allows you to return all terms, even if the frequency count is 0. This should not be
  2024. used on fields that contain a large number of unique terms because it could cause
  2025. <em>out-of-memory</em> errors.</p>
  2026. @member ejs.TermsFacet
  2027. @param {String} trueFalse <code>true</code> or <code>false</code>
  2028. @returns {Object} returns <code>this</code> so that calls can be chained.
  2029. */
  2030. allTerms: function (trueFalse) {
  2031. if (trueFalse == null) {
  2032. return facet[name].terms.all_terms;
  2033. }
  2034. facet[name].terms.all_terms = trueFalse;
  2035. return this;
  2036. },
  2037. /**
  2038. <p>Allows you to filter out unwanted facet entries. When passed
  2039. a single term, it is appended to the list of currently excluded
  2040. terms. If passed an array, it overwrites all existing values.</p>
  2041. @member ejs.TermsFacet
  2042. @param {String || Array} exclude A single term to exclude or an
  2043. array of terms to exclude.
  2044. @returns {Object} returns <code>this</code> so that calls can be chained.
  2045. */
  2046. exclude: function (exclude) {
  2047. if (facet[name].terms.exclude == null) {
  2048. facet[name].terms.exclude = [];
  2049. }
  2050. if (exclude == null) {
  2051. return facet[name].terms.exclude;
  2052. }
  2053. if (isString(exclude)) {
  2054. facet[name].terms.exclude.push(exclude);
  2055. } else if (isArray(exclude)) {
  2056. facet[name].terms.exclude = exclude;
  2057. } else {
  2058. throw new TypeError('Argument must be string or array');
  2059. }
  2060. return this;
  2061. },
  2062. /**
  2063. <p>Allows you to only include facet entries matching a specified regular expression.</p>
  2064. @member ejs.TermsFacet
  2065. @param {String} exp A valid regular expression.
  2066. @returns {Object} returns <code>this</code> so that calls can be chained.
  2067. */
  2068. regex: function (exp) {
  2069. if (exp == null) {
  2070. return facet[name].terms.regex;
  2071. }
  2072. facet[name].terms.regex = exp;
  2073. return this;
  2074. },
  2075. /**
  2076. <p>Allows you to set the regular expression flags to be used
  2077. with the <code>regex</code></p>
  2078. @member ejs.TermsFacet
  2079. @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>
  2080. @returns {Object} returns <code>this</code> so that calls can be chained.
  2081. */
  2082. regexFlags: function (flags) {
  2083. if (flags == null) {
  2084. return facet[name].terms.regex_flags;
  2085. }
  2086. facet[name].terms.regex_flags = flags;
  2087. return this;
  2088. },
  2089. /**
  2090. Allows you modify the term using a script. The modified value
  2091. is then used in the facet collection.
  2092. @member ejs.TermsFacet
  2093. @param {String} scriptCode A valid script string to execute.
  2094. @returns {Object} returns <code>this</code> so that calls can be chained.
  2095. */
  2096. script: function (scriptCode) {
  2097. if (scriptCode == null) {
  2098. return facet[name].terms.script;
  2099. }
  2100. facet[name].terms.script = scriptCode;
  2101. return this;
  2102. },
  2103. /**
  2104. The script language being used. Currently supported values are
  2105. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  2106. @member ejs.TermsFacet
  2107. @param {String} language The language of the script.
  2108. @returns {Object} returns <code>this</code> so that calls can be chained.
  2109. */
  2110. lang: function (language) {
  2111. if (language == null) {
  2112. return facet[name].terms.lang;
  2113. }
  2114. facet[name].terms.lang = language;
  2115. return this;
  2116. },
  2117. /**
  2118. Sets parameters that will be applied to the script. Overwrites
  2119. any existing params.
  2120. @member ejs.TermsFacet
  2121. @param {Object} p An object where the keys are the parameter name and
  2122. values are the parameter value.
  2123. @returns {Object} returns <code>this</code> so that calls can be chained.
  2124. */
  2125. params: function (p) {
  2126. if (p == null) {
  2127. return facet[name].terms.params;
  2128. }
  2129. facet[name].terms.params = p;
  2130. return this;
  2131. },
  2132. /**
  2133. Sets the execution hint determines how the facet is computed.
  2134. Currently only supported value is "map".
  2135. @member ejs.TermsFacet
  2136. @param {Object} h The hint value as a string.
  2137. @returns {Object} returns <code>this</code> so that calls can be chained.
  2138. */
  2139. executionHint: function (h) {
  2140. if (h == null) {
  2141. return facet[name].terms.execution_hint;
  2142. }
  2143. facet[name].terms.execution_hint = h;
  2144. return this;
  2145. },
  2146. /**
  2147. <p>Allows you to reduce the documents used for computing facet results.</p>
  2148. @member ejs.TermsFacet
  2149. @param {Object} oFilter A valid <code>Filter</code> object.
  2150. @returns {Object} returns <code>this</code> so that calls can be chained.
  2151. */
  2152. facetFilter: function (oFilter) {
  2153. if (oFilter == null) {
  2154. return facet[name].facet_filter;
  2155. }
  2156. if (!isFilter(oFilter)) {
  2157. throw new TypeError('Argument must be a Filter');
  2158. }
  2159. facet[name].facet_filter = oFilter._self();
  2160. return this;
  2161. },
  2162. /**
  2163. <p>Computes values across the entire index</p>
  2164. @member ejs.TermsFacet
  2165. @param {Boolean} trueFalse Calculate facet counts globally or not.
  2166. @returns {Object} returns <code>this</code> so that calls can be chained.
  2167. */
  2168. global: function (trueFalse) {
  2169. if (trueFalse == null) {
  2170. return facet[name].global;
  2171. }
  2172. facet[name].global = trueFalse;
  2173. return this;
  2174. },
  2175. /**
  2176. <p>Computes values across the the specified scope</p>
  2177. @member ejs.TermsFacet
  2178. @param {String} scope The scope name to calculate facet counts with.
  2179. @returns {Object} returns <code>this</code> so that calls can be chained.
  2180. */
  2181. scope: function (scope) {
  2182. if (scope == null) {
  2183. return facet[name].scope;
  2184. }
  2185. facet[name].scope = scope;
  2186. return this;
  2187. },
  2188. /**
  2189. <p>Enables caching of the <code>facetFilter</code></p>
  2190. @member ejs.TermsFacet
  2191. @param {Boolean} trueFalse If the facetFilter should be cached or not
  2192. @returns {Object} returns <code>this</code> so that calls can be chained.
  2193. */
  2194. cacheFilter: function (trueFalse) {
  2195. if (trueFalse == null) {
  2196. return facet[name].cache_filter;
  2197. }
  2198. facet[name].cache_filter = trueFalse;
  2199. return this;
  2200. },
  2201. /**
  2202. <p>Sets the path to the nested document if faceting against a
  2203. nested field.</p>
  2204. @member ejs.TermsFacet
  2205. @param {String} path The nested path
  2206. @returns {Object} returns <code>this</code> so that calls can be chained.
  2207. */
  2208. nested: function (path) {
  2209. if (path == null) {
  2210. return facet[name].nested;
  2211. }
  2212. facet[name].nested = path;
  2213. return this;
  2214. },
  2215. /**
  2216. <p>Allows you to serialize this object into a JSON encoded string.</p>
  2217. @member ejs.TermsFacet
  2218. @returns {String} returns this object as a serialized JSON string.
  2219. */
  2220. toString: function () {
  2221. return JSON.stringify(facet);
  2222. },
  2223. /**
  2224. The type of ejs object. For internal use only.
  2225. @member ejs.TermsFacet
  2226. @returns {String} the type of object
  2227. */
  2228. _type: function () {
  2229. return 'facet';
  2230. },
  2231. /**
  2232. <p>Retrieves the internal <code>facet</code> property. This is typically used by
  2233. internal API functions so use with caution.</p>
  2234. @member ejs.TermsFacet
  2235. @returns {String} returns this object's internal <code>facet</code> property.
  2236. */
  2237. _self: function () {
  2238. return facet;
  2239. }
  2240. };
  2241. };
  2242. /**
  2243. @class
  2244. <p>A termsStatsFacet allows you to compute statistics over an aggregate key (term). Essentially this
  2245. facet provides the functionality of what is often refered to as a <em>pivot table</em>.</p>
  2246. <p>Facets are similar to SQL <code>GROUP BY</code> statements but perform much
  2247. better. You can also construct several <em>"groups"</em> at once by simply
  2248. specifying multiple facets.</p>
  2249. <div class="alert-message block-message info">
  2250. <p>
  2251. <strong>Tip: </strong>
  2252. For more information on faceted navigation, see
  2253. <a href="http://en.wikipedia.org/wiki/Faceted_classification">this</a>
  2254. Wikipedia article on Faceted Classification.
  2255. </p>
  2256. </div>
  2257. @name ejs.TermStatsFacet
  2258. @desc
  2259. <p>A facet which computes statistical data based on an aggregate key.</p>
  2260. @param {String} name The name which be used to refer to this facet. For instance,
  2261. the facet itself might utilize a field named <code>doc_authors</code>. Setting
  2262. <code>name</code> to <code>Authors</code> would allow you to refer to the
  2263. facet by that name, possibly simplifying some of the display logic.
  2264. */
  2265. ejs.TermStatsFacet = function (name) {
  2266. /**
  2267. The internal facet object.
  2268. @member ejs.TermStatsFacet
  2269. @property {Object} facet
  2270. */
  2271. var facet = {};
  2272. facet[name] = {
  2273. terms_stats: {}
  2274. };
  2275. return {
  2276. /**
  2277. Sets the field for which statistical information will be generated.
  2278. @member ejs.TermStatsFacet
  2279. @param {String} fieldName The field name whose data will be used to construct the facet.
  2280. @returns {Object} returns <code>this</code> so that calls can be chained.
  2281. */
  2282. valueField: function (fieldName) {
  2283. if (fieldName == null) {
  2284. return facet[name].terms_stats.value_field;
  2285. }
  2286. facet[name].terms_stats.value_field = fieldName;
  2287. return this;
  2288. },
  2289. /**
  2290. Sets the field which will be used to pivot on (group-by).
  2291. @member ejs.TermStatsFacet
  2292. @param {String} fieldName The field name whose data will be used to construct the facet.
  2293. @returns {Object} returns <code>this</code> so that calls can be chained.
  2294. */
  2295. keyField: function (fieldName) {
  2296. if (fieldName == null) {
  2297. return facet[name].terms_stats.key_field;
  2298. }
  2299. facet[name].terms_stats.key_field = fieldName;
  2300. return this;
  2301. },
  2302. /**
  2303. Sets a script that will provide the terms for a given document.
  2304. @member ejs.TermStatsFacet
  2305. @param {String} script The script code.
  2306. @returns {Object} returns <code>this</code> so that calls can be chained.
  2307. */
  2308. scriptField: function (script) {
  2309. if (script == null) {
  2310. return facet[name].terms_stats.script_field;
  2311. }
  2312. facet[name].terms_stats.script_field = script;
  2313. return this;
  2314. },
  2315. /**
  2316. Define a script to evaluate of which the result will be used to generate
  2317. the statistical information.
  2318. @member ejs.TermStatsFacet
  2319. @param {String} code The script code to execute.
  2320. @returns {Object} returns <code>this</code> so that calls can be chained.
  2321. */
  2322. valueScript: function (code) {
  2323. if (code == null) {
  2324. return facet[name].terms_stats.value_script;
  2325. }
  2326. facet[name].terms_stats.value_script = code;
  2327. return this;
  2328. },
  2329. /**
  2330. <p>Allows you to return all terms, even if the frequency count is 0. This should not be
  2331. used on fields that contain a large number of unique terms because it could cause
  2332. <em>out-of-memory</em> errors.</p>
  2333. @member ejs.TermStatsFacet
  2334. @param {String} trueFalse <code>true</code> or <code>false</code>
  2335. @returns {Object} returns <code>this</code> so that calls can be chained.
  2336. */
  2337. allTerms: function (trueFalse) {
  2338. if (trueFalse == null) {
  2339. return facet[name].terms_stats.all_terms;
  2340. }
  2341. facet[name].terms_stats.all_terms = trueFalse;
  2342. return this;
  2343. },
  2344. /**
  2345. The script language being used. Currently supported values are
  2346. <code>javascript</code>, <code>groovy</code>, and <code>mvel</code>.
  2347. @member ejs.TermStatsFacet
  2348. @param {String} language The language of the script.
  2349. @returns {Object} returns <code>this</code> so that calls can be chained.
  2350. */
  2351. lang: function (language) {
  2352. if (language == null) {
  2353. return facet[name].terms_stats.lang;
  2354. }
  2355. facet[name].terms_stats.lang = language;
  2356. return this;
  2357. },
  2358. /**
  2359. Allows you to set script parameters to be used during the execution of the script.
  2360. @member ejs.TermStatsFacet
  2361. @param {Object} oParams An object containing key/value pairs representing param name/value.
  2362. @returns {Object} returns <code>this</code> so that calls can be chained.
  2363. */
  2364. params: function (oParams) {
  2365. if (oParams == null) {
  2366. return facet[name].terms_stats.params;
  2367. }
  2368. facet[name].terms_stats.params = oParams;
  2369. return this;
  2370. },
  2371. /**
  2372. Sets the number of facet entries that will be returned for this facet. For instance, you
  2373. might ask for only the top 5 aggregate keys although there might be hundreds of
  2374. unique keys. <strong>Higher settings could cause memory strain</strong>.
  2375. @member ejs.TermStatsFacet
  2376. @param {Integer} facetSize The numer of facet entries to be returned.
  2377. @returns {Object} returns <code>this</code> so that calls can be chained.
  2378. */
  2379. size: function (facetSize) {
  2380. if (facetSize == null) {
  2381. return facet[name].terms_stats.size;
  2382. }
  2383. facet[name].terms_stats.size = facetSize;
  2384. return this;
  2385. },
  2386. /**
  2387. Sets the type of ordering that will be performed on the date
  2388. buckets. Valid values are:
  2389. count - default, sort by the number of items in the bucket
  2390. term - sort by term value.
  2391. reverse_count - reverse sort of the number of items in the bucket
  2392. reverse_term - reverse sort of the term value.
  2393. total - sorts by the total value of the bucket contents
  2394. reverse_total - reverse sort of the total value of bucket contents
  2395. min - the minimum value in the bucket
  2396. reverse_min - the reverse sort of the minimum value
  2397. max - the maximum value in the bucket
  2398. reverse_max - the reverse sort of the maximum value
  2399. mean - the mean value of the bucket contents
  2400. reverse_mean - the reverse sort of the mean value of bucket contents.
  2401. @member ejs.TermStatsFacet
  2402. @param {String} o The ordering method
  2403. @returns {Object} returns <code>this</code> so that calls can be chained.
  2404. */
  2405. order: function (o) {
  2406. if (o == null) {
  2407. return facet[name].terms_stats.order;
  2408. }
  2409. o = o.toLowerCase();
  2410. if (o === 'count' || o === 'term' || o === 'reverse_count' ||
  2411. o === 'reverse_term' || o === 'total' || o === 'reverse_total' ||
  2412. o === 'min' || o === 'reverse_min' || o === 'max' ||
  2413. o === 'reverse_max' || o === 'mean' || o === 'reverse_mean') {
  2414. facet[name].terms_stats.order = o;
  2415. }
  2416. return this;
  2417. },
  2418. /**
  2419. <p>Allows you to reduce the documents used for computing facet results.</p>
  2420. @member ejs.TermStatsFacet
  2421. @param {Object} oFilter A valid <code>Filter</code> object.
  2422. @returns {Object} returns <code>this</code> so that calls can be chained.
  2423. */
  2424. facetFilter: function (oFilter) {
  2425. if (oFilter == null) {
  2426. return facet[name].facet_filter;
  2427. }
  2428. if (!isFilter(oFilter)) {
  2429. throw new TypeError('Argument must be a Filter');
  2430. }
  2431. facet[name].facet_filter = oFilter._self();
  2432. return this;
  2433. },
  2434. /**
  2435. <p>Computes values across the entire index</p>
  2436. @member ejs.TermStatsFacet
  2437. @param {Boolean} trueFalse Calculate facet counts globally or not.
  2438. @returns {Object} returns <code>this</code> so that calls can be chained.
  2439. */
  2440. global: function (trueFalse) {
  2441. if (trueFalse == null) {
  2442. return facet[name].global;
  2443. }
  2444. facet[name].global = trueFalse;
  2445. return this;
  2446. },
  2447. /**
  2448. <p>Computes values across the the specified scope</p>
  2449. @member ejs.TermStatsFacet
  2450. @param {String} scope The scope name to calculate facet counts with.
  2451. @returns {Object} returns <code>this</code> so that calls can be chained.
  2452. */
  2453. scope: function (scope) {
  2454. if (scope == null) {
  2455. return facet[name].scope;
  2456. }
  2457. facet[name].scope = scope;
  2458. return this;
  2459. },
  2460. /**
  2461. <p>Enables caching of the <code>facetFilter</code></p>
  2462. @member ejs.TermStatsFacet
  2463. @param {Boolean} trueFalse If the facetFilter should be cached or not
  2464. @returns {Object} returns <code>this</code> so that calls can be chained.
  2465. */
  2466. cacheFilter: function (trueFalse) {
  2467. if (trueFalse == null) {
  2468. return facet[name].cache_filter;
  2469. }
  2470. facet[name].cache_filter = trueFalse;
  2471. return this;
  2472. },
  2473. /**
  2474. <p>Sets the path to the nested document if faceting against a
  2475. nested field.</p>
  2476. @member ejs.TermStatsFacet
  2477. @param {String} path The nested path
  2478. @returns {Object} returns <code>this</code> so that calls can be chained.
  2479. */
  2480. nested: function (path) {
  2481. if (path == null) {
  2482. return facet[name].nested;
  2483. }
  2484. facet[name].nested = path;
  2485. return this;
  2486. },
  2487. /**
  2488. <p>Allows you to serialize this object into a JSON encoded string.</p>
  2489. @member ejs.TermStatsFacet
  2490. @returns {String} returns this object as a serialized JSON string.
  2491. */
  2492. toString: function () {
  2493. return JSON.stringify(facet);
  2494. },
  2495. /**
  2496. The type of ejs object. For internal use only.
  2497. @member ejs.TermStatsFacet
  2498. @returns {String} the type of object
  2499. */
  2500. _type: function () {
  2501. return 'facet';
  2502. },
  2503. /**
  2504. <p>Retrieves the internal <code>facet</code> object. This is typically used by
  2505. internal API functions so use with caution.</p>
  2506. @member ejs.TermStatsFacet
  2507. @returns {String} returns this object's internal <code>facet</code> property.
  2508. */
  2509. _self: function () {
  2510. return facet;
  2511. }
  2512. };
  2513. };
  2514. /**
  2515. @class
  2516. A container Filter that allows Boolean AND composition of Filters.
  2517. @name ejs.AndFilter
  2518. @desc
  2519. A container Filter that allows Boolean AND composition of Filters.
  2520. @param {Filter || Array} f A single Filter object or an array of valid
  2521. Filter objects.
  2522. */
  2523. ejs.AndFilter = function (f) {
  2524. /**
  2525. The internal filter object. Use <code>_self()</code>
  2526. @member ejs.AndFilter
  2527. @property {Object} filter
  2528. */
  2529. var i,
  2530. len,
  2531. filter = {
  2532. and: {
  2533. filters: []
  2534. }
  2535. };
  2536. if (isFilter(f)) {
  2537. filter.and.filters.push(f._self());
  2538. } else if (isArray(f)) {
  2539. for (i = 0, len = f.length; i < len; i++) {
  2540. if (!isFilter(f[i])) {
  2541. throw new TypeError('Array must contain only Filter objects');
  2542. }
  2543. filter.and.filters.push(f[i]._self());
  2544. }
  2545. } else {
  2546. throw new TypeError('Argument must be a Filter or Array of Filters');
  2547. }
  2548. return {
  2549. /**
  2550. Sets the filters for the filter. If fltr is a single
  2551. Filter, it is added to the current filters. If fltr is an array
  2552. of Filters, then they replace all existing filters.
  2553. @member ejs.AndFilter
  2554. @param {Filter || Array} fltr A valid filter object or an array of filters.
  2555. @returns {Object} returns <code>this</code> so that calls can be chained.
  2556. */
  2557. filters: function (fltr) {
  2558. var i,
  2559. len;
  2560. if (fltr == null) {
  2561. return filter.and.filters;
  2562. }
  2563. if (isFilter(fltr)) {
  2564. filter.and.filters.push(fltr._self());
  2565. } else if (isArray(fltr)) {
  2566. filter.and.filters = [];
  2567. for (i = 0, len = fltr.length; i < len; i++) {
  2568. if (!isFilter(fltr[i])) {
  2569. throw new TypeError('Array must contain only Filter objects');
  2570. }
  2571. filter.and.filters.push(fltr[i]._self());
  2572. }
  2573. } else {
  2574. throw new TypeError('Argument must be a Filter or an Array of Filters');
  2575. }
  2576. return this;
  2577. },
  2578. /**
  2579. Sets the filter name.
  2580. @member ejs.AndFilter
  2581. @param {String} name A name for the filter.
  2582. @returns {Object} returns <code>this</code> so that calls can be chained.
  2583. */
  2584. name: function (name) {
  2585. if (name == null) {
  2586. return filter.and._name;
  2587. }
  2588. filter.and._name = name;
  2589. return this;
  2590. },
  2591. /**
  2592. Enable or disable caching of the filter
  2593. @member ejs.AndFilter
  2594. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  2595. @returns {Object} returns <code>this</code> so that calls can be chained.
  2596. */
  2597. cache: function (trueFalse) {
  2598. if (trueFalse == null) {
  2599. return filter.and._cache;
  2600. }
  2601. filter.and._cache = trueFalse;
  2602. return this;
  2603. },
  2604. /**
  2605. Sets the cache key.
  2606. @member ejs.AndFilter
  2607. @param {String} key the cache key as a string.
  2608. @returns {Object} returns <code>this</code> so that calls can be chained.
  2609. */
  2610. cacheKey: function (key) {
  2611. if (key == null) {
  2612. return filter.and._cache_key;
  2613. }
  2614. filter.and._cache_key = key;
  2615. return this;
  2616. },
  2617. /**
  2618. Returns the filter container as a JSON string
  2619. @member ejs.AndFilter
  2620. @returns {String} JSON representation of the andFilter object
  2621. */
  2622. toString: function () {
  2623. return JSON.stringify(filter);
  2624. },
  2625. /**
  2626. The type of ejs object. For internal use only.
  2627. @member ejs.AndFilter
  2628. @returns {String} the type of object
  2629. */
  2630. _type: function () {
  2631. return 'filter';
  2632. },
  2633. /**
  2634. Returns the filter object.
  2635. @member ejs.AndFilter
  2636. @returns {Object} filter object
  2637. */
  2638. _self: function () {
  2639. return filter;
  2640. }
  2641. };
  2642. };
  2643. /**
  2644. @class
  2645. <p>A <code>BoolFilter</code> allows you to build <em>Boolean</em> filter constructs
  2646. from individual filters. Similar in concept to Boolean query, except that
  2647. the clauses are other filters. Can be placed within queries that accept a
  2648. filter.
  2649. @name ejs.BoolFilter
  2650. @desc
  2651. A Filter that matches documents matching boolean combinations of other
  2652. filters.
  2653. */
  2654. ejs.BoolFilter = function () {
  2655. /**
  2656. The internal filter object. <code>Use _self()</code>
  2657. @member ejs.BoolFilter
  2658. @property {Object} filter
  2659. */
  2660. var filter = {
  2661. bool: {}
  2662. };
  2663. return {
  2664. /**
  2665. Adds filter to boolean container. Given filter "must" appear in
  2666. matching documents. If passed a single Filter it is added to the
  2667. list of existing filters. If passed an array of Filters, they
  2668. replace all existing filters.
  2669. @member ejs.BoolFilter
  2670. @param {Filter || Array} oFilter A valid Filter or array of
  2671. Filter objects.
  2672. @returns {Object} returns <code>this</code> so that calls can be chained.
  2673. */
  2674. must: function (oFilter) {
  2675. var i, len;
  2676. if (filter.bool.must == null) {
  2677. filter.bool.must = [];
  2678. }
  2679. if (oFilter == null) {
  2680. return filter.bool.must;
  2681. }
  2682. if (isFilter(oFilter)) {
  2683. filter.bool.must.push(oFilter._self());
  2684. } else if (isArray(oFilter)) {
  2685. filter.bool.must = [];
  2686. for (i = 0, len = oFilter.length; i < len; i++) {
  2687. if (!isFilter(oFilter[i])) {
  2688. throw new TypeError('Argument must be an array of Filters');
  2689. }
  2690. filter.bool.must.push(oFilter[i]._self());
  2691. }
  2692. } else {
  2693. throw new TypeError('Argument must be a Filter or array of Filters');
  2694. }
  2695. return this;
  2696. },
  2697. /**
  2698. Adds filter to boolean container. Given filter "must not" appear
  2699. in matching documents. If passed a single Filter it is added to
  2700. the list of existing filters. If passed an array of Filters,
  2701. they replace all existing filters.
  2702. @member ejs.BoolFilter
  2703. @param {Filter || Array} oFilter A valid Filter or array of
  2704. Filter objects.
  2705. @returns {Object} returns <code>this</code> so that calls can be chained.
  2706. */
  2707. mustNot: function (oFilter) {
  2708. var i, len;
  2709. if (filter.bool.must_not == null) {
  2710. filter.bool.must_not = [];
  2711. }
  2712. if (oFilter == null) {
  2713. return filter.bool.must_not;
  2714. }
  2715. if (isFilter(oFilter)) {
  2716. filter.bool.must_not.push(oFilter._self());
  2717. } else if (isArray(oFilter)) {
  2718. filter.bool.must_not = [];
  2719. for (i = 0, len = oFilter.length; i < len; i++) {
  2720. if (!isFilter(oFilter[i])) {
  2721. throw new TypeError('Argument must be an array of Filters');
  2722. }
  2723. filter.bool.must_not.push(oFilter[i]._self());
  2724. }
  2725. } else {
  2726. throw new TypeError('Argument must be a Filter or array of Filters');
  2727. }
  2728. return this;
  2729. },
  2730. /**
  2731. Adds filter to boolean container. Given filter "should" appear in
  2732. matching documents. If passed a single Filter it is added to
  2733. the list of existing filters. If passed an array of Filters,
  2734. they replace all existing filters.
  2735. @member ejs.BoolFilter
  2736. @param {Filter || Array} oFilter A valid Filter or array of
  2737. Filter objects.
  2738. @returns {Object} returns <code>this</code> so that calls can be chained.
  2739. */
  2740. should: function (oFilter) {
  2741. var i, len;
  2742. if (filter.bool.should == null) {
  2743. filter.bool.should = [];
  2744. }
  2745. if (oFilter == null) {
  2746. return filter.bool.should;
  2747. }
  2748. if (isFilter(oFilter)) {
  2749. filter.bool.should.push(oFilter._self());
  2750. } else if (isArray(oFilter)) {
  2751. filter.bool.should = [];
  2752. for (i = 0, len = oFilter.length; i < len; i++) {
  2753. if (!isFilter(oFilter[i])) {
  2754. throw new TypeError('Argument must be an array of Filters');
  2755. }
  2756. filter.bool.should.push(oFilter[i]._self());
  2757. }
  2758. } else {
  2759. throw new TypeError('Argument must be a Filter or array of Filters');
  2760. }
  2761. return this;
  2762. },
  2763. /**
  2764. Sets the filter name.
  2765. @member ejs.BoolFilter
  2766. @param {String} name A name for the filter.
  2767. @returns {Object} returns <code>this</code> so that calls can be chained.
  2768. */
  2769. name: function (name) {
  2770. if (name == null) {
  2771. return filter.bool._name;
  2772. }
  2773. filter.bool._name = name;
  2774. return this;
  2775. },
  2776. /**
  2777. Enable or disable caching of the filter
  2778. @member ejs.BoolFilter
  2779. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  2780. @returns {Object} returns <code>this</code> so that calls can be chained.
  2781. */
  2782. cache: function (trueFalse) {
  2783. if (trueFalse == null) {
  2784. return filter.bool._cache;
  2785. }
  2786. filter.bool._cache = trueFalse;
  2787. return this;
  2788. },
  2789. /**
  2790. Sets the cache key.
  2791. @member ejs.BoolFilter
  2792. @param {String} key the cache key as a string.
  2793. @returns {Object} returns <code>this</code> so that calls can be chained.
  2794. */
  2795. cacheKey: function (key) {
  2796. if (key == null) {
  2797. return filter.bool._cache_key;
  2798. }
  2799. filter.bool._cache_key = key;
  2800. return this;
  2801. },
  2802. /**
  2803. Allows you to serialize this object into a JSON encoded string.
  2804. @member ejs.BoolFilter
  2805. @returns {String} returns this object as a serialized JSON string.
  2806. */
  2807. toString: function () {
  2808. return JSON.stringify(filter);
  2809. },
  2810. /**
  2811. The type of ejs object. For internal use only.
  2812. @member ejs.BoolFilter
  2813. @returns {String} the type of object
  2814. */
  2815. _type: function () {
  2816. return 'filter';
  2817. },
  2818. /**
  2819. Retrieves the internal <code>filter</code> object. This is typically used by
  2820. internal API functions so use with caution.
  2821. @member ejs.BoolFilter
  2822. @returns {String} returns this object's internal <code>filter</code> property.
  2823. */
  2824. _self: function () {
  2825. return filter;
  2826. }
  2827. };
  2828. };
  2829. /**
  2830. @class
  2831. <p>An existsFilter matches documents where the specified field is present
  2832. and the field contains a legitimate value.</p>
  2833. @name ejs.ExistsFilter
  2834. @desc
  2835. Filters documents where a specified field exists and contains a value.
  2836. @param {String} fieldName the field name that must exists and contain a value.
  2837. */
  2838. ejs.ExistsFilter = function (fieldName) {
  2839. /**
  2840. The internal filter object. Use <code>get()</code>
  2841. @member ejs.ExistsFilter
  2842. @property {Object} filter
  2843. */
  2844. var filter = {
  2845. exists: {
  2846. field: fieldName
  2847. }
  2848. };
  2849. return {
  2850. /**
  2851. Sets the field to check for missing values.
  2852. @member ejs.ExistsFilter
  2853. @param {String} name A name of the field.
  2854. @returns {Object} returns <code>this</code> so that calls can be chained.
  2855. */
  2856. field: function (name) {
  2857. if (name == null) {
  2858. return filter.exists.field;
  2859. }
  2860. filter.exists.field = name;
  2861. return this;
  2862. },
  2863. /**
  2864. Sets the filter name.
  2865. @member ejs.ExistsFilter
  2866. @param {String} name A name for the filter.
  2867. @returns {Object} returns <code>this</code> so that calls can be chained.
  2868. */
  2869. name: function (name) {
  2870. if (name == null) {
  2871. return filter.exists._name;
  2872. }
  2873. filter.exists._name = name;
  2874. return this;
  2875. },
  2876. /**
  2877. Returns the filter container as a JSON string
  2878. @member ejs.ExistsFilter
  2879. @returns {String} JSON representation of the existsFilter object
  2880. */
  2881. toString: function () {
  2882. return JSON.stringify(filter);
  2883. },
  2884. /**
  2885. The type of ejs object. For internal use only.
  2886. @member ejs.ExistsFilter
  2887. @returns {String} the type of object
  2888. */
  2889. _type: function () {
  2890. return 'filter';
  2891. },
  2892. /**
  2893. Returns the filter object.
  2894. @member ejs.ExistsFilter
  2895. @returns {Object} filter object
  2896. */
  2897. _self: function () {
  2898. return filter;
  2899. }
  2900. };
  2901. };
  2902. /**
  2903. @class
  2904. <p>A filter that restricts matched results/docs to a geographic bounding box described by
  2905. the specified lon and lat coordinates. The format conforms with the GeoJSON specification.</p>
  2906. @name ejs.GeoBboxFilter
  2907. @desc
  2908. Filter results to those which are contained within the defined bounding box.
  2909. @param {String} fieldName the document property/field containing the Geo Point (lon/lat).
  2910. */
  2911. ejs.GeoBboxFilter = function (fieldName) {
  2912. /**
  2913. The internal filter object. Use <code>_self()</code>
  2914. @member ejs.GeoBboxFilter
  2915. @property {Object} filter
  2916. */
  2917. var filter = {
  2918. geo_bounding_box: {}
  2919. };
  2920. filter.geo_bounding_box[fieldName] = {};
  2921. return {
  2922. /**
  2923. Sets the fields to filter against.
  2924. @member ejs.GeoBboxFilter
  2925. @param {String} f A valid field name.
  2926. @returns {Object} returns <code>this</code> so that calls can be chained.
  2927. */
  2928. field: function (f) {
  2929. var oldValue = filter.geo_bounding_box[fieldName];
  2930. if (f == null) {
  2931. return fieldName;
  2932. }
  2933. delete filter.geo_bounding_box[fieldName];
  2934. fieldName = f;
  2935. filter.geo_bounding_box[f] = oldValue;
  2936. return this;
  2937. },
  2938. /**
  2939. Sets the top-left coordinate of the bounding box
  2940. @member ejs.GeoBboxFilter
  2941. @param {GeoPoint} p A valid GeoPoint object
  2942. @returns {Object} returns <code>this</code> so that calls can be chained.
  2943. */
  2944. topLeft: function (p) {
  2945. if (p == null) {
  2946. return filter.geo_bounding_box[fieldName].top_left;
  2947. }
  2948. if (isGeoPoint(p)) {
  2949. filter.geo_bounding_box[fieldName].top_left = p._self();
  2950. } else {
  2951. throw new TypeError('Argument must be a GeoPoint');
  2952. }
  2953. return this;
  2954. },
  2955. /**
  2956. Sets the bottom-right coordinate of the bounding box
  2957. @member ejs.GeoBboxFilter
  2958. @param {GeoPoint} p A valid GeoPoint object
  2959. @returns {Object} returns <code>this</code> so that calls can be chained.
  2960. */
  2961. bottomRight: function (p) {
  2962. if (p == null) {
  2963. return filter.geo_bounding_box[fieldName].bottom_right;
  2964. }
  2965. if (isGeoPoint(p)) {
  2966. filter.geo_bounding_box[fieldName].bottom_right = p._self();
  2967. } else {
  2968. throw new TypeError('Argument must be a GeoPoint');
  2969. }
  2970. return this;
  2971. },
  2972. /**
  2973. Sets the type of the bounding box execution. Valid values are
  2974. "memory" and "indexed". Default is memory.
  2975. @member ejs.GeoBboxFilter
  2976. @param {String} type The execution type as a string.
  2977. @returns {Object} returns <code>this</code> so that calls can be chained.
  2978. */
  2979. type: function (type) {
  2980. if (type == null) {
  2981. return filter.geo_bounding_box.type;
  2982. }
  2983. type = type.toLowerCase();
  2984. if (type === 'memory' || type === 'indexed') {
  2985. filter.geo_bounding_box.type = type;
  2986. }
  2987. return this;
  2988. },
  2989. /**
  2990. If the lat/long points should be normalized to lie within their
  2991. respective normalized ranges.
  2992. Normalized ranges are:
  2993. lon = -180 (exclusive) to 180 (inclusive) range
  2994. lat = -90 to 90 (both inclusive) range
  2995. @member ejs.GeoBboxFilter
  2996. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  2997. @returns {Object} returns <code>this</code> so that calls can be chained.
  2998. */
  2999. normalize: function (trueFalse) {
  3000. if (trueFalse == null) {
  3001. return filter.geo_bounding_box.normalize;
  3002. }
  3003. filter.geo_bounding_box.normalize = trueFalse;
  3004. return this;
  3005. },
  3006. /**
  3007. Sets the filter name.
  3008. @member ejs.GeoBboxFilter
  3009. @param {String} name A name for the filter.
  3010. @returns {Object} returns <code>this</code> so that calls can be chained.
  3011. */
  3012. name: function (name) {
  3013. if (name == null) {
  3014. return filter.geo_bounding_box._name;
  3015. }
  3016. filter.geo_bounding_box._name = name;
  3017. return this;
  3018. },
  3019. /**
  3020. Enable or disable caching of the filter
  3021. @member ejs.GeoBboxFilter
  3022. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  3023. @returns {Object} returns <code>this</code> so that calls can be chained.
  3024. */
  3025. cache: function (trueFalse) {
  3026. if (trueFalse == null) {
  3027. return filter.geo_bounding_box._cache;
  3028. }
  3029. filter.geo_bounding_box._cache = trueFalse;
  3030. return this;
  3031. },
  3032. /**
  3033. Sets the cache key.
  3034. @member ejs.GeoBboxFilter
  3035. @param {String} key the cache key as a string.
  3036. @returns {Object} returns <code>this</code> so that calls can be chained.
  3037. */
  3038. cacheKey: function (key) {
  3039. if (key == null) {
  3040. return filter.geo_bounding_box._cache_key;
  3041. }
  3042. filter.geo_bounding_box._cache_key = key;
  3043. return this;
  3044. },
  3045. /**
  3046. Returns the filter container as a JSON string
  3047. @member ejs.GeoBboxFilter
  3048. @returns {String} JSON representation of the notFilter object
  3049. */
  3050. toString: function () {
  3051. return JSON.stringify(filter);
  3052. },
  3053. /**
  3054. The type of ejs object. For internal use only.
  3055. @member ejs.GeoBboxFilter
  3056. @returns {String} the type of object
  3057. */
  3058. _type: function () {
  3059. return 'filter';
  3060. },
  3061. /**
  3062. Returns the filter object.
  3063. @member ejs.GeoBboxFilter
  3064. @returns {Object} filter object
  3065. */
  3066. _self: function () {
  3067. return filter;
  3068. }
  3069. };
  3070. };
  3071. /**
  3072. @class
  3073. <p>A filter that restricts matched results/docs to a given distance from the
  3074. point of origin. The format conforms with the GeoJSON specification.</p>
  3075. @name ejs.GeoDistanceFilter
  3076. @desc
  3077. Filter results to those which fall within the given distance of the point of origin.
  3078. @param {String} fieldName the document property/field containing the Geo Point (lon/lat).
  3079. */
  3080. ejs.GeoDistanceFilter = function (fieldName) {
  3081. /**
  3082. The internal filter object. Use <code>_self()</code>
  3083. @member ejs.GeoDistanceFilter
  3084. @property {Object} filter
  3085. */
  3086. var filter = {
  3087. geo_distance: {
  3088. }
  3089. };
  3090. filter.geo_distance[fieldName] = [0, 0];
  3091. return {
  3092. /**
  3093. Sets the fields to filter against.
  3094. @member ejs.GeoDistanceFilter
  3095. @param {String} f A valid field name.
  3096. @returns {Object} returns <code>this</code> so that calls can be chained.
  3097. */
  3098. field: function (f) {
  3099. var oldValue = filter.geo_distance[fieldName];
  3100. if (f == null) {
  3101. return fieldName;
  3102. }
  3103. delete filter.geo_distance[fieldName];
  3104. fieldName = f;
  3105. filter.geo_distance[f] = oldValue;
  3106. return this;
  3107. },
  3108. /**
  3109. Sets the numeric distance to be used. The distance can be a
  3110. numeric value, and then the unit (either mi or km can be set)
  3111. controlling the unit. Or a single string with the unit as well.
  3112. @member ejs.GeoDistanceFilter
  3113. @param {Number} numericDistance the numeric distance
  3114. @returns {Object} returns <code>this</code> so that calls can be chained.
  3115. */
  3116. distance: function (numericDistance) {
  3117. if (numericDistance == null) {
  3118. return filter.geo_distance.distance;
  3119. }
  3120. if (!isNumber(numericDistance)) {
  3121. throw new TypeError('Argument must be a numeric value');
  3122. }
  3123. filter.geo_distance.distance = numericDistance;
  3124. return this;
  3125. },
  3126. /**
  3127. Sets the distance unit. Valid values are "mi" for miles or "km"
  3128. for kilometers. Defaults to "km".
  3129. @member ejs.GeoDistanceFilter
  3130. @param {Number} unit the unit of distance measure.
  3131. @returns {Object} returns <code>this</code> so that calls can be chained.
  3132. */
  3133. unit: function (unit) {
  3134. if (unit == null) {
  3135. return filter.geo_distance.unit;
  3136. }
  3137. unit = unit.toLowerCase();
  3138. if (unit === 'mi' || unit === 'km') {
  3139. filter.geo_distance.unit = unit;
  3140. }
  3141. return this;
  3142. },
  3143. /**
  3144. Sets the point of origin in which distance will be measured from
  3145. @member ejs.GeoDistanceFilter
  3146. @param {GeoPoint} p A valid GeoPoint object.
  3147. @returns {Object} returns <code>this</code> so that calls can be chained.
  3148. */
  3149. point: function (p) {
  3150. if (p == null) {
  3151. return filter.geo_distance[fieldName];
  3152. }
  3153. if (isGeoPoint(p)) {
  3154. filter.geo_distance[fieldName] = p._self();
  3155. } else {
  3156. throw new TypeError('Argument must be a GeoPoint');
  3157. }
  3158. return this;
  3159. },
  3160. /**
  3161. How to compute the distance. Can either be arc (better precision)
  3162. or plane (faster). Defaults to arc.
  3163. @member ejs.GeoDistanceFilter
  3164. @param {String} type The execution type as a string.
  3165. @returns {Object} returns <code>this</code> so that calls can be chained.
  3166. */
  3167. distanceType: function (type) {
  3168. if (type == null) {
  3169. return filter.geo_distance.distance_type;
  3170. }
  3171. type = type.toLowerCase();
  3172. if (type === 'arc' || type === 'plane') {
  3173. filter.geo_distance.distance_type = type;
  3174. }
  3175. return this;
  3176. },
  3177. /**
  3178. If the lat/long points should be normalized to lie within their
  3179. respective normalized ranges.
  3180. Normalized ranges are:
  3181. lon = -180 (exclusive) to 180 (inclusive) range
  3182. lat = -90 to 90 (both inclusive) range
  3183. @member ejs.GeoDistanceFilter
  3184. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  3185. @returns {Object} returns <code>this</code> so that calls can be chained.
  3186. */
  3187. normalize: function (trueFalse) {
  3188. if (trueFalse == null) {
  3189. return filter.geo_distance.normalize;
  3190. }
  3191. filter.geo_distance.normalize = trueFalse;
  3192. return this;
  3193. },
  3194. /**
  3195. Will an optimization of using first a bounding box check will be
  3196. used. Defaults to memory which will do in memory checks. Can also
  3197. have values of indexed to use indexed value check, or none which
  3198. disables bounding box optimization.
  3199. @member ejs.GeoDistanceFilter
  3200. @param {String} t optimization type of memory, indexed, or none.
  3201. @returns {Object} returns <code>this</code> so that calls can be chained.
  3202. */
  3203. optimizeBbox: function (t) {
  3204. if (t == null) {
  3205. return filter.geo_distance.optimize_bbox;
  3206. }
  3207. t = t.toLowerCase();
  3208. if (t === 'memory' || t === 'indexed' || t === 'none') {
  3209. filter.geo_distance.optimize_bbox = t;
  3210. }
  3211. return this;
  3212. },
  3213. /**
  3214. Sets the filter name.
  3215. @member ejs.GeoDistanceFilter
  3216. @param {String} name A name for the filter.
  3217. @returns {Object} returns <code>this</code> so that calls can be chained.
  3218. */
  3219. name: function (name) {
  3220. if (name == null) {
  3221. return filter.geo_distance._name;
  3222. }
  3223. filter.geo_distance._name = name;
  3224. return this;
  3225. },
  3226. /**
  3227. Enable or disable caching of the filter
  3228. @member ejs.GeoDistanceFilter
  3229. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  3230. @returns {Object} returns <code>this</code> so that calls can be chained.
  3231. */
  3232. cache: function (trueFalse) {
  3233. if (trueFalse == null) {
  3234. return filter.geo_distance._cache;
  3235. }
  3236. filter.geo_distance._cache = trueFalse;
  3237. return this;
  3238. },
  3239. /**
  3240. Sets the cache key.
  3241. @member ejs.GeoDistanceFilter
  3242. @param {String} key the cache key as a string.
  3243. @returns {Object} returns <code>this</code> so that calls can be chained.
  3244. */
  3245. cacheKey: function (key) {
  3246. if (key == null) {
  3247. return filter.geo_distance._cache_key;
  3248. }
  3249. filter.geo_distance._cache_key = key;
  3250. return this;
  3251. },
  3252. /**
  3253. Returns the filter container as a JSON string
  3254. @member ejs.GeoDistanceFilter
  3255. @returns {String} JSON representation of the notFilter object
  3256. */
  3257. toString: function () {
  3258. return JSON.stringify(filter);
  3259. },
  3260. /**
  3261. The type of ejs object. For internal use only.
  3262. @member ejs.GeoDistanceFilter
  3263. @returns {String} the type of object
  3264. */
  3265. _type: function () {
  3266. return 'filter';
  3267. },
  3268. /**
  3269. Returns the filter object.
  3270. @member ejs.GeoDistanceFilter
  3271. @returns {Object} filter object
  3272. */
  3273. _self: function () {
  3274. return filter;
  3275. }
  3276. };
  3277. };
  3278. /**
  3279. @class
  3280. <p>A filter that restricts matched results/docs to a given distance range from the
  3281. point of origin. The format conforms with the GeoJSON specification.</p>
  3282. @name ejs.GeoDistanceRangeFilter
  3283. @desc
  3284. Filter results to those which fall within the given distance range of the point of origin.
  3285. @param {String} fieldName the document property/field containing the Geo Point (lon/lat).
  3286. */
  3287. ejs.GeoDistanceRangeFilter = function (fieldName) {
  3288. /**
  3289. The internal filter object. Use <code>_self()</code>
  3290. @member ejs.GeoDistanceRangeFilter
  3291. @property {Object} filter
  3292. */
  3293. var filter = {
  3294. geo_distance_range: {}
  3295. };
  3296. filter.geo_distance_range[fieldName] = [0, 0];
  3297. return {
  3298. /**
  3299. Sets the fields to filter against.
  3300. @member ejs.GeoDistanceRangeFilter
  3301. @param {String} f A valid field name.
  3302. @returns {Object} returns <code>this</code> so that calls can be chained.
  3303. */
  3304. field: function (f) {
  3305. var oldValue = filter.geo_distance_range[fieldName];
  3306. if (f == null) {
  3307. return fieldName;
  3308. }
  3309. delete filter.geo_distance_range[fieldName];
  3310. fieldName = f;
  3311. filter.geo_distance_range[f] = oldValue;
  3312. return this;
  3313. },
  3314. /**
  3315. * Sets the start point of the distance range
  3316. @member ejs.GeoDistanceRangeFilter
  3317. @param {Number} numericDistance the numeric distance
  3318. @returns {Object} returns <code>this</code> so that calls can be chained.
  3319. */
  3320. from: function (numericDistance) {
  3321. if (numericDistance == null) {
  3322. return filter.geo_distance_range.from;
  3323. }
  3324. if (!isNumber(numericDistance)) {
  3325. throw new TypeError('Argument must be a numeric value');
  3326. }
  3327. filter.geo_distance_range.from = numericDistance;
  3328. return this;
  3329. },
  3330. /**
  3331. * Sets the end point of the distance range
  3332. @member ejs.GeoDistanceRangeFilter
  3333. @param {Number} numericDistance the numeric distance
  3334. @returns {Object} returns <code>this</code> so that calls can be chained.
  3335. */
  3336. to: function (numericDistance) {
  3337. if (numericDistance == null) {
  3338. return filter.geo_distance_range.to;
  3339. }
  3340. if (!isNumber(numericDistance)) {
  3341. throw new TypeError('Argument must be a numeric value');
  3342. }
  3343. filter.geo_distance_range.to = numericDistance;
  3344. return this;
  3345. },
  3346. /**
  3347. Should the first from (if set) be inclusive or not.
  3348. Defaults to true
  3349. @member ejs.GeoDistanceRangeFilter
  3350. @param {Boolean} trueFalse true to include, false to exclude
  3351. @returns {Object} returns <code>this</code> so that calls can be chained.
  3352. */
  3353. includeLower: function (trueFalse) {
  3354. if (trueFalse == null) {
  3355. return filter.geo_distance_range.include_lower;
  3356. }
  3357. filter.geo_distance_range.include_lower = trueFalse;
  3358. return this;
  3359. },
  3360. /**
  3361. Should the last to (if set) be inclusive or not. Defaults to true.
  3362. @member ejs.GeoDistanceRangeFilter
  3363. @param {Boolean} trueFalse true to include, false to exclude
  3364. @returns {Object} returns <code>this</code> so that calls can be chained.
  3365. */
  3366. includeUpper: function (trueFalse) {
  3367. if (trueFalse == null) {
  3368. return filter.geo_distance_range.include_upper;
  3369. }
  3370. filter.geo_distance_range.include_upper = trueFalse;
  3371. return this;
  3372. },
  3373. /**
  3374. Greater than value. Same as setting from to the value, and
  3375. include_lower to false,
  3376. @member ejs.GeoDistanceRangeFilter
  3377. @param {Number} val the numeric distance
  3378. @returns {Object} returns <code>this</code> so that calls can be chained.
  3379. */
  3380. gt: function (val) {
  3381. if (val == null) {
  3382. return filter.geo_distance_range.gt;
  3383. }
  3384. if (!isNumber(val)) {
  3385. throw new TypeError('Argument must be a numeric value');
  3386. }
  3387. filter.geo_distance_range.gt = val;
  3388. return this;
  3389. },
  3390. /**
  3391. Greater than or equal to value. Same as setting from to the value,
  3392. and include_lower to true.
  3393. @member ejs.GeoDistanceRangeFilter
  3394. @param {Number} val the numeric distance
  3395. @returns {Object} returns <code>this</code> so that calls can be chained.
  3396. */
  3397. gte: function (val) {
  3398. if (val == null) {
  3399. return filter.geo_distance_range.gte;
  3400. }
  3401. if (!isNumber(val)) {
  3402. throw new TypeError('Argument must be a numeric value');
  3403. }
  3404. filter.geo_distance_range.gte = val;
  3405. return this;
  3406. },
  3407. /**
  3408. Less than value. Same as setting to to the value, and include_upper
  3409. to false.
  3410. @member ejs.GeoDistanceRangeFilter
  3411. @param {Number} val the numeric distance
  3412. @returns {Object} returns <code>this</code> so that calls can be chained.
  3413. */
  3414. lt: function (val) {
  3415. if (val == null) {
  3416. return filter.geo_distance_range.lt;
  3417. }
  3418. if (!isNumber(val)) {
  3419. throw new TypeError('Argument must be a numeric value');
  3420. }
  3421. filter.geo_distance_range.lt = val;
  3422. return this;
  3423. },
  3424. /**
  3425. Less than or equal to value. Same as setting to to the value,
  3426. and include_upper to true.
  3427. @member ejs.GeoDistanceRangeFilter
  3428. @param {Number} val the numeric distance
  3429. @returns {Object} returns <code>this</code> so that calls can be chained.
  3430. */
  3431. lte: function (val) {
  3432. if (val == null) {
  3433. return filter.geo_distance_range.lte;
  3434. }
  3435. if (!isNumber(val)) {
  3436. throw new TypeError('Argument must be a numeric value');
  3437. }
  3438. filter.geo_distance_range.lte = val;
  3439. return this;
  3440. },
  3441. /**
  3442. Sets the distance unit. Valid values are "mi" for miles or "km"
  3443. for kilometers. Defaults to "km".
  3444. @member ejs.GeoDistanceRangeFilter
  3445. @param {Number} unit the unit of distance measure.
  3446. @returns {Object} returns <code>this</code> so that calls can be chained.
  3447. */
  3448. unit: function (unit) {
  3449. if (unit == null) {
  3450. return filter.geo_distance_range.unit;
  3451. }
  3452. unit = unit.toLowerCase();
  3453. if (unit === 'mi' || unit === 'km') {
  3454. filter.geo_distance_range.unit = unit;
  3455. }
  3456. return this;
  3457. },
  3458. /**
  3459. Sets the point of origin in which distance will be measured from
  3460. @member ejs.GeoDistanceRangeFilter
  3461. @param {GeoPoint} p A valid GeoPoint object.
  3462. @returns {Object} returns <code>this</code> so that calls can be chained.
  3463. */
  3464. point: function (p) {
  3465. if (p == null) {
  3466. return filter.geo_distance_range[fieldName];
  3467. }
  3468. if (isGeoPoint(p)) {
  3469. filter.geo_distance_range[fieldName] = p._self();
  3470. } else {
  3471. throw new TypeError('Argument must be a GeoPoint');
  3472. }
  3473. return this;
  3474. },
  3475. /**
  3476. How to compute the distance. Can either be arc (better precision)
  3477. or plane (faster). Defaults to arc.
  3478. @member ejs.GeoDistanceRangeFilter
  3479. @param {String} type The execution type as a string.
  3480. @returns {Object} returns <code>this</code> so that calls can be chained.
  3481. */
  3482. distanceType: function (type) {
  3483. if (type == null) {
  3484. return filter.geo_distance_range.distance_type;
  3485. }
  3486. type = type.toLowerCase();
  3487. if (type === 'arc' || type === 'plane') {
  3488. filter.geo_distance_range.distance_type = type;
  3489. }
  3490. return this;
  3491. },
  3492. /**
  3493. If the lat/long points should be normalized to lie within their
  3494. respective normalized ranges.
  3495. Normalized ranges are:
  3496. lon = -180 (exclusive) to 180 (inclusive) range
  3497. lat = -90 to 90 (both inclusive) range
  3498. @member ejs.GeoDistanceRangeFilter
  3499. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  3500. @returns {Object} returns <code>this</code> so that calls can be chained.
  3501. */
  3502. normalize: function (trueFalse) {
  3503. if (trueFalse == null) {
  3504. return filter.geo_distance_range.normalize;
  3505. }
  3506. filter.geo_distance_range.normalize = trueFalse;
  3507. return this;
  3508. },
  3509. /**
  3510. Will an optimization of using first a bounding box check will be
  3511. used. Defaults to memory which will do in memory checks. Can also
  3512. have values of indexed to use indexed value check, or none which
  3513. disables bounding box optimization.
  3514. @member ejs.GeoDistanceRangeFilter
  3515. @param {String} t optimization type of memory, indexed, or none.
  3516. @returns {Object} returns <code>this</code> so that calls can be chained.
  3517. */
  3518. optimizeBbox: function (t) {
  3519. if (t == null) {
  3520. return filter.geo_distance_range.optimize_bbox;
  3521. }
  3522. t = t.toLowerCase();
  3523. if (t === 'memory' || t === 'indexed' || t === 'none') {
  3524. filter.geo_distance_range.optimize_bbox = t;
  3525. }
  3526. return this;
  3527. },
  3528. /**
  3529. Sets the filter name.
  3530. @member ejs.GeoDistanceRangeFilter
  3531. @param {String} name A name for the filter.
  3532. @returns {Object} returns <code>this</code> so that calls can be chained.
  3533. */
  3534. name: function (name) {
  3535. if (name == null) {
  3536. return filter.geo_distance_range._name;
  3537. }
  3538. filter.geo_distance_range._name = name;
  3539. return this;
  3540. },
  3541. /**
  3542. Enable or disable caching of the filter
  3543. @member ejs.GeoDistanceRangeFilter
  3544. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  3545. @returns {Object} returns <code>this</code> so that calls can be chained.
  3546. */
  3547. cache: function (trueFalse) {
  3548. if (trueFalse == null) {
  3549. return filter.geo_distance_range._cache;
  3550. }
  3551. filter.geo_distance_range._cache = trueFalse;
  3552. return this;
  3553. },
  3554. /**
  3555. Sets the cache key.
  3556. @member ejs.GeoDistanceRangeFilter
  3557. @param {String} key the cache key as a string.
  3558. @returns {Object} returns <code>this</code> so that calls can be chained.
  3559. */
  3560. cacheKey: function (key) {
  3561. if (key == null) {
  3562. return filter.geo_distance_range._cache_key;
  3563. }
  3564. filter.geo_distance_range._cache_key = key;
  3565. return this;
  3566. },
  3567. /**
  3568. Returns the filter container as a JSON string
  3569. @member ejs.GeoDistanceRangeFilter
  3570. @returns {String} JSON representation of the notFilter object
  3571. */
  3572. toString: function () {
  3573. return JSON.stringify(filter);
  3574. },
  3575. /**
  3576. The type of ejs object. For internal use only.
  3577. @member ejs.GeoDistanceRangeFilter
  3578. @returns {String} the type of object
  3579. */
  3580. _type: function () {
  3581. return 'filter';
  3582. },
  3583. /**
  3584. Returns the filter object.
  3585. @member ejs.GeoDistanceRangeFilter
  3586. @returns {Object} filter object
  3587. */
  3588. _self: function () {
  3589. return filter;
  3590. }
  3591. };
  3592. };
  3593. /**
  3594. @class
  3595. <p>A filter for locating documents that fall within a polygon of points. Simply provide a lon/lat
  3596. for each document as a Geo Point type. The format conforms with the GeoJSON specification.</p>
  3597. @name ejs.GeoPolygonFilter
  3598. @desc
  3599. Filter results to those which are contained within the polygon of points.
  3600. @param {String} fieldName the document property/field containing the Geo Point (lon/lat).
  3601. */
  3602. ejs.GeoPolygonFilter = function (fieldName) {
  3603. /**
  3604. The internal filter object. Use <code>_self()</code>
  3605. @member ejs.GeoPolygonFilter
  3606. @property {Object} filter
  3607. */
  3608. var filter = {
  3609. geo_polygon: {}
  3610. };
  3611. filter.geo_polygon[fieldName] = {
  3612. points: []
  3613. };
  3614. return {
  3615. /**
  3616. Sets the fields to filter against.
  3617. @member ejs.GeoPolygonFilter
  3618. @param {String} f A valid field name.
  3619. @returns {Object} returns <code>this</code> so that calls can be chained.
  3620. */
  3621. field: function (f) {
  3622. var oldValue = filter.geo_polygon[fieldName];
  3623. if (f == null) {
  3624. return fieldName;
  3625. }
  3626. delete filter.geo_polygon[fieldName];
  3627. fieldName = f;
  3628. filter.geo_polygon[f] = oldValue;
  3629. return this;
  3630. },
  3631. /**
  3632. Sets a series of points that represent a polygon. If passed a
  3633. single <code>GeoPoint</code> object, it is added to the current
  3634. list of points. If passed an array of <code>GeoPoint</code>
  3635. objects it replaces all current values.
  3636. @member ejs.GeoPolygonFilter
  3637. @param {Array} pointsArray the array of points that represent the polygon
  3638. @returns {Object} returns <code>this</code> so that calls can be chained.
  3639. */
  3640. points: function (p) {
  3641. var i, len;
  3642. if (p == null) {
  3643. return filter.geo_polygon[fieldName].points;
  3644. }
  3645. if (isGeoPoint(p)) {
  3646. filter.geo_polygon[fieldName].points.push(p._self());
  3647. } else if (isArray(p)) {
  3648. filter.geo_polygon[fieldName].points = [];
  3649. for (i = 0, len = p.length; i < len; i++) {
  3650. if (!isGeoPoint(p[i])) {
  3651. throw new TypeError('Argument must be Array of GeoPoints');
  3652. }
  3653. filter.geo_polygon[fieldName].points.push(p[i]._self());
  3654. }
  3655. } else {
  3656. throw new TypeError('Argument must be a GeoPoint or Array of GeoPoints');
  3657. }
  3658. return this;
  3659. },
  3660. /**
  3661. If the lat/long points should be normalized to lie within their
  3662. respective normalized ranges.
  3663. Normalized ranges are:
  3664. lon = -180 (exclusive) to 180 (inclusive) range
  3665. lat = -90 to 90 (both inclusive) range
  3666. @member ejs.GeoPolygonFilter
  3667. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  3668. @returns {Object} returns <code>this</code> so that calls can be chained.
  3669. */
  3670. normalize: function (trueFalse) {
  3671. if (trueFalse == null) {
  3672. return filter.geo_polygon.normalize;
  3673. }
  3674. filter.geo_polygon.normalize = trueFalse;
  3675. return this;
  3676. },
  3677. /**
  3678. Sets the filter name.
  3679. @member ejs.GeoPolygonFilter
  3680. @param {String} name A name for the filter.
  3681. @returns {Object} returns <code>this</code> so that calls can be chained.
  3682. */
  3683. name: function (name) {
  3684. if (name == null) {
  3685. return filter.geo_polygon._name;
  3686. }
  3687. filter.geo_polygon._name = name;
  3688. return this;
  3689. },
  3690. /**
  3691. Enable or disable caching of the filter
  3692. @member ejs.GeoPolygonFilter
  3693. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  3694. @returns {Object} returns <code>this</code> so that calls can be chained.
  3695. */
  3696. cache: function (trueFalse) {
  3697. if (trueFalse == null) {
  3698. return filter.geo_polygon._cache;
  3699. }
  3700. filter.geo_polygon._cache = trueFalse;
  3701. return this;
  3702. },
  3703. /**
  3704. Sets the cache key.
  3705. @member ejs.GeoPolygonFilter
  3706. @param {String} key the cache key as a string.
  3707. @returns {Object} returns <code>this</code> so that calls can be chained.
  3708. */
  3709. cacheKey: function (key) {
  3710. if (key == null) {
  3711. return filter.geo_polygon._cache_key;
  3712. }
  3713. filter.geo_polygon._cache_key = key;
  3714. return this;
  3715. },
  3716. /**
  3717. Returns the filter container as a JSON string
  3718. @member ejs.GeoPolygonFilter
  3719. @returns {String} JSON representation of the notFilter object
  3720. */
  3721. toString: function () {
  3722. return JSON.stringify(filter);
  3723. },
  3724. /**
  3725. The type of ejs object. For internal use only.
  3726. @member ejs.GeoPolygonFilter
  3727. @returns {String} the type of object
  3728. */
  3729. _type: function () {
  3730. return 'filter';
  3731. },
  3732. /**
  3733. Returns the filter object.
  3734. @member ejs.GeoPolygonFilter
  3735. @returns {Object} filter object
  3736. */
  3737. _self: function () {
  3738. return filter;
  3739. }
  3740. };
  3741. };
  3742. /**
  3743. @class
  3744. <p>Efficient filtering of documents containing shapes indexed using the
  3745. geo_shape type.</p>
  3746. <p>Much like the geo_shape type, the geo_shape filter uses a grid square
  3747. representation of the filter shape to find those documents which have shapes
  3748. that relate to the filter shape in a specified way. In order to do this, the
  3749. field being queried must be of geo_shape type. The filter will use the same
  3750. PrefixTree configuration as defined for the field.</p>
  3751. @name ejs.GeoShapeFilter
  3752. @desc
  3753. A Filter to find documents with a geo_shapes matching a specific shape.
  3754. */
  3755. ejs.GeoShapeFilter = function (field) {
  3756. /**
  3757. The internal filter object. <code>Use _self()</code>
  3758. @member ejs.GeoShapeFilter
  3759. @property {Object} GeoShapeFilter
  3760. */
  3761. var filter = {
  3762. geo_shape: {}
  3763. };
  3764. filter.geo_shape[field] = {};
  3765. return {
  3766. /**
  3767. Sets the field to filter against.
  3768. @member ejs.GeoShapeFilter
  3769. @param {String} f A valid field name.
  3770. @returns {Object} returns <code>this</code> so that calls can be chained.
  3771. */
  3772. field: function (f) {
  3773. var oldValue = filter.geo_shape[field];
  3774. if (f == null) {
  3775. return field;
  3776. }
  3777. delete filter.geo_shape[field];
  3778. field = f;
  3779. filter.geo_shape[f] = oldValue;
  3780. return this;
  3781. },
  3782. /**
  3783. Sets the shape
  3784. @member ejs.GeoShapeFilter
  3785. @param {String} shape A valid <code>Shape</code> object.
  3786. @returns {Object} returns <code>this</code> so that calls can be chained.
  3787. */
  3788. shape: function (shape) {
  3789. if (shape == null) {
  3790. return filter.geo_shape[field].shape;
  3791. }
  3792. if (filter.geo_shape[field].indexed_shape != null) {
  3793. delete filter.geo_shape[field].indexed_shape;
  3794. }
  3795. filter.geo_shape[field].shape = shape._self();
  3796. return this;
  3797. },
  3798. /**
  3799. Sets the indexed shape. Use this if you already have shape definitions
  3800. already indexed.
  3801. @member ejs.GeoShapeFilter
  3802. @param {String} indexedShape A valid <code>IndexedShape</code> object.
  3803. @returns {Object} returns <code>this</code> so that calls can be chained.
  3804. */
  3805. indexedShape: function (indexedShape) {
  3806. if (indexedShape == null) {
  3807. return filter.geo_shape[field].indexed_shape;
  3808. }
  3809. if (filter.geo_shape[field].shape != null) {
  3810. delete filter.geo_shape[field].shape;
  3811. }
  3812. filter.geo_shape[field].indexed_shape = indexedShape._self();
  3813. return this;
  3814. },
  3815. /**
  3816. Sets the shape relation type. A relationship between a Query Shape
  3817. and indexed Shapes that will be used to determine if a Document
  3818. should be matched or not. Valid values are: intersects, disjoint,
  3819. and within.
  3820. @member ejs.GeoShapeFilter
  3821. @param {String} indexedShape A valid <code>IndexedShape</code> object.
  3822. @returns {Object} returns <code>this</code> so that calls can be chained.
  3823. */
  3824. relation: function (relation) {
  3825. if (relation == null) {
  3826. return filter.geo_shape[field].relation;
  3827. }
  3828. relation = relation.toLowerCase();
  3829. if (relation === 'intersects' || relation === 'disjoint' || relation === 'within') {
  3830. filter.geo_shape[field].relation = relation;
  3831. }
  3832. return this;
  3833. },
  3834. /**
  3835. Sets the filter name.
  3836. @member ejs.GeoShapeFilter
  3837. @param {String} name A name for the filter.
  3838. @returns {Object} returns <code>this</code> so that calls can be chained.
  3839. */
  3840. name: function (name) {
  3841. if (name == null) {
  3842. return filter.geo_shape._name;
  3843. }
  3844. filter.geo_shape._name = name;
  3845. return this;
  3846. },
  3847. /**
  3848. Enable or disable caching of the filter
  3849. @member ejs.GeoShapeFilter
  3850. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  3851. @returns {Object} returns <code>this</code> so that calls can be chained.
  3852. */
  3853. cache: function (trueFalse) {
  3854. if (trueFalse == null) {
  3855. return filter.geo_shape._cache;
  3856. }
  3857. filter.geo_shape._cache = trueFalse;
  3858. return this;
  3859. },
  3860. /**
  3861. Sets the cache key.
  3862. @member ejs.GeoShapeFilter
  3863. @param {String} key the cache key as a string.
  3864. @returns {Object} returns <code>this</code> so that calls can be chained.
  3865. */
  3866. cacheKey: function (key) {
  3867. if (key == null) {
  3868. return filter.geo_shape._cache_key;
  3869. }
  3870. filter.geo_shape._cache_key = key;
  3871. return this;
  3872. },
  3873. /**
  3874. Allows you to serialize this object into a JSON encoded string.
  3875. @member ejs.GeoShapeFilter
  3876. @returns {String} returns this object as a serialized JSON string.
  3877. */
  3878. toString: function () {
  3879. return JSON.stringify(filter);
  3880. },
  3881. /**
  3882. The type of ejs object. For internal use only.
  3883. @member ejs.GeoShapeFilter
  3884. @returns {String} the type of object
  3885. */
  3886. _type: function () {
  3887. return 'filter';
  3888. },
  3889. /**
  3890. Retrieves the internal <code>filter</code> object. This is typically used by
  3891. internal API functions so use with caution.
  3892. @member ejs.GeoShapeFilter
  3893. @returns {String} returns this object's internal <code>filter</code> property.
  3894. */
  3895. _self: function () {
  3896. return filter;
  3897. }
  3898. };
  3899. };
  3900. /**
  3901. @class
  3902. <p>The has_child filter results in parent documents that have child docs
  3903. matching the query being returned.</p>
  3904. @name ejs.HasChildFilter
  3905. @desc
  3906. Returns results that have child documents matching the filter.
  3907. @param {Object} qry A valid query object.
  3908. @param {String} type The child type
  3909. */
  3910. ejs.HasChildFilter = function (qry, type) {
  3911. if (!isQuery(qry)) {
  3912. throw new TypeError('No Query object found');
  3913. }
  3914. /**
  3915. The internal query object. <code>Use _self()</code>
  3916. @member ejs.HasChildFilter
  3917. @property {Object} query
  3918. */
  3919. var filter = {
  3920. has_child: {
  3921. query: qry._self(),
  3922. type: type
  3923. }
  3924. };
  3925. return {
  3926. /**
  3927. Sets the query
  3928. @member ejs.HasChildFilter
  3929. @param {Query} q A valid Query object
  3930. @returns {Object} returns <code>this</code> so that calls can be chained.
  3931. */
  3932. query: function (q) {
  3933. if (q == null) {
  3934. return filter.has_child.query;
  3935. }
  3936. if (!isQuery(q)) {
  3937. throw new TypeError('Argument must be a Query object');
  3938. }
  3939. filter.has_child.query = q._self();
  3940. return this;
  3941. },
  3942. /**
  3943. Sets the child document type to search against
  3944. @member ejs.HasChildFilter
  3945. @param {String} t A valid type name
  3946. @returns {Object} returns <code>this</code> so that calls can be chained.
  3947. */
  3948. type: function (t) {
  3949. if (t == null) {
  3950. return filter.has_child.type;
  3951. }
  3952. filter.has_child.type = t;
  3953. return this;
  3954. },
  3955. /**
  3956. Sets the scope of the filter. A scope allows to run facets on the
  3957. same scope name that will work against the child documents.
  3958. @member ejs.HasChildFilter
  3959. @param {String} s The scope name as a string.
  3960. @returns {Object} returns <code>this</code> so that calls can be chained.
  3961. */
  3962. scope: function (s) {
  3963. if (s == null) {
  3964. return filter.has_child._scope;
  3965. }
  3966. filter.has_child._scope = s;
  3967. return this;
  3968. },
  3969. /**
  3970. Sets the filter name.
  3971. @member ejs.HasChildFilter
  3972. @param {String} name A name for the filter.
  3973. @returns {Object} returns <code>this</code> so that calls can be chained.
  3974. */
  3975. name: function (name) {
  3976. if (name == null) {
  3977. return filter.has_child._name;
  3978. }
  3979. filter.has_child._name = name;
  3980. return this;
  3981. },
  3982. /**
  3983. Allows you to serialize this object into a JSON encoded string.
  3984. @member ejs.HasChildFilter
  3985. @returns {String} returns this object as a serialized JSON string.
  3986. */
  3987. toString: function () {
  3988. return JSON.stringify(filter);
  3989. },
  3990. /**
  3991. The type of ejs object. For internal use only.
  3992. @member ejs.HasChildFilter
  3993. @returns {String} the type of object
  3994. */
  3995. _type: function () {
  3996. return 'filter';
  3997. },
  3998. /**
  3999. Retrieves the internal <code>filter</code> object. This is typically used by
  4000. internal API functions so use with caution.
  4001. @member ejs.HasChildFilter
  4002. @returns {String} returns this object's internal <code>filter</code> property.
  4003. */
  4004. _self: function () {
  4005. return filter;
  4006. }
  4007. };
  4008. };
  4009. /**
  4010. @class
  4011. <p>The has_parent results in child documents that have parent docs matching
  4012. the query being returned.</p>
  4013. @name ejs.HasParentFilter
  4014. @desc
  4015. Returns results that have parent documents matching the filter.
  4016. @param {Object} qry A valid query object.
  4017. @param {String} parentType The child type
  4018. */
  4019. ejs.HasParentFilter = function (qry, parentType) {
  4020. if (!isQuery(qry)) {
  4021. throw new TypeError('No Query object found');
  4022. }
  4023. /**
  4024. The internal filter object. <code>Use _self()</code>
  4025. @member ejs.HasParentFilter
  4026. @property {Object} query
  4027. */
  4028. var filter = {
  4029. has_parent: {
  4030. query: qry._self(),
  4031. parent_type: parentType
  4032. }
  4033. };
  4034. return {
  4035. /**
  4036. Sets the query
  4037. @member ejs.HasParentFilter
  4038. @param {Object} q A valid Query object
  4039. @returns {Object} returns <code>this</code> so that calls can be chained.
  4040. */
  4041. query: function (q) {
  4042. if (q == null) {
  4043. return filter.has_parent.query;
  4044. }
  4045. if (!isQuery(q)) {
  4046. throw new TypeError('Argument must be a Query object');
  4047. }
  4048. filter.has_parent.query = q._self();
  4049. return this;
  4050. },
  4051. /**
  4052. Sets the child document type to search against
  4053. @member ejs.HasParentFilter
  4054. @param {String} t A valid type name
  4055. @returns {Object} returns <code>this</code> so that calls can be chained.
  4056. */
  4057. parentType: function (t) {
  4058. if (t == null) {
  4059. return filter.has_parent.parent_type;
  4060. }
  4061. filter.has_parent.parent_type = t;
  4062. return this;
  4063. },
  4064. /**
  4065. Sets the scope of the filter. A scope allows to run facets on the
  4066. same scope name that will work against the parent documents.
  4067. @member ejs.HasParentFilter
  4068. @param {String} s The scope name as a string.
  4069. @returns {Object} returns <code>this</code> so that calls can be chained.
  4070. */
  4071. scope: function (s) {
  4072. if (s == null) {
  4073. return filter.has_parent._scope;
  4074. }
  4075. filter.has_parent._scope = s;
  4076. return this;
  4077. },
  4078. /**
  4079. Sets the filter name.
  4080. @member ejs.HasParentFilter
  4081. @param {String} name A name for the filter.
  4082. @returns {Object} returns <code>this</code> so that calls can be chained.
  4083. */
  4084. name: function (name) {
  4085. if (name == null) {
  4086. return filter.has_parent._name;
  4087. }
  4088. filter.has_parent._name = name;
  4089. return this;
  4090. },
  4091. /**
  4092. Allows you to serialize this object into a JSON encoded string.
  4093. @member ejs.HasParentFilter
  4094. @returns {String} returns this object as a serialized JSON string.
  4095. */
  4096. toString: function () {
  4097. return JSON.stringify(filter);
  4098. },
  4099. /**
  4100. The type of ejs object. For internal use only.
  4101. @member ejs.HasParentFilter
  4102. @returns {String} the type of object
  4103. */
  4104. _type: function () {
  4105. return 'filter';
  4106. },
  4107. /**
  4108. Retrieves the internal <code>filter</code> object. This is typically used by
  4109. internal API functions so use with caution.
  4110. @member ejs.HasParentFilter
  4111. @returns {String} returns this object's internal <code>filter</code> property.
  4112. */
  4113. _self: function () {
  4114. return filter;
  4115. }
  4116. };
  4117. };
  4118. /**
  4119. @class
  4120. <p>Filters documents that only have the provided ids. Note, this filter
  4121. does not require the _id field to be indexed since it works using the
  4122. _uid field.</p>
  4123. @name ejs.IdsFilter
  4124. @desc
  4125. Matches documents with the specified id(s).
  4126. @param {Array || String} ids A single document id or a list of document ids.
  4127. */
  4128. ejs.IdsFilter = function (ids) {
  4129. /**
  4130. The internal filter object. <code>Use get()</code>
  4131. @member ejs.IdsFilter
  4132. @property {Object} filter
  4133. */
  4134. var filter = {
  4135. ids: {}
  4136. };
  4137. if (isString(ids)) {
  4138. filter.ids.values = [ids];
  4139. } else if (isArray(ids)) {
  4140. filter.ids.values = ids;
  4141. } else {
  4142. throw new TypeError('Argument must be a string or an array');
  4143. }
  4144. return {
  4145. /**
  4146. Sets the values array or adds a new value. if val is a string, it
  4147. is added to the list of existing document ids. If val is an
  4148. array it is set as the document values and replaces any existing values.
  4149. @member ejs.IdsFilter
  4150. @param {Array || String} val An single document id or an array of document ids.
  4151. @returns {Object} returns <code>this</code> so that calls can be chained.
  4152. */
  4153. values: function (val) {
  4154. if (val == null) {
  4155. return filter.ids.values;
  4156. }
  4157. if (isString(val)) {
  4158. filter.ids.values.push(val);
  4159. } else if (isArray(val)) {
  4160. filter.ids.values = val;
  4161. } else {
  4162. throw new TypeError('Argument must be a string or an array');
  4163. }
  4164. return this;
  4165. },
  4166. /**
  4167. Sets the type as a single type or an array of types. If type is a
  4168. string, it is added to the list of existing types. If type is an
  4169. array, it is set as the types and overwrites an existing types. This
  4170. parameter is optional.
  4171. @member ejs.IdsFilter
  4172. @param {Array || String} type A type or a list of types
  4173. @returns {Object} returns <code>this</code> so that calls can be chained.
  4174. */
  4175. type: function (type) {
  4176. if (filter.ids.type == null) {
  4177. filter.ids.type = [];
  4178. }
  4179. if (type == null) {
  4180. return filter.ids.type;
  4181. }
  4182. if (isString(type)) {
  4183. filter.ids.type.push(type);
  4184. } else if (isArray(type)) {
  4185. filter.ids.type = type;
  4186. } else {
  4187. throw new TypeError('Argument must be a string or an array');
  4188. }
  4189. return this;
  4190. },
  4191. /**
  4192. Sets the filter name.
  4193. @member ejs.IdsFilter
  4194. @param {String} name A name for the filter.
  4195. @returns {Object} returns <code>this</code> so that calls can be chained.
  4196. */
  4197. name: function (name) {
  4198. if (name == null) {
  4199. return filter.ids._name;
  4200. }
  4201. filter.ids._name = name;
  4202. return this;
  4203. },
  4204. /**
  4205. Allows you to serialize this object into a JSON encoded string.
  4206. @member ejs.IdsFilter
  4207. @returns {String} returns this object as a serialized JSON string.
  4208. */
  4209. toString: function () {
  4210. return JSON.stringify(filter);
  4211. },
  4212. /**
  4213. The type of ejs object. For internal use only.
  4214. @member ejs.IdsFilter
  4215. @returns {String} the type of object
  4216. */
  4217. _type: function () {
  4218. return 'filter';
  4219. },
  4220. /**
  4221. Retrieves the internal <code>filter</code> object. This is typically used by
  4222. internal API functions so use with caution.
  4223. @member ejs.IdsFilter
  4224. @returns {String} returns this object's internal <code>filter</code> property.
  4225. */
  4226. _self: function () {
  4227. return filter;
  4228. }
  4229. };
  4230. };
  4231. /**
  4232. @class
  4233. <p>The indices filter can be used when executed across multiple indices,
  4234. allowing to have a filter that executes only when executed on an index that
  4235. matches a specific list of indices, and another filter that executes when it
  4236. is executed on an index that does not match the listed indices.</p>
  4237. @name ejs.IndicesFilter
  4238. @desc
  4239. A configurable filter that is dependent on the index name.
  4240. @param {Object} fltr A valid filter object.
  4241. @param {String || Array} indices a single index name or an array of index
  4242. names.
  4243. */
  4244. ejs.IndicesFilter = function (fltr, indices) {
  4245. if (!isFilter(fltr)) {
  4246. throw new TypeError('Argument must be a Filter');
  4247. }
  4248. /**
  4249. The internal filter object. <code>Use _self()</code>
  4250. @member ejs.IndicesFilter
  4251. @property {Object} filter
  4252. */
  4253. var filter = {
  4254. indices: {
  4255. filter: fltr._self()
  4256. }
  4257. };
  4258. if (isString(indices)) {
  4259. filter.indices.indices = [indices];
  4260. } else if (isArray(indices)) {
  4261. filter.indices.indices = indices;
  4262. } else {
  4263. throw new TypeError('Argument must be a string or array');
  4264. }
  4265. return {
  4266. /**
  4267. Sets the indicies the filter should match. When passed a string,
  4268. the index name is added to the current list of indices. When passed
  4269. an array, it overwites all current indices.
  4270. @member ejs.IndicesFilter
  4271. @param {String || Array} i A single index name or an array of index names.
  4272. @returns {Object} returns <code>this</code> so that calls can be chained.
  4273. */
  4274. indices: function (i) {
  4275. if (i == null) {
  4276. return filter.indices.indices;
  4277. }
  4278. if (isString(i)) {
  4279. filter.indices.indices.push(i);
  4280. } else if (isArray(i)) {
  4281. filter.indices.indices = i;
  4282. } else {
  4283. throw new TypeError('Argument must be a string or array');
  4284. }
  4285. return this;
  4286. },
  4287. /**
  4288. Sets the filter to be used when executing on one of the indicies
  4289. specified.
  4290. @member ejs.IndicesFilter
  4291. @param {Object} f A valid Filter object
  4292. @returns {Object} returns <code>this</code> so that calls can be chained.
  4293. */
  4294. filter: function (f) {
  4295. if (f == null) {
  4296. return filter.indices.filter;
  4297. }
  4298. if (!isFilter(f)) {
  4299. throw new TypeError('Argument must be a Filter');
  4300. }
  4301. filter.indices.filter = f._self();
  4302. return this;
  4303. },
  4304. /**
  4305. Sets the filter to be used on an index that does not match an index
  4306. name in the indices list. Can also be set to "none" to not match any
  4307. documents or "all" to match all documents.
  4308. @member ejs.IndicesFilter
  4309. @param {Object || String} f A valid Filter object or "none" or "all"
  4310. @returns {Object} returns <code>this</code> so that calls can be chained.
  4311. */
  4312. noMatchFilter: function (f) {
  4313. if (f == null) {
  4314. return filter.indices.no_match_filter;
  4315. }
  4316. if (isString(f)) {
  4317. f = f.toLowerCase();
  4318. if (f === 'none' || f === 'all') {
  4319. filter.indices.no_match_filter = f;
  4320. }
  4321. } else if (isFilter(f)) {
  4322. filter.indices.no_match_filter = f._self();
  4323. } else {
  4324. throw new TypeError('Argument must be string or Filter');
  4325. }
  4326. return this;
  4327. },
  4328. /**
  4329. Allows you to serialize this object into a JSON encoded string.
  4330. @member ejs.IndicesFilter
  4331. @returns {String} returns this object as a serialized JSON string.
  4332. */
  4333. toString: function () {
  4334. return JSON.stringify(filter);
  4335. },
  4336. /**
  4337. The type of ejs object. For internal use only.
  4338. @member ejs.IndicesFilter
  4339. @returns {String} the type of object
  4340. */
  4341. _type: function () {
  4342. return 'filter';
  4343. },
  4344. /**
  4345. Retrieves the internal <code>filter</code> object. This is typically used by
  4346. internal API functions so use with caution.
  4347. @member ejs.IndicesFilter
  4348. @returns {String} returns this object's internal <code>filter</code> property.
  4349. */
  4350. _self: function () {
  4351. return filter;
  4352. }
  4353. };
  4354. };
  4355. /**
  4356. @class
  4357. <p>A limit filter limits the number of documents (per shard) to execute on.</p>
  4358. @name ejs.LimitFilter
  4359. @desc
  4360. Limits the number of documents to execute on.
  4361. @param {Integer} limit The number of documents to execute on.
  4362. */
  4363. ejs.LimitFilter = function (limit) {
  4364. /**
  4365. The internal filter object. <code>Use get()</code>
  4366. @member ejs.LimitFilter
  4367. @property {Object} filter
  4368. */
  4369. var filter = {
  4370. limit: {
  4371. value: limit
  4372. }
  4373. };
  4374. return {
  4375. /**
  4376. Sets the limit value.
  4377. @member ejs.LimitFilter
  4378. @param {Integer} val An The number of documents to execute on.
  4379. @returns {Object} returns <code>this</code> so that calls can be chained.
  4380. */
  4381. value: function (val) {
  4382. if (val == null) {
  4383. return filter.limit.value;
  4384. }
  4385. if (!isNumber(val)) {
  4386. throw new TypeError('Argument must be a numeric value');
  4387. }
  4388. filter.limit.value = val;
  4389. return this;
  4390. },
  4391. /**
  4392. Allows you to serialize this object into a JSON encoded string.
  4393. @member ejs.LimitFilter
  4394. @returns {String} returns this object as a serialized JSON string.
  4395. */
  4396. toString: function () {
  4397. return JSON.stringify(filter);
  4398. },
  4399. /**
  4400. The type of ejs object. For internal use only.
  4401. @member ejs.LimitFilter
  4402. @returns {String} the type of object
  4403. */
  4404. _type: function () {
  4405. return 'filter';
  4406. },
  4407. /**
  4408. Retrieves the internal <code>filter</code> object. This is typically used by
  4409. internal API functions so use with caution.
  4410. @member ejs.LimitFilter
  4411. @returns {String} returns this object's internal <code>filter</code> property.
  4412. */
  4413. _self: function () {
  4414. return filter;
  4415. }
  4416. };
  4417. };
  4418. /**
  4419. @class
  4420. <p>This filter can be used to match on all the documents
  4421. in a given set of collections and/or types.</p>
  4422. @name ejs.MatchAllFilter
  4423. @desc
  4424. <p>A filter that matches on all documents</p>
  4425. */
  4426. ejs.MatchAllFilter = function () {
  4427. /**
  4428. The internal Query object. Use <code>get()</code>.
  4429. @member ejs.MatchAllFilter
  4430. @property {Object} filter
  4431. */
  4432. var filter = {
  4433. match_all: {}
  4434. };
  4435. return {
  4436. /**
  4437. Serializes the internal <em>filter</em> object as a JSON string.
  4438. @member ejs.MatchAllFilter
  4439. @returns {String} Returns a JSON representation of the object.
  4440. */
  4441. toString: function () {
  4442. return JSON.stringify(filter);
  4443. },
  4444. /**
  4445. The type of ejs object. For internal use only.
  4446. @member ejs.MatchAllFilter
  4447. @returns {String} the type of object
  4448. */
  4449. _type: function () {
  4450. return 'filter';
  4451. },
  4452. /**
  4453. This method is used to retrieve the raw filter object. It's designed
  4454. for internal use when composing and serializing queries.
  4455. @member ejs.MatchAllFilter
  4456. @returns {Object} Returns the object's <em>filter</em> property.
  4457. */
  4458. _self: function () {
  4459. return filter;
  4460. }
  4461. };
  4462. };
  4463. /**
  4464. @class
  4465. <p>An missingFilter matches documents where the specified field contains no legitimate value.</p>
  4466. @name ejs.MissingFilter
  4467. @desc
  4468. Filters documents where a specific field has no value present.
  4469. @param {String} fieldName the field name to check for missing values.
  4470. */
  4471. ejs.MissingFilter = function (fieldName) {
  4472. /**
  4473. The internal filter object. Use <code>get()</code>
  4474. @member ejs.MissingFilter
  4475. @property {Object} filter
  4476. */
  4477. var filter = {
  4478. missing: {
  4479. field: fieldName
  4480. }
  4481. };
  4482. return {
  4483. /**
  4484. Sets the field to check for missing values.
  4485. @member ejs.MissingFilter
  4486. @param {String} name A name of the field.
  4487. @returns {Object} returns <code>this</code> so that calls can be chained.
  4488. */
  4489. field: function (name) {
  4490. if (name == null) {
  4491. return filter.missing.field;
  4492. }
  4493. filter.missing.field = name;
  4494. return this;
  4495. },
  4496. /**
  4497. Checks if the field doesn't exist.
  4498. @member ejs.MissingFilter
  4499. @param {Boolean} trueFalse True to check if the field doesn't exist.
  4500. @returns {Object} returns <code>this</code> so that calls can be chained.
  4501. */
  4502. existence: function (trueFalse) {
  4503. if (trueFalse == null) {
  4504. return filter.missing.existence;
  4505. }
  4506. filter.missing.existence = trueFalse;
  4507. return this;
  4508. },
  4509. /**
  4510. Checks if the field has null values.
  4511. @member ejs.MissingFilter
  4512. @param {Boolean} trueFalse True to check if the field has nulls.
  4513. @returns {Object} returns <code>this</code> so that calls can be chained.
  4514. */
  4515. nullValue: function (trueFalse) {
  4516. if (trueFalse == null) {
  4517. return filter.missing.null_value;
  4518. }
  4519. filter.missing.null_value = trueFalse;
  4520. return this;
  4521. },
  4522. /**
  4523. Sets the filter name.
  4524. @member ejs.MissingFilter
  4525. @param {String} name A name for the filter.
  4526. @returns {Object} returns <code>this</code> so that calls can be chained.
  4527. */
  4528. name: function (name) {
  4529. if (name == null) {
  4530. return filter.missing._name;
  4531. }
  4532. filter.missing._name = name;
  4533. return this;
  4534. },
  4535. /**
  4536. Returns the filter container as a JSON string
  4537. @member ejs.MissingFilter
  4538. @returns {String} JSON representation of the missingFilter object
  4539. */
  4540. toString: function () {
  4541. return JSON.stringify(filter);
  4542. },
  4543. /**
  4544. The type of ejs object. For internal use only.
  4545. @member ejs.MissingFilter
  4546. @returns {String} the type of object
  4547. */
  4548. _type: function () {
  4549. return 'filter';
  4550. },
  4551. /**
  4552. Returns the filter object.
  4553. @member ejs.MissingFilter
  4554. @returns {Object} filter object
  4555. */
  4556. _self: function () {
  4557. return filter;
  4558. }
  4559. };
  4560. };
  4561. /**
  4562. @class
  4563. <p>Nested filters allow you to search against content within objects that are
  4564. embedded inside of other objects. It is similar to <code>XPath</code>
  4565. expressions in <code>XML</code> both conceptually and syntactically.</p>
  4566. <p>
  4567. The filter is executed against the nested objects / docs as if they were
  4568. indexed as separate docs and resulting in the root
  4569. parent doc (or parent nested mapping).</p>
  4570. @name ejs.NestedFilter
  4571. @desc
  4572. <p>Constructs a filter that is capable of executing a filter against objects
  4573. nested within a document.</p>
  4574. @param {String} path The nested object path.
  4575. */
  4576. ejs.NestedFilter = function (path) {
  4577. /**
  4578. The internal Filter object. Use <code>_self()</code>.
  4579. @member ejs.NestedFilter
  4580. @property {Object} filter
  4581. */
  4582. var filter = {
  4583. nested: {
  4584. path: path
  4585. }
  4586. };
  4587. return {
  4588. /**
  4589. Sets the root context for the nested filter.
  4590. @member ejs.NestedFilter
  4591. @param {String} p The path defining the root for the nested filter.
  4592. @returns {Object} returns <code>this</code> so that calls can be chained.
  4593. */
  4594. path: function (p) {
  4595. if (p == null) {
  4596. return filter.nested.path;
  4597. }
  4598. filter.nested.path = p;
  4599. return this;
  4600. },
  4601. /**
  4602. Sets the nested query to be executed.
  4603. @member ejs.NestedFilter
  4604. @param {Query} oQuery A valid Query object
  4605. @returns {Object} returns <code>this</code> so that calls can be chained.
  4606. */
  4607. query: function (oQuery) {
  4608. if (oQuery == null) {
  4609. return filter.nested.query;
  4610. }
  4611. if (!isQuery(oQuery)) {
  4612. throw new TypeError('Argument must be a Query object');
  4613. }
  4614. filter.nested.query = oQuery._self();
  4615. return this;
  4616. },
  4617. /**
  4618. Sets the nested filter to be executed.
  4619. @member ejs.NestedFilter
  4620. @param {Object} oFilter A valid Filter object
  4621. @returns {Object} returns <code>this</code> so that calls can be chained.
  4622. */
  4623. filter: function (oFilter) {
  4624. if (oFilter == null) {
  4625. return filter.nested.filter;
  4626. }
  4627. if (!isFilter(oFilter)) {
  4628. throw new TypeError('Argument must be a Filter object');
  4629. }
  4630. filter.nested.filter = oFilter._self();
  4631. return this;
  4632. },
  4633. /**
  4634. Sets the boost value of the nested <code>Query</code>.
  4635. @member ejs.NestedFilter
  4636. @param {Double} boost A positive <code>double</code> value.
  4637. @returns {Object} returns <code>this</code> so that calls can be chained.
  4638. */
  4639. boost: function (boost) {
  4640. if (boost == null) {
  4641. return filter.nested.boost;
  4642. }
  4643. filter.nested.boost = boost;
  4644. return this;
  4645. },
  4646. /**
  4647. Sets the scope of the filter. A scope allows to run facets on the
  4648. same scope name that will work against the nested documents.
  4649. @member ejs.NestedFilter
  4650. @param {String} s The scope name as a string.
  4651. @returns {Object} returns <code>this</code> so that calls can be chained.
  4652. */
  4653. scope: function (s) {
  4654. if (s == null) {
  4655. return filter.nested._scope;
  4656. }
  4657. filter.nested._scope = s;
  4658. return this;
  4659. },
  4660. /**
  4661. Sets the filter name.
  4662. @member ejs.NestedFilter
  4663. @param {String} name A name for the filter.
  4664. @returns {Object} returns <code>this</code> so that calls can be chained.
  4665. */
  4666. name: function (name) {
  4667. if (name == null) {
  4668. return filter.nested._name;
  4669. }
  4670. filter.nested._name = name;
  4671. return this;
  4672. },
  4673. /**
  4674. Enable or disable caching of the filter
  4675. @member ejs.NestedFilter
  4676. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  4677. @returns {Object} returns <code>this</code> so that calls can be chained.
  4678. */
  4679. cache: function (trueFalse) {
  4680. if (trueFalse == null) {
  4681. return filter.nested._cache;
  4682. }
  4683. filter.nested._cache = trueFalse;
  4684. return this;
  4685. },
  4686. /**
  4687. Sets the cache key.
  4688. @member ejs.NestedFilter
  4689. @param {String} key the cache key as a string.
  4690. @returns {Object} returns <code>this</code> so that calls can be chained.
  4691. */
  4692. cacheKey: function (key) {
  4693. if (key == null) {
  4694. return filter.nested._cache_key;
  4695. }
  4696. filter.nested._cache_key = key;
  4697. return this;
  4698. },
  4699. /**
  4700. Serializes the internal <em>filter</em> object as a JSON string.
  4701. @member ejs.NestedFilter
  4702. @returns {String} Returns a JSON representation of the termFilter object.
  4703. */
  4704. toString: function () {
  4705. return JSON.stringify(filter);
  4706. },
  4707. /**
  4708. The type of ejs object. For internal use only.
  4709. @member ejs.NestedFilter
  4710. @returns {String} the type of object
  4711. */
  4712. _type: function () {
  4713. return 'filter';
  4714. },
  4715. /**
  4716. This method is used to retrieve the raw filter object. It's designed
  4717. for internal use when composing and serializing filters.
  4718. @member ejs.NestedFilter
  4719. @returns {Object} Returns the object's <em>filter</em> property.
  4720. */
  4721. _self: function () {
  4722. return filter;
  4723. }
  4724. };
  4725. };
  4726. /**
  4727. @class
  4728. <p>A container Filter that excludes the documents matched by the
  4729. contained filter.</p>
  4730. @name ejs.NotFilter
  4731. @desc
  4732. Container filter that excludes the matched documents of the contained filter.
  4733. @param {Object} oFilter a valid Filter object such as a termFilter, etc.
  4734. */
  4735. ejs.NotFilter = function (oFilter) {
  4736. if (!isFilter(oFilter)) {
  4737. throw new TypeError('Argument must be a Filter');
  4738. }
  4739. /**
  4740. The internal filter object. Use <code>_self()</code>
  4741. @member ejs.NotFilter
  4742. @property {Object} filter
  4743. */
  4744. var filter = {
  4745. not: oFilter._self()
  4746. };
  4747. return {
  4748. /**
  4749. Sets the filter
  4750. @member ejs.NotFilter
  4751. @param {Object} fltr A valid filter object such as a termFilter, etc.
  4752. @returns {Object} returns <code>this</code> so that calls can be chained.
  4753. */
  4754. filter: function (fltr) {
  4755. if (fltr == null) {
  4756. return filter.not;
  4757. }
  4758. if (!isFilter(fltr)) {
  4759. throw new TypeError('Argument must be a Filter');
  4760. }
  4761. filter.not = fltr._self();
  4762. return this;
  4763. },
  4764. /**
  4765. Sets the filter name.
  4766. @member ejs.NotFilter
  4767. @param {String} name A name for the filter.
  4768. @returns {Object} returns <code>this</code> so that calls can be chained.
  4769. */
  4770. name: function (name) {
  4771. if (name == null) {
  4772. return filter.not._name;
  4773. }
  4774. filter.not._name = name;
  4775. return this;
  4776. },
  4777. /**
  4778. Enable or disable caching of the filter
  4779. @member ejs.NotFilter
  4780. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  4781. @returns {Object} returns <code>this</code> so that calls can be chained.
  4782. */
  4783. cache: function (trueFalse) {
  4784. if (trueFalse == null) {
  4785. return filter.not._cache;
  4786. }
  4787. filter.not._cache = trueFalse;
  4788. return this;
  4789. },
  4790. /**
  4791. Sets the cache key.
  4792. @member ejs.NotFilter
  4793. @param {String} key the cache key as a string.
  4794. @returns {Object} returns <code>this</code> so that calls can be chained.
  4795. */
  4796. cacheKey: function (key) {
  4797. if (key == null) {
  4798. return filter.not._cache_key;
  4799. }
  4800. filter.not._cache_key = key;
  4801. return this;
  4802. },
  4803. /**
  4804. Returns the filter container as a JSON string
  4805. @member ejs.NotFilter
  4806. @returns {String} JSON representation of the notFilter object
  4807. */
  4808. toString: function () {
  4809. return JSON.stringify(filter);
  4810. },
  4811. /**
  4812. The type of ejs object. For internal use only.
  4813. @member ejs.NotFilter
  4814. @returns {String} the type of object
  4815. */
  4816. _type: function () {
  4817. return 'filter';
  4818. },
  4819. /**
  4820. Returns the filter object.
  4821. @member ejs.NotFilter
  4822. @returns {Object} filter object
  4823. */
  4824. _self: function () {
  4825. return filter;
  4826. }
  4827. };
  4828. };
  4829. /**
  4830. @class
  4831. <p>Filters documents with fields that have values within a certain numeric
  4832. range. Similar to range filter, except that it works only with numeric
  4833. values, and the filter execution works differently.</p>
  4834. <p>The numeric range filter works by loading all the relevant field values
  4835. into memory, and checking for the relevant docs if they satisfy the range
  4836. requirements. This requires more memory since the numeric range data are
  4837. loaded to memory, but can provide a significant increase in performance.</p>
  4838. <p>Note, if the relevant field values have already been loaded to memory,
  4839. for example because it was used in facets or was sorted on, then this
  4840. filter should be used.</p>
  4841. @name ejs.NumericRangeFilter
  4842. @desc
  4843. A Filter that only accepts numeric values within a specified range.
  4844. @param {string} fieldName The name of the field to filter on.
  4845. */
  4846. ejs.NumericRangeFilter = function (fieldName) {
  4847. /**
  4848. The internal filter object. Use <code>get()</code>
  4849. @member ejs.NumericRangeFilter
  4850. @property {Object} filter
  4851. */
  4852. var filter = {
  4853. numeric_range: {}
  4854. };
  4855. filter.numeric_range[fieldName] = {};
  4856. return {
  4857. /**
  4858. Returns the field name used to create this object.
  4859. @member ejs.NumericRangeFilter
  4860. @param {String} field the field name
  4861. @returns {Object} returns <code>this</code> so that calls can be
  4862. chained. Returns {String}, field name when field is not specified.
  4863. */
  4864. field: function (field) {
  4865. var oldValue = filter.numeric_range[fieldName];
  4866. if (field == null) {
  4867. return fieldName;
  4868. }
  4869. delete filter.numeric_range[fieldName];
  4870. fieldName = field;
  4871. filter.numeric_range[fieldName] = oldValue;
  4872. return this;
  4873. },
  4874. /**
  4875. Sets the endpoint for the current range.
  4876. @member ejs.NumericRangeFilter
  4877. @param {Number} startPoint A numeric value representing the start of the range
  4878. @returns {Object} returns <code>this</code> so that calls can be chained.
  4879. */
  4880. from: function (from) {
  4881. if (from == null) {
  4882. return filter.numeric_range[fieldName].from;
  4883. }
  4884. if (!isNumber(from)) {
  4885. throw new TypeError('Argument must be a numeric value');
  4886. }
  4887. filter.numeric_range[fieldName].from = from;
  4888. return this;
  4889. },
  4890. /**
  4891. Sets the endpoint for the current range.
  4892. @member ejs.NumericRangeFilter
  4893. @param {Number} endPoint A numeric value representing the end of the range
  4894. @returns {Object} returns <code>this</code> so that calls can be chained.
  4895. */
  4896. to: function (to) {
  4897. if (to == null) {
  4898. return filter.numeric_range[fieldName].to;
  4899. }
  4900. if (!isNumber(to)) {
  4901. throw new TypeError('Argument must be a numeric value');
  4902. }
  4903. filter.numeric_range[fieldName].to = to;
  4904. return this;
  4905. },
  4906. /**
  4907. Should the first from (if set) be inclusive or not.
  4908. Defaults to true
  4909. @member ejs.NumericRangeFilter
  4910. @param {Boolean} trueFalse true to include, false to exclude
  4911. @returns {Object} returns <code>this</code> so that calls can be chained.
  4912. */
  4913. includeLower: function (trueFalse) {
  4914. if (trueFalse == null) {
  4915. return filter.numeric_range[fieldName].include_lower;
  4916. }
  4917. filter.numeric_range[fieldName].include_lower = trueFalse;
  4918. return this;
  4919. },
  4920. /**
  4921. Should the last to (if set) be inclusive or not. Defaults to true.
  4922. @member ejs.NumericRangeFilter
  4923. @param {Boolean} trueFalse true to include, false to exclude
  4924. @returns {Object} returns <code>this</code> so that calls can be chained.
  4925. */
  4926. includeUpper: function (trueFalse) {
  4927. if (trueFalse == null) {
  4928. return filter.numeric_range[fieldName].include_upper;
  4929. }
  4930. filter.numeric_range[fieldName].include_upper = trueFalse;
  4931. return this;
  4932. },
  4933. /**
  4934. Greater than value. Same as setting from to the value, and
  4935. include_lower to false,
  4936. @member ejs.NumericRangeFilter
  4937. @param {Variable Type} val the value, type depends on field type
  4938. @returns {Object} returns <code>this</code> so that calls can be chained.
  4939. */
  4940. gt: function (val) {
  4941. if (val == null) {
  4942. return filter.numeric_range[fieldName].gt;
  4943. }
  4944. if (!isNumber(val)) {
  4945. throw new TypeError('Argument must be a numeric value');
  4946. }
  4947. filter.numeric_range[fieldName].gt = val;
  4948. return this;
  4949. },
  4950. /**
  4951. Greater than or equal to value. Same as setting from to the value,
  4952. and include_lower to true.
  4953. @member ejs.NumericRangeFilter
  4954. @param {Variable Type} val the value, type depends on field type
  4955. @returns {Object} returns <code>this</code> so that calls can be chained.
  4956. */
  4957. gte: function (val) {
  4958. if (val == null) {
  4959. return filter.numeric_range[fieldName].gte;
  4960. }
  4961. if (!isNumber(val)) {
  4962. throw new TypeError('Argument must be a numeric value');
  4963. }
  4964. filter.numeric_range[fieldName].gte = val;
  4965. return this;
  4966. },
  4967. /**
  4968. Less than value. Same as setting to to the value, and include_upper
  4969. to false.
  4970. @member ejs.NumericRangeFilter
  4971. @param {Variable Type} val the value, type depends on field type
  4972. @returns {Object} returns <code>this</code> so that calls can be chained.
  4973. */
  4974. lt: function (val) {
  4975. if (val == null) {
  4976. return filter.numeric_range[fieldName].lt;
  4977. }
  4978. if (!isNumber(val)) {
  4979. throw new TypeError('Argument must be a numeric value');
  4980. }
  4981. filter.numeric_range[fieldName].lt = val;
  4982. return this;
  4983. },
  4984. /**
  4985. Less than or equal to value. Same as setting to to the value,
  4986. and include_upper to true.
  4987. @member ejs.NumericRangeFilter
  4988. @param {Variable Type} val the value, type depends on field type
  4989. @returns {Object} returns <code>this</code> so that calls can be chained.
  4990. */
  4991. lte: function (val) {
  4992. if (val == null) {
  4993. return filter.numeric_range[fieldName].lte;
  4994. }
  4995. if (!isNumber(val)) {
  4996. throw new TypeError('Argument must be a numeric value');
  4997. }
  4998. filter.numeric_range[fieldName].lte = val;
  4999. return this;
  5000. },
  5001. /**
  5002. Sets the filter name.
  5003. @member ejs.NumericRangeFilter
  5004. @param {String} name A name for the filter.
  5005. @returns {Object} returns <code>this</code> so that calls can be chained.
  5006. */
  5007. name: function (name) {
  5008. if (name == null) {
  5009. return filter.numeric_range._name;
  5010. }
  5011. filter.numeric_range._name = name;
  5012. return this;
  5013. },
  5014. /**
  5015. Enable or disable caching of the filter
  5016. @member ejs.NumericRangeFilter
  5017. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5018. @returns {Object} returns <code>this</code> so that calls can be chained.
  5019. */
  5020. cache: function (trueFalse) {
  5021. if (trueFalse == null) {
  5022. return filter.numeric_range._cache;
  5023. }
  5024. filter.numeric_range._cache = trueFalse;
  5025. return this;
  5026. },
  5027. /**
  5028. Sets the cache key.
  5029. @member ejs.NumericRangeFilter
  5030. @param {String} key the cache key as a string.
  5031. @returns {Object} returns <code>this</code> so that calls can be chained.
  5032. */
  5033. cacheKey: function (key) {
  5034. if (key == null) {
  5035. return filter.numeric_range._cache_key;
  5036. }
  5037. filter.numeric_range._cache_key = key;
  5038. return this;
  5039. },
  5040. /**
  5041. Returns the filter container as a JSON string.
  5042. @member ejs.NumericRangeFilter
  5043. @returns {String} JSON representation of the numericRangeFilter object
  5044. */
  5045. toString: function () {
  5046. return JSON.stringify(filter);
  5047. },
  5048. /**
  5049. The type of ejs object. For internal use only.
  5050. @member ejs.NumericRangeFilter
  5051. @returns {String} the type of object
  5052. */
  5053. _type: function () {
  5054. return 'filter';
  5055. },
  5056. /**
  5057. Returns the filter object.
  5058. @member ejs.NumericRangeFilter
  5059. @returns {Object} filter object
  5060. */
  5061. _self: function () {
  5062. return filter;
  5063. }
  5064. };
  5065. };
  5066. /**
  5067. @class
  5068. A container filter that allows Boolean OR composition of filters.
  5069. @name ejs.OrFilter
  5070. @desc
  5071. A container Filter that allows Boolean OR composition of filters.
  5072. @param {Filter || Array} filters A valid Filter or array of Filters.
  5073. */
  5074. ejs.OrFilter = function (filters) {
  5075. /**
  5076. The internal filter object. Use <code>_self()</code>
  5077. @member ejs.OrFilter
  5078. @property {Object} filter
  5079. */
  5080. var filter, i, len;
  5081. filter = {
  5082. or: {
  5083. filters: []
  5084. }
  5085. };
  5086. if (isFilter(filters)) {
  5087. filter.or.filters.push(filters._self());
  5088. } else if (isArray(filters)) {
  5089. for (i = 0, len = filters.length; i < len; i++) {
  5090. if (!isFilter(filters[i])) {
  5091. throw new TypeError('Argument must be array of Filters');
  5092. }
  5093. filter.or.filters.push(filters[i]._self());
  5094. }
  5095. } else {
  5096. throw new TypeError('Argument must be a Filter or array of Filters');
  5097. }
  5098. return {
  5099. /**
  5100. Updates the filters. If passed a single Filter it is added to
  5101. the existing filters. If passed an array of Filters, they
  5102. replace all existing Filters.
  5103. @member ejs.OrFilter
  5104. @param {Filter || Array} fltr A Filter or array of Filters
  5105. @returns {Object} returns <code>this</code> so that calls can be chained.
  5106. */
  5107. filters: function (fltr) {
  5108. var i, len;
  5109. if (fltr == null) {
  5110. return filter.or.filters;
  5111. }
  5112. if (isFilter(fltr)) {
  5113. filter.or.filters.push(fltr._self());
  5114. } else if (isArray(fltr)) {
  5115. filter.or.filters = [];
  5116. for (i = 0, len = fltr.length; i < len; i++) {
  5117. if (!isFilter(fltr[i])) {
  5118. throw new TypeError('Argument must be an array of Filters');
  5119. }
  5120. filter.or.filters.push(fltr[i]._self());
  5121. }
  5122. } else {
  5123. throw new TypeError('Argument must be a Filter or array of Filters');
  5124. }
  5125. return this;
  5126. },
  5127. /**
  5128. Sets the filter name.
  5129. @member ejs.OrFilter
  5130. @param {String} name A name for the filter.
  5131. @returns {Object} returns <code>this</code> so that calls can be chained.
  5132. */
  5133. name: function (name) {
  5134. if (name == null) {
  5135. return filter.or._name;
  5136. }
  5137. filter.or._name = name;
  5138. return this;
  5139. },
  5140. /**
  5141. Enable or disable caching of the filter
  5142. @member ejs.OrFilter
  5143. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5144. @returns {Object} returns <code>this</code> so that calls can be chained.
  5145. */
  5146. cache: function (trueFalse) {
  5147. if (trueFalse == null) {
  5148. return filter.or._cache;
  5149. }
  5150. filter.or._cache = trueFalse;
  5151. return this;
  5152. },
  5153. /**
  5154. Sets the cache key.
  5155. @member ejs.OrFilter
  5156. @param {String} key the cache key as a string.
  5157. @returns {Object} returns <code>this</code> so that calls can be chained.
  5158. */
  5159. cacheKey: function (key) {
  5160. if (key == null) {
  5161. return filter.or._cache_key;
  5162. }
  5163. filter.or._cache_key = key;
  5164. return this;
  5165. },
  5166. /**
  5167. Returns the filter container as a JSON string
  5168. @member ejs.OrFilter
  5169. @returns {String} JSON representation of the orFilter object
  5170. */
  5171. toString: function () {
  5172. return JSON.stringify(filter);
  5173. },
  5174. /**
  5175. The type of ejs object. For internal use only.
  5176. @member ejs.OrFilter
  5177. @returns {String} the type of object
  5178. */
  5179. _type: function () {
  5180. return 'filter';
  5181. },
  5182. /**
  5183. Returns the filter object.
  5184. @member ejs.OrFilter
  5185. @returns {Object} filter object
  5186. */
  5187. _self: function () {
  5188. return filter;
  5189. }
  5190. };
  5191. };
  5192. /**
  5193. @class
  5194. <p>Filters documents that have fields containing terms with a specified prefix (not analyzed). Similar
  5195. to phrase query, except that it acts as a filter. Can be placed within queries that accept a filter.</p>
  5196. @name ejs.PrefixFilter
  5197. @desc
  5198. Filters documents that have fields containing terms with a specified prefix.
  5199. @param {String} fieldName the field name to be used during matching.
  5200. @param {String} prefix the prefix value.
  5201. */
  5202. ejs.PrefixFilter = function (fieldName, prefix) {
  5203. /**
  5204. The internal filter object. Use <code>get()</code>
  5205. @member ejs.PrefixFilter
  5206. @property {Object} filter
  5207. */
  5208. var filter = {
  5209. prefix: {}
  5210. };
  5211. filter.prefix[fieldName] = prefix;
  5212. return {
  5213. /**
  5214. Returns the field name used to create this object.
  5215. @member ejs.PrefixFilter
  5216. @param {String} field the field name
  5217. @returns {Object} returns <code>this</code> so that calls can be
  5218. chained. Returns {String}, field name when field is not specified.
  5219. */
  5220. field: function (field) {
  5221. var oldValue = filter.prefix[fieldName];
  5222. if (field == null) {
  5223. return fieldName;
  5224. }
  5225. delete filter.prefix[fieldName];
  5226. fieldName = field;
  5227. filter.prefix[fieldName] = oldValue;
  5228. return this;
  5229. },
  5230. /**
  5231. Sets the prefix to search for.
  5232. @member ejs.PrefixFilter
  5233. @param {String} value the prefix value to match
  5234. @returns {Object} returns <code>this</code> so that calls can be chained.
  5235. */
  5236. prefix: function (value) {
  5237. if (value == null) {
  5238. return filter.prefix[fieldName];
  5239. }
  5240. filter.prefix[fieldName] = value;
  5241. return this;
  5242. },
  5243. /**
  5244. Sets the filter name.
  5245. @member ejs.PrefixFilter
  5246. @param {String} name A name for the filter.
  5247. @returns {Object} returns <code>this</code> so that calls can be chained.
  5248. */
  5249. name: function (name) {
  5250. if (name == null) {
  5251. return filter.prefix._name;
  5252. }
  5253. filter.prefix._name = name;
  5254. return this;
  5255. },
  5256. /**
  5257. Enable or disable caching of the filter
  5258. @member ejs.PrefixFilter
  5259. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5260. @returns {Object} returns <code>this</code> so that calls can be chained.
  5261. */
  5262. cache: function (trueFalse) {
  5263. if (trueFalse == null) {
  5264. return filter.prefix._cache;
  5265. }
  5266. filter.prefix._cache = trueFalse;
  5267. return this;
  5268. },
  5269. /**
  5270. Sets the cache key.
  5271. @member ejs.PrefixFilter
  5272. @param {String} key the cache key as a string.
  5273. @returns {Object} returns <code>this</code> so that calls can be chained.
  5274. */
  5275. cacheKey: function (key) {
  5276. if (key == null) {
  5277. return filter.prefix._cache_key;
  5278. }
  5279. filter.prefix._cache_key = key;
  5280. return this;
  5281. },
  5282. /**
  5283. Returns the filter container as a JSON string
  5284. @member ejs.PrefixFilter
  5285. @returns {String} JSON representation of the prefixFilter object
  5286. */
  5287. toString: function () {
  5288. return JSON.stringify(filter);
  5289. },
  5290. /**
  5291. The type of ejs object. For internal use only.
  5292. @member ejs.PrefixFilter
  5293. @returns {String} the type of object
  5294. */
  5295. _type: function () {
  5296. return 'filter';
  5297. },
  5298. /**
  5299. Returns the filter object.
  5300. @member ejs.PrefixFilter
  5301. @returns {Object} filter object
  5302. */
  5303. _self: function () {
  5304. return filter;
  5305. }
  5306. };
  5307. };
  5308. /**
  5309. @class
  5310. <p>Wraps any query to be used as a filter. Can be placed within queries
  5311. that accept a filter.</p>
  5312. <p>The result of the filter is not cached by default. Set the cache
  5313. parameter to true to cache the result of the filter. This is handy when the
  5314. same query is used on several (many) other queries.</p>
  5315. <p>Note, the process of caching the first execution is higher when not
  5316. caching (since it needs to satisfy different queries).</p>
  5317. @name ejs.QueryFilter
  5318. @desc
  5319. Filters documents matching the wrapped query.
  5320. @param {Object} qry A valid query object.
  5321. */
  5322. ejs.QueryFilter = function (qry) {
  5323. if (!isQuery(qry)) {
  5324. throw new TypeError('Argument must be a Query');
  5325. }
  5326. /**
  5327. The internal query object. <code>Use _self()</code>
  5328. @member ejs.QueryFilter
  5329. @property {Object} query
  5330. */
  5331. var filter = {
  5332. fquery: {
  5333. query: qry._self()
  5334. }
  5335. };
  5336. return {
  5337. /**
  5338. Sets the query
  5339. @member ejs.QueryFilter
  5340. @param {Object} q A valid Query object
  5341. @returns {Object} returns <code>this</code> so that calls can be chained.
  5342. */
  5343. query: function (q) {
  5344. if (q == null) {
  5345. return filter.fquery.query;
  5346. }
  5347. if (!isQuery(q)) {
  5348. throw new TypeError('Argument must be a Query');
  5349. }
  5350. filter.fquery.query = q._self();
  5351. return this;
  5352. },
  5353. /**
  5354. Sets the filter name.
  5355. @member ejs.QueryFilter
  5356. @param {String} name A name for the filter.
  5357. @returns {Object} returns <code>this</code> so that calls can be chained.
  5358. */
  5359. name: function (name) {
  5360. if (name == null) {
  5361. return filter.fquery._name;
  5362. }
  5363. filter.fquery._name = name;
  5364. return this;
  5365. },
  5366. /**
  5367. Enable or disable caching of the filter
  5368. @member ejs.QueryFilter
  5369. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5370. @returns {Object} returns <code>this</code> so that calls can be chained.
  5371. */
  5372. cache: function (trueFalse) {
  5373. if (trueFalse == null) {
  5374. return filter.fquery._cache;
  5375. }
  5376. filter.fquery._cache = trueFalse;
  5377. return this;
  5378. },
  5379. /**
  5380. Sets the cache key.
  5381. @member ejs.QueryFilter
  5382. @param {String} key the cache key as a string.
  5383. @returns {Object} returns <code>this</code> so that calls can be chained.
  5384. */
  5385. cacheKey: function (key) {
  5386. if (key == null) {
  5387. return filter.fquery._cache_key;
  5388. }
  5389. filter.fquery._cache_key = key;
  5390. return this;
  5391. },
  5392. /**
  5393. Allows you to serialize this object into a JSON encoded string.
  5394. @member ejs.QueryFilter
  5395. @returns {String} returns this object as a serialized JSON string.
  5396. */
  5397. toString: function () {
  5398. return JSON.stringify(filter);
  5399. },
  5400. /**
  5401. The type of ejs object. For internal use only.
  5402. @member ejs.QueryFilter
  5403. @returns {String} the type of object
  5404. */
  5405. _type: function () {
  5406. return 'filter';
  5407. },
  5408. /**
  5409. Retrieves the internal <code>filter</code> object. This is typically used by
  5410. internal API functions so use with caution.
  5411. @member ejs.QueryFilter
  5412. @returns {String} returns this object's internal <code>filter</code> property.
  5413. */
  5414. _self: function () {
  5415. return filter;
  5416. }
  5417. };
  5418. };
  5419. /**
  5420. @class
  5421. <p>Matches documents with fields that have terms within a certain range.</p>
  5422. @name ejs.RangeFilter
  5423. @desc
  5424. Filters documents with fields that have terms within a certain range.
  5425. @param {String} field A valid field name.
  5426. */
  5427. ejs.RangeFilter = function (field) {
  5428. /**
  5429. The internal filter object. <code>Use get()</code>
  5430. @member ejs.RangeFilter
  5431. @property {Object} filter
  5432. */
  5433. var filter = {
  5434. range: {}
  5435. };
  5436. filter.range[field] = {};
  5437. return {
  5438. /**
  5439. The field to run the filter against.
  5440. @member ejs.RangeFilter
  5441. @param {String} f A single field name.
  5442. @returns {Object} returns <code>this</code> so that calls can be chained.
  5443. */
  5444. field: function (f) {
  5445. var oldValue = filter.range[field];
  5446. if (f == null) {
  5447. return field;
  5448. }
  5449. delete filter.range[field];
  5450. field = f;
  5451. filter.range[f] = oldValue;
  5452. return this;
  5453. },
  5454. /**
  5455. The lower bound. Defaults to start from the first.
  5456. @member ejs.RangeFilter
  5457. @param {Variable Type} f the lower bound value, type depends on field type
  5458. @returns {Object} returns <code>this</code> so that calls can be chained.
  5459. */
  5460. from: function (f) {
  5461. if (f == null) {
  5462. return filter.range[field].from;
  5463. }
  5464. filter.range[field].from = f;
  5465. return this;
  5466. },
  5467. /**
  5468. The upper bound. Defaults to unbounded.
  5469. @member ejs.RangeFilter
  5470. @param {Variable Type} t the upper bound value, type depends on field type
  5471. @returns {Object} returns <code>this</code> so that calls can be chained.
  5472. */
  5473. to: function (t) {
  5474. if (t == null) {
  5475. return filter.range[field].to;
  5476. }
  5477. filter.range[field].to = t;
  5478. return this;
  5479. },
  5480. /**
  5481. Should the first from (if set) be inclusive or not.
  5482. Defaults to true
  5483. @member ejs.RangeFilter
  5484. @param {Boolean} trueFalse true to include, false to exclude
  5485. @returns {Object} returns <code>this</code> so that calls can be chained.
  5486. */
  5487. includeLower: function (trueFalse) {
  5488. if (trueFalse == null) {
  5489. return filter.range[field].include_lower;
  5490. }
  5491. filter.range[field].include_lower = trueFalse;
  5492. return this;
  5493. },
  5494. /**
  5495. Should the last to (if set) be inclusive or not. Defaults to true.
  5496. @member ejs.RangeFilter
  5497. @param {Boolean} trueFalse true to include, false to exclude
  5498. @returns {Object} returns <code>this</code> so that calls can be chained.
  5499. */
  5500. includeUpper: function (trueFalse) {
  5501. if (trueFalse == null) {
  5502. return filter.range[field].include_upper;
  5503. }
  5504. filter.range[field].include_upper = trueFalse;
  5505. return this;
  5506. },
  5507. /**
  5508. Greater than value. Same as setting from to the value, and
  5509. include_lower to false,
  5510. @member ejs.RangeFilter
  5511. @param {Variable Type} val the value, type depends on field type
  5512. @returns {Object} returns <code>this</code> so that calls can be chained.
  5513. */
  5514. gt: function (val) {
  5515. if (val == null) {
  5516. return filter.range[field].gt;
  5517. }
  5518. filter.range[field].gt = val;
  5519. return this;
  5520. },
  5521. /**
  5522. Greater than or equal to value. Same as setting from to the value,
  5523. and include_lower to true.
  5524. @member ejs.RangeFilter
  5525. @param {Variable Type} val the value, type depends on field type
  5526. @returns {Object} returns <code>this</code> so that calls can be chained.
  5527. */
  5528. gte: function (val) {
  5529. if (val == null) {
  5530. return filter.range[field].gte;
  5531. }
  5532. filter.range[field].gte = val;
  5533. return this;
  5534. },
  5535. /**
  5536. Less than value. Same as setting to to the value, and include_upper
  5537. to false.
  5538. @member ejs.RangeFilter
  5539. @param {Variable Type} val the value, type depends on field type
  5540. @returns {Object} returns <code>this</code> so that calls can be chained.
  5541. */
  5542. lt: function (val) {
  5543. if (val == null) {
  5544. return filter.range[field].lt;
  5545. }
  5546. filter.range[field].lt = val;
  5547. return this;
  5548. },
  5549. /**
  5550. Less than or equal to value. Same as setting to to the value,
  5551. and include_upper to true.
  5552. @member ejs.RangeFilter
  5553. @param {Variable Type} val the value, type depends on field type
  5554. @returns {Object} returns <code>this</code> so that calls can be chained.
  5555. */
  5556. lte: function (val) {
  5557. if (val == null) {
  5558. return filter.range[field].lte;
  5559. }
  5560. filter.range[field].lte = val;
  5561. return this;
  5562. },
  5563. /**
  5564. Sets the filter name.
  5565. @member ejs.RangeFilter
  5566. @param {String} name A name for the filter.
  5567. @returns {Object} returns <code>this</code> so that calls can be chained.
  5568. */
  5569. name: function (name) {
  5570. if (name == null) {
  5571. return filter.range._name;
  5572. }
  5573. filter.range._name = name;
  5574. return this;
  5575. },
  5576. /**
  5577. Enable or disable caching of the filter
  5578. @member ejs.RangeFilter
  5579. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5580. @returns {Object} returns <code>this</code> so that calls can be chained.
  5581. */
  5582. cache: function (trueFalse) {
  5583. if (trueFalse == null) {
  5584. return filter.range._cache;
  5585. }
  5586. filter.range._cache = trueFalse;
  5587. return this;
  5588. },
  5589. /**
  5590. Sets the cache key.
  5591. @member ejs.RangeFilter
  5592. @param {String} key the cache key as a string.
  5593. @returns {Object} returns <code>this</code> so that calls can be chained.
  5594. */
  5595. cacheKey: function (key) {
  5596. if (key == null) {
  5597. return filter.range._cache_key;
  5598. }
  5599. filter.range._cache_key = key;
  5600. return this;
  5601. },
  5602. /**
  5603. Allows you to serialize this object into a JSON encoded string.
  5604. @member ejs.RangeFilter
  5605. @returns {String} returns this object as a serialized JSON string.
  5606. */
  5607. toString: function () {
  5608. return JSON.stringify(filter);
  5609. },
  5610. /**
  5611. The type of ejs object. For internal use only.
  5612. @member ejs.RangeFilter
  5613. @returns {String} the type of object
  5614. */
  5615. _type: function () {
  5616. return 'filter';
  5617. },
  5618. /**
  5619. Retrieves the internal <code>filter</code> object. This is typically used by
  5620. internal API functions so use with caution.
  5621. @member ejs.RangeFilter
  5622. @returns {String} returns this object's internal <code>filter</code> property.
  5623. */
  5624. _self: function () {
  5625. return filter;
  5626. }
  5627. };
  5628. };
  5629. /**
  5630. @class
  5631. <p>Filters documents that have a field value matching a regular expression.
  5632. Based on Lucene 4.0 RegexpFilter which uses automaton to efficiently iterate
  5633. over index terms.</p>
  5634. @name ejs.RegexpFilter
  5635. @desc
  5636. Matches documents that have fields matching a regular expression.
  5637. @param {String} field A valid field name.
  5638. @param {String} value A regex pattern.
  5639. */
  5640. ejs.RegexpFilter = function (field, value) {
  5641. /**
  5642. The internal filter object. <code>Use get()</code>
  5643. @member ejs.RegexpFilter
  5644. @property {Object} filter
  5645. */
  5646. var filter = {
  5647. regexp: {}
  5648. };
  5649. filter.regexp[field] = {
  5650. value: value
  5651. };
  5652. return {
  5653. /**
  5654. The field to run the filter against.
  5655. @member ejs.RegexpFilter
  5656. @param {String} f A single field name.
  5657. @returns {Object} returns <code>this</code> so that calls can be chained.
  5658. */
  5659. field: function (f) {
  5660. var oldValue = filter.regexp[field];
  5661. if (f == null) {
  5662. return field;
  5663. }
  5664. delete filter.regexp[field];
  5665. field = f;
  5666. filter.regexp[f] = oldValue;
  5667. return this;
  5668. },
  5669. /**
  5670. The regexp value.
  5671. @member ejs.RegexpFilter
  5672. @param {String} p A string regexp
  5673. @returns {Object} returns <code>this</code> so that calls can be chained.
  5674. */
  5675. value: function (p) {
  5676. if (p == null) {
  5677. return filter.regexp[field].value;
  5678. }
  5679. filter.regexp[field].value = p;
  5680. return this;
  5681. },
  5682. /**
  5683. The regex flags to use. Valid flags are:
  5684. INTERSECTION - Support for intersection notation
  5685. COMPLEMENT - Support for complement notation
  5686. EMPTY - Support for the empty language symbol: #
  5687. ANYSTRING - Support for the any string symbol: @
  5688. INTERVAL - Support for numerical interval notation: <n-m>
  5689. NONE - Disable support for all syntax options
  5690. ALL - Enables support for all syntax options
  5691. Use multiple flags by separating with a "|" character. Example:
  5692. INTERSECTION|COMPLEMENT|EMPTY
  5693. @member ejs.RegexpFilter
  5694. @param {String} f The flags as a string, separate multiple flags with "|".
  5695. @returns {Object} returns <code>this</code> so that calls can be chained.
  5696. */
  5697. flags: function (f) {
  5698. if (f == null) {
  5699. return filter.regexp[field].flags;
  5700. }
  5701. filter.regexp[field].flags = f;
  5702. return this;
  5703. },
  5704. /**
  5705. The regex flags to use as a numeric value. Advanced use only,
  5706. it is probably better to stick with the <code>flags</code> option.
  5707. @member ejs.RegexpFilter
  5708. @param {String} v The flags as a numeric value.
  5709. @returns {Object} returns <code>this</code> so that calls can be chained.
  5710. */
  5711. flagsValue: function (v) {
  5712. if (v == null) {
  5713. return filter.regexp[field].flags_value;
  5714. }
  5715. filter.regexp[field].flags_value = v;
  5716. return this;
  5717. },
  5718. /**
  5719. Sets the filter name.
  5720. @member ejs.RegexpFilter
  5721. @param {String} name A name for the filter.
  5722. @returns {Object} returns <code>this</code> so that calls can be chained.
  5723. */
  5724. name: function (name) {
  5725. if (name == null) {
  5726. return filter.regexp._name;
  5727. }
  5728. filter.regexp._name = name;
  5729. return this;
  5730. },
  5731. /**
  5732. Enable or disable caching of the filter
  5733. @member ejs.RegexpFilter
  5734. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5735. @returns {Object} returns <code>this</code> so that calls can be chained.
  5736. */
  5737. cache: function (trueFalse) {
  5738. if (trueFalse == null) {
  5739. return filter.regexp._cache;
  5740. }
  5741. filter.regexp._cache = trueFalse;
  5742. return this;
  5743. },
  5744. /**
  5745. Sets the cache key.
  5746. @member ejs.RegexpFilter
  5747. @param {String} key the cache key as a string.
  5748. @returns {Object} returns <code>this</code> so that calls can be chained.
  5749. */
  5750. cacheKey: function (key) {
  5751. if (key == null) {
  5752. return filter.regexp._cache_key;
  5753. }
  5754. filter.regexp._cache_key = key;
  5755. return this;
  5756. },
  5757. /**
  5758. Allows you to serialize this object into a JSON encoded string.
  5759. @member ejs.RegexpFilter
  5760. @returns {String} returns this object as a serialized JSON string.
  5761. */
  5762. toString: function () {
  5763. return JSON.stringify(filter);
  5764. },
  5765. /**
  5766. The type of ejs object. For internal use only.
  5767. @member ejs.RegexpFilter
  5768. @returns {String} the type of object
  5769. */
  5770. _type: function () {
  5771. return 'filter';
  5772. },
  5773. /**
  5774. Retrieves the internal <code>filter</code> object. This is typically used by
  5775. internal API functions so use with caution.
  5776. @member ejs.RegexpFilter
  5777. @returns {String} returns this object's internal <code>filter</code> property.
  5778. */
  5779. _self: function () {
  5780. return filter;
  5781. }
  5782. };
  5783. };
  5784. /**
  5785. @class
  5786. <p>A filter allowing to define scripts as filters</p>
  5787. @name ejs.ScriptFilter
  5788. @desc
  5789. A filter allowing to define scripts as filters.
  5790. @param {String} script The script as a string.
  5791. */
  5792. ejs.ScriptFilter = function (script) {
  5793. /**
  5794. The internal filter object. <code>Use get()</code>
  5795. @member ejs.ScriptFilter
  5796. @property {Object} filter
  5797. */
  5798. var filter = {
  5799. script: {
  5800. script: script
  5801. }
  5802. };
  5803. return {
  5804. /**
  5805. Sets the script.
  5806. @member ejs.ScriptFilter
  5807. @param {String} s The script as a string.
  5808. @returns {Object} returns <code>this</code> so that calls can be chained.
  5809. */
  5810. script: function (s) {
  5811. if (s == null) {
  5812. return filter.script.script;
  5813. }
  5814. filter.script.script = s;
  5815. return this;
  5816. },
  5817. /**
  5818. Sets parameters that will be applied to the script. Overwrites
  5819. any existing params.
  5820. @member ejs.ScriptFilter
  5821. @param {Object} p An object where the keys are the parameter name and
  5822. values are the parameter value.
  5823. @returns {Object} returns <code>this</code> so that calls can be chained.
  5824. */
  5825. params: function (p) {
  5826. if (p == null) {
  5827. return filter.script.params;
  5828. }
  5829. filter.script.params = p;
  5830. return this;
  5831. },
  5832. /**
  5833. Sets the script language.
  5834. @member ejs.ScriptFilter
  5835. @param {String} lang The script language, default mvel.
  5836. @returns {Object} returns <code>this</code> so that calls can be chained.
  5837. */
  5838. lang: function (lang) {
  5839. if (lang == null) {
  5840. return filter.script.lang;
  5841. }
  5842. filter.script.lang = lang;
  5843. return this;
  5844. },
  5845. /**
  5846. Sets the filter name.
  5847. @member ejs.ScriptFilter
  5848. @param {String} name A name for the filter.
  5849. @returns {Object} returns <code>this</code> so that calls can be chained.
  5850. */
  5851. name: function (name) {
  5852. if (name == null) {
  5853. return filter.script._name;
  5854. }
  5855. filter.script._name = name;
  5856. return this;
  5857. },
  5858. /**
  5859. Enable or disable caching of the filter
  5860. @member ejs.ScriptFilter
  5861. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5862. @returns {Object} returns <code>this</code> so that calls can be chained.
  5863. */
  5864. cache: function (trueFalse) {
  5865. if (trueFalse == null) {
  5866. return filter.script._cache;
  5867. }
  5868. filter.script._cache = trueFalse;
  5869. return this;
  5870. },
  5871. /**
  5872. Sets the cache key.
  5873. @member ejs.ScriptFilter
  5874. @param {String} key the cache key as a string.
  5875. @returns {Object} returns <code>this</code> so that calls can be chained.
  5876. */
  5877. cacheKey: function (key) {
  5878. if (key == null) {
  5879. return filter.script._cache_key;
  5880. }
  5881. filter.script._cache_key = key;
  5882. return this;
  5883. },
  5884. /**
  5885. Allows you to serialize this object into a JSON encoded string.
  5886. @member ejs.ScriptFilter
  5887. @returns {String} returns this object as a serialized JSON string.
  5888. */
  5889. toString: function () {
  5890. return JSON.stringify(filter);
  5891. },
  5892. /**
  5893. The type of ejs object. For internal use only.
  5894. @member ejs.ScriptFilter
  5895. @returns {String} the type of object
  5896. */
  5897. _type: function () {
  5898. return 'filter';
  5899. },
  5900. /**
  5901. Retrieves the internal <code>filter</code> object. This is typically used by
  5902. internal API functions so use with caution.
  5903. @member ejs.ScriptFilter
  5904. @returns {String} returns this object's internal <code>filter</code> property.
  5905. */
  5906. _self: function () {
  5907. return filter;
  5908. }
  5909. };
  5910. };
  5911. /**
  5912. @class
  5913. <p>Constructs a filter for docs matching any of the terms added to this
  5914. object. Unlike a RangeFilter this can be used for filtering on multiple
  5915. terms that are not necessarily in a sequence.</p>
  5916. @name ejs.TermFilter
  5917. @desc
  5918. Constructs a filter for docs matching the term added to this object.
  5919. @param {string} fieldName The document field/fieldName to execute the filter against.
  5920. @param {string} term The literal term used to filter the results.
  5921. */
  5922. ejs.TermFilter = function (fieldName, term) {
  5923. /**
  5924. The internal filter object. Use the get() method for access.
  5925. @member ejs.TermFilter
  5926. @property {Object} filter
  5927. */
  5928. var filter = {
  5929. term: {}
  5930. };
  5931. filter.term[fieldName] = term;
  5932. return {
  5933. /**
  5934. Provides access to the filter fieldName used to construct the
  5935. termFilter object.
  5936. @member ejs.TermFilter
  5937. @param {String} f the fieldName term
  5938. @returns {Object} returns <code>this</code> so that calls can be chained.
  5939. When k is not specified, Returns {String}, the filter fieldName used to construct
  5940. the termFilter object.
  5941. */
  5942. field: function (f) {
  5943. var oldValue = filter.term[fieldName];
  5944. if (f == null) {
  5945. return fieldName;
  5946. }
  5947. delete filter.term[fieldName];
  5948. fieldName = f;
  5949. filter.term[fieldName] = oldValue;
  5950. return this;
  5951. },
  5952. /**
  5953. Provides access to the filter term used to construct the
  5954. termFilter object.
  5955. @member ejs.TermFilter
  5956. @returns {Object} returns <code>this</code> so that calls can be chained.
  5957. When k is not specified, Returns {String}, the filter term used
  5958. to construct the termFilter object.
  5959. */
  5960. term: function (v) {
  5961. if (v == null) {
  5962. return filter.term[fieldName];
  5963. }
  5964. filter.term[fieldName] = v;
  5965. return this;
  5966. },
  5967. /**
  5968. Sets the filter name.
  5969. @member ejs.TermFilter
  5970. @param {String} name A name for the filter.
  5971. @returns {Object} returns <code>this</code> so that calls can be chained.
  5972. */
  5973. name: function (name) {
  5974. if (name == null) {
  5975. return filter.term._name;
  5976. }
  5977. filter.term._name = name;
  5978. return this;
  5979. },
  5980. /**
  5981. Enable or disable caching of the filter
  5982. @member ejs.TermFilter
  5983. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  5984. @returns {Object} returns <code>this</code> so that calls can be chained.
  5985. */
  5986. cache: function (trueFalse) {
  5987. if (trueFalse == null) {
  5988. return filter.term._cache;
  5989. }
  5990. filter.term._cache = trueFalse;
  5991. return this;
  5992. },
  5993. /**
  5994. Sets the cache key.
  5995. @member ejs.TermFilter
  5996. @param {String} key the cache key as a string.
  5997. @returns {Object} returns <code>this</code> so that calls can be chained.
  5998. */
  5999. cacheKey: function (key) {
  6000. if (key == null) {
  6001. return filter.term._cache_key;
  6002. }
  6003. filter.term._cache_key = key;
  6004. return this;
  6005. },
  6006. /**
  6007. Serializes the internal filter object as a JSON string.
  6008. @member ejs.TermFilter
  6009. @returns {String} Returns a JSON representation of the termFilter object.
  6010. */
  6011. toString: function () {
  6012. return JSON.stringify(filter);
  6013. },
  6014. /**
  6015. The type of ejs object. For internal use only.
  6016. @member ejs.TermFilter
  6017. @returns {String} the type of object
  6018. */
  6019. _type: function () {
  6020. return 'filter';
  6021. },
  6022. /**
  6023. Returns the filter object. For internal use only.
  6024. @member ejs.TermFilter
  6025. @returns {Object} Returns the object's filter property.
  6026. */
  6027. _self: function () {
  6028. return filter;
  6029. }
  6030. };
  6031. };
  6032. /**
  6033. @class
  6034. <p>Filters documents that have fields that match any of the provided
  6035. terms (not analyzed)</p>
  6036. @name ejs.TermsFilter
  6037. @desc
  6038. A Filter that matches documents containing provided terms.
  6039. @param {String} field the document field/key to filter against
  6040. @param {String || Array} terms a single term or an array of terms.
  6041. */
  6042. ejs.TermsFilter = function (field, terms) {
  6043. /**
  6044. The internal filter object. <code>Use get()</code>
  6045. @member ejs.TermsFilter
  6046. @property {Object} filter
  6047. */
  6048. var filter = {
  6049. terms: {}
  6050. };
  6051. if (isArray(terms)) {
  6052. filter.terms[field] = terms;
  6053. } else {
  6054. filter.terms[field] = [terms];
  6055. }
  6056. return {
  6057. /**
  6058. Sets the fields to filter against.
  6059. @member ejs.TermsFilter
  6060. @param {String} f A valid field name.
  6061. @returns {Object} returns <code>this</code> so that calls can be chained.
  6062. */
  6063. field: function (f) {
  6064. var oldValue = filter.terms[field];
  6065. if (f == null) {
  6066. return field;
  6067. }
  6068. delete filter.terms[field];
  6069. field = f;
  6070. filter.terms[f] = oldValue;
  6071. return this;
  6072. },
  6073. /**
  6074. Sets the terms. If t is a String, it is added to the existing
  6075. list of terms. If t is an array, the list of terms replaces the
  6076. existing terms.
  6077. @member ejs.TermsFilter
  6078. @param {String || Array} t A single term or an array or terms.
  6079. @returns {Object} returns <code>this</code> so that calls can be chained.
  6080. */
  6081. terms: function (t) {
  6082. if (t == null) {
  6083. return filter.terms[field];
  6084. }
  6085. if (isArray(t)) {
  6086. filter.terms[field] = t;
  6087. } else {
  6088. filter.terms[field].push(t);
  6089. }
  6090. return this;
  6091. },
  6092. /**
  6093. Sets the way terms filter executes is by iterating over the terms
  6094. provided and finding matches docs (loading into a bitset) and
  6095. caching it. Valid values are: plain, bool, bool_nocache, and,
  6096. and_nocache, or, or_nocache. Defaults to plain.
  6097. @member ejs.TermsFilter
  6098. @param {String} e A valid execution method.
  6099. @returns {Object} returns <code>this</code> so that calls can be chained.
  6100. */
  6101. execution: function (e) {
  6102. if (e == null) {
  6103. return filter.terms.execution;
  6104. }
  6105. e = e.toLowerCase();
  6106. if (e === 'plain' || e === 'bool' || e === 'bool_nocache' ||
  6107. e === 'and' || e === 'and_nocache' || e === 'or' || e === 'or_nocache') {
  6108. filter.terms.execution = e;
  6109. }
  6110. return this;
  6111. },
  6112. /**
  6113. Sets the filter name.
  6114. @member ejs.TermsFilter
  6115. @param {String} name A name for the filter.
  6116. @returns {Object} returns <code>this</code> so that calls can be chained.
  6117. */
  6118. name: function (name) {
  6119. if (name == null) {
  6120. return filter.terms._name;
  6121. }
  6122. filter.terms._name = name;
  6123. return this;
  6124. },
  6125. /**
  6126. Enable or disable caching of the filter
  6127. @member ejs.TermsFilter
  6128. @param {Boolean} trueFalse True to cache the filter, false otherwise.
  6129. @returns {Object} returns <code>this</code> so that calls can be chained.
  6130. */
  6131. cache: function (trueFalse) {
  6132. if (trueFalse == null) {
  6133. return filter.terms._cache;
  6134. }
  6135. filter.terms._cache = trueFalse;
  6136. return this;
  6137. },
  6138. /**
  6139. Sets the cache key.
  6140. @member ejs.TermsFilter
  6141. @param {String} key the cache key as a string.
  6142. @returns {Object} returns <code>this</code> so that calls can be chained.
  6143. */
  6144. cacheKey: function (key) {
  6145. if (key == null) {
  6146. return filter.terms._cache_key;
  6147. }
  6148. filter.terms._cache_key = key;
  6149. return this;
  6150. },
  6151. /**
  6152. Allows you to serialize this object into a JSON encoded string.
  6153. @member ejs.TermsFilter
  6154. @returns {String} returns this object as a serialized JSON string.
  6155. */
  6156. toString: function () {
  6157. return JSON.stringify(filter);
  6158. },
  6159. /**
  6160. The type of ejs object. For internal use only.
  6161. @member ejs.TermsFilter
  6162. @returns {String} the type of object
  6163. */
  6164. _type: function () {
  6165. return 'filter';
  6166. },
  6167. /**
  6168. Retrieves the internal <code>filter</code> object. This is typically used by
  6169. internal API functions so use with caution.
  6170. @member ejs.TermsFilter
  6171. @returns {String} returns this object's internal <code>filter</code> property.
  6172. */
  6173. _self: function () {
  6174. return filter;
  6175. }
  6176. };
  6177. };
  6178. /**
  6179. @class
  6180. <p>A Filter that filters results by a specified index type.</p>
  6181. @name ejs.TypeFilter
  6182. @desc
  6183. Filter results by a specified index type.
  6184. @param {String} type the index type to filter on.
  6185. */
  6186. ejs.TypeFilter = function (type) {
  6187. /**
  6188. The internal filter object. Use <code>get()</code>
  6189. @member ejs.TypeFilter
  6190. @property {Object} filter
  6191. */
  6192. var filter = {
  6193. "type": {
  6194. "value": type
  6195. }
  6196. };
  6197. return {
  6198. /**
  6199. * Sets the type
  6200. @member ejs.TypeFilter
  6201. @param {String} type the index type to filter on
  6202. @returns {Object} returns <code>this</code> so that calls can be chained.
  6203. */
  6204. type: function (type) {
  6205. if (type == null) {
  6206. return filter.type.value;
  6207. }
  6208. filter.type.value = type;
  6209. return this;
  6210. },
  6211. /**
  6212. Returns the filter container as a JSON string
  6213. @member ejs.TypeFilter
  6214. @returns {String} JSON representation of the notFilter object
  6215. */
  6216. toString: function () {
  6217. return JSON.stringify(filter);
  6218. },
  6219. /**
  6220. The type of ejs object. For internal use only.
  6221. @member ejs.TypeFilter
  6222. @returns {String} the type of object
  6223. */
  6224. _type: function () {
  6225. return 'filter';
  6226. },
  6227. /**
  6228. Returns the filter object.
  6229. @member ejs.TypeFilter
  6230. @returns {Object} filter object
  6231. */
  6232. _self: function () {
  6233. return filter;
  6234. }
  6235. };
  6236. };
  6237. /**
  6238. @class
  6239. <p>The <code>Document</code> object provides an interface for working with
  6240. Documents. Some example operations avaiable are storing documents,
  6241. retreiving documents, updating documents, and deleting documents from an
  6242. index.</p>
  6243. @name ejs.Document
  6244. @desc
  6245. Object used to create, replace, update, and delete documents
  6246. <div class="alert-message block-message info">
  6247. <p>
  6248. <strong>Tip: </strong>
  6249. It is not necessary to first create a index or content-type. If either of these
  6250. do not exist, they will be automatically created when you attempt to store the document.
  6251. </p>
  6252. </div>
  6253. @param {String} index The index the document belongs to.
  6254. @param {String} type The type the document belongs to.
  6255. @param {String} id The id of the document. The id is required except
  6256. for indexing. If no id is specified during indexing, one will be
  6257. created for you.
  6258. */
  6259. ejs.Document = function (index, type, id) {
  6260. var params = {},
  6261. // converts client params to a string param1=val1&param2=val1
  6262. genParamStr = function () {
  6263. var clientParams = genClientParams(),
  6264. parts = [];
  6265. for (var p in clientParams) {
  6266. if (!has(clientParams, p)) {
  6267. continue;
  6268. }
  6269. parts.push(p + '=' + encodeURIComponent(clientParams[p]));
  6270. }
  6271. return parts.join('&');
  6272. },
  6273. // Converts the stored params into parameters that will be passed
  6274. // to a client. Certain parameter are skipped, and others require
  6275. // special processing before being sent to the client.
  6276. genClientParams = function () {
  6277. var clientParams = {};
  6278. for (var param in params) {
  6279. if (!has(params, param)) {
  6280. continue;
  6281. }
  6282. // skip params that don't go in the query string
  6283. if (param === 'upsert' || param === 'source' ||
  6284. param === 'script' || param === 'lang' || param === 'params') {
  6285. continue;
  6286. }
  6287. // process all over params
  6288. var paramVal = params[param];
  6289. if (isArray(paramVal)) {
  6290. paramVal = paramVal.join();
  6291. }
  6292. clientParams[param] = paramVal;
  6293. }
  6294. return clientParams;
  6295. };
  6296. return {
  6297. /**
  6298. Sets the index the document belongs to.
  6299. @member ejs.Document
  6300. @param {String} idx The index name
  6301. @returns {Object} returns <code>this</code> so that calls can be chained.
  6302. */
  6303. index: function (idx) {
  6304. if (idx == null) {
  6305. return index;
  6306. }
  6307. index = idx;
  6308. return this;
  6309. },
  6310. /**
  6311. Sets the type of the document.
  6312. @member ejs.Document
  6313. @param {String} t The type name
  6314. @returns {Object} returns <code>this</code> so that calls can be chained.
  6315. */
  6316. type: function (t) {
  6317. if (t == null) {
  6318. return type;
  6319. }
  6320. type = t;
  6321. return this;
  6322. },
  6323. /**
  6324. Sets the id of the document.
  6325. @member ejs.Document
  6326. @param {String} i The document id
  6327. @returns {Object} returns <code>this</code> so that calls can be chained.
  6328. */
  6329. id: function (i) {
  6330. if (i == null) {
  6331. return id;
  6332. }
  6333. id = i;
  6334. return this;
  6335. },
  6336. /**
  6337. Sets the routing value. By default, the shard the document is
  6338. placed on is controlled by using a hash of the document’s id
  6339. value. For more explicit control, this routing value will be fed
  6340. into the hash function used by the router.
  6341. This option is valid during the following operations:
  6342. index, delete, get, and update.
  6343. @member ejs.Document
  6344. @param {String} route The routing value
  6345. @returns {Object} returns <code>this</code> so that calls can be chained.
  6346. */
  6347. routing: function (route) {
  6348. if (route == null) {
  6349. return params.routing;
  6350. }
  6351. params.routing = route;
  6352. return this;
  6353. },
  6354. /**
  6355. Sets parent value for a child document. When indexing a child
  6356. document, the routing value is automatically set to be the same
  6357. as it’s parent, unless the routing value is explicitly specified
  6358. using the routing parameter.
  6359. This option is valid during the following operations:
  6360. index, delete, get, and update.
  6361. @member ejs.Document
  6362. @param {String} parent The parent value
  6363. @returns {Object} returns <code>this</code> so that calls can be chained.
  6364. */
  6365. parent: function (parent) {
  6366. if (parent == null) {
  6367. return params.parent;
  6368. }
  6369. params.parent = parent;
  6370. return this;
  6371. },
  6372. /**
  6373. Sets timestamp of the document. By default the timestamp will
  6374. be set to the time the docuement was indexed.
  6375. This option is valid during the following operations:
  6376. index and update
  6377. @member ejs.Document
  6378. @param {String} parent The parent value
  6379. @returns {Object} returns <code>this</code> so that calls can be chained.
  6380. */
  6381. timestamp: function (ts) {
  6382. if (ts == null) {
  6383. return params.timestamp;
  6384. }
  6385. params.timestamp = ts;
  6386. return this;
  6387. },
  6388. /**
  6389. Sets the documents time to live (ttl). The expiration date that
  6390. will be set for a document with a provided ttl is relative to the
  6391. timestamp of the document, meaning it can be based on the time of
  6392. indexing or on any time provided. The provided ttl must be
  6393. strictly positive and can be a number (in milliseconds) or any
  6394. valid time value such as "1d", "2h", "5m", etc.
  6395. This option is valid during the following operations:
  6396. index and update
  6397. @member ejs.Document
  6398. @param {String} length The amount of time after which the document
  6399. will expire.
  6400. @returns {Object} returns <code>this</code> so that calls can be chained.
  6401. */
  6402. ttl: function (length) {
  6403. if (length == null) {
  6404. return params.ttl;
  6405. }
  6406. params.ttl = length;
  6407. return this;
  6408. },
  6409. /**
  6410. Set's a timeout for the given operation. If the primary shard
  6411. has not completed the operation before this value, an error will
  6412. occur. The default timeout is 1 minute. The provided timeout
  6413. must be strictly positive and can be a number (in milliseconds) or
  6414. any valid time value such as "1d", "2h", "5m", etc.
  6415. This option is valid during the following operations:
  6416. index, delete, and update
  6417. @member ejs.Document
  6418. @param {String} length The amount of time after which the operation
  6419. will timeout.
  6420. @returns {Object} returns <code>this</code> so that calls can be chained.
  6421. */
  6422. timeout: function (length) {
  6423. if (length == null) {
  6424. return params.timeout;
  6425. }
  6426. params.timeout = length;
  6427. return this;
  6428. },
  6429. /**
  6430. Enables the index to be refreshed immediately after the operation
  6431. occurs. This is an advanced setting and can lead to performance
  6432. issues.
  6433. This option is valid during the following operations:
  6434. index, delete, get, and update
  6435. @member ejs.Document
  6436. @param {Boolean} trueFalse If the index should be refreshed or not.
  6437. @returns {Object} returns <code>this</code> so that calls can be chained.
  6438. */
  6439. refresh: function (trueFalse) {
  6440. if (trueFalse == null) {
  6441. return params.refresh;
  6442. }
  6443. params.refresh = trueFalse;
  6444. return this;
  6445. },
  6446. /**
  6447. Sets the document version. Used for optimistic concurrency
  6448. control when set. If the version of the currently indexed
  6449. document is less-than or equal to the version specified, an
  6450. error is produced, otherwise the operation is permitted.
  6451. By default, internal versioning is used that starts at 1 and
  6452. increments with each update.
  6453. This option is valid during the following operations:
  6454. index, delete, and update
  6455. @member ejs.Document
  6456. @param {Long} version A positive long value
  6457. @returns {Object} returns <code>this</code> so that calls can be chained.
  6458. */
  6459. version: function (version) {
  6460. if (version == null) {
  6461. return params.version;
  6462. }
  6463. params.version = version;
  6464. return this;
  6465. },
  6466. /**
  6467. Sets the version type. Possible values are:
  6468. internal - the default
  6469. external - to use your own version (ie. version number from a database)
  6470. This option is valid during the following operations:
  6471. index, delete, and update
  6472. @member ejs.Document
  6473. @param {String} vt A version type (internal or external)
  6474. @returns {Object} returns <code>this</code> so that calls can be chained.
  6475. */
  6476. versionType: function (vt) {
  6477. // internal or external
  6478. if (vt == null) {
  6479. return params.version_type;
  6480. }
  6481. vt = vt.toLowerCase();
  6482. if (vt === 'internal' || vt === 'external') {
  6483. params.version_type = vt;
  6484. }
  6485. return this;
  6486. },
  6487. /**
  6488. Perform percolation at index time. Set to * to run document
  6489. against all registered queries. It is also possible to set this
  6490. value to a string in query string format, ie. "color:green".
  6491. This option is valid during the following operations:
  6492. index and update
  6493. @member ejs.Document
  6494. @param {String} qry A percolation query string
  6495. @returns {Object} returns <code>this</code> so that calls can be chained.
  6496. */
  6497. percolate: function (qry) {
  6498. if (qry == null) {
  6499. return params.percolate;
  6500. }
  6501. params.percolate = qry;
  6502. return this;
  6503. },
  6504. /**
  6505. Sets the indexing operation type. Valid values are:
  6506. index - the default, create or replace
  6507. create - create only
  6508. This option is valid during the following operations:
  6509. index
  6510. @member ejs.Document
  6511. @param {String} op The operation type (index or create)
  6512. @returns {Object} returns <code>this</code> so that calls can be chained.
  6513. */
  6514. opType: function (op) {
  6515. if (op == null) {
  6516. return params.op_type;
  6517. }
  6518. op = op.toLowerCase();
  6519. if (op === 'index' || op === 'create') {
  6520. params.op_type = op;
  6521. }
  6522. return this;
  6523. },
  6524. /**
  6525. Sets the replication mode. Valid values are:
  6526. async - asynchronous replication to slaves
  6527. sync - synchronous replication to the slaves
  6528. default - the currently configured system default.
  6529. This option is valid during the following operations:
  6530. index, delete, and update
  6531. @member ejs.Document
  6532. @param {String} r The replication mode (async, sync, or default)
  6533. @returns {Object} returns <code>this</code> so that calls can be chained.
  6534. */
  6535. replication: function (r) {
  6536. if (r == null) {
  6537. return params.replication;
  6538. }
  6539. r = r.toLowerCase();
  6540. if (r === 'async' || r === 'sync' || r === 'default') {
  6541. params.replication = r;
  6542. }
  6543. return this;
  6544. },
  6545. /**
  6546. Sets the write consistency. Valid values are:
  6547. one - only requires write to one shard
  6548. quorum - requires writes to quorum (N/2 + 1)
  6549. all - requires write to succeed on all shards
  6550. default - the currently configured system default
  6551. This option is valid during the following operations:
  6552. index, delete, and update
  6553. @member ejs.Document
  6554. @param {String} c The write consistency (one, quorum, all, or default)
  6555. @returns {Object} returns <code>this</code> so that calls can be chained.
  6556. */
  6557. consistency: function (c) {
  6558. if (c == null) {
  6559. return params.consistency;
  6560. }
  6561. c = c.toLowerCase();
  6562. if (c === 'default' || c === 'one' || c === 'quorum' || c === 'all') {
  6563. params.consistency = c;
  6564. }
  6565. return this;
  6566. },
  6567. /**
  6568. Sets the preference of which shard replicas to execute the get
  6569. request on. By default, the operation is randomized between the
  6570. shard replicas. This value can be:
  6571. _primary - execute only on the primary shard
  6572. _local - the local shard if possible
  6573. any string value - to guarentee the same shards will always be used
  6574. This option is valid during the following operations:
  6575. get
  6576. @member ejs.Document
  6577. @param {String} p The preference value as a string
  6578. @returns {Object} returns <code>this</code> so that calls can be chained.
  6579. */
  6580. preference: function (p) {
  6581. if (p == null) {
  6582. return params.preference;
  6583. }
  6584. params.preference = p;
  6585. return this;
  6586. },
  6587. /**
  6588. Sets if the get request is performed in realtime or waits for
  6589. the indexing operations to complete. By default it is realtime.
  6590. This option is valid during the following operations:
  6591. get
  6592. @member ejs.Document
  6593. @param {Boolean} trueFalse If realtime get is used or not.
  6594. @returns {Object} returns <code>this</code> so that calls can be chained.
  6595. */
  6596. realtime: function (trueFalse) {
  6597. if (trueFalse == null) {
  6598. return params.realtime;
  6599. }
  6600. params.realtime = trueFalse;
  6601. return this;
  6602. },
  6603. /**
  6604. Sets the fields of the document to return. By default the
  6605. _source field is returned. Pass a single value to append to the
  6606. current list of fields, pass an array to overwrite the current
  6607. list of fields. The returned fields will either be loaded if
  6608. they are stored, or fetched from the _source
  6609. This option is valid during the following operations:
  6610. get and update
  6611. @member ejs.Document
  6612. @param {String || Array} fields a single field name or array of field names.
  6613. @returns {Object} returns <code>this</code> so that calls can be chained.
  6614. */
  6615. fields: function (fields) {
  6616. if (params.fields == null) {
  6617. params.fields = [];
  6618. }
  6619. if (fields == null) {
  6620. return params.fields;
  6621. }
  6622. if (isString(fields)) {
  6623. params.fields.push(fields);
  6624. } else if (isArray(fields)) {
  6625. params.fields = fields;
  6626. } else {
  6627. throw new TypeError('Argument must be string or array');
  6628. }
  6629. return this;
  6630. },
  6631. /**
  6632. Sets the update script.
  6633. This option is valid during the following operations:
  6634. update
  6635. @member ejs.Document
  6636. @param {String} script a script to use for docuement updates
  6637. @returns {Object} returns <code>this</code> so that calls can be chained.
  6638. */
  6639. script: function (script) {
  6640. if (script == null) {
  6641. return params.script;
  6642. }
  6643. params.script = script;
  6644. return this;
  6645. },
  6646. /**
  6647. Sets the update script lanauge. Defaults to mvel.
  6648. This option is valid during the following operations:
  6649. update
  6650. @member ejs.Document
  6651. @param {String} lang a valid script lanauge type such as mvel.
  6652. @returns {Object} returns <code>this</code> so that calls can be chained.
  6653. */
  6654. lang: function (lang) {
  6655. if (lang == null) {
  6656. return params.lang;
  6657. }
  6658. params.lang = lang;
  6659. return this;
  6660. },
  6661. /**
  6662. Sets the parameters sent to the update script. The params must
  6663. be an object where the key is the parameter name and the value is
  6664. the parameter value to use in the script.
  6665. This option is valid during the following operations:
  6666. update
  6667. @member ejs.Document
  6668. @param {Object} p a object with script parameters.
  6669. @returns {Object} returns <code>this</code> so that calls can be chained.
  6670. */
  6671. params: function (p) {
  6672. // accept object, prefix keys as sp_{key}
  6673. if (p == null) {
  6674. return params.params;
  6675. }
  6676. if (!isObject(p)) {
  6677. throw new TypeError('Argument must be an object');
  6678. }
  6679. params.params = p;
  6680. return this;
  6681. },
  6682. /**
  6683. Sets how many times to retry if there is a version conflict
  6684. between getting the document and indexing / deleting it.
  6685. Defaults to 0.
  6686. This option is valid during the following operations:
  6687. update
  6688. @member ejs.Document
  6689. @param {Integer} num the number of times to retry operation.
  6690. @returns {Object} returns <code>this</code> so that calls can be chained.
  6691. */
  6692. retryOnConflict: function (num) {
  6693. if (num == null) {
  6694. return params.retry_on_conflict;
  6695. }
  6696. params.retry_on_conflict = num;
  6697. return this;
  6698. },
  6699. /**
  6700. Sets the upsert document. The upsert document is used during
  6701. updates when the specified document you are attempting to
  6702. update does not exist.
  6703. This option is valid during the following operations:
  6704. update
  6705. @member ejs.Document
  6706. @param {Object} doc the upset document.
  6707. @returns {Object} returns <code>this</code> so that calls can be chained.
  6708. */
  6709. upsert: function (doc) {
  6710. if (doc == null) {
  6711. return params.upsert;
  6712. }
  6713. if (!isObject(doc)) {
  6714. throw new TypeError('Argument must be an object');
  6715. }
  6716. params.upsert = doc;
  6717. return this;
  6718. },
  6719. /**
  6720. Sets the source document. When set during an update operation,
  6721. it is used as the partial update document.
  6722. This option is valid during the following operations:
  6723. index and update
  6724. @member ejs.Document
  6725. @param {Object} doc the source document.
  6726. @returns {Object} returns <code>this</code> so that calls can be chained.
  6727. */
  6728. source: function (doc) {
  6729. if (doc == null) {
  6730. return params.source;
  6731. }
  6732. if (!isObject(doc)) {
  6733. throw new TypeError('Argument must be an object');
  6734. }
  6735. params.source = doc;
  6736. return this;
  6737. },
  6738. /**
  6739. <p>Allows you to serialize this object into a JSON encoded string.</p>
  6740. @member ejs.Document
  6741. @returns {String} returns this object as a serialized JSON string.
  6742. */
  6743. toString: function () {
  6744. return JSON.stringify(params);
  6745. },
  6746. /**
  6747. The type of ejs object. For internal use only.
  6748. @member ejs.Document
  6749. @returns {String} the type of object
  6750. */
  6751. _type: function () {
  6752. return 'document';
  6753. },
  6754. /**
  6755. <p>Retrieves the internal <code>document</code> object. This is
  6756. typically used by internal API functions so use with caution.</p>
  6757. @member ejs.Document
  6758. @returns {Object} returns this object's internal object.
  6759. */
  6760. _self: function () {
  6761. return params;
  6762. },
  6763. /**
  6764. <p>Retrieves a document from the given index and type.</p>
  6765. @member ejs.Document
  6766. @param {Function} fnCallBack A callback function that handles the response.
  6767. @returns {Object} The return value is dependent on client implementation.
  6768. */
  6769. doGet: function (fnCallBack) {
  6770. // make sure the user has set a client
  6771. if (ejs.client == null) {
  6772. throw new Error("No Client Set");
  6773. }
  6774. if (index == null || type == null || id == null) {
  6775. throw new Error('Index, Type, and ID must be set');
  6776. }
  6777. // we don't need to convert the client params to a string
  6778. // on get requests, just create the url and pass the client
  6779. // params as the data
  6780. var url = '/' + index + '/' + type + '/' + id;
  6781. return ejs.client.get(url, genClientParams(), fnCallBack);
  6782. },
  6783. /**
  6784. <p>Stores a document in the given index and type. If no id
  6785. is set, one is created during indexing.</p>
  6786. @member ejs.Document
  6787. @param {Function} fnCallBack A callback function that handles the response.
  6788. @returns {Object} The return value is dependent on client implementation.
  6789. */
  6790. doIndex: function (fnCallBack) {
  6791. // make sure the user has set a client
  6792. if (ejs.client == null) {
  6793. throw new Error("No Client Set");
  6794. }
  6795. if (index == null || type == null) {
  6796. throw new Error('Index and Type must be set');
  6797. }
  6798. if (params.source == null) {
  6799. throw new Error('No source document found');
  6800. }
  6801. var url = '/' + index + '/' + type,
  6802. data = JSON.stringify(params.source),
  6803. paramStr = genParamStr(),
  6804. response;
  6805. if (id != null) {
  6806. url = url + '/' + id;
  6807. }
  6808. if (paramStr !== '') {
  6809. url = url + '?' + paramStr;
  6810. }
  6811. // do post if id not set so one is created
  6812. if (id == null) {
  6813. response = ejs.client.post(url, data, fnCallBack);
  6814. } else {
  6815. // put when id is specified
  6816. response = ejs.client.put(url, data, fnCallBack);
  6817. }
  6818. return response;
  6819. },
  6820. /**
  6821. <p>Updates a document in the given index and type. If the
  6822. document is not found in the index, the "upsert" value is used
  6823. if set. The document is updated via an update script or partial
  6824. document. To use a script, set the script option, to use a
  6825. partial document, set the source with the partial document.</p>
  6826. @member ejs.Document
  6827. @param {Function} fnCallBack A callback function that handles the response.
  6828. @returns {Object} The return value is dependent on client implementation.
  6829. */
  6830. doUpdate: function (fnCallBack) {
  6831. // make sure the user has set a client
  6832. if (ejs.client == null) {
  6833. throw new Error("No Client Set");
  6834. }
  6835. if (index == null || type == null || id == null) {
  6836. throw new Error('Index, Type, and ID must be set');
  6837. }
  6838. if (params.script == null && params.source == null) {
  6839. throw new Error('Update script or document required');
  6840. }
  6841. var url = '/' + index + '/' + type + '/' + id + '/_update',
  6842. data = {},
  6843. paramStr = genParamStr();
  6844. if (paramStr !== '') {
  6845. url = url + '?' + paramStr;
  6846. }
  6847. if (params.script != null) {
  6848. data.script = params.script;
  6849. }
  6850. if (params.lang != null) {
  6851. data.lang = params.lang;
  6852. }
  6853. if (params.params != null) {
  6854. data.params = params.params;
  6855. }
  6856. if (params.upsert != null) {
  6857. data.upsert = params.upsert;
  6858. }
  6859. if (params.source != null) {
  6860. data.doc = params.source;
  6861. }
  6862. return ejs.client.post(url, JSON.stringify(data), fnCallBack);
  6863. },
  6864. /**
  6865. <p>Deletes the document from the given index and type using the
  6866. speciifed id.</p>
  6867. @member ejs.Document
  6868. @param {Function} fnCallBack A callback function that handles the response.
  6869. @returns {void} Returns the value of the callback when executing on the server.
  6870. */
  6871. doDelete: function (fnCallBack) {
  6872. // make sure the user has set a client
  6873. if (ejs.client == null) {
  6874. throw new Error("No Client Set");
  6875. }
  6876. if (index == null || type == null || id == null) {
  6877. throw new Error('Index, Type, and ID must be set');
  6878. }
  6879. var url = '/' + index + '/' + type + '/' + id,
  6880. data = '',
  6881. paramStr = genParamStr();
  6882. if (paramStr !== '') {
  6883. url = url + '?' + paramStr;
  6884. }
  6885. return ejs.client.del(url, data, fnCallBack);
  6886. }
  6887. };
  6888. };
  6889. /**
  6890. @class
  6891. <p>A <code>boolQuery</code> allows you to build <em>Boolean</em> query constructs
  6892. from individual term or phrase queries. For example you might want to search
  6893. for documents containing the terms <code>javascript</code> and <code>python</code>.</p>
  6894. @name ejs.BoolQuery
  6895. @desc
  6896. A Query that matches documents matching boolean combinations of other
  6897. queries, e.g. <code>termQuerys, phraseQuerys</code> or other <code>boolQuerys</code>.
  6898. */
  6899. ejs.BoolQuery = function () {
  6900. /**
  6901. The internal query object. <code>Use _self()</code>
  6902. @member ejs.BoolQuery
  6903. @property {Object} query
  6904. */
  6905. var query = {
  6906. bool: {}
  6907. };
  6908. return {
  6909. /**
  6910. Adds query to boolean container. Given query "must" appear in matching documents.
  6911. @member ejs.BoolQuery
  6912. @param {Object} oQuery A valid <code>Query</code> object
  6913. @returns {Object} returns <code>this</code> so that calls can be chained.
  6914. */
  6915. must: function (oQuery) {
  6916. var i, len;
  6917. if (query.bool.must == null) {
  6918. query.bool.must = [];
  6919. }
  6920. if (oQuery == null) {
  6921. return query.bool.must;
  6922. }
  6923. if (isQuery(oQuery)) {
  6924. query.bool.must.push(oQuery._self());
  6925. } else if (isArray(oQuery)) {
  6926. query.bool.must = [];
  6927. for (i = 0, len = oQuery.length; i < len; i++) {
  6928. if (!isQuery(oQuery[i])) {
  6929. throw new TypeError('Argument must be an array of Queries');
  6930. }
  6931. query.bool.must.push(oQuery[i]._self());
  6932. }
  6933. } else {
  6934. throw new TypeError('Argument must be a Query or array of Queries');
  6935. }
  6936. return this;
  6937. },
  6938. /**
  6939. Adds query to boolean container. Given query "must not" appear in matching documents.
  6940. @member ejs.BoolQuery
  6941. @param {Object} oQuery A valid query object
  6942. @returns {Object} returns <code>this</code> so that calls can be chained.
  6943. */
  6944. mustNot: function (oQuery) {
  6945. var i, len;
  6946. if (query.bool.must_not == null) {
  6947. query.bool.must_not = [];
  6948. }
  6949. if (oQuery == null) {
  6950. return query.bool.must_not;
  6951. }
  6952. if (isQuery(oQuery)) {
  6953. query.bool.must_not.push(oQuery._self());
  6954. } else if (isArray(oQuery)) {
  6955. query.bool.must_not = [];
  6956. for (i = 0, len = oQuery.length; i < len; i++) {
  6957. if (!isQuery(oQuery[i])) {
  6958. throw new TypeError('Argument must be an array of Queries');
  6959. }
  6960. query.bool.must_not.push(oQuery[i]._self());
  6961. }
  6962. } else {
  6963. throw new TypeError('Argument must be a Query or array of Queries');
  6964. }
  6965. return this;
  6966. },
  6967. /**
  6968. Adds query to boolean container. Given query "should" appear in matching documents.
  6969. @member ejs.BoolQuery
  6970. @param {Object} oQuery A valid query object
  6971. @returns {Object} returns <code>this</code> so that calls can be chained.
  6972. */
  6973. should: function (oQuery) {
  6974. var i, len;
  6975. if (query.bool.should == null) {
  6976. query.bool.should = [];
  6977. }
  6978. if (oQuery == null) {
  6979. return query.bool.should;
  6980. }
  6981. if (isQuery(oQuery)) {
  6982. query.bool.should.push(oQuery._self());
  6983. } else if (isArray(oQuery)) {
  6984. query.bool.should = [];
  6985. for (i = 0, len = oQuery.length; i < len; i++) {
  6986. if (!isQuery(oQuery[i])) {
  6987. throw new TypeError('Argument must be an array of Queries');
  6988. }
  6989. query.bool.should.push(oQuery[i]._self());
  6990. }
  6991. } else {
  6992. throw new TypeError('Argument must be a Query or array of Queries');
  6993. }
  6994. return this;
  6995. },
  6996. /**
  6997. Sets the boost value for documents matching the <code>Query</code>.
  6998. @member ejs.BoolQuery
  6999. @param {Double} boost A positive <code>double</code> value.
  7000. @returns {Object} returns <code>this</code> so that calls can be chained.
  7001. */
  7002. boost: function (boost) {
  7003. if (boost == null) {
  7004. return query.bool.boost;
  7005. }
  7006. query.bool.boost = boost;
  7007. return this;
  7008. },
  7009. /**
  7010. Enables or disables similarity coordinate scoring of documents
  7011. matching the <code>Query</code>. Default: false.
  7012. @member ejs.BoolQuery
  7013. @param {String} trueFalse A <code>true/false</code value.
  7014. @returns {Object} returns <code>this</code> so that calls can be chained.
  7015. */
  7016. disableCoord: function (trueFalse) {
  7017. if (trueFalse == null) {
  7018. return query.bool.disable_coord;
  7019. }
  7020. query.bool.disable_coord = trueFalse;
  7021. return this;
  7022. },
  7023. /**
  7024. Sets the number of optional clauses that must match.
  7025. By default no optional clauses are necessary for a match
  7026. (unless there are no required clauses). If this method is used,
  7027. then the specified number of clauses is required..
  7028. Use of this method is totally independent of specifying that
  7029. any specific clauses are required (or prohibited). This number will
  7030. only be compared against the number of matching optional clauses.
  7031. @member ejs.BoolQuery
  7032. @param {Integer} minMatch A positive <code>integer</code> value.
  7033. @returns {Object} returns <code>this</code> so that calls can be chained.
  7034. */
  7035. minimumNumberShouldMatch: function (minMatch) {
  7036. if (minMatch == null) {
  7037. return query.bool.minimum_number_should_match;
  7038. }
  7039. query.bool.minimum_number_should_match = minMatch;
  7040. return this;
  7041. },
  7042. /**
  7043. Allows you to serialize this object into a JSON encoded string.
  7044. @member ejs.BoolQuery
  7045. @returns {String} returns this object as a serialized JSON string.
  7046. */
  7047. toString: function () {
  7048. return JSON.stringify(query);
  7049. },
  7050. /**
  7051. The type of ejs object. For internal use only.
  7052. @member ejs.BoolQuery
  7053. @returns {String} the type of object
  7054. */
  7055. _type: function () {
  7056. return 'query';
  7057. },
  7058. /**
  7059. Retrieves the internal <code>query</code> object. This is typically used by
  7060. internal API functions so use with caution.
  7061. @member ejs.BoolQuery
  7062. @returns {String} returns this object's internal <code>query</code> property.
  7063. */
  7064. _self: function () {
  7065. return query;
  7066. }
  7067. };
  7068. };
  7069. /**
  7070. @class
  7071. <p>The boosting query can be used to effectively demote results that match
  7072. a given query. Unlike the “NOT” clause in bool query, this still selects
  7073. documents that contain undesirable terms, but reduces their overall
  7074. score.</p>
  7075. @name ejs.BoostingQuery
  7076. @desc
  7077. <p>Constructs a query that can demote search results. A negative boost.</p>
  7078. @param {Object} positiveQry Valid query object used to select all matching docs.
  7079. @param {Object} negativeQry Valid query object to match the undesirable docs
  7080. returned within the positiveQry result set.
  7081. @param {Double} negativeBoost A double value where 0 < n < 1.
  7082. */
  7083. ejs.BoostingQuery = function (positiveQry, negativeQry, negativeBoost) {
  7084. if (!isQuery(positiveQry) || !isQuery(negativeQry)) {
  7085. throw new TypeError('Arguments must be Queries');
  7086. }
  7087. /**
  7088. The internal Query object. Use <code>_self()</code>.
  7089. @member ejs.BoostingQuery
  7090. @property {Object} BoostingQuery
  7091. */
  7092. var query = {
  7093. boosting: {
  7094. positive: positiveQry._self(),
  7095. negative: negativeQry._self(),
  7096. negative_boost: negativeBoost
  7097. }
  7098. };
  7099. return {
  7100. /**
  7101. Sets the "master" query that determines which results are returned.
  7102. @member ejs.BoostingQuery
  7103. @param {Object} oQuery A valid <code>Query</code> object
  7104. @returns {Object} returns <code>this</code> so that calls can be
  7105. chained. Returns {Object} current positive query if oQuery is
  7106. not specified.
  7107. */
  7108. positive: function (oQuery) {
  7109. if (oQuery == null) {
  7110. return query.boosting.positive;
  7111. }
  7112. if (!isQuery(oQuery)) {
  7113. throw new TypeError('Argument must be a Query');
  7114. }
  7115. query.boosting.positive = oQuery._self();
  7116. return this;
  7117. },
  7118. /**
  7119. Sets the query used to match documents in the <code>positive</code>
  7120. query that will be negatively boosted.
  7121. @member ejs.BoostingQuery
  7122. @param {Object} oQuery A valid <code>Query</code> object
  7123. @returns {Object} returns <code>this</code> so that calls can be
  7124. chained. Returns {Object} current negative query if oQuery is
  7125. not specified.
  7126. */
  7127. negative: function (oQuery) {
  7128. if (oQuery == null) {
  7129. return query.boosting.negative;
  7130. }
  7131. if (!isQuery(oQuery)) {
  7132. throw new TypeError('Argument must be a Query');
  7133. }
  7134. query.boosting.negative = oQuery._self();
  7135. return this;
  7136. },
  7137. /**
  7138. Sets the negative boost value.
  7139. @member ejs.BoostingQuery
  7140. @param {Double} boost A positive <code>double</code> value where 0 < n < 1.
  7141. @returns {Object} returns <code>this</code> so that calls can be chained.
  7142. */
  7143. negativeBoost: function (negBoost) {
  7144. if (negBoost == null) {
  7145. return query.boosting.negative_boost;
  7146. }
  7147. query.boosting.negative_boost = negBoost;
  7148. return this;
  7149. },
  7150. /**
  7151. Sets the boost value of the <code>Query</code>.
  7152. @member ejs.BoostingQuery
  7153. @param {Double} boost A positive <code>double</code> value.
  7154. @returns {Object} returns <code>this</code> so that calls can be chained.
  7155. */
  7156. boost: function (boost) {
  7157. if (boost == null) {
  7158. return query.boosting.boost;
  7159. }
  7160. query.boosting.boost = boost;
  7161. return this;
  7162. },
  7163. /**
  7164. Serializes the internal <em>query</em> object as a JSON string.
  7165. @member ejs.BoostingQuery
  7166. @returns {String} Returns a JSON representation of the Query object.
  7167. */
  7168. toString: function () {
  7169. return JSON.stringify(query);
  7170. },
  7171. /**
  7172. The type of ejs object. For internal use only.
  7173. @member ejs.BoostingQuery
  7174. @returns {String} the type of object
  7175. */
  7176. _type: function () {
  7177. return 'query';
  7178. },
  7179. /**
  7180. This method is used to retrieve the raw query object. It's designed
  7181. for internal use when composing and serializing queries.
  7182. @member ejs.BoostingQuery
  7183. @returns {Object} Returns the object's <em>query</em> property.
  7184. */
  7185. _self: function () {
  7186. return query;
  7187. }
  7188. };
  7189. };
  7190. /**
  7191. @class
  7192. <p>A constant score query wraps another <code>Query</code> or
  7193. <code>Filter</code> and returns a constant score for each
  7194. result that is equal to the query boost.</p>
  7195. <p>Note that lucene's query normalization (queryNorm) attempts
  7196. to make scores between different queries comparable. It does not
  7197. change the relevance of your query, but it might confuse you when
  7198. you look at the score of your documents and they are not equal to
  7199. the query boost value as expected. The scores were normalized by
  7200. queryNorm, but maintain the same relevance.</p>
  7201. @name ejs.ConstantScoreQuery
  7202. @desc
  7203. <p>Constructs a query where each documents returned by the internal
  7204. query or filter have a constant score equal to the boost factor.</p>
  7205. */
  7206. ejs.ConstantScoreQuery = function () {
  7207. /**
  7208. The internal Query object. Use <code>_self()</code>.
  7209. @member ejs.ConstantScoreQuery
  7210. @property {Object} query
  7211. */
  7212. var query = {
  7213. constant_score: {}
  7214. };
  7215. return {
  7216. /**
  7217. Adds the query to apply a constant score to.
  7218. @member ejs.ConstantScoreQuery
  7219. @param {Object} oQuery A valid <code>Query</code> object
  7220. @returns {Object} returns <code>this</code> so that calls can be chained.
  7221. */
  7222. query: function (oQuery) {
  7223. if (oQuery == null) {
  7224. return query.constant_score.query;
  7225. }
  7226. if (!isQuery(oQuery)) {
  7227. throw new TypeError('Argument must be a Query');
  7228. }
  7229. query.constant_score.query = oQuery._self();
  7230. return this;
  7231. },
  7232. /**
  7233. Adds the filter to apply a constant score to.
  7234. @member ejs.ConstantScoreQuery
  7235. @param {Object} oFilter A valid <code>Filter</code> object
  7236. @returns {Object} returns <code>this</code> so that calls can be chained.
  7237. */
  7238. filter: function (oFilter) {
  7239. if (oFilter == null) {
  7240. return query.constant_score.filter;
  7241. }
  7242. if (!isFilter(oFilter)) {
  7243. throw new TypeError('Argument must be a Filter');
  7244. }
  7245. query.constant_score.filter = oFilter._self();
  7246. return this;
  7247. },
  7248. /**
  7249. Enables caching of the filter.
  7250. @member ejs.ConstantScoreQuery
  7251. @param {Boolean} trueFalse A boolean value.
  7252. @returns {Object} returns <code>this</code> so that calls can be chained.
  7253. */
  7254. cache: function (trueFalse) {
  7255. if (trueFalse == null) {
  7256. return query.constant_score._cache;
  7257. }
  7258. query.constant_score._cache = trueFalse;
  7259. return this;
  7260. },
  7261. /**
  7262. Set the cache key.
  7263. @member ejs.ConstantScoreQuery
  7264. @param {String} k A string cache key.
  7265. @returns {Object} returns <code>this</code> so that calls can be chained.
  7266. */
  7267. cacheKey: function (k) {
  7268. if (k == null) {
  7269. return query.constant_score._cache_key;
  7270. }
  7271. query.constant_score._cache_key = k;
  7272. return this;
  7273. },
  7274. /**
  7275. Sets the boost value of the <code>Query</code>.
  7276. @member ejs.ConstantScoreQuery
  7277. @param {Double} boost A positive <code>double</code> value.
  7278. @returns {Object} returns <code>this</code> so that calls can be chained.
  7279. */
  7280. boost: function (boost) {
  7281. if (boost == null) {
  7282. return query.constant_score.boost;
  7283. }
  7284. query.constant_score.boost = boost;
  7285. return this;
  7286. },
  7287. /**
  7288. Serializes the internal <em>query</em> object as a JSON string.
  7289. @member ejs.ConstantScoreQuery
  7290. @returns {String} Returns a JSON representation of the Query object.
  7291. */
  7292. toString: function () {
  7293. return JSON.stringify(query);
  7294. },
  7295. /**
  7296. The type of ejs object. For internal use only.
  7297. @member ejs.ConstantScoreQuery
  7298. @returns {String} the type of object
  7299. */
  7300. _type: function () {
  7301. return 'query';
  7302. },
  7303. /**
  7304. This method is used to retrieve the raw query object. It's designed
  7305. for internal use when composing and serializing queries.
  7306. @member ejs.ConstantScoreQuery
  7307. @returns {Object} Returns the object's <em>query</em> property.
  7308. */
  7309. _self: function () {
  7310. return query;
  7311. }
  7312. };
  7313. };
  7314. /**
  7315. @class
  7316. <p>A query allows to wrap another query and multiply its score by the
  7317. provided boost_factor. This can sometimes be desired since boost value set
  7318. on specific queries gets normalized, while this query boost factor does not.</p>
  7319. @name ejs.CustomBoostFactorQuery
  7320. @desc
  7321. Boosts a queries score without that boost being normalized.
  7322. @param {Object} qry A valid query object.
  7323. */
  7324. ejs.CustomBoostFactorQuery = function (qry) {
  7325. if (!isQuery(qry)) {
  7326. throw new TypeError('Argument must be a Query');
  7327. }
  7328. /**
  7329. The internal query object. <code>Use _self()</code>
  7330. @member ejs.CustomBoostFactorQuery
  7331. @property {Object} query
  7332. */
  7333. var query = {
  7334. custom_boost_factor: {
  7335. query: qry._self()
  7336. }
  7337. };
  7338. return {
  7339. /**
  7340. Sets the query to be apply the custom boost to.
  7341. @member ejs.CustomBoostFactorQuery
  7342. @param {Object} q A valid Query object
  7343. @returns {Object} returns <code>this</code> so that calls can be chained.
  7344. */
  7345. query: function (q) {
  7346. if (q == null) {
  7347. return query.custom_boost_factor.query;
  7348. }
  7349. if (!isQuery(q)) {
  7350. throw new TypeError('Argument must be a Query');
  7351. }
  7352. query.custom_boost_factor.query = q._self();
  7353. return this;
  7354. },
  7355. /**
  7356. Sets the language used in the script.
  7357. @member ejs.CustomBoostFactorQuery
  7358. @param {Double} boost The boost value.
  7359. @returns {Object} returns <code>this</code> so that calls can be chained.
  7360. */
  7361. boostFactor: function (boost) {
  7362. if (boost == null) {
  7363. return query.custom_boost_factor.boost_factor;
  7364. }
  7365. query.custom_boost_factor.boost_factor = boost;
  7366. return this;
  7367. },
  7368. /**
  7369. Sets the boost value of the <code>Query</code>.
  7370. @member ejs.CustomBoostFactorQuery
  7371. @param {Double} boost A positive <code>double</code> value.
  7372. @returns {Object} returns <code>this</code> so that calls can be chained.
  7373. */
  7374. boost: function (boost) {
  7375. if (boost == null) {
  7376. return query.custom_boost_factor.boost;
  7377. }
  7378. query.custom_boost_factor.boost = boost;
  7379. return this;
  7380. },
  7381. /**
  7382. Allows you to serialize this object into a JSON encoded string.
  7383. @member ejs.CustomBoostFactorQuery
  7384. @returns {String} returns this object as a serialized JSON string.
  7385. */
  7386. toString: function () {
  7387. return JSON.stringify(query);
  7388. },
  7389. /**
  7390. The type of ejs object. For internal use only.
  7391. @member ejs.CustomBoostFactorQuery
  7392. @returns {String} the type of object
  7393. */
  7394. _type: function () {
  7395. return 'query';
  7396. },
  7397. /**
  7398. Retrieves the internal <code>query</code> object. This is typically used by
  7399. internal API functions so use with caution.
  7400. @member ejs.CustomBoostFactorQuery
  7401. @returns {String} returns this object's internal <code>query</code> property.
  7402. */
  7403. _self: function () {
  7404. return query;
  7405. }
  7406. };
  7407. };
  7408. /**
  7409. @class
  7410. <p>A custom_filters_score query allows to execute a query, and if the hit
  7411. matches a provided filter (ordered), use either a boost or a script
  7412. associated with it to compute the score.</p>
  7413. <p>This can considerably simplify and increase performance for parameterized
  7414. based scoring since filters are easily cached for faster performance, and
  7415. boosting / script is considerably simpler.</p>
  7416. @name ejs.CustomFiltersScoreQuery
  7417. @desc
  7418. Returned documents matched by the query and scored based on if the document
  7419. matched in a filter.
  7420. @param {Object} qry A valid query object.
  7421. @param {Object || Array} filters A single object or array of objects. Each
  7422. object must have a 'filter' property and either a 'boost' or 'script'
  7423. property.
  7424. */
  7425. ejs.CustomFiltersScoreQuery = function (qry, filters) {
  7426. if (!isQuery(qry)) {
  7427. throw new TypeError('Argument must be a Query');
  7428. }
  7429. /**
  7430. The internal query object. <code>Use _self()</code>
  7431. @member ejs.CustomFiltersScoreQuery
  7432. @property {Object} query
  7433. */
  7434. var query = {
  7435. custom_filters_score: {
  7436. query: qry._self(),
  7437. filters: []
  7438. }
  7439. },
  7440. // generate a valid filter object that can be inserted into the filters
  7441. // array. Returns null when an invalid filter is passed in.
  7442. genFilterObject = function (filter) {
  7443. var obj = null;
  7444. if (filter.filter && isFilter(filter.filter)) {
  7445. obj = {
  7446. filter: filter.filter._self()
  7447. };
  7448. if (filter.boost) {
  7449. obj.boost = filter.boost;
  7450. } else if (filter.script) {
  7451. obj.script = filter.script;
  7452. } else {
  7453. // invalid filter, must boost or script must be specified
  7454. obj = null;
  7455. }
  7456. }
  7457. return obj;
  7458. };
  7459. each((isArray(filters) ? filters : [filters]), function (filter) {
  7460. var fObj = genFilterObject(filter);
  7461. if (fObj !== null) {
  7462. query.custom_filters_score.filters.push(fObj);
  7463. }
  7464. });
  7465. return {
  7466. /**
  7467. Sets the query to be apply the custom boost to.
  7468. @member ejs.CustomFiltersScoreQuery
  7469. @param {Object} q A valid Query object
  7470. @returns {Object} returns <code>this</code> so that calls can be chained.
  7471. */
  7472. query: function (q) {
  7473. if (q == null) {
  7474. return query.custom_filters_score.query;
  7475. }
  7476. if (!isQuery(q)) {
  7477. throw new TypeError('Argument must be a Query');
  7478. }
  7479. query.custom_filters_score.query = q._self();
  7480. return this;
  7481. },
  7482. /**
  7483. Sets the filters and their related boost or script scoring method.
  7484. Takes an array of objects where each object has a 'filter' property
  7485. and either a 'boost' or 'script' property. Pass a single object to
  7486. add to the current list of filters or pass a list of objects to
  7487. overwrite all existing filters.
  7488. <code>
  7489. {filter: someFilter, boost: 2.1}
  7490. </code>
  7491. @member ejs.CustomFiltersScoreQuery
  7492. @param {Object || Array} fltrs An object or array of objects
  7493. contining a filter and either a boost or script property.
  7494. @returns {Object} returns <code>this</code> so that calls can be chained.
  7495. */
  7496. filters: function (fltrs) {
  7497. if (fltrs == null) {
  7498. return query.custom_filters_score.filters;
  7499. }
  7500. if (isArray(fltrs)) {
  7501. query.custom_filters_score.filters = [];
  7502. }
  7503. each((isArray(fltrs) ? fltrs : [fltrs]), function (f) {
  7504. var fObj = genFilterObject(f);
  7505. if (fObj !== null) {
  7506. query.custom_filters_score.filters.push(fObj);
  7507. }
  7508. });
  7509. return this;
  7510. },
  7511. /**
  7512. A score_mode can be defined to control how multiple matching
  7513. filters control the score. By default, it is set to first which
  7514. means the first matching filter will control the score of the
  7515. result. It can also be set to min/max/total/avg/multiply which
  7516. will aggregate the result from all matching filters based on the
  7517. aggregation type.
  7518. @member ejs.CustomFiltersScoreQuery
  7519. @param {String} s The scoring type as a string.
  7520. @returns {Object} returns <code>this</code> so that calls can be chained.
  7521. */
  7522. scoreMode: function (s) {
  7523. if (s == null) {
  7524. return query.custom_filters_score.score_mode;
  7525. }
  7526. s = s.toLowerCase();
  7527. if (s === 'first' || s === 'min' || s === 'max' || s === 'total' || s === 'avg' || s === 'multiply') {
  7528. query.custom_filters_score.score_mode = s;
  7529. }
  7530. return this;
  7531. },
  7532. /**
  7533. Sets parameters that will be applied to the script. Overwrites
  7534. any existing params.
  7535. @member ejs.CustomFiltersScoreQuery
  7536. @param {Object} q An object where the keys are the parameter name and
  7537. values are the parameter value.
  7538. @returns {Object} returns <code>this</code> so that calls can be chained.
  7539. */
  7540. params: function (p) {
  7541. if (p == null) {
  7542. return query.custom_filters_score.params;
  7543. }
  7544. query.custom_filters_score.params = p;
  7545. return this;
  7546. },
  7547. /**
  7548. Sets the language used in the script.
  7549. @member ejs.CustomFiltersScoreQuery
  7550. @param {String} l The script language, defatuls to mvel.
  7551. @returns {Object} returns <code>this</code> so that calls can be chained.
  7552. */
  7553. lang: function (l) {
  7554. if (l == null) {
  7555. return query.custom_filters_score.lang;
  7556. }
  7557. query.custom_filters_score.lang = l;
  7558. return this;
  7559. },
  7560. /**
  7561. Sets the maximum value a computed boost can reach.
  7562. @member ejs.CustomFiltersScoreQuery
  7563. @param {Double} max A positive <code>double</code> value.
  7564. @returns {Object} returns <code>this</code> so that calls can be chained.
  7565. */
  7566. maxBoost: function (max) {
  7567. if (max == null) {
  7568. return query.custom_filters_score.max_boost;
  7569. }
  7570. query.custom_filters_score.max_boost = max;
  7571. return this;
  7572. },
  7573. /**
  7574. Sets the boost value of the <code>Query</code>.
  7575. @member ejs.CustomFiltersScoreQuery
  7576. @param {Double} boost A positive <code>double</code> value.
  7577. @returns {Object} returns <code>this</code> so that calls can be chained.
  7578. */
  7579. boost: function (boost) {
  7580. if (boost == null) {
  7581. return query.custom_filters_score.boost;
  7582. }
  7583. query.custom_filters_score.boost = boost;
  7584. return this;
  7585. },
  7586. /**
  7587. Allows you to serialize this object into a JSON encoded string.
  7588. @member ejs.CustomFiltersScoreQuery
  7589. @returns {String} returns this object as a serialized JSON string.
  7590. */
  7591. toString: function () {
  7592. return JSON.stringify(query);
  7593. },
  7594. /**
  7595. The type of ejs object. For internal use only.
  7596. @member ejs.CustomFiltersScoreQuery
  7597. @returns {String} the type of object
  7598. */
  7599. _type: function () {
  7600. return 'query';
  7601. },
  7602. /**
  7603. Retrieves the internal <code>query</code> object. This is typically used by
  7604. internal API functions so use with caution.
  7605. @member ejs.CustomFiltersScoreQuery
  7606. @returns {String} returns this object's internal <code>query</code> property.
  7607. */
  7608. _self: function () {
  7609. return query;
  7610. }
  7611. };
  7612. };
  7613. /**
  7614. @class
  7615. <p>A query that wraps another query and customize the scoring of it
  7616. optionally with a computation derived from other field values in the
  7617. doc (numeric ones) using script expression.</p>
  7618. @name ejs.CustomScoreQuery
  7619. @desc
  7620. Scores a query based on a script.
  7621. @param {Object} qry A valid query object.
  7622. @param {String} script A valid script expression.
  7623. */
  7624. ejs.CustomScoreQuery = function (qry, script) {
  7625. if (!isQuery(qry)) {
  7626. throw new TypeError('Argument must be a Query');
  7627. }
  7628. /**
  7629. The internal query object. <code>Use _self()</code>
  7630. @member ejs.CustomScoreQuery
  7631. @property {Object} query
  7632. */
  7633. var query = {
  7634. custom_score: {
  7635. query: qry._self(),
  7636. script: script
  7637. }
  7638. };
  7639. return {
  7640. /**
  7641. Sets the query to be apply the custom score to.
  7642. @member ejs.CustomScoreQuery
  7643. @param {Object} q A valid Query object
  7644. @returns {Object} returns <code>this</code> so that calls can be chained.
  7645. */
  7646. query: function (q) {
  7647. if (q == null) {
  7648. return query.custom_score.query;
  7649. }
  7650. if (!isQuery(q)) {
  7651. throw new TypeError('Argument must be a Query');
  7652. }
  7653. query.custom_score.query = q._self();
  7654. return this;
  7655. },
  7656. /**
  7657. Sets the script that calculates the custom score
  7658. @member ejs.CustomScoreQuery
  7659. @param {String} s A valid script expression
  7660. @returns {Object} returns <code>this</code> so that calls can be chained.
  7661. */
  7662. script: function (s) {
  7663. if (s == null) {
  7664. return query.custom_score.script;
  7665. }
  7666. query.custom_score.script = s;
  7667. return this;
  7668. },
  7669. /**
  7670. Sets parameters that will be applied to the script. Overwrites
  7671. any existing params.
  7672. @member ejs.CustomScoreQuery
  7673. @param {Object} p An object where the keys are the parameter name and
  7674. values are the parameter value.
  7675. @returns {Object} returns <code>this</code> so that calls can be chained.
  7676. */
  7677. params: function (p) {
  7678. if (p == null) {
  7679. return query.custom_score.params;
  7680. }
  7681. query.custom_score.params = p;
  7682. return this;
  7683. },
  7684. /**
  7685. Sets the language used in the script.
  7686. @member ejs.CustomScoreQuery
  7687. @param {String} l The script language, defatuls to mvel.
  7688. @returns {Object} returns <code>this</code> so that calls can be chained.
  7689. */
  7690. lang: function (l) {
  7691. if (l == null) {
  7692. return query.custom_score.lang;
  7693. }
  7694. query.custom_score.lang = l;
  7695. return this;
  7696. },
  7697. /**
  7698. Sets the boost value of the <code>Query</code>.
  7699. @member ejs.CustomScoreQuery
  7700. @param {Double} boost A positive <code>double</code> value.
  7701. @returns {Object} returns <code>this</code> so that calls can be chained.
  7702. */
  7703. boost: function (boost) {
  7704. if (boost == null) {
  7705. return query.custom_score.boost;
  7706. }
  7707. query.custom_score.boost = boost;
  7708. return this;
  7709. },
  7710. /**
  7711. Allows you to serialize this object into a JSON encoded string.
  7712. @member ejs.CustomScoreQuery
  7713. @returns {String} returns this object as a serialized JSON string.
  7714. */
  7715. toString: function () {
  7716. return JSON.stringify(query);
  7717. },
  7718. /**
  7719. The type of ejs object. For internal use only.
  7720. @member ejs.CustomScoreQuery
  7721. @returns {String} the type of object
  7722. */
  7723. _type: function () {
  7724. return 'query';
  7725. },
  7726. /**
  7727. Retrieves the internal <code>query</code> object. This is typically used by
  7728. internal API functions so use with caution.
  7729. @member ejs.CustomScoreQuery
  7730. @returns {String} returns this object's internal <code>query</code> property.
  7731. */
  7732. _self: function () {
  7733. return query;
  7734. }
  7735. };
  7736. };
  7737. /**
  7738. @class
  7739. A query that generates the union of documents produced by its subqueries, and
  7740. that scores each document with the maximum score for that document as produced
  7741. by any subquery, plus a tie breaking increment for any additional matching
  7742. subqueries.
  7743. @name ejs.DisMaxQuery
  7744. @desc
  7745. A query that generates the union of documents produced by its subqueries such
  7746. as <code>termQuerys, phraseQuerys</code>, <code>boolQuerys</code>, etc.
  7747. */
  7748. ejs.DisMaxQuery = function () {
  7749. /**
  7750. The internal query object. <code>Use _self()</code>
  7751. @member ejs.DisMaxQuery
  7752. @property {Object} query
  7753. */
  7754. var query = {
  7755. dis_max: {}
  7756. };
  7757. return {
  7758. /**
  7759. Updates the queries. If passed a single Query, it is added to the
  7760. list of existing queries. If passed an array of Queries, it
  7761. replaces all existing values.
  7762. @member ejs.DisMaxQuery
  7763. @param {Query || Array} qs A single Query or an array of Queries
  7764. @returns {Object} returns <code>this</code> so that calls can be chained.
  7765. */
  7766. queries: function (qs) {
  7767. var i, len;
  7768. if (qs == null) {
  7769. return query.dis_max.queries;
  7770. }
  7771. if (query.dis_max.queries == null) {
  7772. query.dis_max.queries = [];
  7773. }
  7774. if (isQuery(qs)) {
  7775. query.dis_max.queries.push(qs._self());
  7776. } else if (isArray(qs)) {
  7777. query.dis_max.queries = [];
  7778. for (i = 0, len = qs.length; i < len; i++) {
  7779. if (!isQuery(qs[i])) {
  7780. throw new TypeError('Argument must be array of Queries');
  7781. }
  7782. query.dis_max.queries.push(qs[i]._self());
  7783. }
  7784. } else {
  7785. throw new TypeError('Argument must be a Query or array of Queries');
  7786. }
  7787. return this;
  7788. },
  7789. /**
  7790. Sets the boost value of the <code>Query</code>. Default: 1.0.
  7791. @member ejs.DisMaxQuery
  7792. @param {Double} boost A positive <code>double</code> value.
  7793. @returns {Object} returns <code>this</code> so that calls can be chained.
  7794. */
  7795. boost: function (boost) {
  7796. if (boost == null) {
  7797. return query.dis_max.boost;
  7798. }
  7799. query.dis_max.boost = boost;
  7800. return this;
  7801. },
  7802. /**
  7803. The tie breaker value. The tie breaker capability allows results
  7804. that include the same term in multiple fields to be judged better than
  7805. results that include this term in only the best of those multiple
  7806. fields, without confusing this with the better case of two different
  7807. terms in the multiple fields. Default: 0.0.
  7808. @member ejs.DisMaxQuery
  7809. @param {Double} tieBreaker A positive <code>double</code> value.
  7810. @returns {Object} returns <code>this</code> so that calls can be chained.
  7811. */
  7812. tieBreaker: function (tieBreaker) {
  7813. if (tieBreaker == null) {
  7814. return query.dis_max.tie_breaker;
  7815. }
  7816. query.dis_max.tie_breaker = tieBreaker;
  7817. return this;
  7818. },
  7819. /**
  7820. Allows you to serialize this object into a JSON encoded string.
  7821. @member ejs.DisMaxQuery
  7822. @returns {String} returns this object as a serialized JSON string.
  7823. */
  7824. toString: function () {
  7825. return JSON.stringify(query);
  7826. },
  7827. /**
  7828. The type of ejs object. For internal use only.
  7829. @member ejs.DisMaxQuery
  7830. @returns {String} the type of object
  7831. */
  7832. _type: function () {
  7833. return 'query';
  7834. },
  7835. /**
  7836. Retrieves the internal <code>query</code> object. This is typically used by
  7837. internal API functions so use with caution.
  7838. @member ejs.DisMaxQuery
  7839. @returns {String} returns this object's internal <code>query</code> property.
  7840. */
  7841. _self: function () {
  7842. return query;
  7843. }
  7844. };
  7845. };
  7846. /**
  7847. @class
  7848. <p>Wrapper to allow SpanQuery objects participate in composite single-field
  7849. SpanQueries by 'lying' about their search field. That is, the masked
  7850. SpanQuery will function as normal, but when asked for the field it
  7851. queries against, it will return the value specified as the masked field vs.
  7852. the real field used in the wrapped span query.</p>
  7853. @name ejs.FieldMaskingSpanQuery
  7854. @desc
  7855. Wraps a SpanQuery and hides the real field being searched across.
  7856. @param {Query} spanQry A valid SpanQuery
  7857. @param {Integer} field the maximum field position in a match.
  7858. */
  7859. ejs.FieldMaskingSpanQuery = function (spanQry, field) {
  7860. if (!isQuery(spanQry)) {
  7861. throw new TypeError('Argument must be a SpanQuery');
  7862. }
  7863. /**
  7864. The internal query object. <code>Use _self()</code>
  7865. @member ejs.FieldMaskingSpanQuery
  7866. @property {Object} query
  7867. */
  7868. var query = {
  7869. field_masking_span: {
  7870. query: spanQry._self(),
  7871. field: field
  7872. }
  7873. };
  7874. return {
  7875. /**
  7876. Sets the span query to wrap.
  7877. @member ejs.FieldMaskingSpanQuery
  7878. @param {Query} spanQuery Any valid span type query.
  7879. @returns {Object} returns <code>this</code> so that calls can be chained.
  7880. */
  7881. query: function (spanQuery) {
  7882. if (spanQuery == null) {
  7883. return query.field_masking_span.query;
  7884. }
  7885. if (!isQuery(spanQuery)) {
  7886. throw new TypeError('Argument must be a SpanQuery');
  7887. }
  7888. query.field_masking_span.query = spanQuery._self();
  7889. return this;
  7890. },
  7891. /**
  7892. Sets the value of the "masked" field.
  7893. @member ejs.FieldMaskingSpanQuery
  7894. @param {String} f A field name the wrapped span query should use
  7895. @returns {Object} returns <code>this</code> so that calls can be chained.
  7896. */
  7897. field: function (f) {
  7898. if (f == null) {
  7899. return query.field_masking_span.field;
  7900. }
  7901. query.field_masking_span.field = f;
  7902. return this;
  7903. },
  7904. /**
  7905. Sets the boost value of the <code>Query</code>.
  7906. @member ejs.FieldMaskingSpanQuery
  7907. @param {Double} boost A positive <code>double</code> value.
  7908. @returns {Object} returns <code>this</code> so that calls can be chained.
  7909. */
  7910. boost: function (boost) {
  7911. if (boost == null) {
  7912. return query.field_masking_span.boost;
  7913. }
  7914. query.field_masking_span.boost = boost;
  7915. return this;
  7916. },
  7917. /**
  7918. Allows you to serialize this object into a JSON encoded string.
  7919. @member ejs.FieldMaskingSpanQuery
  7920. @returns {String} returns this object as a serialized JSON string.
  7921. */
  7922. toString: function () {
  7923. return JSON.stringify(query);
  7924. },
  7925. /**
  7926. The type of ejs object. For internal use only.
  7927. @member ejs.FieldMaskingSpanQuery
  7928. @returns {String} the type of object
  7929. */
  7930. _type: function () {
  7931. return 'query';
  7932. },
  7933. /**
  7934. Retrieves the internal <code>query</code> object. This is typically used by
  7935. internal API functions so use with caution.
  7936. @member ejs.FieldMaskingSpanQuery
  7937. @returns {String} returns this object's internal <code>query</code> property.
  7938. */
  7939. _self: function () {
  7940. return query;
  7941. }
  7942. };
  7943. };
  7944. /**
  7945. @class
  7946. A query that executes against a given field or document property. It is a simplified version
  7947. of the <code><a href="/jsdocs/ejs.queryString.html">queryString</a></code> object.
  7948. @name ejs.FieldQuery
  7949. @desc
  7950. A query that executes against a given field or document property.
  7951. @param {String} field The field or document property to search against.
  7952. @param {String} qstr The value to match.
  7953. */
  7954. ejs.FieldQuery = function (field, qstr) {
  7955. /**
  7956. The internal query object. <code>Use get()</code>
  7957. @member ejs.FieldQuery
  7958. @property {Object} query
  7959. */
  7960. var query = {
  7961. field: {}
  7962. };
  7963. query.field[field] = {
  7964. query: qstr
  7965. };
  7966. return {
  7967. /**
  7968. The field to run the query against.
  7969. @member ejs.FieldQuery
  7970. @param {String} f A single field name.
  7971. @returns {Object} returns <code>this</code> so that calls can be chained.
  7972. */
  7973. field: function (f) {
  7974. var oldValue = query.field[field];
  7975. if (f == null) {
  7976. return field;
  7977. }
  7978. delete query.field[field];
  7979. field = f;
  7980. query.field[f] = oldValue;
  7981. return this;
  7982. },
  7983. /**
  7984. Sets the query string.
  7985. @member ejs.FieldQuery
  7986. @param {String} q The lucene query string.
  7987. @returns {Object} returns <code>this</code> so that calls can be chained.
  7988. */
  7989. query: function (q) {
  7990. if (q == null) {
  7991. return query.field[field].query;
  7992. }
  7993. query.field[field].query = q;
  7994. return this;
  7995. },
  7996. /**
  7997. Set the default <em>Boolean</em> operator. This operator is used
  7998. to join individual query terms when no operator is explicity used
  7999. in the query string (i.e., <code>this AND that</code>).
  8000. Defaults to <code>OR</code> (<em>same as Google</em>).
  8001. @member ejs.FieldQuery
  8002. @param {String} op The operator, AND or OR.
  8003. @returns {Object} returns <code>this</code> so that calls can be chained.
  8004. */
  8005. defaultOperator: function (op) {
  8006. if (op == null) {
  8007. return query.field[field].default_operator;
  8008. }
  8009. op = op.toUpperCase();
  8010. if (op === 'AND' || op === 'OR') {
  8011. query.field[field].default_operator = op;
  8012. }
  8013. return this;
  8014. },
  8015. /**
  8016. Sets the analyzer name used to analyze the <code>Query</code> object.
  8017. @member ejs.FieldQuery
  8018. @param {String} analyzer A valid analyzer name.
  8019. @returns {Object} returns <code>this</code> so that calls can be chained.
  8020. */
  8021. analyzer: function (analyzer) {
  8022. if (analyzer == null) {
  8023. return query.field[field].analyzer;
  8024. }
  8025. query.field[field].analyzer = analyzer;
  8026. return this;
  8027. },
  8028. /**
  8029. Sets the quote analyzer name used to analyze the <code>query</code>
  8030. when in quoted text.
  8031. @member ejs.FieldQuery
  8032. @param {String} analyzer A valid analyzer name.
  8033. @returns {Object} returns <code>this</code> so that calls can be chained.
  8034. */
  8035. quoteAnalyzer: function (analyzer) {
  8036. if (analyzer == null) {
  8037. return query.field[field].quote_analyzer;
  8038. }
  8039. query.field[field].quote_analyzer = analyzer;
  8040. return this;
  8041. },
  8042. /**
  8043. Sets whether or not we should auto generate phrase queries *if* the
  8044. analyzer returns more than one term. Default: false.
  8045. @member ejs.FieldQuery
  8046. @param {Boolean} trueFalse A <code>true/false</code> value.
  8047. @returns {Object} returns <code>this</code> so that calls can be chained.
  8048. */
  8049. autoGeneratePhraseQueries: function (trueFalse) {
  8050. if (trueFalse == null) {
  8051. return query.field[field].auto_generate_phrase_queries;
  8052. }
  8053. query.field[field].auto_generate_phrase_queries = trueFalse;
  8054. return this;
  8055. },
  8056. /**
  8057. Sets whether or not wildcard characters (* and ?) are allowed as the
  8058. first character of the <code>Query</code>. Default: true.
  8059. @member ejs.FieldQuery
  8060. @param {Boolean} trueFalse A <code>true/false</code> value.
  8061. @returns {Object} returns <code>this</code> so that calls can be chained.
  8062. */
  8063. allowLeadingWildcard: function (trueFalse) {
  8064. if (trueFalse == null) {
  8065. return query.field[field].allow_leading_wildcard;
  8066. }
  8067. query.field[field].allow_leading_wildcard = trueFalse;
  8068. return this;
  8069. },
  8070. /**
  8071. Sets whether or not terms from wildcard, prefix, fuzzy, and
  8072. range queries should automatically be lowercased in the <code>Query</code>
  8073. since they are not analyzed. Default: true.
  8074. @member ejs.FieldQuery
  8075. @param {Boolean} trueFalse A <code>true/false</code> value.
  8076. @returns {Object} returns <code>this</code> so that calls can be chained.
  8077. */
  8078. lowercaseExpandedTerms: function (trueFalse) {
  8079. if (trueFalse == null) {
  8080. return query.field[field].lowercase_expanded_terms;
  8081. }
  8082. query.field[field].lowercase_expanded_terms = trueFalse;
  8083. return this;
  8084. },
  8085. /**
  8086. Sets whether or not position increments will be used in the
  8087. <code>Query</code>. Default: true.
  8088. @member ejs.FieldQuery
  8089. @param {Boolean} trueFalse A <code>true/false</code> value.
  8090. @returns {Object} returns <code>this</code> so that calls can be chained.
  8091. */
  8092. enablePositionIncrements: function (trueFalse) {
  8093. if (trueFalse == null) {
  8094. return query.field[field].enable_position_increments;
  8095. }
  8096. query.field[field].enable_position_increments = trueFalse;
  8097. return this;
  8098. },
  8099. /**
  8100. Set the minimum similarity for fuzzy queries. Default: 0.5.
  8101. @member ejs.FieldQuery
  8102. @param {Double} minSim A <code>double</code> value between 0 and 1.
  8103. @returns {Object} returns <code>this</code> so that calls can be chained.
  8104. */
  8105. fuzzyMinSim: function (minSim) {
  8106. if (minSim == null) {
  8107. return query.field[field].fuzzy_min_sim;
  8108. }
  8109. query.field[field].fuzzy_min_sim = minSim;
  8110. return this;
  8111. },
  8112. /**
  8113. Sets the boost value of the <code>Query</code>. Default: 1.0.
  8114. @member ejs.FieldQuery
  8115. @param {Double} boost A positive <code>double</code> value.
  8116. @returns {Object} returns <code>this</code> so that calls can be chained.
  8117. */
  8118. boost: function (boost) {
  8119. if (boost == null) {
  8120. return query.field[field].boost;
  8121. }
  8122. query.field[field].boost = boost;
  8123. return this;
  8124. },
  8125. /**
  8126. Sets the prefix length for fuzzy queries. Default: 0.
  8127. @member ejs.FieldQuery
  8128. @param {Integer} fuzzLen A positive <code>integer</code> value.
  8129. @returns {Object} returns <code>this</code> so that calls can be chained.
  8130. */
  8131. fuzzyPrefixLength: function (fuzzLen) {
  8132. if (fuzzLen == null) {
  8133. return query.field[field].fuzzy_prefix_length;
  8134. }
  8135. query.field[field].fuzzy_prefix_length = fuzzLen;
  8136. return this;
  8137. },
  8138. /**
  8139. Sets the max number of term expansions for fuzzy queries.
  8140. @member ejs.FieldQuery
  8141. @param {Integer} max A positive <code>integer</code> value.
  8142. @returns {Object} returns <code>this</code> so that calls can be chained.
  8143. */
  8144. fuzzyMaxExpansions: function (max) {
  8145. if (max == null) {
  8146. return query.field[field].fuzzy_max_expansions;
  8147. }
  8148. query.field[field].fuzzy_max_expansions = max;
  8149. return this;
  8150. },
  8151. /**
  8152. Sets fuzzy rewrite method. Valid values are:
  8153. constant_score_auto - tries to pick the best constant-score rewrite
  8154. method based on term and document counts from the query
  8155. scoring_boolean - translates each term into boolean should and
  8156. keeps the scores as computed by the query
  8157. constant_score_boolean - same as scoring_boolean, expect no scores
  8158. are computed.
  8159. constant_score_filter - first creates a private Filter, by visiting
  8160. each term in sequence and marking all docs for that term
  8161. top_terms_boost_N - first translates each term into boolean should
  8162. and scores are only computed as the boost using the top N
  8163. scoring terms. Replace N with an integer value.
  8164. top_terms_N - first translates each term into boolean should
  8165. and keeps the scores as computed by the query. Only the top N
  8166. scoring terms are used. Replace N with an integer value.
  8167. Default is constant_score_auto.
  8168. This is an advanced option, use with care.
  8169. @member ejs.FieldQuery
  8170. @param {String} m The rewrite method as a string.
  8171. @returns {Object} returns <code>this</code> so that calls can be chained.
  8172. */
  8173. fuzzyRewrite: function (m) {
  8174. if (m == null) {
  8175. return query.field[field].fuzzy_rewrite;
  8176. }
  8177. m = m.toLowerCase();
  8178. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  8179. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  8180. m.indexOf('top_terms_boost_') === 0 ||
  8181. m.indexOf('top_terms_') === 0) {
  8182. query.field[field].fuzzy_rewrite = m;
  8183. }
  8184. return this;
  8185. },
  8186. /**
  8187. Sets rewrite method. Valid values are:
  8188. constant_score_auto - tries to pick the best constant-score rewrite
  8189. method based on term and document counts from the query
  8190. scoring_boolean - translates each term into boolean should and
  8191. keeps the scores as computed by the query
  8192. constant_score_boolean - same as scoring_boolean, expect no scores
  8193. are computed.
  8194. constant_score_filter - first creates a private Filter, by visiting
  8195. each term in sequence and marking all docs for that term
  8196. top_terms_boost_N - first translates each term into boolean should
  8197. and scores are only computed as the boost using the top N
  8198. scoring terms. Replace N with an integer value.
  8199. top_terms_N - first translates each term into boolean should
  8200. and keeps the scores as computed by the query. Only the top N
  8201. scoring terms are used. Replace N with an integer value.
  8202. Default is constant_score_auto.
  8203. This is an advanced option, use with care.
  8204. @member ejs.FieldQuery
  8205. @param {String} m The rewrite method as a string.
  8206. @returns {Object} returns <code>this</code> so that calls can be chained.
  8207. */
  8208. rewrite: function (m) {
  8209. if (m == null) {
  8210. return query.field[field].rewrite;
  8211. }
  8212. m = m.toLowerCase();
  8213. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  8214. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  8215. m.indexOf('top_terms_boost_') === 0 ||
  8216. m.indexOf('top_terms_') === 0) {
  8217. query.field[field].rewrite = m;
  8218. }
  8219. return this;
  8220. },
  8221. /**
  8222. Sets the suffix to automatically add to the field name when
  8223. performing a quoted search.
  8224. @member ejs.FieldQuery
  8225. @param {String} s The suffix as a string.
  8226. @returns {Object} returns <code>this</code> so that calls can be chained.
  8227. */
  8228. quoteFieldSuffix: function (s) {
  8229. if (s == null) {
  8230. return query.field[field].quote_field_suffix;
  8231. }
  8232. query.field[field].quote_field_suffix = s;
  8233. return this;
  8234. },
  8235. /**
  8236. Sets the default slop for phrases. If zero, then exact phrase matches
  8237. are required. Default: 0.
  8238. @member ejs.FieldQuery
  8239. @param {Integer} slop A positive <code>integer</code> value.
  8240. @returns {Object} returns <code>this</code> so that calls can be chained.
  8241. */
  8242. phraseSlop: function (slop) {
  8243. if (slop == null) {
  8244. return query.field[field].phrase_slop;
  8245. }
  8246. query.field[field].phrase_slop = slop;
  8247. return this;
  8248. },
  8249. /**
  8250. Sets whether or not we should attempt to analyzed wilcard terms in the
  8251. <code>Query</code>. By default, wildcard terms are not analyzed.
  8252. Analysis of wildcard characters is not perfect. Default: false.
  8253. @member ejs.FieldQuery
  8254. @param {Boolean} trueFalse A <code>true/false</code> value.
  8255. @returns {Object} returns <code>this</code> so that calls can be chained.
  8256. */
  8257. analyzeWildcard: function (trueFalse) {
  8258. if (trueFalse == null) {
  8259. return query.field[field].analyze_wildcard;
  8260. }
  8261. query.field[field].analyze_wildcard = trueFalse;
  8262. return this;
  8263. },
  8264. /**
  8265. If they query string should be escaped or not.
  8266. @member ejs.FieldQuery
  8267. @param {Boolean} trueFalse A <code>true/false</code> value.
  8268. @returns {Object} returns <code>this</code> so that calls can be chained.
  8269. */
  8270. escape: function (trueFalse) {
  8271. if (trueFalse == null) {
  8272. return query.field[field].escape;
  8273. }
  8274. query.field[field].escape = trueFalse;
  8275. return this;
  8276. },
  8277. /**
  8278. Sets a percent value controlling how many "should" clauses in the
  8279. resulting <code>Query</code> should match.
  8280. @member ejs.FieldQuery
  8281. @param {Integer} minMatch An <code>integer</code> between 0 and 100.
  8282. @returns {Object} returns <code>this</code> so that calls can be chained.
  8283. */
  8284. minimumShouldMatch: function (minMatch) {
  8285. if (minMatch == null) {
  8286. return query.field[field].minimum_should_match;
  8287. }
  8288. query.field[field].minimum_should_match = minMatch;
  8289. return this;
  8290. },
  8291. /**
  8292. Allows you to serialize this object into a JSON encoded string.
  8293. @member ejs.FieldQuery
  8294. @returns {String} returns this object as a serialized JSON string.
  8295. */
  8296. toString: function () {
  8297. return JSON.stringify(query);
  8298. },
  8299. /**
  8300. The type of ejs object. For internal use only.
  8301. @member ejs.FieldQuery
  8302. @returns {String} the type of object
  8303. */
  8304. _type: function () {
  8305. return 'query';
  8306. },
  8307. /**
  8308. Retrieves the internal <code>query</code> object. This is typically used by
  8309. internal API functions so use with caution.
  8310. @member ejs.FieldQuery
  8311. @returns {String} returns this object's internal <code>query</code> property.
  8312. */
  8313. _self: function () {
  8314. return query;
  8315. }
  8316. };
  8317. };
  8318. /**
  8319. @class
  8320. <p>Filter queries allow you to restrict the results returned by a query. There are
  8321. several different types of filters that can be applied
  8322. (see <a href="/jsdocs/ejs.filter.html">filter</a> module). A <code>filterQuery</code>
  8323. takes a <code>Query</code> and a <code>Filter</code> object as arguments and constructs
  8324. a new <code>Query</code> that is then used for the search.</p>
  8325. @name ejs.FilteredQuery
  8326. @desc
  8327. <p>A query that applies a filter to the results of another query.</p>
  8328. @param {Object} someQuery a valid <code>Query</code> object
  8329. @param {Object} someFilter a valid <code>Filter</code> object. This parameter
  8330. is optional.
  8331. */
  8332. ejs.FilteredQuery = function (someQuery, someFilter) {
  8333. if (!isQuery(someQuery)) {
  8334. throw new TypeError('Argument must be a Query');
  8335. }
  8336. if (someFilter != null && !isFilter(someFilter)) {
  8337. throw new TypeError('Argument must be a Filter');
  8338. }
  8339. /**
  8340. The internal query object. Use <code>_self()</code>
  8341. @member ejs.FilteredQuery
  8342. @property {Object} query
  8343. */
  8344. var query = {
  8345. filtered: {
  8346. query: someQuery._self()
  8347. }
  8348. };
  8349. if (someFilter != null) {
  8350. query.filtered.filter = someFilter._self();
  8351. }
  8352. return {
  8353. /**
  8354. Adds the query to apply a constant score to.
  8355. @member ejs.FilteredQuery
  8356. @param {Object} oQuery A valid <code>Query</code> object
  8357. @returns {Object} returns <code>this</code> so that calls can be chained.
  8358. */
  8359. query: function (oQuery) {
  8360. if (oQuery == null) {
  8361. return query.filtered.query;
  8362. }
  8363. if (!isQuery(oQuery)) {
  8364. throw new TypeError('Argument must be a Query');
  8365. }
  8366. query.filtered.query = oQuery._self();
  8367. return this;
  8368. },
  8369. /**
  8370. Adds the filter to apply a constant score to.
  8371. @member ejs.FilteredQuery
  8372. @param {Object} oFilter A valid <code>Filter</code> object
  8373. @returns {Object} returns <code>this</code> so that calls can be chained.
  8374. */
  8375. filter: function (oFilter) {
  8376. if (oFilter == null) {
  8377. return query.filtered.filter;
  8378. }
  8379. if (!isFilter(oFilter)) {
  8380. throw new TypeError('Argument must be a Filter');
  8381. }
  8382. query.filtered.filter = oFilter._self();
  8383. return this;
  8384. },
  8385. /**
  8386. Sets the filter strategy. The strategy defines how the filter is
  8387. applied during document collection. Valid values are:
  8388. query_filter - advance query scorer first then filter
  8389. random_access_random - random access filter
  8390. leap_frog - query scorer and filter "leap-frog", query goes first
  8391. leap_frog_filter_first - same as leap_frog, but filter goes first
  8392. random_access_N - replace N with integer, same as random access
  8393. except you can specify a custom threshold
  8394. This is an advanced setting, use with care.
  8395. @member ejs.FilteredQuery
  8396. @param {String} strategy The strategy as a string.
  8397. @returns {Object} returns <code>this</code> so that calls can be chained.
  8398. */
  8399. strategy: function (strategy) {
  8400. if (strategy == null) {
  8401. return query.filtered.strategy;
  8402. }
  8403. strategy = strategy.toLowerCase();
  8404. if (strategy === 'query_filter' || strategy === 'random_access_random' ||
  8405. strategy === 'leap_frog' || strategy === 'leap_frog_filter_first' ||
  8406. strategy.indexOf('random_access_') === 0) {
  8407. query.filtered.strategy = strategy;
  8408. }
  8409. return this;
  8410. },
  8411. /**
  8412. Enables caching of the filter.
  8413. @member ejs.FilteredQuery
  8414. @param {Boolean} trueFalse A boolean value.
  8415. @returns {Object} returns <code>this</code> so that calls can be chained.
  8416. */
  8417. cache: function (trueFalse) {
  8418. if (trueFalse == null) {
  8419. return query.filtered._cache;
  8420. }
  8421. query.filtered._cache = trueFalse;
  8422. return this;
  8423. },
  8424. /**
  8425. Set the cache key.
  8426. @member ejs.FilteredQuery
  8427. @param {String} k A string cache key.
  8428. @returns {Object} returns <code>this</code> so that calls can be chained.
  8429. */
  8430. cacheKey: function (k) {
  8431. if (k == null) {
  8432. return query.filtered._cache_key;
  8433. }
  8434. query.filtered._cache_key = k;
  8435. return this;
  8436. },
  8437. /**
  8438. Sets the boost value of the <code>Query</code>.
  8439. @member ejs.FilteredQuery
  8440. @param {Double} boost A positive <code>double</code> value.
  8441. @returns {Object} returns <code>this</code> so that calls can be chained.
  8442. */
  8443. boost: function (boost) {
  8444. if (boost == null) {
  8445. return query.filtered.boost;
  8446. }
  8447. query.filtered.boost = boost;
  8448. return this;
  8449. },
  8450. /**
  8451. Converts this object to a json string
  8452. @member ejs.FilteredQuery
  8453. @returns {Object} string
  8454. */
  8455. toString: function () {
  8456. return JSON.stringify(query);
  8457. },
  8458. /**
  8459. The type of ejs object. For internal use only.
  8460. @member ejs.FilteredQuery
  8461. @returns {String} the type of object
  8462. */
  8463. _type: function () {
  8464. return 'query';
  8465. },
  8466. /**
  8467. returns the query object.
  8468. @member ejs.FilteredQuery
  8469. @returns {Object} query object
  8470. */
  8471. _self: function () {
  8472. return query;
  8473. }
  8474. };
  8475. };
  8476. /**
  8477. @class
  8478. <p>The fuzzy_like_this_field query is the same as the fuzzy_like_this
  8479. query, except that it runs against a single field. It provides nicer query
  8480. DSL over the generic fuzzy_like_this query, and support typed fields
  8481. query (automatically wraps typed fields with type filter to match only on
  8482. the specific type).</p>
  8483. <p>Fuzzifies ALL terms provided as strings and then picks the best n
  8484. differentiating terms. In effect this mixes the behaviour of FuzzyQuery and
  8485. MoreLikeThis but with special consideration of fuzzy scoring factors. This
  8486. generally produces good results for queries where users may provide details
  8487. in a number of fields and have no knowledge of boolean query syntax and
  8488. also want a degree of fuzzy matching and a fast query.</p>
  8489. <p>For each source term the fuzzy variants are held in a BooleanQuery with
  8490. no coord factor (because we are not looking for matches on multiple variants
  8491. in any one doc). Additionally, a specialized TermQuery is used for variants
  8492. and does not use that variant term’s IDF because this would favour rarer
  8493. terms eg misspellings. Instead, all variants use the same IDF
  8494. ranking (the one for the source query term) and this is factored into the
  8495. variant’s boost. If the source query term does not exist in the index the
  8496. average IDF of the variants is used.</p>
  8497. @name ejs.FuzzyLikeThisFieldQuery
  8498. @desc
  8499. <p>Constructs a query where each documents returned are “like” provided text</p>
  8500. @param {String} field The field to run the query against.
  8501. @param {String} likeText The text to find documents like it.
  8502. */
  8503. ejs.FuzzyLikeThisFieldQuery = function (field, likeText) {
  8504. /**
  8505. The internal Query object. Use <code>get()</code>.
  8506. @member ejs.FuzzyLikeThisFieldQuery
  8507. @property {Object} query
  8508. */
  8509. var query = {
  8510. flt_field: {}
  8511. };
  8512. query.flt_field[field] = {
  8513. like_text: likeText
  8514. };
  8515. return {
  8516. /**
  8517. The field to run the query against.
  8518. @member ejs.FuzzyLikeThisFieldQuery
  8519. @param {String} f A single field name.
  8520. @returns {Object} returns <code>this</code> so that calls can be chained.
  8521. */
  8522. field: function (f) {
  8523. var oldValue = query.flt_field[field];
  8524. if (f == null) {
  8525. return field;
  8526. }
  8527. delete query.flt_field[field];
  8528. field = f;
  8529. query.flt_field[f] = oldValue;
  8530. return this;
  8531. },
  8532. /**
  8533. The text to find documents like
  8534. @member ejs.FuzzyLikeThisFieldQuery
  8535. @param {String} s A text string.
  8536. @returns {Object} returns <code>this</code> so that calls can be chained.
  8537. */
  8538. likeText: function (txt) {
  8539. if (txt == null) {
  8540. return query.flt_field[field].like_text;
  8541. }
  8542. query.flt_field[field].like_text = txt;
  8543. return this;
  8544. },
  8545. /**
  8546. Should term frequency be ignored. Defaults to false.
  8547. @member ejs.FuzzyLikeThisFieldQuery
  8548. @param {Boolean} trueFalse A boolean value
  8549. @returns {Object} returns <code>this</code> so that calls can be chained.
  8550. */
  8551. ignoreTf: function (trueFalse) {
  8552. if (trueFalse == null) {
  8553. return query.flt_field[field].ignore_tf;
  8554. }
  8555. query.flt_field[field].ignore_tf = trueFalse;
  8556. return this;
  8557. },
  8558. /**
  8559. The maximum number of query terms that will be included in any
  8560. generated query. Defaults to 25.
  8561. @member ejs.FuzzyLikeThisFieldQuery
  8562. @param {Integer} max A positive integer value.
  8563. @returns {Object} returns <code>this</code> so that calls can be chained.
  8564. */
  8565. maxQueryTerms: function (max) {
  8566. if (max == null) {
  8567. return query.flt_field[field].max_query_terms;
  8568. }
  8569. query.flt_field[field].max_query_terms = max;
  8570. return this;
  8571. },
  8572. /**
  8573. The minimum similarity of the term variants. Defaults to 0.5.
  8574. @member ejs.FuzzyLikeThisFieldQuery
  8575. @param {Double} min A positive double value.
  8576. @returns {Object} returns <code>this</code> so that calls can be chained.
  8577. */
  8578. minSimilarity: function (min) {
  8579. if (min == null) {
  8580. return query.flt_field[field].min_similarity;
  8581. }
  8582. query.flt_field[field].min_similarity = min;
  8583. return this;
  8584. },
  8585. /**
  8586. Length of required common prefix on variant terms. Defaults to 0..
  8587. @member ejs.FuzzyLikeThisFieldQuery
  8588. @param {Integer} len A positive integer value.
  8589. @returns {Object} returns <code>this</code> so that calls can be chained.
  8590. */
  8591. prefixLength: function (len) {
  8592. if (len == null) {
  8593. return query.flt_field[field].prefix_length;
  8594. }
  8595. query.flt_field[field].prefix_length = len;
  8596. return this;
  8597. },
  8598. /**
  8599. The analyzer that will be used to analyze the text. Defaults to the
  8600. analyzer associated with the field.
  8601. @member ejs.FuzzyLikeThisFieldQuery
  8602. @param {String} analyzerName The name of the analyzer.
  8603. @returns {Object} returns <code>this</code> so that calls can be chained.
  8604. */
  8605. analyzer: function (analyzerName) {
  8606. if (analyzerName == null) {
  8607. return query.flt_field[field].analyzer;
  8608. }
  8609. query.flt_field[field].analyzer = analyzerName;
  8610. return this;
  8611. },
  8612. /**
  8613. Sets the boost value of the <code>Query</code>.
  8614. @member ejs.FuzzyLikeThisFieldQuery
  8615. @param {Double} boost A positive <code>double</code> value.
  8616. @returns {Object} returns <code>this</code> so that calls can be chained.
  8617. */
  8618. boost: function (boost) {
  8619. if (boost == null) {
  8620. return query.flt_field[field].boost;
  8621. }
  8622. query.flt_field[field].boost = boost;
  8623. return this;
  8624. },
  8625. /**
  8626. Serializes the internal <em>query</em> object as a JSON string.
  8627. @member ejs.FuzzyLikeThisFieldQuery
  8628. @returns {String} Returns a JSON representation of the Query object.
  8629. */
  8630. toString: function () {
  8631. return JSON.stringify(query);
  8632. },
  8633. /**
  8634. The type of ejs object. For internal use only.
  8635. @member ejs.FuzzyLikeThisFieldQuery
  8636. @returns {String} the type of object
  8637. */
  8638. _type: function () {
  8639. return 'query';
  8640. },
  8641. /**
  8642. This method is used to retrieve the raw query object. It's designed
  8643. for internal use when composing and serializing queries.
  8644. @member ejs.FuzzyLikeThisFieldQuery
  8645. @returns {Object} Returns the object's <em>query</em> property.
  8646. */
  8647. _self: function () {
  8648. return query;
  8649. }
  8650. };
  8651. };
  8652. /**
  8653. @class
  8654. <p>Fuzzy like this query find documents that are “like” provided text by
  8655. running it against one or more fields.</p>
  8656. <p>Fuzzifies ALL terms provided as strings and then picks the best n
  8657. differentiating terms. In effect this mixes the behaviour of FuzzyQuery and
  8658. MoreLikeThis but with special consideration of fuzzy scoring factors. This
  8659. generally produces good results for queries where users may provide details
  8660. in a number of fields and have no knowledge of boolean query syntax and
  8661. also want a degree of fuzzy matching and a fast query.</p>
  8662. <p>For each source term the fuzzy variants are held in a BooleanQuery with
  8663. no coord factor (because we are not looking for matches on multiple variants
  8664. in any one doc). Additionally, a specialized TermQuery is used for variants
  8665. and does not use that variant term’s IDF because this would favour rarer
  8666. terms eg misspellings. Instead, all variants use the same IDF
  8667. ranking (the one for the source query term) and this is factored into the
  8668. variant’s boost. If the source query term does not exist in the index the
  8669. average IDF of the variants is used.</p>
  8670. @name ejs.FuzzyLikeThisQuery
  8671. @desc
  8672. <p>Constructs a query where each documents returned are “like” provided text</p>
  8673. @param {String} likeText The text to find documents like it.
  8674. */
  8675. ejs.FuzzyLikeThisQuery = function (likeText) {
  8676. /**
  8677. The internal Query object. Use <code>get()</code>.
  8678. @member ejs.FuzzyLikeThisQuery
  8679. @property {Object} query
  8680. */
  8681. var query = {
  8682. flt: {
  8683. like_text: likeText
  8684. }
  8685. };
  8686. return {
  8687. /**
  8688. The fields to run the query against. If you call with a single field,
  8689. it is added to the existing list of fields. If called with an array
  8690. of field names, it replaces any existing values with the new array.
  8691. @member ejs.FuzzyLikeThisQuery
  8692. @param {String || Array} f A single field name or a list of field names.
  8693. @returns {Object} returns <code>this</code> so that calls can be chained.
  8694. */
  8695. fields: function (f) {
  8696. if (query.flt.fields == null) {
  8697. query.flt.fields = [];
  8698. }
  8699. if (f == null) {
  8700. return query.flt.fields;
  8701. }
  8702. if (isString(f)) {
  8703. query.flt.fields.push(f);
  8704. } else if (isArray(f)) {
  8705. query.flt.fields = f;
  8706. } else {
  8707. throw new TypeError('Argument must be a string or array');
  8708. }
  8709. return this;
  8710. },
  8711. /**
  8712. The text to find documents like
  8713. @member ejs.FuzzyLikeThisQuery
  8714. @param {String} s A text string.
  8715. @returns {Object} returns <code>this</code> so that calls can be chained.
  8716. */
  8717. likeText: function (txt) {
  8718. if (txt == null) {
  8719. return query.flt.like_text;
  8720. }
  8721. query.flt.like_text = txt;
  8722. return this;
  8723. },
  8724. /**
  8725. Should term frequency be ignored. Defaults to false.
  8726. @member ejs.FuzzyLikeThisQuery
  8727. @param {Boolean} trueFalse A boolean value
  8728. @returns {Object} returns <code>this</code> so that calls can be chained.
  8729. */
  8730. ignoreTf: function (trueFalse) {
  8731. if (trueFalse == null) {
  8732. return query.flt.ignore_tf;
  8733. }
  8734. query.flt.ignore_tf = trueFalse;
  8735. return this;
  8736. },
  8737. /**
  8738. The maximum number of query terms that will be included in any
  8739. generated query. Defaults to 25.
  8740. @member ejs.FuzzyLikeThisQuery
  8741. @param {Integer} max A positive integer value.
  8742. @returns {Object} returns <code>this</code> so that calls can be chained.
  8743. */
  8744. maxQueryTerms: function (max) {
  8745. if (max == null) {
  8746. return query.flt.max_query_terms;
  8747. }
  8748. query.flt.max_query_terms = max;
  8749. return this;
  8750. },
  8751. /**
  8752. The minimum similarity of the term variants. Defaults to 0.5.
  8753. @member ejs.FuzzyLikeThisQuery
  8754. @param {Double} min A positive double value.
  8755. @returns {Object} returns <code>this</code> so that calls can be chained.
  8756. */
  8757. minSimilarity: function (min) {
  8758. if (min == null) {
  8759. return query.flt.min_similarity;
  8760. }
  8761. query.flt.min_similarity = min;
  8762. return this;
  8763. },
  8764. /**
  8765. Length of required common prefix on variant terms. Defaults to 0..
  8766. @member ejs.FuzzyLikeThisQuery
  8767. @param {Integer} len A positive integer value.
  8768. @returns {Object} returns <code>this</code> so that calls can be chained.
  8769. */
  8770. prefixLength: function (len) {
  8771. if (len == null) {
  8772. return query.flt.prefix_length;
  8773. }
  8774. query.flt.prefix_length = len;
  8775. return this;
  8776. },
  8777. /**
  8778. The analyzer that will be used to analyze the text. Defaults to the
  8779. analyzer associated with the field.
  8780. @member ejs.FuzzyLikeThisQuery
  8781. @param {String} analyzerName The name of the analyzer.
  8782. @returns {Object} returns <code>this</code> so that calls can be chained.
  8783. */
  8784. analyzer: function (analyzerName) {
  8785. if (analyzerName == null) {
  8786. return query.flt.analyzer;
  8787. }
  8788. query.flt.analyzer = analyzerName;
  8789. return this;
  8790. },
  8791. /**
  8792. Sets the boost value of the <code>Query</code>.
  8793. @member ejs.FuzzyLikeThisQuery
  8794. @param {Double} boost A positive <code>double</code> value.
  8795. @returns {Object} returns <code>this</code> so that calls can be chained.
  8796. */
  8797. boost: function (boost) {
  8798. if (boost == null) {
  8799. return query.flt.boost;
  8800. }
  8801. query.flt.boost = boost;
  8802. return this;
  8803. },
  8804. /**
  8805. Serializes the internal <em>query</em> object as a JSON string.
  8806. @member ejs.FuzzyLikeThisQuery
  8807. @returns {String} Returns a JSON representation of the Query object.
  8808. */
  8809. toString: function () {
  8810. return JSON.stringify(query);
  8811. },
  8812. /**
  8813. The type of ejs object. For internal use only.
  8814. @member ejs.FuzzyLikeThisQuery
  8815. @returns {String} the type of object
  8816. */
  8817. _type: function () {
  8818. return 'query';
  8819. },
  8820. /**
  8821. This method is used to retrieve the raw query object. It's designed
  8822. for internal use when composing and serializing queries.
  8823. @member ejs.FuzzyLikeThisQuery
  8824. @returns {Object} Returns the object's <em>query</em> property.
  8825. */
  8826. _self: function () {
  8827. return query;
  8828. }
  8829. };
  8830. };
  8831. /**
  8832. @class
  8833. <p>A fuzzy search query based on the Damerau-Levenshtein (optimal string
  8834. alignment) algorithm, though you can explicitly choose classic Levenshtein
  8835. by passing false to the transpositions parameter./p>
  8836. <p>fuzzy query on a numeric field will result in a range query “around”
  8837. the value using the min_similarity value. As an example, if you perform a
  8838. fuzzy query against a field value of "12" with a min similarity setting
  8839. of "2", the query will search for values between "10" and "14".</p>
  8840. @name ejs.FuzzyQuery
  8841. @desc
  8842. <p>Constructs a query where each documents returned are “like” provided text</p>
  8843. @param {String} field The field to run the fuzzy query against.
  8844. @param {String} value The value to fuzzify.
  8845. */
  8846. ejs.FuzzyQuery = function (field, value) {
  8847. /**
  8848. The internal Query object. Use <code>get()</code>.
  8849. @member ejs.FuzzyQuery
  8850. @property {Object} query
  8851. */
  8852. var query = {
  8853. fuzzy: {}
  8854. };
  8855. query.fuzzy[field] = {
  8856. value: value
  8857. };
  8858. return {
  8859. /**
  8860. The field to run the query against.
  8861. @member ejs.FuzzyQuery
  8862. @param {String} f A single field name.
  8863. @returns {Object} returns <code>this</code> so that calls can be chained.
  8864. */
  8865. field: function (f) {
  8866. var oldValue = query.fuzzy[field];
  8867. if (f == null) {
  8868. return field;
  8869. }
  8870. delete query.fuzzy[field];
  8871. field = f;
  8872. query.fuzzy[f] = oldValue;
  8873. return this;
  8874. },
  8875. /**
  8876. The query text to fuzzify.
  8877. @member ejs.FuzzyQuery
  8878. @param {String} s A text string.
  8879. @returns {Object} returns <code>this</code> so that calls can be chained.
  8880. */
  8881. value: function (txt) {
  8882. if (txt == null) {
  8883. return query.fuzzy[field].value;
  8884. }
  8885. query.fuzzy[field].value = txt;
  8886. return this;
  8887. },
  8888. /**
  8889. Set to false to use classic Levenshtein edit distance.
  8890. @member ejs.FuzzyQuery
  8891. @param {Boolean} trueFalse A boolean value
  8892. @returns {Object} returns <code>this</code> so that calls can be chained.
  8893. */
  8894. transpositions: function (trueFalse) {
  8895. if (trueFalse == null) {
  8896. return query.fuzzy[field].transpositions;
  8897. }
  8898. query.fuzzy[field].transpositions = trueFalse;
  8899. return this;
  8900. },
  8901. /**
  8902. The maximum number of query terms that will be included in any
  8903. generated query. Defaults to 50.
  8904. @member ejs.FuzzyQuery
  8905. @param {Integer} max A positive integer value.
  8906. @returns {Object} returns <code>this</code> so that calls can be chained.
  8907. */
  8908. maxExpansions: function (max) {
  8909. if (max == null) {
  8910. return query.fuzzy[field].max_expansions;
  8911. }
  8912. query.fuzzy[field].max_expansions = max;
  8913. return this;
  8914. },
  8915. /**
  8916. The minimum similarity of the term variants. Defaults to 0.5.
  8917. @member ejs.FuzzyQuery
  8918. @param {Double} min A positive double value.
  8919. @returns {Object} returns <code>this</code> so that calls can be chained.
  8920. */
  8921. minSimilarity: function (min) {
  8922. if (min == null) {
  8923. return query.fuzzy[field].min_similarity;
  8924. }
  8925. query.fuzzy[field].min_similarity = min;
  8926. return this;
  8927. },
  8928. /**
  8929. Length of required common prefix on variant terms. Defaults to 0..
  8930. @member ejs.FuzzyQuery
  8931. @param {Integer} len A positive integer value.
  8932. @returns {Object} returns <code>this</code> so that calls can be chained.
  8933. */
  8934. prefixLength: function (len) {
  8935. if (len == null) {
  8936. return query.fuzzy[field].prefix_length;
  8937. }
  8938. query.fuzzy[field].prefix_length = len;
  8939. return this;
  8940. },
  8941. /**
  8942. Sets rewrite method. Valid values are:
  8943. constant_score_auto - tries to pick the best constant-score rewrite
  8944. method based on term and document counts from the query
  8945. scoring_boolean - translates each term into boolean should and
  8946. keeps the scores as computed by the query
  8947. constant_score_boolean - same as scoring_boolean, expect no scores
  8948. are computed.
  8949. constant_score_filter - first creates a private Filter, by visiting
  8950. each term in sequence and marking all docs for that term
  8951. top_terms_boost_N - first translates each term into boolean should
  8952. and scores are only computed as the boost using the top N
  8953. scoring terms. Replace N with an integer value.
  8954. top_terms_N - first translates each term into boolean should
  8955. and keeps the scores as computed by the query. Only the top N
  8956. scoring terms are used. Replace N with an integer value.
  8957. Default is constant_score_auto.
  8958. This is an advanced option, use with care.
  8959. @member ejs.FuzzyQuery
  8960. @param {String} m The rewrite method as a string.
  8961. @returns {Object} returns <code>this</code> so that calls can be chained.
  8962. */
  8963. rewrite: function (m) {
  8964. if (m == null) {
  8965. return query.fuzzy[field].rewrite;
  8966. }
  8967. m = m.toLowerCase();
  8968. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  8969. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  8970. m.indexOf('top_terms_boost_') === 0 ||
  8971. m.indexOf('top_terms_') === 0) {
  8972. query.fuzzy[field].rewrite = m;
  8973. }
  8974. return this;
  8975. },
  8976. /**
  8977. Sets the boost value of the <code>Query</code>.
  8978. @member ejs.FuzzyQuery
  8979. @param {Double} boost A positive <code>double</code> value.
  8980. @returns {Object} returns <code>this</code> so that calls can be chained.
  8981. */
  8982. boost: function (boost) {
  8983. if (boost == null) {
  8984. return query.fuzzy[field].boost;
  8985. }
  8986. query.fuzzy[field].boost = boost;
  8987. return this;
  8988. },
  8989. /**
  8990. Serializes the internal <em>query</em> object as a JSON string.
  8991. @member ejs.FuzzyQuery
  8992. @returns {String} Returns a JSON representation of the Query object.
  8993. */
  8994. toString: function () {
  8995. return JSON.stringify(query);
  8996. },
  8997. /**
  8998. The type of ejs object. For internal use only.
  8999. @member ejs.FuzzyQuery
  9000. @returns {String} the type of object
  9001. */
  9002. _type: function () {
  9003. return 'query';
  9004. },
  9005. /**
  9006. This method is used to retrieve the raw query object. It's designed
  9007. for internal use when composing and serializing queries.
  9008. @member ejs.FuzzyQuery
  9009. @returns {Object} Returns the object's <em>query</em> property.
  9010. */
  9011. _self: function () {
  9012. return query;
  9013. }
  9014. };
  9015. };
  9016. /**
  9017. @class
  9018. <p>Efficient querying of documents containing shapes indexed using the
  9019. geo_shape type.</p>
  9020. <p>Much like the geo_shape type, the geo_shape query uses a grid square
  9021. representation of the query shape to find those documents which have shapes
  9022. that relate to the query shape in a specified way. In order to do this, the
  9023. field being queried must be of geo_shape type. The query will use the same
  9024. PrefixTree configuration as defined for the field.</p>
  9025. @name ejs.GeoShapeQuery
  9026. @desc
  9027. A Query to find documents with a geo_shapes matching a specific shape.
  9028. */
  9029. ejs.GeoShapeQuery = function (field) {
  9030. /**
  9031. The internal query object. <code>Use _self()</code>
  9032. @member ejs.GeoShapeQuery
  9033. @property {Object} GeoShapeQuery
  9034. */
  9035. var query = {
  9036. geo_shape: {}
  9037. };
  9038. query.geo_shape[field] = {};
  9039. return {
  9040. /**
  9041. Sets the field to query against.
  9042. @member ejs.GeoShapeQuery
  9043. @param {String} f A valid field name.
  9044. @returns {Object} returns <code>this</code> so that calls can be chained.
  9045. */
  9046. field: function (f) {
  9047. var oldValue = query.geo_shape[field];
  9048. if (f == null) {
  9049. return field;
  9050. }
  9051. delete query.geo_shape[field];
  9052. field = f;
  9053. query.geo_shape[f] = oldValue;
  9054. return this;
  9055. },
  9056. /**
  9057. Sets the shape
  9058. @member ejs.GeoShapeQuery
  9059. @param {String} shape A valid <code>Shape</code> object.
  9060. @returns {Object} returns <code>this</code> so that calls can be chained.
  9061. */
  9062. shape: function (shape) {
  9063. if (shape == null) {
  9064. return query.geo_shape[field].shape;
  9065. }
  9066. if (query.geo_shape[field].indexed_shape != null) {
  9067. delete query.geo_shape[field].indexed_shape;
  9068. }
  9069. query.geo_shape[field].shape = shape._self();
  9070. return this;
  9071. },
  9072. /**
  9073. Sets the indexed shape. Use this if you already have shape definitions
  9074. already indexed.
  9075. @member ejs.GeoShapeQuery
  9076. @param {String} indexedShape A valid <code>IndexedShape</code> object.
  9077. @returns {Object} returns <code>this</code> so that calls can be chained.
  9078. */
  9079. indexedShape: function (indexedShape) {
  9080. if (indexedShape == null) {
  9081. return query.geo_shape[field].indexed_shape;
  9082. }
  9083. if (query.geo_shape[field].shape != null) {
  9084. delete query.geo_shape[field].shape;
  9085. }
  9086. query.geo_shape[field].indexed_shape = indexedShape._self();
  9087. return this;
  9088. },
  9089. /**
  9090. Sets the shape relation type. A relationship between a Query Shape
  9091. and indexed Shapes that will be used to determine if a Document
  9092. should be matched or not. Valid values are: intersects, disjoint,
  9093. and within.
  9094. @member ejs.GeoShapeQuery
  9095. @param {String} indexedShape A valid <code>IndexedShape</code> object.
  9096. @returns {Object} returns <code>this</code> so that calls can be chained.
  9097. */
  9098. relation: function (relation) {
  9099. if (relation == null) {
  9100. return query.geo_shape[field].relation;
  9101. }
  9102. relation = relation.toLowerCase();
  9103. if (relation === 'intersects' || relation === 'disjoint' || relation === 'within') {
  9104. query.geo_shape[field].relation = relation;
  9105. }
  9106. return this;
  9107. },
  9108. /**
  9109. Sets the boost value for documents matching the <code>Query</code>.
  9110. @member ejs.GeoShapeQuery
  9111. @param {Number} boost A positive <code>double</code> value.
  9112. @returns {Object} returns <code>this</code> so that calls can be chained.
  9113. */
  9114. boost: function (boost) {
  9115. if (boost == null) {
  9116. return query.geo_shape[field].boost;
  9117. }
  9118. query.geo_shape[field].boost = boost;
  9119. return this;
  9120. },
  9121. /**
  9122. Allows you to serialize this object into a JSON encoded string.
  9123. @member ejs.GeoShapeQuery
  9124. @returns {String} returns this object as a serialized JSON string.
  9125. */
  9126. toString: function () {
  9127. return JSON.stringify(query);
  9128. },
  9129. /**
  9130. The type of ejs object. For internal use only.
  9131. @member ejs.GeoShapeQuery
  9132. @returns {String} the type of object
  9133. */
  9134. _type: function () {
  9135. return 'query';
  9136. },
  9137. /**
  9138. Retrieves the internal <code>query</code> object. This is typically used by
  9139. internal API functions so use with caution.
  9140. @member ejs.GeoShapeQuery
  9141. @returns {String} returns this object's internal <code>query</code> property.
  9142. */
  9143. _self: function () {
  9144. return query;
  9145. }
  9146. };
  9147. };
  9148. /**
  9149. @class
  9150. <p>The has_child query works the same as the has_child filter,
  9151. by automatically wrapping the filter with a constant_score. Results in
  9152. parent documents that have child docs matching the query being returned.</p>
  9153. @name ejs.HasChildQuery
  9154. @desc
  9155. Returns results that have child documents matching the query.
  9156. @param {Object} qry A valid query object.
  9157. @param {String} type The child type
  9158. */
  9159. ejs.HasChildQuery = function (qry, type) {
  9160. if (!isQuery(qry)) {
  9161. throw new TypeError('Argument must be a valid Query');
  9162. }
  9163. /**
  9164. The internal query object. <code>Use _self()</code>
  9165. @member ejs.HasChildQuery
  9166. @property {Object} query
  9167. */
  9168. var query = {
  9169. has_child: {
  9170. query: qry._self(),
  9171. type: type
  9172. }
  9173. };
  9174. return {
  9175. /**
  9176. Sets the query
  9177. @member ejs.HasChildQuery
  9178. @param {Object} q A valid Query object
  9179. @returns {Object} returns <code>this</code> so that calls can be chained.
  9180. */
  9181. query: function (q) {
  9182. if (q == null) {
  9183. return query.has_child.query;
  9184. }
  9185. if (!isQuery(q)) {
  9186. throw new TypeError('Argument must be a valid Query');
  9187. }
  9188. query.has_child.query = q._self();
  9189. return this;
  9190. },
  9191. /**
  9192. Sets the child document type to search against
  9193. @member ejs.HasChildQuery
  9194. @param {String} t A valid type name
  9195. @returns {Object} returns <code>this</code> so that calls can be chained.
  9196. */
  9197. type: function (t) {
  9198. if (t == null) {
  9199. return query.has_child.type;
  9200. }
  9201. query.has_child.type = t;
  9202. return this;
  9203. },
  9204. /**
  9205. Sets the scope of the query. A scope allows to run facets on the
  9206. same scope name that will work against the child documents.
  9207. @member ejs.HasChildQuery
  9208. @param {String} s The scope name as a string.
  9209. @returns {Object} returns <code>this</code> so that calls can be chained.
  9210. */
  9211. scope: function (s) {
  9212. if (s == null) {
  9213. return query.has_child._scope;
  9214. }
  9215. query.has_child._scope = s;
  9216. return this;
  9217. },
  9218. /**
  9219. Sets the scoring method. Valid values are:
  9220. none - the default, no scoring
  9221. max - the highest score of all matched child documents is used
  9222. sum - the sum the all the matched child documents is used
  9223. avg - the average of all matched child documents is used
  9224. @member ejs.HasChildQuery
  9225. @param {String} s The score type as a string.
  9226. @returns {Object} returns <code>this</code> so that calls can be chained.
  9227. */
  9228. scoreType: function (s) {
  9229. if (s == null) {
  9230. return query.has_child.score_type;
  9231. }
  9232. s = s.toLowerCase();
  9233. if (s === 'none' || s === 'max' || s === 'sum' || s === 'avg') {
  9234. query.has_child.score_type = s;
  9235. }
  9236. return this;
  9237. },
  9238. /**
  9239. Sets the boost value of the <code>Query</code>.
  9240. @member ejs.HasChildQuery
  9241. @param {Double} boost A positive <code>double</code> value.
  9242. @returns {Object} returns <code>this</code> so that calls can be chained.
  9243. */
  9244. boost: function (boost) {
  9245. if (boost == null) {
  9246. return query.has_child.boost;
  9247. }
  9248. query.has_child.boost = boost;
  9249. return this;
  9250. },
  9251. /**
  9252. Allows you to serialize this object into a JSON encoded string.
  9253. @member ejs.HasChildQuery
  9254. @returns {String} returns this object as a serialized JSON string.
  9255. */
  9256. toString: function () {
  9257. return JSON.stringify(query);
  9258. },
  9259. /**
  9260. The type of ejs object. For internal use only.
  9261. @member ejs.HasChildQuery
  9262. @returns {String} the type of object
  9263. */
  9264. _type: function () {
  9265. return 'query';
  9266. },
  9267. /**
  9268. Retrieves the internal <code>query</code> object. This is typically used by
  9269. internal API functions so use with caution.
  9270. @member ejs.HasChildQuery
  9271. @returns {String} returns this object's internal <code>query</code> property.
  9272. */
  9273. _self: function () {
  9274. return query;
  9275. }
  9276. };
  9277. };
  9278. /**
  9279. @class
  9280. <p>The has_parent query works the same as the has_parent filter, by
  9281. automatically wrapping the filter with a constant_score. Results in
  9282. child documents that have parent docs matching the query being returned.</p>
  9283. @name ejs.HasParentQuery
  9284. @desc
  9285. Returns results that have parent documents matching the query.
  9286. @param {Object} qry A valid query object.
  9287. @param {String} parentType The child type
  9288. */
  9289. ejs.HasParentQuery = function (qry, parentType) {
  9290. if (!isQuery(qry)) {
  9291. throw new TypeError('Argument must be a Query');
  9292. }
  9293. /**
  9294. The internal query object. <code>Use _self()</code>
  9295. @member ejs.HasParentQuery
  9296. @property {Object} query
  9297. */
  9298. var query = {
  9299. has_parent: {
  9300. query: qry._self(),
  9301. parent_type: parentType
  9302. }
  9303. };
  9304. return {
  9305. /**
  9306. Sets the query
  9307. @member ejs.HasParentQuery
  9308. @param {Object} q A valid Query object
  9309. @returns {Object} returns <code>this</code> so that calls can be chained.
  9310. */
  9311. query: function (q) {
  9312. if (q == null) {
  9313. return query.has_parent.query;
  9314. }
  9315. if (!isQuery(q)) {
  9316. throw new TypeError('Argument must be a Query');
  9317. }
  9318. query.has_parent.query = q._self();
  9319. return this;
  9320. },
  9321. /**
  9322. Sets the child document type to search against
  9323. @member ejs.HasParentQuery
  9324. @param {String} t A valid type name
  9325. @returns {Object} returns <code>this</code> so that calls can be chained.
  9326. */
  9327. parentType: function (t) {
  9328. if (t == null) {
  9329. return query.has_parent.parent_type;
  9330. }
  9331. query.has_parent.parent_type = t;
  9332. return this;
  9333. },
  9334. /**
  9335. Sets the scope of the query. A scope allows to run facets on the
  9336. same scope name that will work against the parent documents.
  9337. @member ejs.HasParentQuery
  9338. @param {String} s The scope name as a string.
  9339. @returns {Object} returns <code>this</code> so that calls can be chained.
  9340. */
  9341. scope: function (s) {
  9342. if (s == null) {
  9343. return query.has_parent._scope;
  9344. }
  9345. query.has_parent._scope = s;
  9346. return this;
  9347. },
  9348. /**
  9349. Sets the scoring method. Valid values are:
  9350. none - the default, no scoring
  9351. score - the score of the parent is used in all child documents.
  9352. @member ejs.HasParentQuery
  9353. @param {String} s The score type as a string.
  9354. @returns {Object} returns <code>this</code> so that calls can be chained.
  9355. */
  9356. scoreType: function (s) {
  9357. if (s == null) {
  9358. return query.has_parent.score_type;
  9359. }
  9360. s = s.toLowerCase();
  9361. if (s === 'none' || s === 'score') {
  9362. query.has_parent.score_type = s;
  9363. }
  9364. return this;
  9365. },
  9366. /**
  9367. Sets the boost value of the <code>Query</code>.
  9368. @member ejs.HasParentQuery
  9369. @param {Double} boost A positive <code>double</code> value.
  9370. @returns {Object} returns <code>this</code> so that calls can be chained.
  9371. */
  9372. boost: function (boost) {
  9373. if (boost == null) {
  9374. return query.has_parent.boost;
  9375. }
  9376. query.has_parent.boost = boost;
  9377. return this;
  9378. },
  9379. /**
  9380. Allows you to serialize this object into a JSON encoded string.
  9381. @member ejs.HasParentQuery
  9382. @returns {String} returns this object as a serialized JSON string.
  9383. */
  9384. toString: function () {
  9385. return JSON.stringify(query);
  9386. },
  9387. /**
  9388. The type of ejs object. For internal use only.
  9389. @member ejs.HasParentQuery
  9390. @returns {String} the type of object
  9391. */
  9392. _type: function () {
  9393. return 'query';
  9394. },
  9395. /**
  9396. Retrieves the internal <code>query</code> object. This is typically used by
  9397. internal API functions so use with caution.
  9398. @member ejs.HasParentQuery
  9399. @returns {String} returns this object's internal <code>query</code> property.
  9400. */
  9401. _self: function () {
  9402. return query;
  9403. }
  9404. };
  9405. };
  9406. /**
  9407. @class
  9408. <p>Filters documents that only have the provided ids. Note, this filter
  9409. does not require the _id field to be indexed since it works using the
  9410. _uid field.</p>
  9411. @name ejs.IdsQuery
  9412. @desc
  9413. Matches documents with the specified id(s).
  9414. @param {Array || String} ids A single document id or a list of document ids.
  9415. */
  9416. ejs.IdsQuery = function (ids) {
  9417. /**
  9418. The internal query object. <code>Use get()</code>
  9419. @member ejs.IdsQuery
  9420. @property {Object} query
  9421. */
  9422. var query = {
  9423. ids: {}
  9424. };
  9425. if (isString(ids)) {
  9426. query.ids.values = [ids];
  9427. } else if (isArray(ids)) {
  9428. query.ids.values = ids;
  9429. } else {
  9430. throw new TypeError('Argument must be string or array');
  9431. }
  9432. return {
  9433. /**
  9434. Sets the values array or adds a new value. if val is a string, it
  9435. is added to the list of existing document ids. If val is an
  9436. array it is set as the document values and replaces any existing values.
  9437. @member ejs.IdsQuery
  9438. @param {Array || String} val An single document id or an array of document ids.
  9439. @returns {Object} returns <code>this</code> so that calls can be chained.
  9440. */
  9441. values: function (val) {
  9442. if (val == null) {
  9443. return query.ids.values;
  9444. }
  9445. if (isString(val)) {
  9446. query.ids.values.push(val);
  9447. } else if (isArray(val)) {
  9448. query.ids.values = val;
  9449. } else {
  9450. throw new TypeError('Argument must be string or array');
  9451. }
  9452. return this;
  9453. },
  9454. /**
  9455. Sets the type as a single type or an array of types. If type is a
  9456. string, it is added to the list of existing types. If type is an
  9457. array, it is set as the types and overwrites an existing types. This
  9458. parameter is optional.
  9459. @member ejs.IdsQuery
  9460. @param {Array || String} type A type or a list of types
  9461. @returns {Object} returns <code>this</code> so that calls can be chained.
  9462. */
  9463. type: function (type) {
  9464. if (query.ids.type == null) {
  9465. query.ids.type = [];
  9466. }
  9467. if (type == null) {
  9468. return query.ids.type;
  9469. }
  9470. if (isString(type)) {
  9471. query.ids.type.push(type);
  9472. } else if (isArray(type)) {
  9473. query.ids.type = type;
  9474. } else {
  9475. throw new TypeError('Argument must be string or array');
  9476. }
  9477. return this;
  9478. },
  9479. /**
  9480. Sets the boost value of the <code>Query</code>.
  9481. @member ejs.IdsQuery
  9482. @param {Double} boost A positive <code>double</code> value.
  9483. @returns {Object} returns <code>this</code> so that calls can be chained.
  9484. */
  9485. boost: function (boost) {
  9486. if (boost == null) {
  9487. return query.ids.boost;
  9488. }
  9489. query.ids.boost = boost;
  9490. return this;
  9491. },
  9492. /**
  9493. Allows you to serialize this object into a JSON encoded string.
  9494. @member ejs.IdsQuery
  9495. @returns {String} returns this object as a serialized JSON string.
  9496. */
  9497. toString: function () {
  9498. return JSON.stringify(query);
  9499. },
  9500. /**
  9501. The type of ejs object. For internal use only.
  9502. @member ejs.IdsQuery
  9503. @returns {String} the type of object
  9504. */
  9505. _type: function () {
  9506. return 'query';
  9507. },
  9508. /**
  9509. Retrieves the internal <code>query</code> object. This is typically used by
  9510. internal API functions so use with caution.
  9511. @member ejs.IdsQuery
  9512. @returns {String} returns this object's internal <code>query</code> property.
  9513. */
  9514. _self: function () {
  9515. return query;
  9516. }
  9517. };
  9518. };
  9519. /**
  9520. @class
  9521. <p>The indices query can be used when executed across multiple indices,
  9522. allowing to have a query that executes only when executed on an index that
  9523. matches a specific list of indices, and another query that executes when it
  9524. is executed on an index that does not match the listed indices.</p>
  9525. @name ejs.IndicesQuery
  9526. @desc
  9527. A configurable query that is dependent on the index name.
  9528. @param {Object} qry A valid query object.
  9529. @param {String || Array} indices a single index name or an array of index
  9530. names.
  9531. */
  9532. ejs.IndicesQuery = function (qry, indices) {
  9533. if (!isQuery(qry)) {
  9534. throw new TypeError('Argument must be a Query');
  9535. }
  9536. /**
  9537. The internal query object. <code>Use _self()</code>
  9538. @member ejs.IndicesQuery
  9539. @property {Object} query
  9540. */
  9541. var query = {
  9542. indices: {
  9543. query: qry._self()
  9544. }
  9545. };
  9546. if (isString(indices)) {
  9547. query.indices.indices = [indices];
  9548. } else if (isArray(indices)) {
  9549. query.indices.indices = indices;
  9550. } else {
  9551. throw new TypeError('Argument must be a string or array');
  9552. }
  9553. return {
  9554. /**
  9555. Sets the indicies the query should match. When passed a string,
  9556. the index name is added to the current list of indices. When passed
  9557. an array, it overwites all current indices.
  9558. @member ejs.IndicesQuery
  9559. @param {String || Array} i A single index name or an array of index names.
  9560. @returns {Object} returns <code>this</code> so that calls can be chained.
  9561. */
  9562. indices: function (i) {
  9563. if (i == null) {
  9564. return query.indices.indices;
  9565. }
  9566. if (isString(i)) {
  9567. query.indices.indices.push(i);
  9568. } else if (isArray(i)) {
  9569. query.indices.indices = i;
  9570. } else {
  9571. throw new TypeError('Argument must be a string or array');
  9572. }
  9573. return this;
  9574. },
  9575. /**
  9576. Sets the query to be executed against the indices specified.
  9577. @member ejs.IndicesQuery
  9578. @param {Object} q A valid Query object
  9579. @returns {Object} returns <code>this</code> so that calls can be chained.
  9580. */
  9581. query: function (q) {
  9582. if (q == null) {
  9583. return query.indices.query;
  9584. }
  9585. if (!isQuery(q)) {
  9586. throw new TypeError('Argument must be a Query');
  9587. }
  9588. query.indices.query = q._self();
  9589. return this;
  9590. },
  9591. /**
  9592. Sets the query to be used on an index that does not match an index
  9593. name in the indices list. Can also be set to "none" to not match any
  9594. documents or "all" to match all documents.
  9595. @member ejs.IndicesQuery
  9596. @param {Object || String} q A valid Query object or "none" or "all"
  9597. @returns {Object} returns <code>this</code> so that calls can be chained.
  9598. */
  9599. noMatchQuery: function (q) {
  9600. if (q == null) {
  9601. return query.indices.no_match_query;
  9602. }
  9603. if (isString(q)) {
  9604. q = q.toLowerCase();
  9605. if (q === 'none' || q === 'all') {
  9606. query.indices.no_match_query = q;
  9607. }
  9608. } else if (isQuery(q)) {
  9609. query.indices.no_match_query = q._self();
  9610. } else {
  9611. throw new TypeError('Argument must be string or Query');
  9612. }
  9613. return this;
  9614. },
  9615. /**
  9616. Sets the boost value of the <code>Query</code>.
  9617. @member ejs.IndicesQuery
  9618. @param {Double} boost A positive <code>double</code> value.
  9619. @returns {Object} returns <code>this</code> so that calls can be chained.
  9620. */
  9621. boost: function (boost) {
  9622. if (boost == null) {
  9623. return query.indices.boost;
  9624. }
  9625. query.indices.boost = boost;
  9626. return this;
  9627. },
  9628. /**
  9629. Allows you to serialize this object into a JSON encoded string.
  9630. @member ejs.IndicesQuery
  9631. @returns {String} returns this object as a serialized JSON string.
  9632. */
  9633. toString: function () {
  9634. return JSON.stringify(query);
  9635. },
  9636. /**
  9637. The type of ejs object. For internal use only.
  9638. @member ejs.IndicesQuery
  9639. @returns {String} the type of object
  9640. */
  9641. _type: function () {
  9642. return 'query';
  9643. },
  9644. /**
  9645. Retrieves the internal <code>query</code> object. This is typically used by
  9646. internal API functions so use with caution.
  9647. @member ejs.IndicesQuery
  9648. @returns {String} returns this object's internal <code>query</code> property.
  9649. */
  9650. _self: function () {
  9651. return query;
  9652. }
  9653. };
  9654. };
  9655. /**
  9656. @class
  9657. <p>This query can be used to match all the documents
  9658. in a given set of collections and/or types.</p>
  9659. @name ejs.MatchAllQuery
  9660. @desc
  9661. <p>A query that returns all documents.</p>
  9662. */
  9663. ejs.MatchAllQuery = function () {
  9664. /**
  9665. The internal Query object. Use <code>get()</code>.
  9666. @member ejs.MatchAllQuery
  9667. @property {Object} query
  9668. */
  9669. var query = {
  9670. match_all: {}
  9671. };
  9672. return {
  9673. /**
  9674. Sets the boost value of the <code>Query</code>.
  9675. @member ejs.MatchAllQuery
  9676. @param {Double} boost A positive <code>double</code> value.
  9677. @returns {Object} returns <code>this</code> so that calls can be chained.
  9678. */
  9679. boost: function (boost) {
  9680. if (boost == null) {
  9681. return query.match_all.boost;
  9682. }
  9683. query.match_all.boost = boost;
  9684. return this;
  9685. },
  9686. /**
  9687. Serializes the internal <em>query</em> object as a JSON string.
  9688. @member ejs.MatchAllQuery
  9689. @returns {String} Returns a JSON representation of the Query object.
  9690. */
  9691. toString: function () {
  9692. return JSON.stringify(query);
  9693. },
  9694. /**
  9695. The type of ejs object. For internal use only.
  9696. @member ejs.MatchAllQuery
  9697. @returns {String} the type of object
  9698. */
  9699. _type: function () {
  9700. return 'query';
  9701. },
  9702. /**
  9703. This method is used to retrieve the raw query object. It's designed
  9704. for internal use when composing and serializing queries.
  9705. @member ejs.MatchAllQuery
  9706. @returns {Object} Returns the object's <em>query</em> property.
  9707. */
  9708. _self: function () {
  9709. return query;
  9710. }
  9711. };
  9712. };
  9713. /**
  9714. @class
  9715. A <code>MatchQuery</code> is a type of <code>Query</code> that accepts
  9716. text/numerics/dates, analyzes it, generates a query based on the
  9717. <code>MatchQuery</code> type.
  9718. @name ejs.MatchQuery
  9719. @desc
  9720. A Query that appects text, analyzes it, generates internal query based
  9721. on the MatchQuery type.
  9722. @param {String} field the document field/field to query against
  9723. @param {String} qstr the query string
  9724. */
  9725. ejs.MatchQuery = function (field, qstr) {
  9726. /**
  9727. The internal query object. <code>Use get()</code>
  9728. @member ejs.MatchQuery
  9729. @property {Object} query
  9730. */
  9731. var query = {
  9732. match: {}
  9733. };
  9734. query.match[field] = {
  9735. query: qstr
  9736. };
  9737. return {
  9738. /**
  9739. Sets the boost value for documents matching the <code>Query</code>.
  9740. @member ejs.MatchQuery
  9741. @param {Number} boost A positive <code>double</code> value.
  9742. @returns {Object} returns <code>this</code> so that calls can be chained.
  9743. */
  9744. boost: function (boost) {
  9745. if (boost == null) {
  9746. return query.match[field].boost;
  9747. }
  9748. query.match[field].boost = boost;
  9749. return this;
  9750. },
  9751. /**
  9752. Sets the query string for the <code>Query</code>.
  9753. @member ejs.MatchQuery
  9754. @param {String} qstr The query string to search for.
  9755. @returns {Object} returns <code>this</code> so that calls can be chained.
  9756. */
  9757. query: function (qstr) {
  9758. if (qstr == null) {
  9759. return query.match[field].query;
  9760. }
  9761. query.match[field].query = qstr;
  9762. return this;
  9763. },
  9764. /**
  9765. Sets the type of the <code>MatchQuery</code>. Valid values are
  9766. boolean, phrase, and phrase_prefix.
  9767. @member ejs.MatchQuery
  9768. @param {String} type Any of boolean, phrase, phrase_prefix.
  9769. @returns {Object} returns <code>this</code> so that calls can be chained.
  9770. */
  9771. type: function (type) {
  9772. if (type == null) {
  9773. return query.match[field].type;
  9774. }
  9775. type = type.toLowerCase();
  9776. if (type === 'boolean' || type === 'phrase' || type === 'phrase_prefix') {
  9777. query.match[field].type = type;
  9778. }
  9779. return this;
  9780. },
  9781. /**
  9782. Sets the fuzziness value for the <code>Query</code>.
  9783. @member ejs.MatchQuery
  9784. @param {Double} fuzz A <code>double</code> value between 0.0 and 1.0.
  9785. @returns {Object} returns <code>this</code> so that calls can be chained.
  9786. */
  9787. fuzziness: function (fuzz) {
  9788. if (fuzz == null) {
  9789. return query.match[field].fuzziness;
  9790. }
  9791. query.match[field].fuzziness = fuzz;
  9792. return this;
  9793. },
  9794. /**
  9795. Sets the prefix length for a fuzzy prefix <code>MatchQuery</code>.
  9796. @member ejs.MatchQuery
  9797. @param {Integer} l A positive <code>integer</code> length value.
  9798. @returns {Object} returns <code>this</code> so that calls can be chained.
  9799. */
  9800. prefixLength: function (l) {
  9801. if (l == null) {
  9802. return query.match[field].prefix_length;
  9803. }
  9804. query.match[field].prefix_length = l;
  9805. return this;
  9806. },
  9807. /**
  9808. Sets the max expansions of a fuzzy <code>MatchQuery</code>.
  9809. @member ejs.MatchQuery
  9810. @param {Integer} e A positive <code>integer</code> value.
  9811. @returns {Object} returns <code>this</code> so that calls can be chained.
  9812. */
  9813. maxExpansions: function (e) {
  9814. if (e == null) {
  9815. return query.match[field].max_expansions;
  9816. }
  9817. query.match[field].max_expansions = e;
  9818. return this;
  9819. },
  9820. /**
  9821. Sets default operator of the <code>Query</code>. Default: or.
  9822. @member ejs.MatchQuery
  9823. @param {String} op Any of "and" or "or", no quote characters.
  9824. @returns {Object} returns <code>this</code> so that calls can be chained.
  9825. */
  9826. operator: function (op) {
  9827. if (op == null) {
  9828. return query.match[field].operator;
  9829. }
  9830. op = op.toLowerCase();
  9831. if (op === 'and' || op === 'or') {
  9832. query.match[field].operator = op;
  9833. }
  9834. return this;
  9835. },
  9836. /**
  9837. Sets the default slop for phrases. If zero, then exact phrase matches
  9838. are required. Default: 0.
  9839. @member ejs.MatchQuery
  9840. @param {Integer} slop A positive <code>integer</code> value.
  9841. @returns {Object} returns <code>this</code> so that calls can be chained.
  9842. */
  9843. slop: function (slop) {
  9844. if (slop == null) {
  9845. return query.match[field].slop;
  9846. }
  9847. query.match[field].slop = slop;
  9848. return this;
  9849. },
  9850. /**
  9851. Sets the analyzer name used to analyze the <code>Query</code> object.
  9852. @member ejs.MatchQuery
  9853. @param {String} analyzer A valid analyzer name.
  9854. @returns {Object} returns <code>this</code> so that calls can be chained.
  9855. */
  9856. analyzer: function (analyzer) {
  9857. if (analyzer == null) {
  9858. return query.match[field].analyzer;
  9859. }
  9860. query.match[field].analyzer = analyzer;
  9861. return this;
  9862. },
  9863. /**
  9864. Sets a percent value controlling how many "should" clauses in the
  9865. resulting <code>Query</code> should match.
  9866. @member ejs.MatchQuery
  9867. @param {Integer} minMatch An <code>integer</code> between 0 and 100.
  9868. @returns {Object} returns <code>this</code> so that calls can be chained.
  9869. */
  9870. minimumShouldMatch: function (minMatch) {
  9871. if (minMatch == null) {
  9872. return query.match[field].minimum_should_match;
  9873. }
  9874. query.match[field].minimum_should_match = minMatch;
  9875. return this;
  9876. },
  9877. /**
  9878. Sets rewrite method. Valid values are:
  9879. constant_score_auto - tries to pick the best constant-score rewrite
  9880. method based on term and document counts from the query
  9881. scoring_boolean - translates each term into boolean should and
  9882. keeps the scores as computed by the query
  9883. constant_score_boolean - same as scoring_boolean, expect no scores
  9884. are computed.
  9885. constant_score_filter - first creates a private Filter, by visiting
  9886. each term in sequence and marking all docs for that term
  9887. top_terms_boost_N - first translates each term into boolean should
  9888. and scores are only computed as the boost using the top N
  9889. scoring terms. Replace N with an integer value.
  9890. top_terms_N - first translates each term into boolean should
  9891. and keeps the scores as computed by the query. Only the top N
  9892. scoring terms are used. Replace N with an integer value.
  9893. Default is constant_score_auto.
  9894. This is an advanced option, use with care.
  9895. @member ejs.MatchQuery
  9896. @param {String} m The rewrite method as a string.
  9897. @returns {Object} returns <code>this</code> so that calls can be chained.
  9898. */
  9899. rewrite: function (m) {
  9900. if (m == null) {
  9901. return query.match[field].rewrite;
  9902. }
  9903. m = m.toLowerCase();
  9904. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  9905. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  9906. m.indexOf('top_terms_boost_') === 0 ||
  9907. m.indexOf('top_terms_') === 0) {
  9908. query.match[field].rewrite = m;
  9909. }
  9910. return this;
  9911. },
  9912. /**
  9913. Sets fuzzy rewrite method. Valid values are:
  9914. constant_score_auto - tries to pick the best constant-score rewrite
  9915. method based on term and document counts from the query
  9916. scoring_boolean - translates each term into boolean should and
  9917. keeps the scores as computed by the query
  9918. constant_score_boolean - same as scoring_boolean, expect no scores
  9919. are computed.
  9920. constant_score_filter - first creates a private Filter, by visiting
  9921. each term in sequence and marking all docs for that term
  9922. top_terms_boost_N - first translates each term into boolean should
  9923. and scores are only computed as the boost using the top N
  9924. scoring terms. Replace N with an integer value.
  9925. top_terms_N - first translates each term into boolean should
  9926. and keeps the scores as computed by the query. Only the top N
  9927. scoring terms are used. Replace N with an integer value.
  9928. Default is constant_score_auto.
  9929. This is an advanced option, use with care.
  9930. @member ejs.MatchQuery
  9931. @param {String} m The rewrite method as a string.
  9932. @returns {Object} returns <code>this</code> so that calls can be chained.
  9933. */
  9934. fuzzyRewrite: function (m) {
  9935. if (m == null) {
  9936. return query.match[field].fuzzy_rewrite;
  9937. }
  9938. m = m.toLowerCase();
  9939. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  9940. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  9941. m.indexOf('top_terms_boost_') === 0 ||
  9942. m.indexOf('top_terms_') === 0) {
  9943. query.match[field].fuzzy_rewrite = m;
  9944. }
  9945. return this;
  9946. },
  9947. /**
  9948. Set to false to use classic Levenshtein edit distance in the
  9949. fuzzy query.
  9950. @member ejs.MatchQuery
  9951. @param {Boolean} trueFalse A boolean value
  9952. @returns {Object} returns <code>this</code> so that calls can be chained.
  9953. */
  9954. fuzzyTranspositions: function (trueFalse) {
  9955. if (trueFalse == null) {
  9956. return query.match[field].fuzzy_transpositions;
  9957. }
  9958. query.match[field].fuzzy_transpositions = trueFalse;
  9959. return this;
  9960. },
  9961. /**
  9962. Enables lenient parsing of the query string.
  9963. @member ejs.MatchQuery
  9964. @param {Boolean} trueFalse A boolean value
  9965. @returns {Object} returns <code>this</code> so that calls can be chained.
  9966. */
  9967. lenient: function (trueFalse) {
  9968. if (trueFalse == null) {
  9969. return query.match[field].lenient;
  9970. }
  9971. query.match[field].lenient = trueFalse;
  9972. return this;
  9973. },
  9974. /**
  9975. Sets what happens when no terms match. Valid values are
  9976. "all" or "none".
  9977. @member ejs.MatchQuery
  9978. @param {String} q A valid analyzer name.
  9979. @returns {Object} returns <code>this</code> so that calls can be chained.
  9980. */
  9981. zeroTermsQuery: function (q) {
  9982. if (q == null) {
  9983. return query.match[field].zero_terms_query;
  9984. }
  9985. q = q.toLowerCase();
  9986. if (q === 'all' || q === 'none') {
  9987. query.match[field].zero_terms_query = q;
  9988. }
  9989. return this;
  9990. },
  9991. /**
  9992. Allows you to serialize this object into a JSON encoded string.
  9993. @member ejs.MatchQuery
  9994. @returns {String} returns this object as a serialized JSON string.
  9995. */
  9996. toString: function () {
  9997. return JSON.stringify(query);
  9998. },
  9999. /**
  10000. The type of ejs object. For internal use only.
  10001. @member ejs.MatchQuery
  10002. @returns {String} the type of object
  10003. */
  10004. _type: function () {
  10005. return 'query';
  10006. },
  10007. /**
  10008. Retrieves the internal <code>query</code> object. This is typically used by
  10009. internal API functions so use with caution.
  10010. @member ejs.MatchQuery
  10011. @returns {String} returns this object's internal <code>query</code> property.
  10012. */
  10013. _self: function () {
  10014. return query;
  10015. }
  10016. };
  10017. };
  10018. /**
  10019. @class
  10020. <p>The more_like_this_field query is the same as the more_like_this query,
  10021. except it runs against a single field.</p>
  10022. @name ejs.MoreLikeThisFieldQuery
  10023. @desc
  10024. <p>Constructs a query where each documents returned are “like” provided text</p>
  10025. @param {String} field The field to run the query against.
  10026. @param {String} likeText The text to find documents like it.
  10027. */
  10028. ejs.MoreLikeThisFieldQuery = function (field, likeText) {
  10029. /**
  10030. The internal Query object. Use <code>get()</code>.
  10031. @member ejs.MoreLikeThisFieldQuery
  10032. @property {Object} query
  10033. */
  10034. var query = {
  10035. mlt_field: {}
  10036. };
  10037. query.mlt_field[field] = {
  10038. like_text: likeText
  10039. };
  10040. return {
  10041. /**
  10042. The field to run the query against.
  10043. @member ejs.MoreLikeThisFieldQuery
  10044. @param {String} f A single field name.
  10045. @returns {Object} returns <code>this</code> so that calls can be chained.
  10046. */
  10047. field: function (f) {
  10048. var oldValue = query.mlt_field[field];
  10049. if (f == null) {
  10050. return field;
  10051. }
  10052. delete query.mlt_field[field];
  10053. field = f;
  10054. query.mlt_field[f] = oldValue;
  10055. return this;
  10056. },
  10057. /**
  10058. The text to find documents like
  10059. @member ejs.MoreLikeThisFieldQuery
  10060. @param {String} s A text string.
  10061. @returns {Object} returns <code>this</code> so that calls can be chained.
  10062. */
  10063. likeText: function (txt) {
  10064. if (txt == null) {
  10065. return query.mlt_field[field].like_text;
  10066. }
  10067. query.mlt_field[field].like_text = txt;
  10068. return this;
  10069. },
  10070. /**
  10071. The percentage of terms to match on (float value).
  10072. Defaults to 0.3 (30 percent).
  10073. @member ejs.MoreLikeThisFieldQuery
  10074. @param {Double} percent A double value between 0 and 1.
  10075. @returns {Object} returns <code>this</code> so that calls can be chained.
  10076. */
  10077. percentTermsToMatch: function (percent) {
  10078. if (percent == null) {
  10079. return query.mlt_field[field].percent_terms_to_match;
  10080. }
  10081. query.mlt_field[field].percent_terms_to_match = percent;
  10082. return this;
  10083. },
  10084. /**
  10085. The frequency below which terms will be ignored in the source doc.
  10086. The default frequency is 2.
  10087. @member ejs.MoreLikeThisFieldQuery
  10088. @param {Integer} freq A positive integer value.
  10089. @returns {Object} returns <code>this</code> so that calls can be chained.
  10090. */
  10091. minTermFreq: function (freq) {
  10092. if (freq == null) {
  10093. return query.mlt_field[field].min_term_freq;
  10094. }
  10095. query.mlt_field[field].min_term_freq = freq;
  10096. return this;
  10097. },
  10098. /**
  10099. The maximum number of query terms that will be included in any
  10100. generated query. Defaults to 25.
  10101. @member ejs.MoreLikeThisFieldQuery
  10102. @param {Integer} max A positive integer value.
  10103. @returns {Object} returns <code>this</code> so that calls can be chained.
  10104. */
  10105. maxQueryTerms: function (max) {
  10106. if (max == null) {
  10107. return query.mlt_field[field].max_query_terms;
  10108. }
  10109. query.mlt_field[field].max_query_terms = max;
  10110. return this;
  10111. },
  10112. /**
  10113. An array of stop words. Any word in this set is considered
  10114. “uninteresting” and ignored. Even if your Analyzer allows stopwords,
  10115. you might want to tell the MoreLikeThis code to ignore them, as for
  10116. the purposes of document similarity it seems reasonable to assume
  10117. that “a stop word is never interesting”.
  10118. @member ejs.MoreLikeThisFieldQuery
  10119. @param {Array} stopWords An array of string stopwords
  10120. @returns {Object} returns <code>this</code> so that calls can be chained.
  10121. */
  10122. stopWords: function (stopWords) {
  10123. if (stopWords == null) {
  10124. return query.mlt_field[field].stop_words;
  10125. }
  10126. query.mlt_field[field].stop_words = stopWords;
  10127. return this;
  10128. },
  10129. /**
  10130. The frequency at which words will be ignored which do not occur in
  10131. at least this many docs. Defaults to 5.
  10132. @member ejs.MoreLikeThisFieldQuery
  10133. @param {Integer} min A positive integer value.
  10134. @returns {Object} returns <code>this</code> so that calls can be chained.
  10135. */
  10136. minDocFreq: function (min) {
  10137. if (min == null) {
  10138. return query.mlt_field[field].min_doc_freq;
  10139. }
  10140. query.mlt_field[field].min_doc_freq = min;
  10141. return this;
  10142. },
  10143. /**
  10144. The maximum frequency in which words may still appear. Words that
  10145. appear in more than this many docs will be ignored.
  10146. Defaults to unbounded.
  10147. @member ejs.MoreLikeThisFieldQuery
  10148. @param {Integer} max A positive integer value.
  10149. @returns {Object} returns <code>this</code> so that calls can be chained.
  10150. */
  10151. maxDocFreq: function (max) {
  10152. if (max == null) {
  10153. return query.mlt_field[field].max_doc_freq;
  10154. }
  10155. query.mlt_field[field].max_doc_freq = max;
  10156. return this;
  10157. },
  10158. /**
  10159. The minimum word length below which words will be ignored.
  10160. Defaults to 0.
  10161. @member ejs.MoreLikeThisFieldQuery
  10162. @param {Integer} len A positive integer value.
  10163. @returns {Object} returns <code>this</code> so that calls can be chained.
  10164. */
  10165. minWordLen: function (len) {
  10166. if (len == null) {
  10167. return query.mlt_field[field].min_word_len;
  10168. }
  10169. query.mlt_field[field].min_word_len = len;
  10170. return this;
  10171. },
  10172. /**
  10173. The maximum word length above which words will be ignored.
  10174. Defaults to unbounded (0).
  10175. @member ejs.MoreLikeThisFieldQuery
  10176. @param {Integer} len A positive integer value.
  10177. @returns {Object} returns <code>this</code> so that calls can be chained.
  10178. */
  10179. maxWordLen: function (len) {
  10180. if (len == null) {
  10181. return query.mlt_field[field].max_word_len;
  10182. }
  10183. query.mlt_field[field].max_word_len = len;
  10184. return this;
  10185. },
  10186. /**
  10187. The analyzer that will be used to analyze the text. Defaults to the
  10188. analyzer associated with the field.
  10189. @member ejs.MoreLikeThisFieldQuery
  10190. @param {String} analyzerName The name of the analyzer.
  10191. @returns {Object} returns <code>this</code> so that calls can be chained.
  10192. */
  10193. analyzer: function (analyzerName) {
  10194. if (analyzerName == null) {
  10195. return query.mlt_field[field].analyzer;
  10196. }
  10197. query.mlt_field[field].analyzer = analyzerName;
  10198. return this;
  10199. },
  10200. /**
  10201. Sets the boost factor to use when boosting terms.
  10202. Defaults to 1.
  10203. @member ejs.MoreLikeThisFieldQuery
  10204. @param {Double} boost A positive <code>double</code> value.
  10205. @returns {Object} returns <code>this</code> so that calls can be chained.
  10206. */
  10207. boostTerms: function (boost) {
  10208. if (boost == null) {
  10209. return query.mlt_field[field].boost_terms;
  10210. }
  10211. query.mlt_field[field].boost_terms = boost;
  10212. return this;
  10213. },
  10214. /**
  10215. Sets the boost value of the <code>Query</code>.
  10216. @member ejs.MoreLikeThisFieldQuery
  10217. @param {Double} boost A positive <code>double</code> value.
  10218. @returns {Object} returns <code>this</code> so that calls can be chained.
  10219. */
  10220. boost: function (boost) {
  10221. if (boost == null) {
  10222. return query.mlt_field[field].boost;
  10223. }
  10224. query.mlt_field[field].boost = boost;
  10225. return this;
  10226. },
  10227. /**
  10228. Serializes the internal <em>query</em> object as a JSON string.
  10229. @member ejs.MoreLikeThisFieldQuery
  10230. @returns {String} Returns a JSON representation of the Query object.
  10231. */
  10232. toString: function () {
  10233. return JSON.stringify(query);
  10234. },
  10235. /**
  10236. The type of ejs object. For internal use only.
  10237. @member ejs.MoreLikeThisFieldQuery
  10238. @returns {String} the type of object
  10239. */
  10240. _type: function () {
  10241. return 'query';
  10242. },
  10243. /**
  10244. This method is used to retrieve the raw query object. It's designed
  10245. for internal use when composing and serializing queries.
  10246. @member ejs.MoreLikeThisFieldQuery
  10247. @returns {Object} Returns the object's <em>query</em> property.
  10248. */
  10249. _self: function () {
  10250. return query;
  10251. }
  10252. };
  10253. };
  10254. /**
  10255. @class
  10256. <p>More like this query find documents that are “like” provided text by
  10257. running it against one or more fields.</p>
  10258. @name ejs.MoreLikeThisQuery
  10259. @desc
  10260. <p>Constructs a query where each documents returned are “like” provided text</p>
  10261. @param {String || Array} fields A single field or array of fields to run against.
  10262. @param {String} likeText The text to find documents like it.
  10263. */
  10264. ejs.MoreLikeThisQuery = function (fields, likeText) {
  10265. /**
  10266. The internal Query object. Use <code>get()</code>.
  10267. @member ejs.MoreLikeThisQuery
  10268. @property {Object} query
  10269. */
  10270. var query = {
  10271. mlt: {
  10272. like_text: likeText,
  10273. fields: []
  10274. }
  10275. };
  10276. if (isString(fields)) {
  10277. query.mlt.fields.push(fields);
  10278. } else if (isArray(fields)) {
  10279. query.mlt.fields = fields;
  10280. } else {
  10281. throw new TypeError('Argument must be string or array');
  10282. }
  10283. return {
  10284. /**
  10285. The fields to run the query against. If you call with a single field,
  10286. it is added to the existing list of fields. If called with an array
  10287. of field names, it replaces any existing values with the new array.
  10288. @member ejs.MoreLikeThisQuery
  10289. @param {String || Array} f A single field name or a list of field names.
  10290. @returns {Object} returns <code>this</code> so that calls can be chained.
  10291. */
  10292. fields: function (f) {
  10293. if (f == null) {
  10294. return query.mlt.fields;
  10295. }
  10296. if (isString(f)) {
  10297. query.mlt.fields.push(f);
  10298. } else if (isArray(f)) {
  10299. query.mlt.fields = f;
  10300. } else {
  10301. throw new TypeError('Argument must be a string or array');
  10302. }
  10303. return this;
  10304. },
  10305. /**
  10306. The text to find documents like
  10307. @member ejs.MoreLikeThisQuery
  10308. @param {String} s A text string.
  10309. @returns {Object} returns <code>this</code> so that calls can be chained.
  10310. */
  10311. likeText: function (txt) {
  10312. if (txt == null) {
  10313. return query.mlt.like_text;
  10314. }
  10315. query.mlt.like_text = txt;
  10316. return this;
  10317. },
  10318. /**
  10319. The percentage of terms to match on (float value).
  10320. Defaults to 0.3 (30 percent).
  10321. @member ejs.MoreLikeThisQuery
  10322. @param {Double} percent A double value between 0 and 1.
  10323. @returns {Object} returns <code>this</code> so that calls can be chained.
  10324. */
  10325. percentTermsToMatch: function (percent) {
  10326. if (percent == null) {
  10327. return query.mlt.percent_terms_to_match;
  10328. }
  10329. query.mlt.percent_terms_to_match = percent;
  10330. return this;
  10331. },
  10332. /**
  10333. The frequency below which terms will be ignored in the source doc.
  10334. The default frequency is 2.
  10335. @member ejs.MoreLikeThisQuery
  10336. @param {Integer} freq A positive integer value.
  10337. @returns {Object} returns <code>this</code> so that calls can be chained.
  10338. */
  10339. minTermFreq: function (freq) {
  10340. if (freq == null) {
  10341. return query.mlt.min_term_freq;
  10342. }
  10343. query.mlt.min_term_freq = freq;
  10344. return this;
  10345. },
  10346. /**
  10347. The maximum number of query terms that will be included in any
  10348. generated query. Defaults to 25.
  10349. @member ejs.MoreLikeThisQuery
  10350. @param {Integer} max A positive integer value.
  10351. @returns {Object} returns <code>this</code> so that calls can be chained.
  10352. */
  10353. maxQueryTerms: function (max) {
  10354. if (max == null) {
  10355. return query.mlt.max_query_terms;
  10356. }
  10357. query.mlt.max_query_terms = max;
  10358. return this;
  10359. },
  10360. /**
  10361. An array of stop words. Any word in this set is considered
  10362. “uninteresting” and ignored. Even if your Analyzer allows stopwords,
  10363. you might want to tell the MoreLikeThis code to ignore them, as for
  10364. the purposes of document similarity it seems reasonable to assume
  10365. that “a stop word is never interesting”.
  10366. @member ejs.MoreLikeThisQuery
  10367. @param {Array} stopWords An array of string stopwords
  10368. @returns {Object} returns <code>this</code> so that calls can be chained.
  10369. */
  10370. stopWords: function (stopWords) {
  10371. if (stopWords == null) {
  10372. return query.mlt.stop_words;
  10373. }
  10374. query.mlt.stop_words = stopWords;
  10375. return this;
  10376. },
  10377. /**
  10378. The frequency at which words will be ignored which do not occur in
  10379. at least this many docs. Defaults to 5.
  10380. @member ejs.MoreLikeThisQuery
  10381. @param {Integer} min A positive integer value.
  10382. @returns {Object} returns <code>this</code> so that calls can be chained.
  10383. */
  10384. minDocFreq: function (min) {
  10385. if (min == null) {
  10386. return query.mlt.min_doc_freq;
  10387. }
  10388. query.mlt.min_doc_freq = min;
  10389. return this;
  10390. },
  10391. /**
  10392. The maximum frequency in which words may still appear. Words that
  10393. appear in more than this many docs will be ignored.
  10394. Defaults to unbounded.
  10395. @member ejs.MoreLikeThisQuery
  10396. @param {Integer} max A positive integer value.
  10397. @returns {Object} returns <code>this</code> so that calls can be chained.
  10398. */
  10399. maxDocFreq: function (max) {
  10400. if (max == null) {
  10401. return query.mlt.max_doc_freq;
  10402. }
  10403. query.mlt.max_doc_freq = max;
  10404. return this;
  10405. },
  10406. /**
  10407. The minimum word length below which words will be ignored.
  10408. Defaults to 0.
  10409. @member ejs.MoreLikeThisQuery
  10410. @param {Integer} len A positive integer value.
  10411. @returns {Object} returns <code>this</code> so that calls can be chained.
  10412. */
  10413. minWordLen: function (len) {
  10414. if (len == null) {
  10415. return query.mlt.min_word_len;
  10416. }
  10417. query.mlt.min_word_len = len;
  10418. return this;
  10419. },
  10420. /**
  10421. The maximum word length above which words will be ignored.
  10422. Defaults to unbounded (0).
  10423. @member ejs.MoreLikeThisQuery
  10424. @param {Integer} len A positive integer value.
  10425. @returns {Object} returns <code>this</code> so that calls can be chained.
  10426. */
  10427. maxWordLen: function (len) {
  10428. if (len == null) {
  10429. return query.mlt.max_word_len;
  10430. }
  10431. query.mlt.max_word_len = len;
  10432. return this;
  10433. },
  10434. /**
  10435. The analyzer that will be used to analyze the text. Defaults to the
  10436. analyzer associated with the field.
  10437. @member ejs.MoreLikeThisQuery
  10438. @param {String} analyzerName The name of the analyzer.
  10439. @returns {Object} returns <code>this</code> so that calls can be chained.
  10440. */
  10441. analyzer: function (analyzerName) {
  10442. if (analyzerName == null) {
  10443. return query.mlt.analyzer;
  10444. }
  10445. query.mlt.analyzer = analyzerName;
  10446. return this;
  10447. },
  10448. /**
  10449. Sets the boost factor to use when boosting terms.
  10450. Defaults to 1.
  10451. @member ejs.MoreLikeThisQuery
  10452. @param {Double} boost A positive <code>double</code> value.
  10453. @returns {Object} returns <code>this</code> so that calls can be chained.
  10454. */
  10455. boostTerms: function (boost) {
  10456. if (boost == null) {
  10457. return query.mlt.boost_terms;
  10458. }
  10459. query.mlt.boost_terms = boost;
  10460. return this;
  10461. },
  10462. /**
  10463. Sets the boost value of the <code>Query</code>.
  10464. @member ejs.MoreLikeThisQuery
  10465. @param {Double} boost A positive <code>double</code> value.
  10466. @returns {Object} returns <code>this</code> so that calls can be chained.
  10467. */
  10468. boost: function (boost) {
  10469. if (boost == null) {
  10470. return query.mlt.boost;
  10471. }
  10472. query.mlt.boost = boost;
  10473. return this;
  10474. },
  10475. /**
  10476. Serializes the internal <em>query</em> object as a JSON string.
  10477. @member ejs.MoreLikeThisQuery
  10478. @returns {String} Returns a JSON representation of the Query object.
  10479. */
  10480. toString: function () {
  10481. return JSON.stringify(query);
  10482. },
  10483. /**
  10484. The type of ejs object. For internal use only.
  10485. @member ejs.MoreLikeThisQuery
  10486. @returns {String} the type of object
  10487. */
  10488. _type: function () {
  10489. return 'query';
  10490. },
  10491. /**
  10492. This method is used to retrieve the raw query object. It's designed
  10493. for internal use when composing and serializing queries.
  10494. @member ejs.MoreLikeThisQuery
  10495. @returns {Object} Returns the object's <em>query</em> property.
  10496. */
  10497. _self: function () {
  10498. return query;
  10499. }
  10500. };
  10501. };
  10502. /**
  10503. @class
  10504. A <code>MultiMatchQuery</code> query builds further on top of the
  10505. <code>MatchQuery</code> by allowing multiple fields to be specified.
  10506. The idea here is to allow to more easily build a concise match type query
  10507. over multiple fields instead of using a relatively more expressive query
  10508. by using multiple match queries within a bool query.
  10509. @name ejs.MultiMatchQuery
  10510. @desc
  10511. A Query that allow to more easily build a MatchQuery
  10512. over multiple fields
  10513. @param {String || Array} fields the single field or array of fields to search across
  10514. @param {String} qstr the query string
  10515. */
  10516. ejs.MultiMatchQuery = function (fields, qstr) {
  10517. /**
  10518. The internal query object. <code>Use get()</code>
  10519. @member ejs.MultiMatchQuery
  10520. @property {Object} query
  10521. */
  10522. var query = {
  10523. multi_match: {
  10524. query: qstr,
  10525. fields: []
  10526. }
  10527. };
  10528. if (isString(fields)) {
  10529. query.multi_match.fields.push(fields);
  10530. } else if (isArray(fields)) {
  10531. query.multi_match.fields = fields;
  10532. } else {
  10533. throw new TypeError('Argument must be string or array');
  10534. }
  10535. return {
  10536. /**
  10537. Sets the fields to search across. If passed a single value it is
  10538. added to the existing list of fields. If passed an array of
  10539. values, they overwite all existing values.
  10540. @member ejs.MultiMatchQuery
  10541. @param {String || Array} f A single field or list of fields names to
  10542. search across.
  10543. @returns {Object} returns <code>this</code> so that calls can be
  10544. chained. Returns {Array} current value if `f` not specified.
  10545. */
  10546. fields: function (f) {
  10547. if (f == null) {
  10548. return query.multi_match.fields;
  10549. }
  10550. if (isString(f)) {
  10551. query.multi_match.fields.push(f);
  10552. } else if (isArray(f)) {
  10553. query.multi_match.fields = f;
  10554. } else {
  10555. throw new TypeError('Argument must be string or array');
  10556. }
  10557. return this;
  10558. },
  10559. /**
  10560. Sets whether or not queries against multiple fields should be combined using Lucene's
  10561. <a href="http://lucene.apache.org/java/3_0_0/api/core/org/apache/lucene/search/DisjunctionMaxQuery.html">
  10562. DisjunctionMaxQuery</a>
  10563. @member ejs.MultiMatchQuery
  10564. @param {String} trueFalse A <code>true/false</code> value.
  10565. @returns {Object} returns <code>this</code> so that calls can be chained.
  10566. */
  10567. useDisMax: function (trueFalse) {
  10568. if (trueFalse == null) {
  10569. return query.multi_match.use_dis_max;
  10570. }
  10571. query.multi_match.use_dis_max = trueFalse;
  10572. return this;
  10573. },
  10574. /**
  10575. The tie breaker value. The tie breaker capability allows results
  10576. that include the same term in multiple fields to be judged better than
  10577. results that include this term in only the best of those multiple
  10578. fields, without confusing this with the better case of two different
  10579. terms in the multiple fields. Default: 0.0.
  10580. @member ejs.MultiMatchQuery
  10581. @param {Double} tieBreaker A positive <code>double</code> value.
  10582. @returns {Object} returns <code>this</code> so that calls can be chained.
  10583. */
  10584. tieBreaker: function (tieBreaker) {
  10585. if (tieBreaker == null) {
  10586. return query.multi_match.tie_breaker;
  10587. }
  10588. query.multi_match.tie_breaker = tieBreaker;
  10589. return this;
  10590. },
  10591. /**
  10592. Sets a percent value controlling how many "should" clauses in the
  10593. resulting <code>Query</code> should match.
  10594. @member ejs.MultiMatchQuery
  10595. @param {Integer} minMatch An <code>integer</code> between 0 and 100.
  10596. @returns {Object} returns <code>this</code> so that calls can be chained.
  10597. */
  10598. minimumShouldMatch: function (minMatch) {
  10599. if (minMatch == null) {
  10600. return query.multi_match.minimum_should_match;
  10601. }
  10602. query.multi_match.minimum_should_match = minMatch;
  10603. return this;
  10604. },
  10605. /**
  10606. Sets rewrite method. Valid values are:
  10607. constant_score_auto - tries to pick the best constant-score rewrite
  10608. method based on term and document counts from the query
  10609. scoring_boolean - translates each term into boolean should and
  10610. keeps the scores as computed by the query
  10611. constant_score_boolean - same as scoring_boolean, expect no scores
  10612. are computed.
  10613. constant_score_filter - first creates a private Filter, by visiting
  10614. each term in sequence and marking all docs for that term
  10615. top_terms_boost_N - first translates each term into boolean should
  10616. and scores are only computed as the boost using the top N
  10617. scoring terms. Replace N with an integer value.
  10618. top_terms_N - first translates each term into boolean should
  10619. and keeps the scores as computed by the query. Only the top N
  10620. scoring terms are used. Replace N with an integer value.
  10621. Default is constant_score_auto.
  10622. This is an advanced option, use with care.
  10623. @member ejs.MultiMatchQuery
  10624. @param {String} m The rewrite method as a string.
  10625. @returns {Object} returns <code>this</code> so that calls can be chained.
  10626. */
  10627. rewrite: function (m) {
  10628. if (m == null) {
  10629. return query.multi_match.rewrite;
  10630. }
  10631. m = m.toLowerCase();
  10632. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  10633. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  10634. m.indexOf('top_terms_boost_') === 0 ||
  10635. m.indexOf('top_terms_') === 0) {
  10636. query.multi_match.rewrite = m;
  10637. }
  10638. return this;
  10639. },
  10640. /**
  10641. Sets fuzzy rewrite method. Valid values are:
  10642. constant_score_auto - tries to pick the best constant-score rewrite
  10643. method based on term and document counts from the query
  10644. scoring_boolean - translates each term into boolean should and
  10645. keeps the scores as computed by the query
  10646. constant_score_boolean - same as scoring_boolean, expect no scores
  10647. are computed.
  10648. constant_score_filter - first creates a private Filter, by visiting
  10649. each term in sequence and marking all docs for that term
  10650. top_terms_boost_N - first translates each term into boolean should
  10651. and scores are only computed as the boost using the top N
  10652. scoring terms. Replace N with an integer value.
  10653. top_terms_N - first translates each term into boolean should
  10654. and keeps the scores as computed by the query. Only the top N
  10655. scoring terms are used. Replace N with an integer value.
  10656. Default is constant_score_auto.
  10657. This is an advanced option, use with care.
  10658. @member ejs.MultiMatchQuery
  10659. @param {String} m The rewrite method as a string.
  10660. @returns {Object} returns <code>this</code> so that calls can be chained.
  10661. */
  10662. fuzzyRewrite: function (m) {
  10663. if (m == null) {
  10664. return query.multi_match.fuzzy_rewrite;
  10665. }
  10666. m = m.toLowerCase();
  10667. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  10668. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  10669. m.indexOf('top_terms_boost_') === 0 ||
  10670. m.indexOf('top_terms_') === 0) {
  10671. query.multi_match.fuzzy_rewrite = m;
  10672. }
  10673. return this;
  10674. },
  10675. /**
  10676. Enables lenient parsing of the query string.
  10677. @member ejs.MultiMatchQuery
  10678. @param {Boolean} trueFalse A boolean value
  10679. @returns {Object} returns <code>this</code> so that calls can be chained.
  10680. */
  10681. lenient: function (trueFalse) {
  10682. if (trueFalse == null) {
  10683. return query.multi_match.lenient;
  10684. }
  10685. query.multi_match.lenient = trueFalse;
  10686. return this;
  10687. },
  10688. /**
  10689. Sets the boost value for documents matching the <code>Query</code>.
  10690. @member ejs.MultiMatchQuery
  10691. @param {Number} boost A positive <code>double</code> value.
  10692. @returns {Object} returns <code>this</code> so that calls can be chained.
  10693. */
  10694. boost: function (boost) {
  10695. if (boost == null) {
  10696. return query.multi_match.boost;
  10697. }
  10698. query.multi_match.boost = boost;
  10699. return this;
  10700. },
  10701. /**
  10702. Sets the query string for the <code>Query</code>.
  10703. @member ejs.MultiMatchQuery
  10704. @param {String} qstr The query string to search for.
  10705. @returns {Object} returns <code>this</code> so that calls can be chained.
  10706. */
  10707. query: function (qstr) {
  10708. if (qstr == null) {
  10709. return query.multi_match.query;
  10710. }
  10711. query.multi_match.query = qstr;
  10712. return this;
  10713. },
  10714. /**
  10715. Sets the type of the <code>MultiMatchQuery</code>. Valid values are
  10716. boolean, phrase, and phrase_prefix or phrasePrefix.
  10717. @member ejs.MultiMatchQuery
  10718. @param {String} type Any of boolean, phrase, phrase_prefix or phrasePrefix.
  10719. @returns {Object} returns <code>this</code> so that calls can be chained.
  10720. */
  10721. type: function (type) {
  10722. if (type == null) {
  10723. return query.multi_match.type;
  10724. }
  10725. type = type.toLowerCase();
  10726. if (type === 'boolean' || type === 'phrase' || type === 'phrase_prefix') {
  10727. query.multi_match.type = type;
  10728. }
  10729. return this;
  10730. },
  10731. /**
  10732. Sets the fuzziness value for the <code>Query</code>.
  10733. @member ejs.MultiMatchQuery
  10734. @param {Double} fuzz A <code>double</code> value between 0.0 and 1.0.
  10735. @returns {Object} returns <code>this</code> so that calls can be chained.
  10736. */
  10737. fuzziness: function (fuzz) {
  10738. if (fuzz == null) {
  10739. return query.multi_match.fuzziness;
  10740. }
  10741. query.multi_match.fuzziness = fuzz;
  10742. return this;
  10743. },
  10744. /**
  10745. Sets the prefix length for a fuzzy prefix <code>Query</code>.
  10746. @member ejs.MultiMatchQuery
  10747. @param {Integer} l A positive <code>integer</code> length value.
  10748. @returns {Object} returns <code>this</code> so that calls can be chained.
  10749. */
  10750. prefixLength: function (l) {
  10751. if (l == null) {
  10752. return query.multi_match.prefix_length;
  10753. }
  10754. query.multi_match.prefix_length = l;
  10755. return this;
  10756. },
  10757. /**
  10758. Sets the max expansions of a fuzzy <code>Query</code>.
  10759. @member ejs.MultiMatchQuery
  10760. @param {Integer} e A positive <code>integer</code> value.
  10761. @returns {Object} returns <code>this</code> so that calls can be chained.
  10762. */
  10763. maxExpansions: function (e) {
  10764. if (e == null) {
  10765. return query.multi_match.max_expansions;
  10766. }
  10767. query.multi_match.max_expansions = e;
  10768. return this;
  10769. },
  10770. /**
  10771. Sets default operator of the <code>Query</code>. Default: or.
  10772. @member ejs.MultiMatchQuery
  10773. @param {String} op Any of "and" or "or", no quote characters.
  10774. @returns {Object} returns <code>this</code> so that calls can be chained.
  10775. */
  10776. operator: function (op) {
  10777. if (op == null) {
  10778. return query.multi_match.operator;
  10779. }
  10780. op = op.toLowerCase();
  10781. if (op === 'and' || op === 'or') {
  10782. query.multi_match.operator = op;
  10783. }
  10784. return this;
  10785. },
  10786. /**
  10787. Sets the default slop for phrases. If zero, then exact phrase matches
  10788. are required. Default: 0.
  10789. @member ejs.MultiMatchQuery
  10790. @param {Integer} slop A positive <code>integer</code> value.
  10791. @returns {Object} returns <code>this</code> so that calls can be chained.
  10792. */
  10793. slop: function (slop) {
  10794. if (slop == null) {
  10795. return query.multi_match.slop;
  10796. }
  10797. query.multi_match.slop = slop;
  10798. return this;
  10799. },
  10800. /**
  10801. Sets the analyzer name used to analyze the <code>Query</code> object.
  10802. @member ejs.MultiMatchQuery
  10803. @param {String} analyzer A valid analyzer name.
  10804. @returns {Object} returns <code>this</code> so that calls can be chained.
  10805. */
  10806. analyzer: function (analyzer) {
  10807. if (analyzer == null) {
  10808. return query.multi_match.analyzer;
  10809. }
  10810. query.multi_match.analyzer = analyzer;
  10811. return this;
  10812. },
  10813. /**
  10814. Allows you to serialize this object into a JSON encoded string.
  10815. @member ejs.MultiMatchQuery
  10816. @returns {String} returns this object as a serialized JSON string.
  10817. */
  10818. toString: function () {
  10819. return JSON.stringify(query);
  10820. },
  10821. /**
  10822. The type of ejs object. For internal use only.
  10823. @member ejs.MultiMatchQuery
  10824. @returns {String} the type of object
  10825. */
  10826. _type: function () {
  10827. return 'query';
  10828. },
  10829. /**
  10830. Retrieves the internal <code>Query</code> object. This is typically used by
  10831. internal API functions so use with caution.
  10832. @member ejs.MultiMatchQuery
  10833. @returns {String} returns this object's internal <code>query</code> property.
  10834. */
  10835. _self: function () {
  10836. return query;
  10837. }
  10838. };
  10839. };
  10840. /**
  10841. @class
  10842. <p>Nested queries allow you to search against content within objects that are
  10843. embedded inside of other objects. It is similar to <code>XPath</code> expressions
  10844. in <code>XML</code> both conceptually and syntactically.</p>
  10845. <p>The query is executed against the nested objects / docs as if they were
  10846. indexed as separate docs and resulting in the rootparent doc (or parent
  10847. nested mapping).</p>
  10848. @name ejs.NestedQuery
  10849. @desc
  10850. <p>Constructs a query that is capable of executing a search against objects
  10851. nested within a document.</p>
  10852. @param {String} path The nested object path.
  10853. */
  10854. ejs.NestedQuery = function (path) {
  10855. /**
  10856. The internal Query object. Use <code>_self()</code>.
  10857. @member ejs.NestedQuery
  10858. @property {Object} query
  10859. */
  10860. var query = {
  10861. nested: {
  10862. path: path
  10863. }
  10864. };
  10865. return {
  10866. /**
  10867. Sets the root context for the nested query.
  10868. @member ejs.NestedQuery
  10869. @param {String} path The path defining the root context for the nested query.
  10870. @returns {Object} returns <code>this</code> so that calls can be chained.
  10871. */
  10872. path: function (path) {
  10873. if (path == null) {
  10874. return query.nested.path;
  10875. }
  10876. query.nested.path = path;
  10877. return this;
  10878. },
  10879. /**
  10880. Sets the nested query to be executed.
  10881. @member ejs.NestedQuery
  10882. @param {Object} oQuery A valid Query object
  10883. @returns {Object} returns <code>this</code> so that calls can be chained.
  10884. */
  10885. query: function (oQuery) {
  10886. if (oQuery == null) {
  10887. return query.nested.query;
  10888. }
  10889. if (!isQuery(oQuery)) {
  10890. throw new TypeError('Argument must be a Query');
  10891. }
  10892. query.nested.query = oQuery._self();
  10893. return this;
  10894. },
  10895. /**
  10896. Sets the nested filter to be executed.
  10897. @member ejs.NestedQuery
  10898. @param {Object} oFilter A valid Filter object
  10899. @returns {Object} returns <code>this</code> so that calls can be chained.
  10900. */
  10901. filter: function (oFilter) {
  10902. if (oFilter == null) {
  10903. return query.nested.filter;
  10904. }
  10905. if (!isFilter(oFilter)) {
  10906. throw new TypeError('Argument must be a Filter');
  10907. }
  10908. query.nested.filter = oFilter._self();
  10909. return this;
  10910. },
  10911. /**
  10912. Sets how the inner (nested) matches affect scoring on the parent document.
  10913. @member ejs.NestedQuery
  10914. @param {String} mode The mode of scoring to be used for nested matches.
  10915. Options are avg, total, max, none - defaults to avg
  10916. @returns {Object} returns <code>this</code> so that calls can be chained.
  10917. */
  10918. scoreMode: function (mode) {
  10919. if (mode == null) {
  10920. return query.nested.score_mode;
  10921. }
  10922. mode = mode.toLowerCase();
  10923. if (mode === 'avg' || mode === 'total' || mode === 'max' ||
  10924. mode === 'none') {
  10925. query.nested.score_mode = mode;
  10926. }
  10927. return this;
  10928. },
  10929. /**
  10930. Sets the scope of the query. A scope allows to run facets on the
  10931. same scope name that will work against the nested documents.
  10932. @member ejs.NestedQuery
  10933. @param {String} s The scope name as a string.
  10934. @returns {Object} returns <code>this</code> so that calls can be chained.
  10935. */
  10936. scope: function (s) {
  10937. if (s == null) {
  10938. return query.nested._scope;
  10939. }
  10940. query.nested._scope = s;
  10941. return this;
  10942. },
  10943. /**
  10944. Sets the boost value of the nested <code>Query</code>.
  10945. @member ejs.NestedQuery
  10946. @param {Double} boost A positive <code>double</code> value.
  10947. @returns {Object} returns <code>this</code> so that calls can be chained.
  10948. */
  10949. boost: function (boost) {
  10950. if (boost == null) {
  10951. return query.nested.boost;
  10952. }
  10953. query.nested.boost = boost;
  10954. return this;
  10955. },
  10956. /**
  10957. Serializes the internal <em>query</em> object as a JSON string.
  10958. @member ejs.NestedQuery
  10959. @returns {String} Returns a JSON representation of the termFilter object.
  10960. */
  10961. toString: function () {
  10962. return JSON.stringify(query);
  10963. },
  10964. /**
  10965. The type of ejs object. For internal use only.
  10966. @member ejs.NestedQuery
  10967. @returns {String} the type of object
  10968. */
  10969. _type: function () {
  10970. return 'query';
  10971. },
  10972. /**
  10973. This method is used to retrieve the raw query object. It's designed
  10974. for internal use when composing and serializing queries.
  10975. @member ejs.NestedQuery
  10976. @returns {Object} Returns the object's <em>query</em> property.
  10977. */
  10978. _self: function () {
  10979. return query;
  10980. }
  10981. };
  10982. };
  10983. /**
  10984. @class
  10985. <p>Matches documents that have fields containing terms with a specified
  10986. prefix (not analyzed). The prefix query maps to Lucene PrefixQuery.</p>
  10987. @name ejs.PrefixQuery
  10988. @desc
  10989. Matches documents containing the specified un-analyzed prefix.
  10990. @param {String} field A valid field name.
  10991. @param {String} value A string prefix.
  10992. */
  10993. ejs.PrefixQuery = function (field, value) {
  10994. /**
  10995. The internal query object. <code>Use get()</code>
  10996. @member ejs.PrefixQuery
  10997. @property {Object} query
  10998. */
  10999. var query = {
  11000. prefix: {}
  11001. };
  11002. query.prefix[field] = {
  11003. value: value
  11004. };
  11005. return {
  11006. /**
  11007. The field to run the query against.
  11008. @member ejs.PrefixQuery
  11009. @param {String} f A single field name.
  11010. @returns {Object} returns <code>this</code> so that calls can be chained.
  11011. */
  11012. field: function (f) {
  11013. var oldValue = query.prefix[field];
  11014. if (f == null) {
  11015. return field;
  11016. }
  11017. delete query.prefix[field];
  11018. field = f;
  11019. query.prefix[f] = oldValue;
  11020. return this;
  11021. },
  11022. /**
  11023. The prefix value.
  11024. @member ejs.PrefixQuery
  11025. @param {String} p A string prefix
  11026. @returns {Object} returns <code>this</code> so that calls can be chained.
  11027. */
  11028. value: function (p) {
  11029. if (p == null) {
  11030. return query.prefix[field].value;
  11031. }
  11032. query.prefix[field].value = p;
  11033. return this;
  11034. },
  11035. /**
  11036. Sets rewrite method. Valid values are:
  11037. constant_score_auto - tries to pick the best constant-score rewrite
  11038. method based on term and document counts from the query
  11039. scoring_boolean - translates each term into boolean should and
  11040. keeps the scores as computed by the query
  11041. constant_score_boolean - same as scoring_boolean, expect no scores
  11042. are computed.
  11043. constant_score_filter - first creates a private Filter, by visiting
  11044. each term in sequence and marking all docs for that term
  11045. top_terms_boost_N - first translates each term into boolean should
  11046. and scores are only computed as the boost using the top N
  11047. scoring terms. Replace N with an integer value.
  11048. top_terms_N - first translates each term into boolean should
  11049. and keeps the scores as computed by the query. Only the top N
  11050. scoring terms are used. Replace N with an integer value.
  11051. Default is constant_score_auto.
  11052. This is an advanced option, use with care.
  11053. @member ejs.PrefixQuery
  11054. @param {String} m The rewrite method as a string.
  11055. @returns {Object} returns <code>this</code> so that calls can be chained.
  11056. */
  11057. rewrite: function (m) {
  11058. if (m == null) {
  11059. return query.prefix[field].rewrite;
  11060. }
  11061. m = m.toLowerCase();
  11062. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  11063. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  11064. m.indexOf('top_terms_boost_') === 0 ||
  11065. m.indexOf('top_terms_') === 0) {
  11066. query.prefix[field].rewrite = m;
  11067. }
  11068. return this;
  11069. },
  11070. /**
  11071. Sets the boost value of the <code>Query</code>.
  11072. @member ejs.PrefixQuery
  11073. @param {Double} boost A positive <code>double</code> value.
  11074. @returns {Object} returns <code>this</code> so that calls can be chained.
  11075. */
  11076. boost: function (boost) {
  11077. if (boost == null) {
  11078. return query.prefix[field].boost;
  11079. }
  11080. query.prefix[field].boost = boost;
  11081. return this;
  11082. },
  11083. /**
  11084. Allows you to serialize this object into a JSON encoded string.
  11085. @member ejs.PrefixQuery
  11086. @returns {String} returns this object as a serialized JSON string.
  11087. */
  11088. toString: function () {
  11089. return JSON.stringify(query);
  11090. },
  11091. /**
  11092. The type of ejs object. For internal use only.
  11093. @member ejs.PrefixQuery
  11094. @returns {String} the type of object
  11095. */
  11096. _type: function () {
  11097. return 'query';
  11098. },
  11099. /**
  11100. Retrieves the internal <code>query</code> object. This is typically used by
  11101. internal API functions so use with caution.
  11102. @member ejs.PrefixQuery
  11103. @returns {String} returns this object's internal <code>query</code> property.
  11104. */
  11105. _self: function () {
  11106. return query;
  11107. }
  11108. };
  11109. };
  11110. /**
  11111. @class
  11112. <p>A query that is parsed using Lucene's default query parser. Although Lucene provides the
  11113. ability to create your own queries through its API, it also provides a rich query language
  11114. through the Query Parser, a lexer which interprets a string into a Lucene Query.</p>
  11115. </p>See the Lucene <a href="http://lucene.apache.org/java/2_9_1/queryparsersyntax.html">Query Parser Syntax</a>
  11116. for more information.</p>
  11117. @name ejs.QueryStringQuery
  11118. @desc
  11119. A query that is parsed using Lucene's default query parser.
  11120. @param {String} qstr A valid Lucene query string.
  11121. */
  11122. ejs.QueryStringQuery = function (qstr) {
  11123. /**
  11124. The internal Query object. Use <code>get()</code>.
  11125. @member ejs.QueryStringQuery
  11126. @property {Object} query
  11127. */
  11128. var query = {
  11129. query_string: {}
  11130. };
  11131. query.query_string.query = qstr;
  11132. return {
  11133. /**
  11134. Sets the query string on this <code>Query</code> object.
  11135. @member ejs.QueryStringQuery
  11136. @param {String} qstr A valid Lucene query string.
  11137. @returns {Object} returns <code>this</code> so that calls can be chained.
  11138. */
  11139. query: function (qstr) {
  11140. if (qstr == null) {
  11141. return query.query_string.query;
  11142. }
  11143. query.query_string.query = qstr;
  11144. return this;
  11145. },
  11146. /**
  11147. Sets the default field/property this query should execute against.
  11148. @member ejs.QueryStringQuery
  11149. @param {String} fieldName The name of document field/property.
  11150. @returns {Object} returns <code>this</code> so that calls can be chained.
  11151. */
  11152. defaultField: function (fieldName) {
  11153. if (fieldName == null) {
  11154. return query.query_string.default_field;
  11155. }
  11156. query.query_string.default_field = fieldName;
  11157. return this;
  11158. },
  11159. /**
  11160. A set of fields/properties this query should execute against.
  11161. Pass a single value to add to the existing list of fields and
  11162. pass an array to overwrite all existing fields. For each field,
  11163. you can apply a field specific boost by appending a ^boost to the
  11164. field name. For example, title^10, to give the title field a
  11165. boost of 10.
  11166. @member ejs.QueryStringQuery
  11167. @param {Array} fieldNames A list of document fields/properties.
  11168. @returns {Object} returns <code>this</code> so that calls can be chained.
  11169. */
  11170. fields: function (fieldNames) {
  11171. if (query.query_string.fields == null) {
  11172. query.query_string.fields = [];
  11173. }
  11174. if (fieldNames == null) {
  11175. return query.query_string.fields;
  11176. }
  11177. if (isString(fieldNames)) {
  11178. query.query_string.fields.push(fieldNames);
  11179. } else if (isArray(fieldNames)) {
  11180. query.query_string.fields = fieldNames;
  11181. } else {
  11182. throw new TypeError('Argument must be a string or array');
  11183. }
  11184. return this;
  11185. },
  11186. /**
  11187. Sets whether or not queries against multiple fields should be combined using Lucene's
  11188. <a href="http://lucene.apache.org/java/3_0_0/api/core/org/apache/lucene/search/DisjunctionMaxQuery.html">
  11189. DisjunctionMaxQuery</a>
  11190. @member ejs.QueryStringQuery
  11191. @param {String} trueFalse A <code>true/false</code> value.
  11192. @returns {Object} returns <code>this</code> so that calls can be chained.
  11193. */
  11194. useDisMax: function (trueFalse) {
  11195. if (trueFalse == null) {
  11196. return query.query_string.use_dis_max;
  11197. }
  11198. query.query_string.use_dis_max = trueFalse;
  11199. return this;
  11200. },
  11201. /**
  11202. Set the default <em>Boolean</em> operator. This operator is used to join individual query
  11203. terms when no operator is explicity used in the query string (i.e., <code>this AND that</code>).
  11204. Defaults to <code>OR</code> (<em>same as Google</em>).
  11205. @member ejs.QueryStringQuery
  11206. @param {String} op The operator to use, AND or OR.
  11207. @returns {Object} returns <code>this</code> so that calls can be chained.
  11208. */
  11209. defaultOperator: function (op) {
  11210. if (op == null) {
  11211. return query.query_string.default_operator;
  11212. }
  11213. op = op.toUpperCase();
  11214. if (op === 'AND' || op === 'OR') {
  11215. query.query_string.default_operator = op;
  11216. }
  11217. return this;
  11218. },
  11219. /**
  11220. Sets the analyzer name used to analyze the <code>Query</code> object.
  11221. @member ejs.QueryStringQuery
  11222. @param {String} analyzer A valid analyzer name.
  11223. @returns {Object} returns <code>this</code> so that calls can be chained.
  11224. */
  11225. analyzer: function (analyzer) {
  11226. if (analyzer == null) {
  11227. return query.query_string.analyzer;
  11228. }
  11229. query.query_string.analyzer = analyzer;
  11230. return this;
  11231. },
  11232. /**
  11233. Sets the quote analyzer name used to analyze the <code>query</code>
  11234. when in quoted text.
  11235. @member ejs.QueryStringQuery
  11236. @param {String} analyzer A valid analyzer name.
  11237. @returns {Object} returns <code>this</code> so that calls can be chained.
  11238. */
  11239. quoteAnalyzer: function (analyzer) {
  11240. if (analyzer == null) {
  11241. return query.query_string.quote_analyzer;
  11242. }
  11243. query.query_string.quote_analyzer = analyzer;
  11244. return this;
  11245. },
  11246. /**
  11247. Sets whether or not wildcard characters (* and ?) are allowed as the
  11248. first character of the <code>Query</code>. Default: true.
  11249. @member ejs.QueryStringQuery
  11250. @param {Boolean} trueFalse A <code>true/false</code> value.
  11251. @returns {Object} returns <code>this</code> so that calls can be chained.
  11252. */
  11253. allowLeadingWildcard: function (trueFalse) {
  11254. if (trueFalse == null) {
  11255. return query.query_string.allow_leading_wildcard;
  11256. }
  11257. query.query_string.allow_leading_wildcard = trueFalse;
  11258. return this;
  11259. },
  11260. /**
  11261. Sets whether or not terms from wildcard, prefix, fuzzy, and
  11262. range queries should automatically be lowercased in the <code>Query</code>
  11263. since they are not analyzed. Default: true.
  11264. @member ejs.QueryStringQuery
  11265. @param {Boolean} trueFalse A <code>true/false</code> value.
  11266. @returns {Object} returns <code>this</code> so that calls can be chained.
  11267. */
  11268. lowercaseExpandedTerms: function (trueFalse) {
  11269. if (trueFalse == null) {
  11270. return query.query_string.lowercase_expanded_terms;
  11271. }
  11272. query.query_string.lowercase_expanded_terms = trueFalse;
  11273. return this;
  11274. },
  11275. /**
  11276. Sets whether or not position increments will be used in the
  11277. <code>Query</code>. Default: true.
  11278. @member ejs.QueryStringQuery
  11279. @param {Boolean} trueFalse A <code>true/false</code> value.
  11280. @returns {Object} returns <code>this</code> so that calls can be chained.
  11281. */
  11282. enablePositionIncrements: function (trueFalse) {
  11283. if (trueFalse == null) {
  11284. return query.query_string.enable_position_increments;
  11285. }
  11286. query.query_string.enable_position_increments = trueFalse;
  11287. return this;
  11288. },
  11289. /**
  11290. Sets the prefix length for fuzzy queries. Default: 0.
  11291. @member ejs.QueryStringQuery
  11292. @param {Integer} fuzzLen A positive <code>integer</code> value.
  11293. @returns {Object} returns <code>this</code> so that calls can be chained.
  11294. */
  11295. fuzzyPrefixLength: function (fuzzLen) {
  11296. if (fuzzLen == null) {
  11297. return query.query_string.fuzzy_prefix_length;
  11298. }
  11299. query.query_string.fuzzy_prefix_length = fuzzLen;
  11300. return this;
  11301. },
  11302. /**
  11303. Set the minimum similarity for fuzzy queries. Default: 0.5.
  11304. @member ejs.QueryStringQuery
  11305. @param {Double} minSim A <code>double</code> value between 0 and 1.
  11306. @returns {Object} returns <code>this</code> so that calls can be chained.
  11307. */
  11308. fuzzyMinSim: function (minSim) {
  11309. if (minSim == null) {
  11310. return query.query_string.fuzzy_min_sim;
  11311. }
  11312. query.query_string.fuzzy_min_sim = minSim;
  11313. return this;
  11314. },
  11315. /**
  11316. Sets the default slop for phrases. If zero, then exact phrase matches
  11317. are required. Default: 0.
  11318. @member ejs.QueryStringQuery
  11319. @param {Integer} slop A positive <code>integer</code> value.
  11320. @returns {Object} returns <code>this</code> so that calls can be chained.
  11321. */
  11322. phraseSlop: function (slop) {
  11323. if (slop == null) {
  11324. return query.query_string.phrase_slop;
  11325. }
  11326. query.query_string.phrase_slop = slop;
  11327. return this;
  11328. },
  11329. /**
  11330. Sets the boost value of the <code>Query</code>. Default: 1.0.
  11331. @member ejs.QueryStringQuery
  11332. @param {Double} boost A positive <code>double</code> value.
  11333. @returns {Object} returns <code>this</code> so that calls can be chained.
  11334. */
  11335. boost: function (boost) {
  11336. if (boost == null) {
  11337. return query.query_string.boost;
  11338. }
  11339. query.query_string.boost = boost;
  11340. return this;
  11341. },
  11342. /**
  11343. Sets whether or not we should attempt to analyzed wilcard terms in the
  11344. <code>Query</code>. By default, wildcard terms are not analyzed.
  11345. Analysis of wildcard characters is not perfect. Default: false.
  11346. @member ejs.QueryStringQuery
  11347. @param {Boolean} trueFalse A <code>true/false</code> value.
  11348. @returns {Object} returns <code>this</code> so that calls can be chained.
  11349. */
  11350. analyzeWildcard: function (trueFalse) {
  11351. if (trueFalse == null) {
  11352. return query.query_string.analyze_wildcard;
  11353. }
  11354. query.query_string.analyze_wildcard = trueFalse;
  11355. return this;
  11356. },
  11357. /**
  11358. Sets whether or not we should auto generate phrase queries *if* the
  11359. analyzer returns more than one term. Default: false.
  11360. @member ejs.QueryStringQuery
  11361. @param {Boolean} trueFalse A <code>true/false</code> value.
  11362. @returns {Object} returns <code>this</code> so that calls can be chained.
  11363. */
  11364. autoGeneratePhraseQueries: function (trueFalse) {
  11365. if (trueFalse == null) {
  11366. return query.query_string.auto_generate_phrase_queries;
  11367. }
  11368. query.query_string.auto_generate_phrase_queries = trueFalse;
  11369. return this;
  11370. },
  11371. /**
  11372. Sets a percent value controlling how many "should" clauses in the
  11373. resulting <code>Query</code> should match.
  11374. @member ejs.QueryStringQuery
  11375. @param {Integer} minMatch An <code>integer</code> between 0 and 100.
  11376. @returns {Object} returns <code>this</code> so that calls can be chained.
  11377. */
  11378. minimumShouldMatch: function (minMatch) {
  11379. if (minMatch == null) {
  11380. return query.query_string.minimum_should_match;
  11381. }
  11382. query.query_string.minimum_should_match = minMatch;
  11383. return this;
  11384. },
  11385. /**
  11386. Sets the tie breaker value for a <code>Query</code> using
  11387. <code>DisMax</code>. The tie breaker capability allows results
  11388. that include the same term in multiple fields to be judged better than
  11389. results that include this term in only the best of those multiple
  11390. fields, without confusing this with the better case of two different
  11391. terms in the multiple fields. Default: 0.0.
  11392. @member ejs.QueryStringQuery
  11393. @param {Double} tieBreaker A positive <code>double</code> value.
  11394. @returns {Object} returns <code>this</code> so that calls can be chained.
  11395. */
  11396. tieBreaker: function (tieBreaker) {
  11397. if (tieBreaker == null) {
  11398. return query.query_string.tie_breaker;
  11399. }
  11400. query.query_string.tie_breaker = tieBreaker;
  11401. return this;
  11402. },
  11403. /**
  11404. If they query string should be escaped or not.
  11405. @member ejs.QueryStringQuery
  11406. @param {Boolean} trueFalse A <code>true/false</code> value.
  11407. @returns {Object} returns <code>this</code> so that calls can be chained.
  11408. */
  11409. escape: function (trueFalse) {
  11410. if (trueFalse == null) {
  11411. return query.query_string.escape;
  11412. }
  11413. query.query_string.escape = trueFalse;
  11414. return this;
  11415. },
  11416. /**
  11417. Sets the max number of term expansions for fuzzy queries.
  11418. @member ejs.QueryStringQuery
  11419. @param {Integer} max A positive <code>integer</code> value.
  11420. @returns {Object} returns <code>this</code> so that calls can be chained.
  11421. */
  11422. fuzzyMaxExpansions: function (max) {
  11423. if (max == null) {
  11424. return query.query_string.fuzzy_max_expansions;
  11425. }
  11426. query.query_string.fuzzy_max_expansions = max;
  11427. return this;
  11428. },
  11429. /**
  11430. Sets fuzzy rewrite method. Valid values are:
  11431. constant_score_auto - tries to pick the best constant-score rewrite
  11432. method based on term and document counts from the query
  11433. scoring_boolean - translates each term into boolean should and
  11434. keeps the scores as computed by the query
  11435. constant_score_boolean - same as scoring_boolean, expect no scores
  11436. are computed.
  11437. constant_score_filter - first creates a private Filter, by visiting
  11438. each term in sequence and marking all docs for that term
  11439. top_terms_boost_N - first translates each term into boolean should
  11440. and scores are only computed as the boost using the top N
  11441. scoring terms. Replace N with an integer value.
  11442. top_terms_N - first translates each term into boolean should
  11443. and keeps the scores as computed by the query. Only the top N
  11444. scoring terms are used. Replace N with an integer value.
  11445. Default is constant_score_auto.
  11446. This is an advanced option, use with care.
  11447. @member ejs.QueryStringQuery
  11448. @param {String} m The rewrite method as a string.
  11449. @returns {Object} returns <code>this</code> so that calls can be chained.
  11450. */
  11451. fuzzyRewrite: function (m) {
  11452. if (m == null) {
  11453. return query.query_string.fuzzy_rewrite;
  11454. }
  11455. m = m.toLowerCase();
  11456. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  11457. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  11458. m.indexOf('top_terms_boost_') === 0 ||
  11459. m.indexOf('top_terms_') === 0) {
  11460. query.query_string.fuzzy_rewrite = m;
  11461. }
  11462. return this;
  11463. },
  11464. /**
  11465. Sets rewrite method. Valid values are:
  11466. constant_score_auto - tries to pick the best constant-score rewrite
  11467. method based on term and document counts from the query
  11468. scoring_boolean - translates each term into boolean should and
  11469. keeps the scores as computed by the query
  11470. constant_score_boolean - same as scoring_boolean, expect no scores
  11471. are computed.
  11472. constant_score_filter - first creates a private Filter, by visiting
  11473. each term in sequence and marking all docs for that term
  11474. top_terms_boost_N - first translates each term into boolean should
  11475. and scores are only computed as the boost using the top N
  11476. scoring terms. Replace N with an integer value.
  11477. top_terms_N - first translates each term into boolean should
  11478. and keeps the scores as computed by the query. Only the top N
  11479. scoring terms are used. Replace N with an integer value.
  11480. Default is constant_score_auto.
  11481. This is an advanced option, use with care.
  11482. @member ejs.QueryStringQuery
  11483. @param {String} m The rewrite method as a string.
  11484. @returns {Object} returns <code>this</code> so that calls can be chained.
  11485. */
  11486. rewrite: function (m) {
  11487. if (m == null) {
  11488. return query.query_string.rewrite;
  11489. }
  11490. m = m.toLowerCase();
  11491. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  11492. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  11493. m.indexOf('top_terms_boost_') === 0 ||
  11494. m.indexOf('top_terms_') === 0) {
  11495. query.query_string.rewrite = m;
  11496. }
  11497. return this;
  11498. },
  11499. /**
  11500. Sets the suffix to automatically add to the field name when
  11501. performing a quoted search.
  11502. @member ejs.QueryStringQuery
  11503. @param {String} s The suffix as a string.
  11504. @returns {Object} returns <code>this</code> so that calls can be chained.
  11505. */
  11506. quoteFieldSuffix: function (s) {
  11507. if (s == null) {
  11508. return query.query_string.quote_field_suffix;
  11509. }
  11510. query.query_string.quote_field_suffix = s;
  11511. return this;
  11512. },
  11513. /**
  11514. Enables lenient parsing of the query string.
  11515. @member ejs.QueryStringQuery
  11516. @param {Boolean} trueFalse A boolean value
  11517. @returns {Object} returns <code>this</code> so that calls can be chained.
  11518. */
  11519. lenient: function (trueFalse) {
  11520. if (trueFalse == null) {
  11521. return query.query_string.lenient;
  11522. }
  11523. query.query_string.lenient = trueFalse;
  11524. return this;
  11525. },
  11526. /**
  11527. Allows you to serialize this object into a JSON encoded string.
  11528. @member ejs.QueryStringQuery
  11529. @returns {String} returns this object as a serialized JSON string.
  11530. */
  11531. toString: function () {
  11532. return JSON.stringify(query);
  11533. },
  11534. /**
  11535. The type of ejs object. For internal use only.
  11536. @member ejs.QueryStringQuery
  11537. @returns {String} the type of object
  11538. */
  11539. _type: function () {
  11540. return 'query';
  11541. },
  11542. /**
  11543. Retrieves the internal <code>query</code> object. This is typically used by
  11544. internal API functions so use with caution.
  11545. @member ejs.QueryStringQuery
  11546. @returns {String} returns this object's internal <code>query</code> property.
  11547. */
  11548. _self: function () {
  11549. return query;
  11550. }
  11551. };
  11552. };
  11553. /**
  11554. @class
  11555. <p>Matches documents with fields that have terms within a certain range.
  11556. The type of the Lucene query depends on the field type, for string fields,
  11557. the TermRangeQuery, while for number/date fields, the query is a
  11558. NumericRangeQuery.</p>
  11559. @name ejs.RangeQuery
  11560. @desc
  11561. Matches documents with fields that have terms within a certain range.
  11562. @param {String} field A valid field name.
  11563. */
  11564. ejs.RangeQuery = function (field) {
  11565. /**
  11566. The internal query object. <code>Use get()</code>
  11567. @member ejs.RangeQuery
  11568. @property {Object} query
  11569. */
  11570. var query = {
  11571. range: {}
  11572. };
  11573. query.range[field] = {};
  11574. return {
  11575. /**
  11576. The field to run the query against.
  11577. @member ejs.RangeQuery
  11578. @param {String} f A single field name.
  11579. @returns {Object} returns <code>this</code> so that calls can be chained.
  11580. */
  11581. field: function (f) {
  11582. var oldValue = query.range[field];
  11583. if (f == null) {
  11584. return field;
  11585. }
  11586. delete query.range[field];
  11587. field = f;
  11588. query.range[f] = oldValue;
  11589. return this;
  11590. },
  11591. /**
  11592. The lower bound. Defaults to start from the first.
  11593. @member ejs.RangeQuery
  11594. @param {Variable Type} f the lower bound value, type depends on field type
  11595. @returns {Object} returns <code>this</code> so that calls can be chained.
  11596. */
  11597. from: function (f) {
  11598. if (f == null) {
  11599. return query.range[field].from;
  11600. }
  11601. query.range[field].from = f;
  11602. return this;
  11603. },
  11604. /**
  11605. The upper bound. Defaults to unbounded.
  11606. @member ejs.RangeQuery
  11607. @param {Variable Type} t the upper bound value, type depends on field type
  11608. @returns {Object} returns <code>this</code> so that calls can be chained.
  11609. */
  11610. to: function (t) {
  11611. if (t == null) {
  11612. return query.range[field].to;
  11613. }
  11614. query.range[field].to = t;
  11615. return this;
  11616. },
  11617. /**
  11618. Should the first from (if set) be inclusive or not.
  11619. Defaults to true
  11620. @member ejs.RangeQuery
  11621. @param {Boolean} trueFalse true to include, false to exclude
  11622. @returns {Object} returns <code>this</code> so that calls can be chained.
  11623. */
  11624. includeLower: function (trueFalse) {
  11625. if (trueFalse == null) {
  11626. return query.range[field].include_lower;
  11627. }
  11628. query.range[field].include_lower = trueFalse;
  11629. return this;
  11630. },
  11631. /**
  11632. Should the last to (if set) be inclusive or not. Defaults to true.
  11633. @member ejs.RangeQuery
  11634. @param {Boolean} trueFalse true to include, false to exclude
  11635. @returns {Object} returns <code>this</code> so that calls can be chained.
  11636. */
  11637. includeUpper: function (trueFalse) {
  11638. if (trueFalse == null) {
  11639. return query.range[field].include_upper;
  11640. }
  11641. query.range[field].include_upper = trueFalse;
  11642. return this;
  11643. },
  11644. /**
  11645. Greater than value. Same as setting from to the value, and
  11646. include_lower to false,
  11647. @member ejs.RangeQuery
  11648. @param {Variable Type} val the value, type depends on field type
  11649. @returns {Object} returns <code>this</code> so that calls can be chained.
  11650. */
  11651. gt: function (val) {
  11652. if (val == null) {
  11653. return query.range[field].gt;
  11654. }
  11655. query.range[field].gt = val;
  11656. return this;
  11657. },
  11658. /**
  11659. Greater than or equal to value. Same as setting from to the value,
  11660. and include_lower to true.
  11661. @member ejs.RangeQuery
  11662. @param {Variable Type} val the value, type depends on field type
  11663. @returns {Object} returns <code>this</code> so that calls can be chained.
  11664. */
  11665. gte: function (val) {
  11666. if (val == null) {
  11667. return query.range[field].gte;
  11668. }
  11669. query.range[field].gte = val;
  11670. return this;
  11671. },
  11672. /**
  11673. Less than value. Same as setting to to the value, and include_upper
  11674. to false.
  11675. @member ejs.RangeQuery
  11676. @param {Variable Type} val the value, type depends on field type
  11677. @returns {Object} returns <code>this</code> so that calls can be chained.
  11678. */
  11679. lt: function (val) {
  11680. if (val == null) {
  11681. return query.range[field].lt;
  11682. }
  11683. query.range[field].lt = val;
  11684. return this;
  11685. },
  11686. /**
  11687. Less than or equal to value. Same as setting to to the value,
  11688. and include_upper to true.
  11689. @member ejs.RangeQuery
  11690. @param {Variable Type} val the value, type depends on field type
  11691. @returns {Object} returns <code>this</code> so that calls can be chained.
  11692. */
  11693. lte: function (val) {
  11694. if (val == null) {
  11695. return query.range[field].lte;
  11696. }
  11697. query.range[field].lte = val;
  11698. return this;
  11699. },
  11700. /**
  11701. Sets the boost value of the <code>Query</code>.
  11702. @member ejs.RangeQuery
  11703. @param {Double} boost A positive <code>double</code> value.
  11704. @returns {Object} returns <code>this</code> so that calls can be chained.
  11705. */
  11706. boost: function (boost) {
  11707. if (boost == null) {
  11708. return query.range[field].boost;
  11709. }
  11710. query.range[field].boost = boost;
  11711. return this;
  11712. },
  11713. /**
  11714. Allows you to serialize this object into a JSON encoded string.
  11715. @member ejs.RangeQuery
  11716. @returns {String} returns this object as a serialized JSON string.
  11717. */
  11718. toString: function () {
  11719. return JSON.stringify(query);
  11720. },
  11721. /**
  11722. The type of ejs object. For internal use only.
  11723. @member ejs.RangeQuery
  11724. @returns {String} the type of object
  11725. */
  11726. _type: function () {
  11727. return 'query';
  11728. },
  11729. /**
  11730. Retrieves the internal <code>query</code> object. This is typically used by
  11731. internal API functions so use with caution.
  11732. @member ejs.RangeQuery
  11733. @returns {String} returns this object's internal <code>query</code> property.
  11734. */
  11735. _self: function () {
  11736. return query;
  11737. }
  11738. };
  11739. };
  11740. /**
  11741. @class
  11742. <p>Matches documents that have fields matching a regular expression. Based
  11743. on Lucene 4.0 RegexpQuery which uses automaton to efficiently iterate over
  11744. index terms.</p>
  11745. @name ejs.RegexpQuery
  11746. @desc
  11747. Matches documents that have fields matching a regular expression.
  11748. @param {String} field A valid field name.
  11749. @param {String} value A regex pattern.
  11750. */
  11751. ejs.RegexpQuery = function (field, value) {
  11752. /**
  11753. The internal query object. <code>Use get()</code>
  11754. @member ejs.RegexpQuery
  11755. @property {Object} query
  11756. */
  11757. var query = {
  11758. regexp: {}
  11759. };
  11760. query.regexp[field] = {
  11761. value: value
  11762. };
  11763. return {
  11764. /**
  11765. The field to run the query against.
  11766. @member ejs.RegexpQuery
  11767. @param {String} f A single field name.
  11768. @returns {Object} returns <code>this</code> so that calls can be chained.
  11769. */
  11770. field: function (f) {
  11771. var oldValue = query.regexp[field];
  11772. if (f == null) {
  11773. return field;
  11774. }
  11775. delete query.regexp[field];
  11776. field = f;
  11777. query.regexp[f] = oldValue;
  11778. return this;
  11779. },
  11780. /**
  11781. The regexp value.
  11782. @member ejs.RegexpQuery
  11783. @param {String} p A string regexp
  11784. @returns {Object} returns <code>this</code> so that calls can be chained.
  11785. */
  11786. value: function (p) {
  11787. if (p == null) {
  11788. return query.regexp[field].value;
  11789. }
  11790. query.regexp[field].value = p;
  11791. return this;
  11792. },
  11793. /**
  11794. The regex flags to use. Valid flags are:
  11795. INTERSECTION - Support for intersection notation
  11796. COMPLEMENT - Support for complement notation
  11797. EMPTY - Support for the empty language symbol: #
  11798. ANYSTRING - Support for the any string symbol: @
  11799. INTERVAL - Support for numerical interval notation: <n-m>
  11800. NONE - Disable support for all syntax options
  11801. ALL - Enables support for all syntax options
  11802. Use multiple flags by separating with a "|" character. Example:
  11803. INTERSECTION|COMPLEMENT|EMPTY
  11804. @member ejs.RegexpQuery
  11805. @param {String} f The flags as a string, separate multiple flags with "|".
  11806. @returns {Object} returns <code>this</code> so that calls can be chained.
  11807. */
  11808. flags: function (f) {
  11809. if (f == null) {
  11810. return query.regexp[field].flags;
  11811. }
  11812. query.regexp[field].flags = f;
  11813. return this;
  11814. },
  11815. /**
  11816. The regex flags to use as a numeric value. Advanced use only,
  11817. it is probably better to stick with the <code>flags</code> option.
  11818. @member ejs.RegexpQuery
  11819. @param {String} v The flags as a numeric value.
  11820. @returns {Object} returns <code>this</code> so that calls can be chained.
  11821. */
  11822. flagsValue: function (v) {
  11823. if (v == null) {
  11824. return query.regexp[field].flags_value;
  11825. }
  11826. query.regexp[field].flags_value = v;
  11827. return this;
  11828. },
  11829. /**
  11830. Sets rewrite method. Valid values are:
  11831. constant_score_auto - tries to pick the best constant-score rewrite
  11832. method based on term and document counts from the query
  11833. scoring_boolean - translates each term into boolean should and
  11834. keeps the scores as computed by the query
  11835. constant_score_boolean - same as scoring_boolean, expect no scores
  11836. are computed.
  11837. constant_score_filter - first creates a private Filter, by visiting
  11838. each term in sequence and marking all docs for that term
  11839. top_terms_boost_N - first translates each term into boolean should
  11840. and scores are only computed as the boost using the top N
  11841. scoring terms. Replace N with an integer value.
  11842. top_terms_N - first translates each term into boolean should
  11843. and keeps the scores as computed by the query. Only the top N
  11844. scoring terms are used. Replace N with an integer value.
  11845. Default is constant_score_auto.
  11846. This is an advanced option, use with care.
  11847. @member ejs.RegexpQuery
  11848. @param {String} m The rewrite method as a string.
  11849. @returns {Object} returns <code>this</code> so that calls can be chained.
  11850. */
  11851. rewrite: function (m) {
  11852. if (m == null) {
  11853. return query.regexp[field].rewrite;
  11854. }
  11855. m = m.toLowerCase();
  11856. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  11857. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  11858. m.indexOf('top_terms_boost_') === 0 ||
  11859. m.indexOf('top_terms_') === 0) {
  11860. query.regexp[field].rewrite = m;
  11861. }
  11862. return this;
  11863. },
  11864. /**
  11865. Sets the boost value of the <code>Query</code>.
  11866. @member ejs.RegexpQuery
  11867. @param {Double} boost A positive <code>double</code> value.
  11868. @returns {Object} returns <code>this</code> so that calls can be chained.
  11869. */
  11870. boost: function (boost) {
  11871. if (boost == null) {
  11872. return query.regexp[field].boost;
  11873. }
  11874. query.regexp[field].boost = boost;
  11875. return this;
  11876. },
  11877. /**
  11878. Allows you to serialize this object into a JSON encoded string.
  11879. @member ejs.RegexpQuery
  11880. @returns {String} returns this object as a serialized JSON string.
  11881. */
  11882. toString: function () {
  11883. return JSON.stringify(query);
  11884. },
  11885. /**
  11886. The type of ejs object. For internal use only.
  11887. @member ejs.RegexpQuery
  11888. @returns {String} the type of object
  11889. */
  11890. _type: function () {
  11891. return 'query';
  11892. },
  11893. /**
  11894. Retrieves the internal <code>query</code> object. This is typically used by
  11895. internal API functions so use with caution.
  11896. @member ejs.RegexpQuery
  11897. @returns {String} returns this object's internal <code>query</code> property.
  11898. */
  11899. _self: function () {
  11900. return query;
  11901. }
  11902. };
  11903. };
  11904. /**
  11905. @class
  11906. <p>Matches spans near the beginning of a field. The spanFirstQuery allows you to search
  11907. for Spans that start and end within the first <code>n</code> positions of the document.
  11908. The span first query maps to Lucene SpanFirstQuery.</p>
  11909. @name ejs.SpanFirstQuery
  11910. @desc
  11911. Matches spans near the beginning of a field.
  11912. @param {Query} spanQry A valid SpanQuery
  11913. @param {Integer} end the maximum end position in a match.
  11914. */
  11915. ejs.SpanFirstQuery = function (spanQry, end) {
  11916. if (!isQuery(spanQry)) {
  11917. throw new TypeError('Argument must be a SpanQuery');
  11918. }
  11919. /**
  11920. The internal query object. <code>Use _self()</code>
  11921. @member ejs.SpanFirstQuery
  11922. @property {Object} query
  11923. */
  11924. var query = {
  11925. span_first: {
  11926. match: spanQry._self(),
  11927. end: end
  11928. }
  11929. };
  11930. return {
  11931. /**
  11932. Sets the span query to match on.
  11933. @member ejs.SpanFirstQuery
  11934. @param {Object} spanQuery Any valid span type query.
  11935. @returns {Object} returns <code>this</code> so that calls can be chained.
  11936. */
  11937. match: function (spanQuery) {
  11938. if (spanQuery == null) {
  11939. return query.span_first.match;
  11940. }
  11941. if (!isQuery(spanQuery)) {
  11942. throw new TypeError('Argument must be a SpanQuery');
  11943. }
  11944. query.span_first.match = spanQuery._self();
  11945. return this;
  11946. },
  11947. /**
  11948. Sets the maximum end position permitted in a match.
  11949. @member ejs.SpanFirstQuery
  11950. @param {Number} position The maximum position length to consider.
  11951. @returns {Object} returns <code>this</code> so that calls can be chained.
  11952. */
  11953. end: function (position) {
  11954. if (position == null) {
  11955. return query.span_first.end;
  11956. }
  11957. query.span_first.end = position;
  11958. return this;
  11959. },
  11960. /**
  11961. Sets the boost value of the <code>Query</code>.
  11962. @member ejs.SpanFirstQuery
  11963. @param {Double} boost A positive <code>double</code> value.
  11964. @returns {Object} returns <code>this</code> so that calls can be chained.
  11965. */
  11966. boost: function (boost) {
  11967. if (boost == null) {
  11968. return query.span_first.boost;
  11969. }
  11970. query.span_first.boost = boost;
  11971. return this;
  11972. },
  11973. /**
  11974. Allows you to serialize this object into a JSON encoded string.
  11975. @member ejs.SpanFirstQuery
  11976. @returns {String} returns this object as a serialized JSON string.
  11977. */
  11978. toString: function () {
  11979. return JSON.stringify(query);
  11980. },
  11981. /**
  11982. The type of ejs object. For internal use only.
  11983. @member ejs.SpanFirstQuery
  11984. @returns {String} the type of object
  11985. */
  11986. _type: function () {
  11987. return 'query';
  11988. },
  11989. /**
  11990. Retrieves the internal <code>query</code> object. This is typically used by
  11991. internal API functions so use with caution.
  11992. @member ejs.SpanFirstQuery
  11993. @returns {String} returns this object's internal <code>query</code> property.
  11994. */
  11995. _self: function () {
  11996. return query;
  11997. }
  11998. };
  11999. };
  12000. /**
  12001. @class
  12002. <p>A spanNearQuery will look to find a number of spanQuerys within a given
  12003. distance from each other.</p>
  12004. @name ejs.SpanNearQuery
  12005. @desc
  12006. Matches spans which are near one another.
  12007. @param {Query || Array} clauses A single SpanQuery or array of SpanQueries
  12008. @param {Integer} slop The number of intervening unmatched positions
  12009. */
  12010. ejs.SpanNearQuery = function (clauses, slop) {
  12011. /**
  12012. The internal query object. <code>Use _self()</code>
  12013. @member ejs.SpanNearQuery
  12014. @property {Object} query
  12015. */
  12016. var i, len,
  12017. query = {
  12018. span_near: {
  12019. clauses: [],
  12020. slop: slop
  12021. }
  12022. };
  12023. if (isQuery(clauses)) {
  12024. query.span_near.clauses.push(clauses._self());
  12025. } else if (isArray(clauses)) {
  12026. for (i = 0, len = clauses.length; i < len; i++) {
  12027. if (!isQuery(clauses[i])) {
  12028. throw new TypeError('Argument must be array of SpanQueries');
  12029. }
  12030. query.span_near.clauses.push(clauses[i]._self());
  12031. }
  12032. } else {
  12033. throw new TypeError('Argument must be SpanQuery or array of SpanQueries');
  12034. }
  12035. return {
  12036. /**
  12037. Sets the clauses used. If passed a single SpanQuery, it is added
  12038. to the existing list of clauses. If passed an array of
  12039. SpanQueries, they replace any existing clauses.
  12040. @member ejs.SpanNearQuery
  12041. @param {Query || Array} clauses A SpanQuery or array of SpanQueries.
  12042. @returns {Object} returns <code>this</code> so that calls can be chained.
  12043. */
  12044. clauses: function (clauses) {
  12045. var i, len;
  12046. if (clauses == null) {
  12047. return query.span_near.clauses;
  12048. }
  12049. if (isQuery(clauses)) {
  12050. query.span_near.clauses.push(clauses._self());
  12051. } else if (isArray(clauses)) {
  12052. query.span_near.clauses = [];
  12053. for (i = 0, len = clauses.length; i < len; i++) {
  12054. if (!isQuery(clauses[i])) {
  12055. throw new TypeError('Argument must be array of SpanQueries');
  12056. }
  12057. query.span_near.clauses.push(clauses[i]._self());
  12058. }
  12059. } else {
  12060. throw new TypeError('Argument must be SpanQuery or array of SpanQueries');
  12061. }
  12062. return this;
  12063. },
  12064. /**
  12065. Sets the maximum number of intervening unmatched positions.
  12066. @member ejs.SpanNearQuery
  12067. @param {Number} distance The number of intervening unmatched positions.
  12068. @returns {Object} returns <code>this</code> so that calls can be chained.
  12069. */
  12070. slop: function (distance) {
  12071. if (distance == null) {
  12072. return query.span_near.slop;
  12073. }
  12074. query.span_near.slop = distance;
  12075. return this;
  12076. },
  12077. /**
  12078. Sets whether or not matches are required to be in-order.
  12079. @member ejs.SpanNearQuery
  12080. @param {Boolean} trueFalse Determines if matches must be in-order.
  12081. @returns {Object} returns <code>this</code> so that calls can be chained.
  12082. */
  12083. inOrder: function (trueFalse) {
  12084. if (trueFalse == null) {
  12085. return query.span_near.in_order;
  12086. }
  12087. query.span_near.in_order = trueFalse;
  12088. return this;
  12089. },
  12090. /**
  12091. Sets whether or not payloads are being used. A payload is an arbitrary
  12092. byte array stored at a specific position (i.e. token/term).
  12093. @member ejs.SpanNearQuery
  12094. @param {Boolean} trueFalse Whether or not to return payloads.
  12095. @returns {Object} returns <code>this</code> so that calls can be chained.
  12096. */
  12097. collectPayloads: function (trueFalse) {
  12098. if (trueFalse == null) {
  12099. return query.span_near.collect_payloads;
  12100. }
  12101. query.span_near.collect_payloads = trueFalse;
  12102. return this;
  12103. },
  12104. /**
  12105. Sets the boost value of the <code>Query</code>.
  12106. @member ejs.SpanNearQuery
  12107. @param {Double} boost A positive <code>double</code> value.
  12108. @returns {Object} returns <code>this</code> so that calls can be chained.
  12109. */
  12110. boost: function (boost) {
  12111. if (boost == null) {
  12112. return query.span_near.boost;
  12113. }
  12114. query.span_near.boost = boost;
  12115. return this;
  12116. },
  12117. /**
  12118. Allows you to serialize this object into a JSON encoded string.
  12119. @member ejs.SpanNearQuery
  12120. @returns {String} returns this object as a serialized JSON string.
  12121. */
  12122. toString: function () {
  12123. return JSON.stringify(query);
  12124. },
  12125. /**
  12126. The type of ejs object. For internal use only.
  12127. @member ejs.SpanNearQuery
  12128. @returns {String} the type of object
  12129. */
  12130. _type: function () {
  12131. return 'query';
  12132. },
  12133. /**
  12134. Retrieves the internal <code>query</code> object. This is typically used by
  12135. internal API functions so use with caution.
  12136. @member ejs.SpanNearQuery
  12137. @returns {String} returns this object's internal <code>query</code> property.
  12138. */
  12139. _self: function () {
  12140. return query;
  12141. }
  12142. };
  12143. };
  12144. /**
  12145. @class
  12146. <p>Removes matches which overlap with another span query.
  12147. The span not query maps to Lucene SpanNotQuery.</p>
  12148. @name ejs.SpanNotQuery
  12149. @desc
  12150. Removes matches which overlap with another span query.
  12151. @param {Query} includeQry a valid SpanQuery whose matching docs will be returned.
  12152. @param {Query} excludeQry a valid SpanQuery whose matching docs will not be returned
  12153. */
  12154. ejs.SpanNotQuery = function (includeQry, excludeQry) {
  12155. if (!isQuery(includeQry) || !isQuery(excludeQry)) {
  12156. throw new TypeError('Argument must be a SpanQuery');
  12157. }
  12158. /**
  12159. The internal query object. <code>Use _self()</code>
  12160. @member ejs.SpanNotQuery
  12161. @property {Object} query
  12162. */
  12163. var query = {
  12164. span_not: {
  12165. include: includeQry._self(),
  12166. exclude: excludeQry._self()
  12167. }
  12168. };
  12169. return {
  12170. /**
  12171. Set the span query whose matches are filtered.
  12172. @member ejs.SpanNotQuery
  12173. @param {Object} spanQuery Any valid span type query.
  12174. @returns {Object} returns <code>this</code> so that calls can be chained.
  12175. */
  12176. include: function (spanQuery) {
  12177. if (spanQuery == null) {
  12178. return query.span_not.include;
  12179. }
  12180. if (!isQuery(spanQuery)) {
  12181. throw new TypeError('Argument must be a SpanQuery');
  12182. }
  12183. query.span_not.include = spanQuery._self();
  12184. return this;
  12185. },
  12186. /**
  12187. Sets the span query whose matches must not overlap those returned.
  12188. @member ejs.SpanNotQuery
  12189. @param {Object} spanQuery Any valid span type query.
  12190. @returns {Object} returns <code>this</code> so that calls can be chained.
  12191. */
  12192. exclude: function (spanQuery) {
  12193. if (spanQuery == null) {
  12194. return query.span_not.exclude;
  12195. }
  12196. if (!isQuery(spanQuery)) {
  12197. throw new TypeError('Argument must be a SpanQuery');
  12198. }
  12199. query.span_not.exclude = spanQuery._self();
  12200. return this;
  12201. },
  12202. /**
  12203. Sets the boost value of the <code>Query</code>.
  12204. @member ejs.SpanNotQuery
  12205. @param {Double} boost A positive <code>double</code> value.
  12206. @returns {Object} returns <code>this</code> so that calls can be chained.
  12207. */
  12208. boost: function (boost) {
  12209. if (boost == null) {
  12210. return query.span_not.boost;
  12211. }
  12212. query.span_not.boost = boost;
  12213. return this;
  12214. },
  12215. /**
  12216. Allows you to serialize this object into a JSON encoded string.
  12217. @member ejs.SpanNotQuery
  12218. @returns {String} returns this object as a serialized JSON string.
  12219. */
  12220. toString: function () {
  12221. return JSON.stringify(query);
  12222. },
  12223. /**
  12224. The type of ejs object. For internal use only.
  12225. @member ejs.SpanNotQuery
  12226. @returns {String} the type of object
  12227. */
  12228. _type: function () {
  12229. return 'query';
  12230. },
  12231. /**
  12232. Retrieves the internal <code>query</code> object. This is typically used by
  12233. internal API functions so use with caution.
  12234. @member ejs.SpanNotQuery
  12235. @returns {String} returns this object's internal <code>query</code> property.
  12236. */
  12237. _self: function () {
  12238. return query;
  12239. }
  12240. };
  12241. };
  12242. /**
  12243. @class
  12244. <p>The spanOrQuery takes an array of SpanQuerys and will match if any of the
  12245. underlying SpanQueries match. The span or query maps to Lucene SpanOrQuery.</p>
  12246. @name ejs.SpanOrQuery
  12247. @desc
  12248. Matches the union of its span clauses.
  12249. @param {Object} clauses A single SpanQuery or array of SpanQueries.
  12250. */
  12251. ejs.SpanOrQuery = function (clauses) {
  12252. /**
  12253. The internal query object. <code>Use _self()</code>
  12254. @member ejs.SpanOrQuery
  12255. @property {Object} query
  12256. */
  12257. var i,
  12258. len,
  12259. query = {
  12260. span_or: {
  12261. clauses: []
  12262. }
  12263. };
  12264. if (isQuery(clauses)) {
  12265. query.span_or.clauses.push(clauses._self());
  12266. } else if (isArray(clauses)) {
  12267. for (i = 0, len = clauses.length; i < len; i++) {
  12268. if (!isQuery(clauses[i])) {
  12269. throw new TypeError('Argument must be array of SpanQueries');
  12270. }
  12271. query.span_or.clauses.push(clauses[i]._self());
  12272. }
  12273. } else {
  12274. throw new TypeError('Argument must be SpanQuery or array of SpanQueries');
  12275. }
  12276. return {
  12277. /**
  12278. Sets the clauses used. If passed a single SpanQuery, it is added
  12279. to the existing list of clauses. If passed an array of
  12280. SpanQueries, they replace any existing clauses.
  12281. @member ejs.SpanOrQuery
  12282. @param {Query || Array} clauses A SpanQuery or array of SpanQueries.
  12283. @returns {Object} returns <code>this</code> so that calls can be chained.
  12284. */
  12285. clauses: function (clauses) {
  12286. var i, len;
  12287. if (clauses == null) {
  12288. return query.span_or.clauses;
  12289. }
  12290. if (isQuery(clauses)) {
  12291. query.span_or.clauses.push(clauses._self());
  12292. } else if (isArray(clauses)) {
  12293. query.span_or.clauses = [];
  12294. for (i = 0, len = clauses.length; i < len; i++) {
  12295. if (!isQuery(clauses[i])) {
  12296. throw new TypeError('Argument must be array of SpanQueries');
  12297. }
  12298. query.span_or.clauses.push(clauses[i]._self());
  12299. }
  12300. } else {
  12301. throw new TypeError('Argument must be SpanQuery or array of SpanQueries');
  12302. }
  12303. return this;
  12304. },
  12305. /**
  12306. Sets the boost value of the <code>Query</code>.
  12307. @member ejs.SpanOrQuery
  12308. @param {Double} boost A positive <code>double</code> value.
  12309. @returns {Object} returns <code>this</code> so that calls can be chained.
  12310. */
  12311. boost: function (boost) {
  12312. if (boost == null) {
  12313. return query.span_or.boost;
  12314. }
  12315. query.span_or.boost = boost;
  12316. return this;
  12317. },
  12318. /**
  12319. Allows you to serialize this object into a JSON encoded string.
  12320. @member ejs.SpanOrQuery
  12321. @returns {String} returns this object as a serialized JSON string.
  12322. */
  12323. toString: function () {
  12324. return JSON.stringify(query);
  12325. },
  12326. /**
  12327. The type of ejs object. For internal use only.
  12328. @member ejs.SpanOrQuery
  12329. @returns {String} the type of object
  12330. */
  12331. _type: function () {
  12332. return 'query';
  12333. },
  12334. /**
  12335. Retrieves the internal <code>query</code> object. This is typically used by
  12336. internal API functions so use with caution.
  12337. @member ejs.SpanOrQuery
  12338. @returns {String} returns this object's internal <code>query</code> property.
  12339. */
  12340. _self: function () {
  12341. return query;
  12342. }
  12343. };
  12344. };
  12345. /**
  12346. @class
  12347. <p>A spanTermQuery is the basic unit of Lucene's Span Query which allows for nested,
  12348. positional restrictions when matching documents. The spanTermQuery simply matches
  12349. spans containing a term. It's essentially a termQuery with positional information asscoaited.</p>
  12350. @name ejs.SpanTermQuery
  12351. @desc
  12352. Matches spans containing a term
  12353. @param {String} field the document field/field to query against
  12354. @param {String} value the literal value to be matched
  12355. */
  12356. ejs.SpanTermQuery = function (field, value) {
  12357. /**
  12358. The internal query object. <code>Use get()</code>
  12359. @member ejs.SpanTermQuery
  12360. @property {Object} query
  12361. */
  12362. var query = {
  12363. span_term: {}
  12364. };
  12365. query.span_term[field] = {
  12366. term: value
  12367. };
  12368. return {
  12369. /**
  12370. Sets the field to query against.
  12371. @member ejs.SpanTermQuery
  12372. @param {String} f A valid field name.
  12373. @returns {Object} returns <code>this</code> so that calls can be chained.
  12374. */
  12375. field: function (f) {
  12376. var oldValue = query.span_term[field];
  12377. if (f == null) {
  12378. return field;
  12379. }
  12380. delete query.span_term[field];
  12381. field = f;
  12382. query.span_term[f] = oldValue;
  12383. return this;
  12384. },
  12385. /**
  12386. Sets the term.
  12387. @member ejs.SpanTermQuery
  12388. @param {String} t A single term.
  12389. @returns {Object} returns <code>this</code> so that calls can be chained.
  12390. */
  12391. term: function (t) {
  12392. if (t == null) {
  12393. return query.span_term[field].term;
  12394. }
  12395. query.span_term[field].term = t;
  12396. return this;
  12397. },
  12398. /**
  12399. Sets the boost value for documents matching the <code>Query</code>.
  12400. @member ejs.SpanTermQuery
  12401. @param {Double} boost A positive <code>double</code> value.
  12402. @returns {Object} returns <code>this</code> so that calls can be chained.
  12403. */
  12404. boost: function (boost) {
  12405. if (boost == null) {
  12406. return query.span_term[field].boost;
  12407. }
  12408. query.span_term[field].boost = boost;
  12409. return this;
  12410. },
  12411. /**
  12412. Allows you to serialize this object into a JSON encoded string.
  12413. @member ejs.SpanTermQuery
  12414. @returns {String} returns this object as a serialized JSON string.
  12415. */
  12416. toString: function () {
  12417. return JSON.stringify(query);
  12418. },
  12419. /**
  12420. The type of ejs object. For internal use only.
  12421. @member ejs.SpanTermQuery
  12422. @returns {String} the type of object
  12423. */
  12424. _type: function () {
  12425. return 'query';
  12426. },
  12427. /**
  12428. Retrieves the internal <code>query</code> object. This is typically used by
  12429. internal API functions so use with caution.
  12430. @member ejs.SpanTermQuery
  12431. @returns {String} returns this object's internal <code>query</code> property.
  12432. */
  12433. _self: function () {
  12434. return query;
  12435. }
  12436. };
  12437. };
  12438. /**
  12439. @class
  12440. <p>A <code>TermQuery</code> can be used to return documents containing a given
  12441. keyword or <em>term</em>. For instance, you might want to retieve all the
  12442. documents/objects that contain the term <code>Javascript</code>. Term filters
  12443. often serve as the basis for more complex queries such as <em>Boolean</em> queries.</p>
  12444. @name ejs.TermQuery
  12445. @desc
  12446. A Query that matches documents containing a term. This may be
  12447. combined with other terms with a BooleanQuery.
  12448. @param {String} field the document field/key to query against
  12449. @param {String} term the literal value to be matched
  12450. */
  12451. ejs.TermQuery = function (field, term) {
  12452. /**
  12453. The internal query object. <code>Use get()</code>
  12454. @member ejs.TermQuery
  12455. @property {Object} query
  12456. */
  12457. var query = {
  12458. term: {}
  12459. };
  12460. query.term[field] = {
  12461. term: term
  12462. };
  12463. return {
  12464. /**
  12465. Sets the fields to query against.
  12466. @member ejs.TermQuery
  12467. @param {String} f A valid field name.
  12468. @returns {Object} returns <code>this</code> so that calls can be chained.
  12469. */
  12470. field: function (f) {
  12471. var oldValue = query.term[field];
  12472. if (f == null) {
  12473. return field;
  12474. }
  12475. delete query.term[field];
  12476. field = f;
  12477. query.term[f] = oldValue;
  12478. return this;
  12479. },
  12480. /**
  12481. Sets the term.
  12482. @member ejs.TermQuery
  12483. @param {String} t A single term.
  12484. @returns {Object} returns <code>this</code> so that calls can be chained.
  12485. */
  12486. term: function (t) {
  12487. if (t == null) {
  12488. return query.term[field].term;
  12489. }
  12490. query.term[field].term = t;
  12491. return this;
  12492. },
  12493. /**
  12494. Sets the boost value for documents matching the <code>Query</code>.
  12495. @member ejs.TermQuery
  12496. @param {Number} boost A positive <code>double</code> value.
  12497. @returns {Object} returns <code>this</code> so that calls can be chained.
  12498. */
  12499. boost: function (boost) {
  12500. if (boost == null) {
  12501. return query.term[field].boost;
  12502. }
  12503. query.term[field].boost = boost;
  12504. return this;
  12505. },
  12506. /**
  12507. Allows you to serialize this object into a JSON encoded string.
  12508. @member ejs.TermQuery
  12509. @returns {String} returns this object as a serialized JSON string.
  12510. */
  12511. toString: function () {
  12512. return JSON.stringify(query);
  12513. },
  12514. /**
  12515. The type of ejs object. For internal use only.
  12516. @member ejs.TermQuery
  12517. @returns {String} the type of object
  12518. */
  12519. _type: function () {
  12520. return 'query';
  12521. },
  12522. /**
  12523. Retrieves the internal <code>query</code> object. This is typically used by
  12524. internal API functions so use with caution.
  12525. @member ejs.TermQuery
  12526. @returns {String} returns this object's internal <code>query</code> property.
  12527. */
  12528. _self: function () {
  12529. return query;
  12530. }
  12531. };
  12532. };
  12533. /**
  12534. @class
  12535. <p>A query that match on any (configurable) of the provided terms. This is
  12536. a simpler syntax query for using a bool query with several term queries
  12537. in the should clauses.</p>
  12538. @name ejs.TermsQuery
  12539. @desc
  12540. A Query that matches documents containing provided terms.
  12541. @param {String} field the document field/key to query against
  12542. @param {String || Array} terms a single term or array of "terms" to match
  12543. */
  12544. ejs.TermsQuery = function (field, terms) {
  12545. /**
  12546. The internal query object. <code>Use get()</code>
  12547. @member ejs.TermsQuery
  12548. @property {Object} query
  12549. */
  12550. var query = {
  12551. terms: {}
  12552. };
  12553. if (isString(terms)) {
  12554. query.terms[field] = [terms];
  12555. } else if (isArray(terms)) {
  12556. query.terms[field] = terms;
  12557. } else {
  12558. throw new TypeError('Argument must be string or array');
  12559. }
  12560. return {
  12561. /**
  12562. Sets the fields to query against.
  12563. @member ejs.TermsQuery
  12564. @param {String} f A valid field name.
  12565. @returns {Object} returns <code>this</code> so that calls can be chained.
  12566. */
  12567. field: function (f) {
  12568. var oldValue = query.terms[field];
  12569. if (f == null) {
  12570. return field;
  12571. }
  12572. delete query.terms[field];
  12573. field = f;
  12574. query.terms[f] = oldValue;
  12575. return this;
  12576. },
  12577. /**
  12578. Sets the terms. If you t is a String, it is added to the existing
  12579. list of terms. If t is an array, the list of terms replaces the
  12580. existing terms.
  12581. @member ejs.TermsQuery
  12582. @param {String || Array} t A single term or an array or terms.
  12583. @returns {Object} returns <code>this</code> so that calls can be chained.
  12584. */
  12585. terms: function (t) {
  12586. if (t == null) {
  12587. return query.terms[field];
  12588. }
  12589. if (isString(t)) {
  12590. query.terms[field].push(t);
  12591. } else if (isArray(t)) {
  12592. query.terms[field] = t;
  12593. } else {
  12594. throw new TypeError('Argument must be string or array');
  12595. }
  12596. return this;
  12597. },
  12598. /**
  12599. Sets the minimum number of terms that need to match in a document
  12600. before that document is returned in the results.
  12601. @member ejs.TermsQuery
  12602. @param {Integer} min A positive integer.
  12603. @returns {Object} returns <code>this</code> so that calls can be chained.
  12604. */
  12605. minimumShouldMatch: function (min) {
  12606. if (min == null) {
  12607. return query.terms.minimum_should_match;
  12608. }
  12609. query.terms.minimum_should_match = min;
  12610. return this;
  12611. },
  12612. /**
  12613. Enables or disables similarity coordinate scoring of documents
  12614. matching the <code>Query</code>. Default: false.
  12615. @member ejs.TermsQuery
  12616. @param {String} trueFalse A <code>true/false</code value.
  12617. @returns {Object} returns <code>this</code> so that calls can be chained.
  12618. */
  12619. disableCoord: function (trueFalse) {
  12620. if (trueFalse == null) {
  12621. return query.terms.disable_coord;
  12622. }
  12623. query.terms.disable_coord = trueFalse;
  12624. return this;
  12625. },
  12626. /**
  12627. Sets the boost value for documents matching the <code>Query</code>.
  12628. @member ejs.TermsQuery
  12629. @param {Number} boost A positive <code>double</code> value.
  12630. @returns {Object} returns <code>this</code> so that calls can be chained.
  12631. */
  12632. boost: function (boost) {
  12633. if (boost == null) {
  12634. return query.terms.boost;
  12635. }
  12636. query.terms.boost = boost;
  12637. return this;
  12638. },
  12639. /**
  12640. Allows you to serialize this object into a JSON encoded string.
  12641. @member ejs.TermsQuery
  12642. @returns {String} returns this object as a serialized JSON string.
  12643. */
  12644. toString: function () {
  12645. return JSON.stringify(query);
  12646. },
  12647. /**
  12648. The type of ejs object. For internal use only.
  12649. @member ejs.TermsQuery
  12650. @returns {String} the type of object
  12651. */
  12652. _type: function () {
  12653. return 'query';
  12654. },
  12655. /**
  12656. Retrieves the internal <code>query</code> object. This is typically used by
  12657. internal API functions so use with caution.
  12658. @member ejs.TermsQuery
  12659. @returns {String} returns this object's internal <code>query</code> property.
  12660. */
  12661. _self: function () {
  12662. return query;
  12663. }
  12664. };
  12665. };
  12666. /**
  12667. @class
  12668. <p>TThe top_children query runs the child query with an estimated hits size,
  12669. and out of the hit docs, aggregates it into parent docs. If there aren’t
  12670. enough parent docs matching the requested from/size search request, then it
  12671. is run again with a wider (more hits) search.</p>
  12672. <p>The top_children also provide scoring capabilities, with the ability to
  12673. specify max, sum or avg as the score type.</p>
  12674. @name ejs.TopChildrenQuery
  12675. @desc
  12676. Returns child documents matching the query aggregated into the parent docs.
  12677. @param {Object} qry A valid query object.
  12678. @param {String} type The child type to execute the query on
  12679. */
  12680. ejs.TopChildrenQuery = function (qry, type) {
  12681. if (!isQuery(qry)) {
  12682. throw new TypeError('Argument must be a Query');
  12683. }
  12684. /**
  12685. The internal query object. <code>Use _self()</code>
  12686. @member ejs.TopChildrenQuery
  12687. @property {Object} query
  12688. */
  12689. var query = {
  12690. top_children: {
  12691. query: qry._self(),
  12692. type: type
  12693. }
  12694. };
  12695. return {
  12696. /**
  12697. Sets the query
  12698. @member ejs.TopChildrenQuery
  12699. @param {Object} q A valid Query object
  12700. @returns {Object} returns <code>this</code> so that calls can be chained.
  12701. */
  12702. query: function (q) {
  12703. if (q == null) {
  12704. return query.top_children.query;
  12705. }
  12706. if (!isQuery(q)) {
  12707. throw new TypeError('Argument must be a Query');
  12708. }
  12709. query.top_children.query = q._self();
  12710. return this;
  12711. },
  12712. /**
  12713. Sets the child document type to search against
  12714. @member ejs.TopChildrenQuery
  12715. @param {String} t A valid type name
  12716. @returns {Object} returns <code>this</code> so that calls can be chained.
  12717. */
  12718. type: function (t) {
  12719. if (t == null) {
  12720. return query.top_children.type;
  12721. }
  12722. query.top_children.type = t;
  12723. return this;
  12724. },
  12725. /**
  12726. Sets the scope of the query. A scope allows to run facets on the
  12727. same scope name that will work against the child documents.
  12728. @member ejs.TopChildrenQuery
  12729. @param {String} s The scope name as a string.
  12730. @returns {Object} returns <code>this</code> so that calls can be chained.
  12731. */
  12732. scope: function (s) {
  12733. if (s == null) {
  12734. return query.top_children._scope;
  12735. }
  12736. query.top_children._scope = s;
  12737. return this;
  12738. },
  12739. /**
  12740. Sets the scoring type. Valid values are max, sum, or avg. If
  12741. another value is passed it we silently ignore the value.
  12742. @member ejs.TopChildrenQuery
  12743. @param {String} s The scoring type as a string.
  12744. @returns {Object} returns <code>this</code> so that calls can be chained.
  12745. */
  12746. score: function (s) {
  12747. if (s == null) {
  12748. return query.top_children.score;
  12749. }
  12750. s = s.toLowerCase();
  12751. if (s === 'max' || s === 'sum' || s === 'avg') {
  12752. query.top_children.score = s;
  12753. }
  12754. return this;
  12755. },
  12756. /**
  12757. Sets the factor which is the number of hits that are asked for in
  12758. the child query. Defaults to 5.
  12759. @member ejs.TopChildrenQuery
  12760. @param {Integer} f A positive integer value.
  12761. @returns {Object} returns <code>this</code> so that calls can be chained.
  12762. */
  12763. factor: function (f) {
  12764. if (f == null) {
  12765. return query.top_children.factor;
  12766. }
  12767. query.top_children.factor = f;
  12768. return this;
  12769. },
  12770. /**
  12771. Sets the incremental factor. The incremental factor is used when not
  12772. enough child documents are returned so the factor is multiplied by
  12773. the incremental factor to fetch more results. Defaults to 52
  12774. @member ejs.TopChildrenQuery
  12775. @param {Integer} f A positive integer value.
  12776. @returns {Object} returns <code>this</code> so that calls can be chained.
  12777. */
  12778. incrementalFactor: function (f) {
  12779. if (f == null) {
  12780. return query.top_children.incremental_factor;
  12781. }
  12782. query.top_children.incremental_factor = f;
  12783. return this;
  12784. },
  12785. /**
  12786. Sets the boost value of the <code>Query</code>.
  12787. @member ejs.TopChildrenQuery
  12788. @param {Double} boost A positive <code>double</code> value.
  12789. @returns {Object} returns <code>this</code> so that calls can be chained.
  12790. */
  12791. boost: function (boost) {
  12792. if (boost == null) {
  12793. return query.top_children.boost;
  12794. }
  12795. query.top_children.boost = boost;
  12796. return this;
  12797. },
  12798. /**
  12799. Allows you to serialize this object into a JSON encoded string.
  12800. @member ejs.TopChildrenQuery
  12801. @returns {String} returns this object as a serialized JSON string.
  12802. */
  12803. toString: function () {
  12804. return JSON.stringify(query);
  12805. },
  12806. /**
  12807. The type of ejs object. For internal use only.
  12808. @member ejs.TopChildrenQuery
  12809. @returns {String} the type of object
  12810. */
  12811. _type: function () {
  12812. return 'query';
  12813. },
  12814. /**
  12815. Retrieves the internal <code>query</code> object. This is typically used by
  12816. internal API functions so use with caution.
  12817. @member ejs.TopChildrenQuery
  12818. @returns {String} returns this object's internal <code>query</code> property.
  12819. */
  12820. _self: function () {
  12821. return query;
  12822. }
  12823. };
  12824. };
  12825. /**
  12826. @class
  12827. <p>Matches documents that have fields matching a wildcard expression
  12828. (not analyzed). Supported wildcards are *, which matches any character
  12829. sequence (including the empty one), and ?, which matches any single
  12830. character. Note this query can be slow, as it needs to iterate over many
  12831. wildcards. In order to prevent extremely slow wildcard queries, a wildcard
  12832. wildcard should not start with one of the wildcards * or ?. The wildcard query
  12833. maps to Lucene WildcardQuery.</p>
  12834. @name ejs.WildcardQuery
  12835. @desc
  12836. A Query that matches documents containing a wildcard. This may be
  12837. combined with other wildcards with a BooleanQuery.
  12838. @param {String} field the document field/key to query against
  12839. @param {String} value the literal value to be matched
  12840. */
  12841. ejs.WildcardQuery = function (field, value) {
  12842. /**
  12843. The internal query object. <code>Use get()</code>
  12844. @member ejs.WildcardQuery
  12845. @property {Object} query
  12846. */
  12847. var query = {
  12848. wildcard: {}
  12849. };
  12850. query.wildcard[field] = {
  12851. value: value
  12852. };
  12853. return {
  12854. /**
  12855. Sets the fields to query against.
  12856. @member ejs.WildcardQuery
  12857. @param {String} f A valid field name.
  12858. @returns {Object} returns <code>this</code> so that calls can be chained.
  12859. */
  12860. field: function (f) {
  12861. var oldValue = query.wildcard[field];
  12862. if (f == null) {
  12863. return field;
  12864. }
  12865. delete query.wildcard[field];
  12866. field = f;
  12867. query.wildcard[f] = oldValue;
  12868. return this;
  12869. },
  12870. /**
  12871. Sets the wildcard query value.
  12872. @member ejs.WildcardQuery
  12873. @param {String} v A single term.
  12874. @returns {Object} returns <code>this</code> so that calls can be chained.
  12875. */
  12876. value: function (v) {
  12877. if (v == null) {
  12878. return query.wildcard[field].value;
  12879. }
  12880. query.wildcard[field].value = v;
  12881. return this;
  12882. },
  12883. /**
  12884. Sets rewrite method. Valid values are:
  12885. constant_score_auto - tries to pick the best constant-score rewrite
  12886. method based on term and document counts from the query
  12887. scoring_boolean - translates each term into boolean should and
  12888. keeps the scores as computed by the query
  12889. constant_score_boolean - same as scoring_boolean, expect no scores
  12890. are computed.
  12891. constant_score_filter - first creates a private Filter, by visiting
  12892. each term in sequence and marking all docs for that term
  12893. top_terms_boost_N - first translates each term into boolean should
  12894. and scores are only computed as the boost using the top N
  12895. scoring terms. Replace N with an integer value.
  12896. top_terms_N - first translates each term into boolean should
  12897. and keeps the scores as computed by the query. Only the top N
  12898. scoring terms are used. Replace N with an integer value.
  12899. Default is constant_score_auto.
  12900. This is an advanced option, use with care.
  12901. @member ejs.WildcardQuery
  12902. @param {String} m The rewrite method as a string.
  12903. @returns {Object} returns <code>this</code> so that calls can be chained.
  12904. */
  12905. rewrite: function (m) {
  12906. if (m == null) {
  12907. return query.wildcard[field].rewrite;
  12908. }
  12909. m = m.toLowerCase();
  12910. if (m === 'constant_score_auto' || m === 'scoring_boolean' ||
  12911. m === 'constant_score_boolean' || m === 'constant_score_filter' ||
  12912. m.indexOf('top_terms_boost_') === 0 ||
  12913. m.indexOf('top_terms_') === 0) {
  12914. query.wildcard[field].rewrite = m;
  12915. }
  12916. return this;
  12917. },
  12918. /**
  12919. Sets the boost value for documents matching the <code>Query</code>.
  12920. @member ejs.WildcardQuery
  12921. @param {Number} boost A positive <code>double</code> value.
  12922. @returns {Object} returns <code>this</code> so that calls can be chained.
  12923. */
  12924. boost: function (boost) {
  12925. if (boost == null) {
  12926. return query.wildcard[field].boost;
  12927. }
  12928. query.wildcard[field].boost = boost;
  12929. return this;
  12930. },
  12931. /**
  12932. Allows you to serialize this object into a JSON encoded string.
  12933. @member ejs.WildcardQuery
  12934. @returns {String} returns this object as a serialized JSON string.
  12935. */
  12936. toString: function () {
  12937. return JSON.stringify(query);
  12938. },
  12939. /**
  12940. The type of ejs object. For internal use only.
  12941. @member ejs.WildcardQuery
  12942. @returns {String} the type of object
  12943. */
  12944. _type: function () {
  12945. return 'query';
  12946. },
  12947. /**
  12948. Retrieves the internal <code>query</code> object. This is typically used by
  12949. internal API functions so use with caution.
  12950. @member ejs.WildcardQuery
  12951. @returns {String} returns this object's internal <code>query</code> property.
  12952. */
  12953. _self: function () {
  12954. return query;
  12955. }
  12956. };
  12957. };
  12958. /**
  12959. @class
  12960. <p>A GeoPoint object that can be used in queries and filters that
  12961. take a GeoPoint. GeoPoint supports various input formats.</p>
  12962. <p>See http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html</p>
  12963. @name ejs.GeoPoint
  12964. @desc
  12965. <p>Defines a point</p>
  12966. @param {Array} p An optional point as an array in [lat, lon] format.
  12967. */
  12968. ejs.GeoPoint = function (p) {
  12969. var point = [0, 0];
  12970. // p = [lat, lon], convert it to GeoJSON format of [lon, lat]
  12971. if (p != null && isArray(p) && p.length === 2) {
  12972. point = [p[1], p[0]];
  12973. }
  12974. return {
  12975. /**
  12976. Sets the GeoPoint as properties on an object. The object must have
  12977. a 'lat' and 'lon' property.
  12978. Example:
  12979. {lat: 41.12, lon: -71.34}
  12980. @member ejs.GeoPoint
  12981. @param {Object} obj an object with a lat and lon property.
  12982. @returns {Object} returns <code>this</code> so that calls can be chained.
  12983. */
  12984. properties: function (obj) {
  12985. if (obj == null) {
  12986. return point;
  12987. }
  12988. if (isObject(obj) && has(obj, 'lat') && has(obj, 'lon')) {
  12989. point = {
  12990. lat: obj.lat,
  12991. lon: obj.lon
  12992. };
  12993. }
  12994. return this;
  12995. },
  12996. /**
  12997. Sets the GeoPoint as a string. The format is "lat,lon".
  12998. Example:
  12999. "41.12,-71.34"
  13000. @member ejs.GeoPoint
  13001. @param {String} s a String point in "lat,lon" format.
  13002. @returns {Object} returns <code>this</code> so that calls can be chained.
  13003. */
  13004. string: function (s) {
  13005. if (s == null) {
  13006. return point;
  13007. }
  13008. if (isString(s) && s.indexOf(',') !== -1) {
  13009. point = s;
  13010. }
  13011. return this;
  13012. },
  13013. /**
  13014. Sets the GeoPoint as a GeoHash. The hash is a string of
  13015. alpha-numeric characters with a precision length that defaults to 12.
  13016. Example:
  13017. "drm3btev3e86"
  13018. @member ejs.GeoPoint
  13019. @param {String} hash an GeoHash as a string
  13020. @param {Integer} precision an optional precision length, defaults
  13021. to 12 if not specified.
  13022. @returns {Object} returns <code>this</code> so that calls can be chained.
  13023. */
  13024. geohash: function (hash, precision) {
  13025. // set precision, default to 12
  13026. precision = (precision != null && isNumber(precision)) ? precision : 12;
  13027. if (hash == null) {
  13028. return point;
  13029. }
  13030. if (isString(hash) && hash.length === precision) {
  13031. point = hash;
  13032. }
  13033. return this;
  13034. },
  13035. /**
  13036. Sets the GeoPoint from an array point. The array must contain only
  13037. 2 values. The first value is the lat and the 2nd value is the lon.
  13038. Example:
  13039. [41.12, -71.34]
  13040. @member ejs.GeoPoint
  13041. @param {Array} a an array of length 2.
  13042. @returns {Object} returns <code>this</code> so that calls can be chained.
  13043. */
  13044. array: function (a) {
  13045. if (a == null) {
  13046. return point;
  13047. }
  13048. // convert to GeoJSON format of [lon, lat]
  13049. if (isArray(a) && a.length === 2) {
  13050. point = [a[1], a[0]];
  13051. }
  13052. return this;
  13053. },
  13054. /**
  13055. Allows you to serialize this object into a JSON encoded string.
  13056. @member ejs.GeoPoint
  13057. @returns {String} returns this object as a serialized JSON string.
  13058. */
  13059. toString: function () {
  13060. return JSON.stringify(point);
  13061. },
  13062. /**
  13063. The type of ejs object. For internal use only.
  13064. @member ejs.GeoPoint
  13065. @returns {String} the type of object
  13066. */
  13067. _type: function () {
  13068. return 'geo point';
  13069. },
  13070. /**
  13071. Retrieves the internal <code>script</code> object. This is typically used by
  13072. internal API functions so use with caution.
  13073. @member ejs.GeoPoint
  13074. @returns {String} returns this object's internal object representation.
  13075. */
  13076. _self: function () {
  13077. return point;
  13078. }
  13079. };
  13080. };
  13081. /**
  13082. @class
  13083. <p>Allows to highlight search results on one or more fields. In order to
  13084. perform highlighting, the actual content of the field is required. If the
  13085. field in question is stored (has store set to yes in the mapping), it will
  13086. be used, otherwise, the actual _source will be loaded and the relevant
  13087. field will be extracted from it.</p>
  13088. <p>If no term_vector information is provided (by setting it to
  13089. with_positions_offsets in the mapping), then the plain highlighter will be
  13090. used. If it is provided, then the fast vector highlighter will be used.
  13091. When term vectors are available, highlighting will be performed faster at
  13092. the cost of bigger index size.</p>
  13093. <p>See http://www.elasticsearch.org/guide/reference/api/search/highlighting.html</p>
  13094. @name ejs.Highlight
  13095. @desc
  13096. <p>Allows to highlight search results on one or more fields.</p>
  13097. @param {String || Array} fields An optional field or array of fields to highlight.
  13098. */
  13099. ejs.Highlight = function (fields) {
  13100. var highlight = {
  13101. fields: {}
  13102. },
  13103. addOption = function (field, option, val) {
  13104. if (field == null) {
  13105. highlight[option] = val;
  13106. } else {
  13107. if (!has(highlight.fields, field)) {
  13108. highlight.fields[field] = {};
  13109. }
  13110. highlight.fields[field][option] = val;
  13111. }
  13112. };
  13113. if (fields != null) {
  13114. if (isString(fields)) {
  13115. highlight.fields[fields] = {};
  13116. } else if (isArray(fields)) {
  13117. each(fields, function (field) {
  13118. highlight.fields[field] = {};
  13119. });
  13120. }
  13121. }
  13122. return {
  13123. /**
  13124. Allows you to set the fields that will be highlighted. You can
  13125. specify a single field or an array of fields. All fields are
  13126. added to the current list of fields.
  13127. @member ejs.Highlight
  13128. @param {String || Array} vals A field name or array of field names.
  13129. @returns {Object} returns <code>this</code> so that calls can be chained.
  13130. */
  13131. fields: function (vals) {
  13132. if (vals == null) {
  13133. return highlight.fields;
  13134. }
  13135. if (isString(vals)) {
  13136. if (!has(highlight.fields, vals)) {
  13137. highlight.fields[vals] = {};
  13138. }
  13139. } else if (isArray(vals)) {
  13140. each(vals, function (field) {
  13141. if (!has(highlight.fields, field)) {
  13142. highlight.fields[field] = {};
  13143. }
  13144. });
  13145. }
  13146. },
  13147. /**
  13148. Sets the pre tags for highlighted fragments. You can apply the
  13149. tags to a specific field by passing the field name in to the
  13150. <code>oField</code> parameter.
  13151. @member ejs.Highlight
  13152. @param {String || Array} tags A single tag or an array of tags.
  13153. @param {String} oField An optional field name
  13154. @returns {Object} returns <code>this</code> so that calls can be chained.
  13155. */
  13156. preTags: function (tags, oField) {
  13157. if (tags === null && oField != null) {
  13158. return highlight.fields[oField].pre_tags;
  13159. } else if (tags == null) {
  13160. return highlight.pre_tags;
  13161. }
  13162. if (isString(tags)) {
  13163. addOption(oField, 'pre_tags', [tags]);
  13164. } else if (isArray(tags)) {
  13165. addOption(oField, 'pre_tags', tags);
  13166. }
  13167. return this;
  13168. },
  13169. /**
  13170. Sets the post tags for highlighted fragments. You can apply the
  13171. tags to a specific field by passing the field name in to the
  13172. <code>oField</code> parameter.
  13173. @member ejs.Highlight
  13174. @param {String || Array} tags A single tag or an array of tags.
  13175. @param {String} oField An optional field name
  13176. @returns {Object} returns <code>this</code> so that calls can be chained.
  13177. */
  13178. postTags: function (tags, oField) {
  13179. if (tags === null && oField != null) {
  13180. return highlight.fields[oField].post_tags;
  13181. } else if (tags == null) {
  13182. return highlight.post_tags;
  13183. }
  13184. if (isString(tags)) {
  13185. addOption(oField, 'post_tags', [tags]);
  13186. } else if (isArray(tags)) {
  13187. addOption(oField, 'post_tags', tags);
  13188. }
  13189. return this;
  13190. },
  13191. /**
  13192. Sets the order of highlight fragments. You can apply the option
  13193. to a specific field by passing the field name in to the
  13194. <code>oField</code> parameter. Valid values for order are:
  13195. score - the score calculated by Lucene's highlighting framework.
  13196. @member ejs.Highlight
  13197. @param {String} o The order. Currently only "score".
  13198. @param {String} oField An optional field name
  13199. @returns {Object} returns <code>this</code> so that calls can be chained.
  13200. */
  13201. order: function (o, oField) {
  13202. if (o === null && oField != null) {
  13203. return highlight.fields[oField].order;
  13204. } else if (o == null) {
  13205. return highlight.order;
  13206. }
  13207. o = o.toLowerCase();
  13208. if (o === 'score') {
  13209. addOption(oField, 'order', o);
  13210. }
  13211. return this;
  13212. },
  13213. /**
  13214. Sets the schema to be used for the tags. Valid values are:
  13215. styled - 10 <em> pre tags with css class of hltN, where N is 1-10
  13216. @member ejs.Highlight
  13217. @param {String} s The schema. Currently only "styled".
  13218. @returns {Object} returns <code>this</code> so that calls can be chained.
  13219. */
  13220. tagsSchema: function (s) {
  13221. if (s == null) {
  13222. return highlight.tags_schema;
  13223. }
  13224. s = s.toLowerCase();
  13225. if (s === 'styled') {
  13226. highlight.tags_schema = s;
  13227. }
  13228. return this;
  13229. },
  13230. /**
  13231. Enables highlights in documents matched by a filter.
  13232. You can apply the option to a specific field by passing the field
  13233. name in to the <code>oField</code> parameter. Defaults to false.
  13234. @member ejs.Highlight
  13235. @param {Boolean} trueFalse If filtered docs should be highlighted.
  13236. @param {String} oField An optional field name
  13237. @returns {Object} returns <code>this</code> so that calls can be chained.
  13238. */
  13239. highlightFilter: function (trueFalse, oField) {
  13240. if (trueFalse === null && oField != null) {
  13241. return highlight.fields[oField].highlight_filter;
  13242. } else if (trueFalse == null) {
  13243. return highlight.highlight_filter;
  13244. }
  13245. addOption(oField, 'highlight_filter', trueFalse);
  13246. return this;
  13247. },
  13248. /**
  13249. Sets the size of each highlight fragment in characters.
  13250. You can apply the option to a specific field by passing the field
  13251. name in to the <code>oField</code> parameter. Default: 100
  13252. @member ejs.Highlight
  13253. @param {Integer} size The fragment size in characters.
  13254. @param {String} oField An optional field name
  13255. @returns {Object} returns <code>this</code> so that calls can be chained.
  13256. */
  13257. fragmentSize: function (size, oField) {
  13258. if (size === null && oField != null) {
  13259. return highlight.fields[oField].fragment_size;
  13260. } else if (size == null) {
  13261. return highlight.fragment_size;
  13262. }
  13263. addOption(oField, 'fragment_size', size);
  13264. return this;
  13265. },
  13266. /**
  13267. Sets the number of highlight fragments.
  13268. You can apply the option to a specific field by passing the field
  13269. name in to the <code>oField</code> parameter. Default: 5
  13270. @member ejs.Highlight
  13271. @param {Integer} cnt The fragment size in characters.
  13272. @param {String} oField An optional field name
  13273. @returns {Object} returns <code>this</code> so that calls can be chained.
  13274. */
  13275. numberOfFragments: function (cnt, oField) {
  13276. if (cnt === null && oField != null) {
  13277. return highlight.fields[oField].number_of_fragments;
  13278. } else if (cnt == null) {
  13279. return highlight.number_of_fragments;
  13280. }
  13281. addOption(oField, 'number_of_fragments', cnt);
  13282. return this;
  13283. },
  13284. /**
  13285. Sets highlight encoder. Valid values are:
  13286. default - the default, no encoding
  13287. html - to encode html characters if you use html tags
  13288. @member ejs.Highlight
  13289. @param {String} e The encoder. default or html
  13290. @returns {Object} returns <code>this</code> so that calls can be chained.
  13291. */
  13292. encoder: function (e) {
  13293. if (e == null) {
  13294. return highlight.encoder;
  13295. }
  13296. e = e.toLowerCase();
  13297. if (e === 'default' || e === 'html') {
  13298. highlight.encoder = e;
  13299. }
  13300. return this;
  13301. },
  13302. /**
  13303. When enabled it will cause a field to be highlighted only if a
  13304. query matched that field. false means that terms are highlighted
  13305. on all requested fields regardless if the query matches
  13306. specifically on them. You can apply the option to a specific
  13307. field by passing the field name in to the <code>oField</code>
  13308. parameter. Defaults to false.
  13309. @member ejs.Highlight
  13310. @param {Boolean} trueFalse If filtered docs should be highlighted.
  13311. @param {String} oField An optional field name
  13312. @returns {Object} returns <code>this</code> so that calls can be chained.
  13313. */
  13314. requireFieldMatch: function (trueFalse, oField) {
  13315. if (trueFalse === null && oField != null) {
  13316. return highlight.fields[oField].require_field_match;
  13317. } else if (trueFalse == null) {
  13318. return highlight.require_field_match;
  13319. }
  13320. addOption(oField, 'require_field_match', trueFalse);
  13321. return this;
  13322. },
  13323. /**
  13324. Sets the max number of characters to scan while looking for the
  13325. start of a boundary character. You can apply the option to a
  13326. specific field by passing the field name in to the
  13327. <code>oField</code> parameter. Default: 20
  13328. @member ejs.Highlight
  13329. @param {Integer} cnt The max characters to scan.
  13330. @param {String} oField An optional field name
  13331. @returns {Object} returns <code>this</code> so that calls can be chained.
  13332. */
  13333. boundaryMaxScan: function (cnt, oField) {
  13334. if (cnt === null && oField != null) {
  13335. return highlight.fields[oField].boundary_max_scan;
  13336. } else if (cnt == null) {
  13337. return highlight.boundary_max_scan;
  13338. }
  13339. addOption(oField, 'boundary_max_scan', cnt);
  13340. return this;
  13341. },
  13342. /**
  13343. Set's the boundary characters. When highlighting a field that is
  13344. mapped with term vectors, boundary_chars can be configured to
  13345. define what constitutes a boundary for highlighting. It’s a single
  13346. string with each boundary character defined in it. You can apply
  13347. the option to a specific field by passing the field name in to
  13348. the <code>oField</code> parameter. It defaults to ".,!? \t\n".
  13349. @member ejs.Highlight
  13350. @param {String} charStr The boundary chars in a string.
  13351. @param {String} oField An optional field name
  13352. @returns {Object} returns <code>this</code> so that calls can be chained.
  13353. */
  13354. boundaryChars: function (charStr, oField) {
  13355. if (charStr === null && oField != null) {
  13356. return highlight.fields[oField].boundary_chars;
  13357. } else if (charStr == null) {
  13358. return highlight.boundary_chars;
  13359. }
  13360. addOption(oField, 'boundary_chars', charStr);
  13361. return this;
  13362. },
  13363. /**
  13364. Sets the highligher type. You can apply the option
  13365. to a specific field by passing the field name in to the
  13366. <code>oField</code> parameter. Valid values for order are:
  13367. fast-vector-highlighter - the fast vector based highligher
  13368. highlighter - the slower plain highligher
  13369. @member ejs.Highlight
  13370. @param {String} t The highligher.
  13371. @param {String} oField An optional field name
  13372. @returns {Object} returns <code>this</code> so that calls can be chained.
  13373. */
  13374. type: function (t, oField) {
  13375. if (t === null && oField != null) {
  13376. return highlight.fields[oField].type;
  13377. } else if (t == null) {
  13378. return highlight.type;
  13379. }
  13380. t = t.toLowerCase();
  13381. if (t === 'fast-vector-highlighter' || t === 'highlighter') {
  13382. addOption(oField, 'type', t);
  13383. }
  13384. return this;
  13385. },
  13386. /**
  13387. Sets the fragmenter type. You can apply the option
  13388. to a specific field by passing the field name in to the
  13389. <code>oField</code> parameter. Valid values for order are:
  13390. simple - breaks text up into same-size fragments with no concerns
  13391. over spotting sentence boundaries.
  13392. span - breaks text up into same-size fragments but does not split
  13393. up Spans.
  13394. @member ejs.Highlight
  13395. @param {String} f The fragmenter.
  13396. @param {String} oField An optional field name
  13397. @returns {Object} returns <code>this</code> so that calls can be chained.
  13398. */
  13399. fragmenter: function (f, oField) {
  13400. if (f === null && oField != null) {
  13401. return highlight.fields[oField].fragmenter;
  13402. } else if (f == null) {
  13403. return highlight.fragmenter;
  13404. }
  13405. f = f.toLowerCase();
  13406. if (f === 'simple' || f === 'span') {
  13407. addOption(oField, 'fragmenter', f);
  13408. }
  13409. return this;
  13410. },
  13411. /**
  13412. Allows you to serialize this object into a JSON encoded string.
  13413. @member ejs.Highlight
  13414. @returns {String} returns this object as a serialized JSON string.
  13415. */
  13416. toString: function () {
  13417. return JSON.stringify(highlight);
  13418. },
  13419. /**
  13420. The type of ejs object. For internal use only.
  13421. @member ejs.Highlight
  13422. @returns {String} the type of object
  13423. */
  13424. _type: function () {
  13425. return 'highlight';
  13426. },
  13427. /**
  13428. Retrieves the internal <code>script</code> object. This is typically used by
  13429. internal API functions so use with caution.
  13430. @member ejs.Highlight
  13431. @returns {String} returns this object's internal object representation.
  13432. */
  13433. _self: function () {
  13434. return highlight;
  13435. }
  13436. };
  13437. };
  13438. /**
  13439. @class
  13440. <p>A shape which has already been indexed in another index and/or index
  13441. type. This is particularly useful for when you have a pre-defined list of
  13442. shapes which are useful to your application and you want to reference this
  13443. using a logical name (for example ‘New Zealand’) rather than having to
  13444. provide their coordinates each time.</p>
  13445. @name ejs.IndexedShape
  13446. @desc
  13447. <p>Defines a shape that already exists in an index/type.</p>
  13448. @param {String} type The name of the type where the shape is indexed.
  13449. @param {String} id The document id of the shape.
  13450. */
  13451. ejs.IndexedShape = function (type, id) {
  13452. var indexedShape = {
  13453. type: type,
  13454. id: id
  13455. };
  13456. return {
  13457. /**
  13458. Sets the type which the shape is indexed under.
  13459. @member ejs.IndexedShape
  13460. @param {String} t a valid shape type.
  13461. @returns {Object} returns <code>this</code> so that calls can be chained.
  13462. */
  13463. type: function (t) {
  13464. if (t == null) {
  13465. return indexedShape.type;
  13466. }
  13467. indexedShape.type = t;
  13468. return this;
  13469. },
  13470. /**
  13471. Sets the document id of the indexed shape.
  13472. @member ejs.IndexedShape
  13473. @param {String} id a valid document id.
  13474. @returns {Object} returns <code>this</code> so that calls can be chained.
  13475. */
  13476. id: function (id) {
  13477. if (id == null) {
  13478. return indexedShape.id;
  13479. }
  13480. indexedShape.id = id;
  13481. return this;
  13482. },
  13483. /**
  13484. Sets the index which the shape is indexed under.
  13485. Defaults to "shapes".
  13486. @member ejs.IndexedShape
  13487. @param {String} idx a valid index name.
  13488. @returns {Object} returns <code>this</code> so that calls can be chained.
  13489. */
  13490. index: function (idx) {
  13491. if (idx == null) {
  13492. return indexedShape.index;
  13493. }
  13494. indexedShape.index = idx;
  13495. return this;
  13496. },
  13497. /**
  13498. Sets the field name containing the indexed shape.
  13499. Defaults to "shape".
  13500. @member ejs.IndexedShape
  13501. @param {String} field a valid field name.
  13502. @returns {Object} returns <code>this</code> so that calls can be chained.
  13503. */
  13504. shapeFieldName: function (field) {
  13505. if (field == null) {
  13506. return indexedShape.shape_field_name;
  13507. }
  13508. indexedShape.shape_field_name = field;
  13509. return this;
  13510. },
  13511. /**
  13512. Allows you to serialize this object into a JSON encoded string.
  13513. @member ejs.IndexedShape
  13514. @returns {String} returns this object as a serialized JSON string.
  13515. */
  13516. toString: function () {
  13517. return JSON.stringify(indexedShape);
  13518. },
  13519. /**
  13520. The type of ejs object. For internal use only.
  13521. @member ejs.IndexedShape
  13522. @returns {String} the type of object
  13523. */
  13524. _type: function () {
  13525. return 'indexed shape';
  13526. },
  13527. /**
  13528. Retrieves the internal <code>script</code> object. This is typically used by
  13529. internal API functions so use with caution.
  13530. @member ejs.IndexedShape
  13531. @returns {String} returns this object's internal object representation.
  13532. */
  13533. _self: function () {
  13534. return indexedShape;
  13535. }
  13536. };
  13537. };
  13538. /**
  13539. @class
  13540. <p>The <code>Request</code> object provides methods generating and
  13541. executing search requests.</p>
  13542. @name ejs.Request
  13543. @desc
  13544. <p>Provides methods for executing search requests</p>
  13545. @param {Object} conf A configuration object containing the initilization
  13546. parameters. The following parameters can be set in the conf object:
  13547. indices - single index name or array of index names
  13548. types - single type name or array of types
  13549. routing - the shard routing value
  13550. */
  13551. ejs.Request = function (conf) {
  13552. var query, indices, types, routing;
  13553. /**
  13554. The internal query object.
  13555. @member ejs.Request
  13556. @property {Object} query
  13557. */
  13558. query = {};
  13559. conf = conf || {};
  13560. // check if we are searching across any specific indeices
  13561. if (conf.indices == null) {
  13562. indices = [];
  13563. } else if (isString(conf.indices)) {
  13564. indices = [conf.indices];
  13565. } else {
  13566. indices = conf.indices;
  13567. }
  13568. // check if we are searching across any specific types
  13569. if (conf.types == null) {
  13570. types = [];
  13571. } else if (isString(conf.types)) {
  13572. types = [conf.types];
  13573. } else {
  13574. types = conf.types;
  13575. }
  13576. // check that an index is specified when a type is
  13577. // if not, search across _all indices
  13578. if (indices.length === 0 && types.length > 0) {
  13579. indices = ["_all"];
  13580. }
  13581. if (conf.routing != null) {
  13582. routing = conf.routing;
  13583. } else {
  13584. routing = '';
  13585. }
  13586. return {
  13587. /**
  13588. Sets the sorting for the query. This accepts many input formats.
  13589. sort() - The current sorting values are returned.
  13590. sort(fieldName) - Adds the field to the current list of sorting values.
  13591. sort(fieldName, order) - Adds the field to the current list of
  13592. sorting with the specified order. Order must be asc or desc.
  13593. sort(ejs.Sort) - Adds the Sort value to the current list of sorting values.
  13594. sort(array) - Replaces all current sorting values with values
  13595. from the array. The array must contain only strings and Sort
  13596. objects.
  13597. Multi-level sorting is supported so the order in which sort fields
  13598. are added to the query requests is relevant.
  13599. It is recommended to use <code>Sort</code> objects when possible.
  13600. @member ejs.Request
  13601. @param {String} fieldName The field to be sorted by.
  13602. @returns {Object} returns <code>this</code> so that calls can be chained.
  13603. */
  13604. sort: function () {
  13605. var i, len;
  13606. if (!has(query, "sort")) {
  13607. query.sort = [];
  13608. }
  13609. if (arguments.length === 0) {
  13610. return query.sort;
  13611. }
  13612. // if passed a single argument
  13613. if (arguments.length === 1) {
  13614. var sortVal = arguments[0];
  13615. if (isString(sortVal)) {
  13616. // add a single field name
  13617. query.sort.push(sortVal);
  13618. } else if (isSort(sortVal)) {
  13619. // add the Sort object
  13620. query.sort.push(sortVal._self());
  13621. } else if (isArray(sortVal)) {
  13622. // replace with all values in the array
  13623. // the values must be a fieldName (string) or a
  13624. // Sort object. Any other type throws an Error.
  13625. query.sort = [];
  13626. for (i = 0, len = sortVal.length; i < len; i++) {
  13627. if (isString(sortVal[i])) {
  13628. query.sort.push(sortVal[i]);
  13629. } else if (isSort(sortVal[i])) {
  13630. query.sort.push(sortVal[i]._self());
  13631. } else {
  13632. throw new TypeError('Invalid object in array');
  13633. }
  13634. }
  13635. } else {
  13636. // Invalid object type as argument.
  13637. throw new TypeError('Argument must be string, Sort, or array');
  13638. }
  13639. } else if (arguments.length === 2) {
  13640. // handle the case where a single field name and order are passed
  13641. var field = arguments[0],
  13642. order = arguments[1];
  13643. if (isString(field) && isString(order)) {
  13644. order = order.toLowerCase();
  13645. if (order === 'asc' || order === 'desc') {
  13646. var sortObj = {};
  13647. sortObj[field] = {order: order};
  13648. query.sort.push(sortObj);
  13649. }
  13650. }
  13651. }
  13652. return this;
  13653. },
  13654. /**
  13655. Enables score computation and tracking during sorting. Be default,
  13656. when sorting scores are not computed.
  13657. @member ejs.Request
  13658. @param {Boolean} trueFalse If scores should be computed and tracked.
  13659. @returns {Object} returns <code>this</code> so that calls can be chained.
  13660. */
  13661. trackScores: function (trueFalse) {
  13662. if (trueFalse == null) {
  13663. return query.track_scores;
  13664. }
  13665. query.track_scores = trueFalse;
  13666. return this;
  13667. },
  13668. /**
  13669. Sets the number of results/documents to be returned. This is set on a per page basis.
  13670. @member ejs.Request
  13671. @param {Integer} s The number of results that are to be returned by the search.
  13672. @returns {Object} returns <code>this</code> so that calls can be chained.
  13673. */
  13674. size: function (s) {
  13675. if (s == null) {
  13676. return query.size;
  13677. }
  13678. query.size = s;
  13679. return this;
  13680. },
  13681. /**
  13682. A search timeout, bounding the search request to be executed
  13683. within the specified time value and bail with the hits accumulated
  13684. up to that point when expired. Defaults to no timeout.
  13685. @member ejs.Request
  13686. @param {Long} t The timeout value in milliseconds.
  13687. @returns {Object} returns <code>this</code> so that calls can be chained.
  13688. */
  13689. timeout: function (t) {
  13690. if (t == null) {
  13691. return query.timeout;
  13692. }
  13693. query.timeout = t;
  13694. return this;
  13695. },
  13696. /**
  13697. Sets the shard routing parameter. Only shards matching routing
  13698. values will be searched. Set to an empty string to disable routing.
  13699. Disabled by default.
  13700. @member ejs.Request
  13701. @param {String} route The routing values as a comma-separated string.
  13702. @returns {Object} returns <code>this</code> so that calls can be chained.
  13703. */
  13704. routing: function (route) {
  13705. if (route == null) {
  13706. return routing;
  13707. }
  13708. routing = route;
  13709. return this;
  13710. },
  13711. /**
  13712. By default, searches return full documents, meaning every property or field.
  13713. This method allows you to specify which fields you want returned.
  13714. Pass a single field name and it is appended to the current list of
  13715. fields. Pass an array of fields and it replaces all existing
  13716. fields.
  13717. @member ejs.Request
  13718. @param {String || Array} s The field as a string or fields as array
  13719. @returns {Object} returns <code>this</code> so that calls can be chained.
  13720. */
  13721. fields: function (fieldList) {
  13722. if (fieldList == null) {
  13723. return query.fields;
  13724. }
  13725. if (query.fields == null) {
  13726. query.fields = [];
  13727. }
  13728. if (isString(fieldList)) {
  13729. query.fields.push(fieldList);
  13730. } else if (isArray(fieldList)) {
  13731. query.fields = fieldList;
  13732. } else {
  13733. throw new TypeError('Argument must be string or array');
  13734. }
  13735. return this;
  13736. },
  13737. /**
  13738. A search result set could be very large (think Google). Setting the
  13739. <code>from</code> parameter allows you to page through the result set
  13740. by making multiple request. This parameters specifies the starting
  13741. result/document number point. Combine with <code>size()</code> to achieve paging.
  13742. @member ejs.Request
  13743. @param {Array} f The offset at which to start fetching results/documents from the result set.
  13744. @returns {Object} returns <code>this</code> so that calls can be chained.
  13745. */
  13746. from: function (f) {
  13747. if (f == null) {
  13748. return query.from;
  13749. }
  13750. query.from = f;
  13751. return this;
  13752. },
  13753. /**
  13754. Allows you to set the specified query on this search object. This is the
  13755. query that will be used when the search is executed.
  13756. @member ejs.Request
  13757. @param {Query} someQuery Any valid <code>Query</code> object.
  13758. @returns {Object} returns <code>this</code> so that calls can be chained.
  13759. */
  13760. query: function (someQuery) {
  13761. if (someQuery == null) {
  13762. return query.query;
  13763. }
  13764. if (!isQuery(someQuery)) {
  13765. throw new TypeError('Argument must be a Query');
  13766. }
  13767. query.query = someQuery._self();
  13768. return this;
  13769. },
  13770. /**
  13771. Allows you to set the specified indices on this request object. This is the
  13772. set of indices that will be used when the search is executed.
  13773. @member ejs.Request
  13774. @param {Array} indexArray An array of collection names.
  13775. @returns {Object} returns <code>this</code> so that calls can be chained.
  13776. */
  13777. indices: function (indexArray) {
  13778. if (indexArray == null) {
  13779. return indices;
  13780. } else if (isString(indexArray)) {
  13781. indices = [indexArray];
  13782. } else if (isArray(indexArray)) {
  13783. indices = indexArray;
  13784. } else {
  13785. throw new TypeError('Argument must be a string or array');
  13786. }
  13787. // check that an index is specified when a type is
  13788. // if not, search across _all indices
  13789. if (indices.length === 0 && types.length > 0) {
  13790. indices = ["_all"];
  13791. }
  13792. return this;
  13793. },
  13794. /**
  13795. Allows you to set the specified content-types on this request object. This is the
  13796. set of indices that will be used when the search is executed.
  13797. @member ejs.Request
  13798. @param {Array} typeArray An array of content-type names.
  13799. @returns {Object} returns <code>this</code> so that calls can be chained.
  13800. */
  13801. types: function (typeArray) {
  13802. if (typeArray == null) {
  13803. return types;
  13804. } else if (isString(typeArray)) {
  13805. types = [typeArray];
  13806. } else if (isArray(typeArray)) {
  13807. types = typeArray;
  13808. } else {
  13809. throw new TypeError('Argument must be a string or array');
  13810. }
  13811. // check that an index is specified when a type is
  13812. // if not, search across _all indices
  13813. if (indices.length === 0 && types.length > 0) {
  13814. indices = ["_all"];
  13815. }
  13816. return this;
  13817. },
  13818. /**
  13819. Allows you to set the specified facet on this request object. Multiple facets can
  13820. be set, all of which will be returned when the search is executed.
  13821. @member ejs.Request
  13822. @param {Facet} facet Any valid <code>Facet</code> object.
  13823. @returns {Object} returns <code>this</code> so that calls can be chained.
  13824. */
  13825. facet: function (facet) {
  13826. if (facet == null) {
  13827. return query.facets;
  13828. }
  13829. if (query.facets == null) {
  13830. query.facets = {};
  13831. }
  13832. if (!isFacet(facet)) {
  13833. throw new TypeError('Argument must be a Facet');
  13834. }
  13835. extend(query.facets, facet._self());
  13836. return this;
  13837. },
  13838. /**
  13839. Allows you to set a specified filter on this request object.
  13840. @member ejs.Request
  13841. @param {Object} filter Any valid <code>Filter</code> object.
  13842. @returns {Object} returns <code>this</code> so that calls can be chained.
  13843. */
  13844. filter: function (filter) {
  13845. if (filter == null) {
  13846. return query.filter;
  13847. }
  13848. if (!isFilter(filter)) {
  13849. throw new TypeError('Argument must be a Filter');
  13850. }
  13851. query.filter = filter._self();
  13852. return this;
  13853. },
  13854. /**
  13855. Performs highlighting based on the <code>Highlight</code>
  13856. settings.
  13857. @member ejs.Request
  13858. @param {Highlight} h A valid Highlight object
  13859. @returns {Object} returns <code>this</code> so that calls can be chained.
  13860. */
  13861. highlight: function (h) {
  13862. if (h == null) {
  13863. return query.highlight;
  13864. }
  13865. if (!isHighlight(h)) {
  13866. throw new TypeError('Argument must be a Highlight object');
  13867. }
  13868. query.highlight = h._self();
  13869. return this;
  13870. },
  13871. /**
  13872. Computes a document property dynamically based on the supplied <code>ScriptField</code>.
  13873. @member ejs.Request
  13874. @param {ScriptField} oScriptField A valid <code>ScriptField</code>.
  13875. @returns {Object} returns <code>this</code> so that calls can be chained.
  13876. */
  13877. scriptField: function (oScriptField) {
  13878. if (oScriptField == null) {
  13879. return query.script_fields;
  13880. }
  13881. if (query.script_fields == null) {
  13882. query.script_fields = {};
  13883. }
  13884. if (!isScriptField(oScriptField)) {
  13885. throw new TypeError('Argument must be a ScriptField');
  13886. }
  13887. extend(query.script_fields, oScriptField._self());
  13888. return this;
  13889. },
  13890. /**
  13891. Controls a preference of which shard replicas to execute the search request on.
  13892. By default, the operation is randomized between the each shard replicas. The
  13893. preference can be one of the following:
  13894. _primary - the operation will only be executed on primary shards
  13895. _local - the operation will prefer to be executed on local shards
  13896. _only_node:$nodeid - the search will only be executed on node with id $nodeid
  13897. custom - any string, will guarentee searches always happen on same node.
  13898. @member ejs.Request
  13899. @param {String} perf the preference, any of _primary, _local, _only_:$nodeid, or a custom string value.
  13900. @returns {Object} returns <code>this</code> so that calls can be chained.
  13901. */
  13902. preference: function (perf) {
  13903. if (perf == null) {
  13904. return query.preference;
  13905. }
  13906. query.preference = perf;
  13907. return this;
  13908. },
  13909. /**
  13910. Boosts hits in the specified index by the given boost value.
  13911. @member ejs.Request
  13912. @param {String} index the index to boost
  13913. @param {Double} boost the boost value
  13914. @returns {Object} returns <code>this</code> so that calls can be chained.
  13915. */
  13916. indexBoost: function (index, boost) {
  13917. if (query.indices_boost == null) {
  13918. query.indices_boost = {};
  13919. }
  13920. if (arguments.length === 0) {
  13921. return query.indices_boost;
  13922. }
  13923. query.indices_boost[index] = boost;
  13924. return this;
  13925. },
  13926. /**
  13927. Enable/Disable explanation of score for each search result.
  13928. @member ejs.Request
  13929. @param {Boolean} trueFalse true to enable, false to disable
  13930. @returns {Object} returns <code>this</code> so that calls can be chained.
  13931. */
  13932. explain: function (trueFalse) {
  13933. if (trueFalse == null) {
  13934. return query.explain;
  13935. }
  13936. query.explain = trueFalse;
  13937. return this;
  13938. },
  13939. /**
  13940. Enable/Disable returning version number for each search result.
  13941. @member ejs.Request
  13942. @param {Boolean} trueFalse true to enable, false to disable
  13943. @returns {Object} returns <code>this</code> so that calls can be chained.
  13944. */
  13945. version: function (trueFalse) {
  13946. if (trueFalse == null) {
  13947. return query.version;
  13948. }
  13949. query.version = trueFalse;
  13950. return this;
  13951. },
  13952. /**
  13953. Filters out search results will scores less than the specified minimum score.
  13954. @member ejs.Request
  13955. @param {Double} min a positive <code>double</code> value.
  13956. @returns {Object} returns <code>this</code> so that calls can be chained.
  13957. */
  13958. minScore: function (min) {
  13959. if (min == null) {
  13960. return query.min_score;
  13961. }
  13962. query.min_score = min;
  13963. return this;
  13964. },
  13965. /**
  13966. Allows you to serialize this object into a JSON encoded string.
  13967. @member ejs.Request
  13968. @returns {String} returns this object as a serialized JSON string.
  13969. */
  13970. toString: function () {
  13971. return JSON.stringify(query);
  13972. },
  13973. /**
  13974. The type of ejs object. For internal use only.
  13975. @member ejs.Request
  13976. @returns {String} the type of object
  13977. */
  13978. _type: function () {
  13979. return 'request';
  13980. },
  13981. /**
  13982. Retrieves the internal <code>query</code> object. This is typically used by
  13983. internal API functions so use with caution.
  13984. @member ejs.Request
  13985. @returns {String} returns this object's internal object representation.
  13986. */
  13987. _self: function () {
  13988. return query;
  13989. },
  13990. /**
  13991. Executes the search. This call runs synchronously when used on the server side.
  13992. The callback is still executed and the function returns the return value of the callback.
  13993. @member ejs.Request
  13994. @param {Function} fnCallBack A callback function that handles the search response.
  13995. @returns {void} Returns the value of the callback when executing on the server.
  13996. */
  13997. doSearch: function (fnCallBack) {
  13998. var
  13999. queryData = JSON.stringify(query),
  14000. searchUrl = '';
  14001. // make sure the user has set a client
  14002. if (ejs.client == null) {
  14003. throw new Error("No Client Set");
  14004. }
  14005. // generate the search url
  14006. if (indices.length > 0) {
  14007. searchUrl = searchUrl + '/' + indices.join();
  14008. }
  14009. if (types.length > 0) {
  14010. searchUrl = searchUrl + '/' + types.join();
  14011. }
  14012. searchUrl = searchUrl + '/_search';
  14013. if (routing !== '') {
  14014. searchUrl = searchUrl + '?routing=' + encodeURIComponent(routing);
  14015. }
  14016. return ejs.client.post(searchUrl, queryData, fnCallBack);
  14017. }
  14018. };
  14019. };
  14020. /**
  14021. @class
  14022. <p>ScriptField's allow you create dynamic fields on stored documents at query
  14023. time. For example, you might have a set of document thats containsthe fields
  14024. <code>price</code> and <code>quantity</code>. At query time, you could define a computed
  14025. property that dynamically creates a new field called <code>total</code>in each document
  14026. based on the calculation <code>price * quantity</code>.</p>
  14027. @name ejs.ScriptField
  14028. @desc
  14029. <p>Computes dynamic document properties based on information from other fields.</p>
  14030. @param {String} fieldName A name of the script field to create.
  14031. */
  14032. ejs.ScriptField = function (fieldName) {
  14033. var script = {};
  14034. script[fieldName] = {};
  14035. return {
  14036. /**
  14037. The script language being used. Currently supported values are
  14038. <code>javascript</code> and <code>mvel</code>.
  14039. @member ejs.ScriptField
  14040. @param {String} language The language of the script.
  14041. @returns {Object} returns <code>this</code> so that calls can be chained.
  14042. */
  14043. lang: function (language) {
  14044. if (language == null) {
  14045. return script[fieldName].lang;
  14046. }
  14047. script[fieldName].lang = language;
  14048. return this;
  14049. },
  14050. /**
  14051. Sets the script/code that will be used to perform the calculation.
  14052. @member ejs.ScriptField
  14053. @param {String} expression The script/code to use.
  14054. @returns {Object} returns <code>this</code> so that calls can be chained.
  14055. */
  14056. script: function (expression) {
  14057. if (expression == null) {
  14058. return script[fieldName].script;
  14059. }
  14060. script[fieldName].script = expression;
  14061. return this;
  14062. },
  14063. /**
  14064. Allows you to set script parameters to be used during the execution of the script.
  14065. @member ejs.ScriptField
  14066. @param {Object} oParams An object containing key/value pairs representing param name/value.
  14067. @returns {Object} returns <code>this</code> so that calls can be chained.
  14068. */
  14069. params: function (oParams) {
  14070. if (oParams == null) {
  14071. return script[fieldName].params;
  14072. }
  14073. script[fieldName].params = oParams;
  14074. return this;
  14075. },
  14076. /**
  14077. Allows you to serialize this object into a JSON encoded string.
  14078. @member ejs.ScriptField
  14079. @returns {String} returns this object as a serialized JSON string.
  14080. */
  14081. toString: function () {
  14082. return JSON.stringify(script);
  14083. },
  14084. /**
  14085. The type of ejs object. For internal use only.
  14086. @member ejs.ScriptField
  14087. @returns {String} the type of object
  14088. */
  14089. _type: function () {
  14090. return 'script field';
  14091. },
  14092. /**
  14093. Retrieves the internal <code>script</code> object. This is typically used by
  14094. internal API functions so use with caution.
  14095. @member ejs.ScriptField
  14096. @returns {String} returns this object's internal <code>facet</code> property.
  14097. */
  14098. _self: function () {
  14099. return script;
  14100. }
  14101. };
  14102. };
  14103. /**
  14104. @class
  14105. <p>A Shape object that can be used in queries and filters that
  14106. take a Shape. Shape uses the GeoJSON format.</p>
  14107. <p>See http://www.geojson.org/</p>
  14108. @name ejs.Shape
  14109. @desc
  14110. <p>Defines a shape</p>
  14111. @param {String} type A valid shape type.
  14112. @param {Array} coords An valid coordinat definition for the given shape.
  14113. */
  14114. ejs.Shape = function (type, coords) {
  14115. var
  14116. shape = {},
  14117. validType = function (t) {
  14118. var valid = false;
  14119. if (t === 'point' || t === 'linestring' || t === 'polygon' ||
  14120. t === 'multipoint' || t === 'envelope' || t === 'multipolygon') {
  14121. valid = true;
  14122. }
  14123. return valid;
  14124. };
  14125. type = type.toLowerCase();
  14126. if (validType(type)) {
  14127. shape.type = type;
  14128. shape.coordinates = coords;
  14129. }
  14130. return {
  14131. /**
  14132. Sets the shape type. Can be set to one of: point, linestring, polygon,
  14133. multipoint, envelope, or multipolygon.
  14134. @member ejs.Shape
  14135. @param {String} t a valid shape type.
  14136. @returns {Object} returns <code>this</code> so that calls can be chained.
  14137. */
  14138. type: function (t) {
  14139. if (t == null) {
  14140. return shape.type;
  14141. }
  14142. t = t.toLowerCase();
  14143. if (validType(t)) {
  14144. shape.type = t;
  14145. }
  14146. return this;
  14147. },
  14148. /**
  14149. Sets the coordinates for the shape definition. Note, the coordinates
  14150. are not validated in this api. Please see GeoJSON and ElasticSearch
  14151. documentation for correct coordinate definitions.
  14152. @member ejs.Shape
  14153. @param {Array} c a valid coordinates definition for the shape.
  14154. @returns {Object} returns <code>this</code> so that calls can be chained.
  14155. */
  14156. coordinates: function (c) {
  14157. if (c == null) {
  14158. return shape.coordinates;
  14159. }
  14160. shape.coordinates = c;
  14161. return this;
  14162. },
  14163. /**
  14164. Allows you to serialize this object into a JSON encoded string.
  14165. @member ejs.Shape
  14166. @returns {String} returns this object as a serialized JSON string.
  14167. */
  14168. toString: function () {
  14169. return JSON.stringify(shape);
  14170. },
  14171. /**
  14172. The type of ejs object. For internal use only.
  14173. @member ejs.Shape
  14174. @returns {String} the type of object
  14175. */
  14176. _type: function () {
  14177. return 'shape';
  14178. },
  14179. /**
  14180. Retrieves the internal <code>script</code> object. This is typically used by
  14181. internal API functions so use with caution.
  14182. @member ejs.Shape
  14183. @returns {String} returns this object's internal object representation.
  14184. */
  14185. _self: function () {
  14186. return shape;
  14187. }
  14188. };
  14189. };
  14190. /**
  14191. @class
  14192. <p>A Sort object that can be used in on the Request object to specify
  14193. various types of sorting.</p>
  14194. <p>See http://www.elasticsearch.org/guide/reference/api/search/sort.html</p>
  14195. @name ejs.Sort
  14196. @desc
  14197. <p>Defines a sort value</p>
  14198. @param {String} fieldName The fieldName to sort against. Defaults to _score
  14199. if not specified.
  14200. */
  14201. ejs.Sort = function (fieldName) {
  14202. // default to sorting against the documents score.
  14203. if (fieldName == null) {
  14204. fieldName = '_score';
  14205. }
  14206. var sort = {},
  14207. key = fieldName, // defaults to field search
  14208. geo_key = '_geo_distance', // used when doing geo distance sort
  14209. script_key = '_script'; // used when doing script sort
  14210. // defaults to a field sort
  14211. sort[key] = {};
  14212. return {
  14213. /**
  14214. Set's the field to sort on
  14215. @member ejs.Sort
  14216. @param {String} f The name of a field
  14217. @returns {Object} returns <code>this</code> so that calls can be chained.
  14218. */
  14219. field: function (f) {
  14220. var oldValue = sort[key];
  14221. if (f == null) {
  14222. return fieldName;
  14223. }
  14224. delete sort[key];
  14225. fieldName = f;
  14226. key = f;
  14227. sort[key] = oldValue;
  14228. return this;
  14229. },
  14230. /**
  14231. Enables sorting based on a distance from a GeoPoint
  14232. @member ejs.Sort
  14233. @param {GeoPoint} point A valid GeoPoint object
  14234. @returns {Object} returns <code>this</code> so that calls can be chained.
  14235. */
  14236. geoDistance: function (point) {
  14237. var oldValue = sort[key];
  14238. if (point == null) {
  14239. return sort[key][fieldName];
  14240. }
  14241. if (!isGeoPoint(point)) {
  14242. throw new TypeError('Argument must be a GeoPoint');
  14243. }
  14244. delete sort[key];
  14245. key = geo_key;
  14246. sort[key] = oldValue;
  14247. sort[key][fieldName] = point._self();
  14248. return this;
  14249. },
  14250. /**
  14251. Enables sorting based on a script.
  14252. @member ejs.Sort
  14253. @param {String} scriptCode The script code as a string
  14254. @returns {Object} returns <code>this</code> so that calls can be chained.
  14255. */
  14256. script: function (scriptCode) {
  14257. var oldValue = sort[key];
  14258. if (scriptCode == null) {
  14259. return sort[key].script;
  14260. }
  14261. delete sort[key];
  14262. key = script_key;
  14263. sort[key] = oldValue;
  14264. sort[key].script = scriptCode;
  14265. return this;
  14266. },
  14267. /**
  14268. Sets the sort order. Valid values are:
  14269. asc - for ascending order
  14270. desc - for descending order
  14271. Valid during sort types: field, geo distance, and script
  14272. @member ejs.Sort
  14273. @param {String} o The sort order as a string, asc or desc.
  14274. @returns {Object} returns <code>this</code> so that calls can be chained.
  14275. */
  14276. order: function (o) {
  14277. if (o == null) {
  14278. return sort[key].order;
  14279. }
  14280. o = o.toLowerCase();
  14281. if (o === 'asc' || o === 'desc') {
  14282. sort[key].order = o;
  14283. }
  14284. return this;
  14285. },
  14286. /**
  14287. Sets the sort order to ascending (asc). Same as calling
  14288. <code>order('asc')</code>.
  14289. @member ejs.Sort
  14290. @returns {Object} returns <code>this</code> so that calls can be chained.
  14291. */
  14292. asc: function () {
  14293. sort[key].order = 'asc';
  14294. return this;
  14295. },
  14296. /**
  14297. Sets the sort order to descending (desc). Same as calling
  14298. <code>order('desc')</code>.
  14299. @member ejs.Sort
  14300. @returns {Object} returns <code>this</code> so that calls can be chained.
  14301. */
  14302. desc: function () {
  14303. sort[key].order = 'desc';
  14304. return this;
  14305. },
  14306. /**
  14307. Sets the order with a boolean value.
  14308. true = descending sort order
  14309. false = ascending sort order
  14310. Valid during sort types: field, geo distance, and script
  14311. @member ejs.Sort
  14312. @param {Boolean} trueFalse If sort should be in reverse order.
  14313. @returns {Object} returns <code>this</code> so that calls can be chained.
  14314. */
  14315. reverse: function (trueFalse) {
  14316. if (trueFalse == null) {
  14317. return sort[key].reverse;
  14318. }
  14319. sort[key].reverse = trueFalse;
  14320. return this;
  14321. },
  14322. /**
  14323. Sets the value to use for missing fields. Valid values are:
  14324. _last - to put documents with the field missing last
  14325. _first - to put documents with the field missing first
  14326. {String} - any string value to use as the sort value.
  14327. Valid during sort types: field
  14328. @member ejs.Sort
  14329. @param {String} m The value to use for documents with the field missing.
  14330. @returns {Object} returns <code>this</code> so that calls can be chained.
  14331. */
  14332. missing: function (m) {
  14333. if (m == null) {
  14334. return sort[key].missing;
  14335. }
  14336. sort[key].missing = m;
  14337. return this;
  14338. },
  14339. /**
  14340. Sets if the sort should ignore unmapped fields vs throwing an error.
  14341. Valid during sort types: field
  14342. @member ejs.Sort
  14343. @param {Boolean} trueFalse If sort should ignore unmapped fields.
  14344. @returns {Object} returns <code>this</code> so that calls can be chained.
  14345. */
  14346. ignoreUnmapped: function (trueFalse) {
  14347. if (trueFalse == null) {
  14348. return sort[key].ignore_unmapped;
  14349. }
  14350. sort[key].ignore_unmapped = trueFalse;
  14351. return this;
  14352. },
  14353. /**
  14354. Sets the distance unit. Valid values are "mi" for miles or "km"
  14355. for kilometers. Defaults to "km".
  14356. Valid during sort types: geo distance
  14357. @member ejs.Sort
  14358. @param {Number} unit the unit of distance measure.
  14359. @returns {Object} returns <code>this</code> so that calls can be chained.
  14360. */
  14361. unit: function (unit) {
  14362. if (unit == null) {
  14363. return sort[key].unit;
  14364. }
  14365. unit = unit.toLowerCase();
  14366. if (unit === 'mi' || unit === 'km') {
  14367. sort[key].unit = unit;
  14368. }
  14369. return this;
  14370. },
  14371. /**
  14372. If the lat/long points should be normalized to lie within their
  14373. respective normalized ranges.
  14374. Normalized ranges are:
  14375. lon = -180 (exclusive) to 180 (inclusive) range
  14376. lat = -90 to 90 (both inclusive) range
  14377. Valid during sort types: geo distance
  14378. @member ejs.Sort
  14379. @param {String} trueFalse True if the coordinates should be normalized. False otherwise.
  14380. @returns {Object} returns <code>this</code> so that calls can be chained.
  14381. */
  14382. normalize: function (trueFalse) {
  14383. if (trueFalse == null) {
  14384. return sort[key].normalize;
  14385. }
  14386. sort[key].normalize = trueFalse;
  14387. return this;
  14388. },
  14389. /**
  14390. How to compute the distance. Can either be arc (better precision)
  14391. or plane (faster). Defaults to arc.
  14392. Valid during sort types: geo distance
  14393. @member ejs.Sort
  14394. @param {String} type The execution type as a string.
  14395. @returns {Object} returns <code>this</code> so that calls can be chained.
  14396. */
  14397. distanceType: function (type) {
  14398. if (type == null) {
  14399. return sort[key].distance_type;
  14400. }
  14401. type = type.toLowerCase();
  14402. if (type === 'arc' || type === 'plane') {
  14403. sort[key].distance_type = type;
  14404. }
  14405. return this;
  14406. },
  14407. /**
  14408. Sets parameters that will be applied to the script. Overwrites
  14409. any existing params.
  14410. Valid during sort types: script
  14411. @member ejs.Sort
  14412. @param {Object} p An object where the keys are the parameter name and
  14413. values are the parameter value.
  14414. @returns {Object} returns <code>this</code> so that calls can be chained.
  14415. */
  14416. params: function (p) {
  14417. if (p == null) {
  14418. return sort[key].params;
  14419. }
  14420. sort[key].params = p;
  14421. return this;
  14422. },
  14423. /**
  14424. Sets the script language.
  14425. Valid during sort types: script
  14426. @member ejs.Sort
  14427. @param {String} lang The script language, default mvel.
  14428. @returns {Object} returns <code>this</code> so that calls can be chained.
  14429. */
  14430. lang: function (lang) {
  14431. if (lang == null) {
  14432. return sort[key].lang;
  14433. }
  14434. sort[key].lang = lang;
  14435. return this;
  14436. },
  14437. /**
  14438. Sets the script sort type. Valid values are:
  14439. string - script return value is sorted as a string
  14440. number - script return value is sorted as a number
  14441. Valid during sort types: script
  14442. @member ejs.Sort
  14443. @param {String} type The sort type. Either string or number.
  14444. @returns {Object} returns <code>this</code> so that calls can be chained.
  14445. */
  14446. type: function (type) {
  14447. if (type == null) {
  14448. return sort[key].type;
  14449. }
  14450. type = type.toLowerCase();
  14451. if (type === 'string' || type === 'number') {
  14452. sort[key].type = type;
  14453. }
  14454. return this;
  14455. },
  14456. /**
  14457. Allows you to serialize this object into a JSON encoded string.
  14458. @member ejs.Sort
  14459. @returns {String} returns this object as a serialized JSON string.
  14460. */
  14461. toString: function () {
  14462. return JSON.stringify(sort);
  14463. },
  14464. /**
  14465. The type of ejs object. For internal use only.
  14466. @member ejs.Sort
  14467. @returns {String} the type of object
  14468. */
  14469. _type: function () {
  14470. return 'sort';
  14471. },
  14472. /**
  14473. Retrieves the internal <code>script</code> object. This is typically used by
  14474. internal API functions so use with caution.
  14475. @member ejs.Sort
  14476. @returns {String} returns this object's internal object representation.
  14477. */
  14478. _self: function () {
  14479. return sort;
  14480. }
  14481. };
  14482. };
  14483. // run in noConflict mode
  14484. ejs.noConflict = function () {
  14485. root.ejs = _ejs;
  14486. return this;
  14487. };
  14488. }).call(this);