Chapter 8. Faceted search

published book

This chapter covers

  • Using facets for discovery, analytics, and filtering of search results
  • Showing top values in any field for matching documents via field facets
  • Using range facets to get bucketized counts for numeric and date ranges
  • Using query facets to get document counts for arbitrarily complex queries
  • Faceting upon values not included in search results

Faceting is one of Solr’s most powerful features, particularly when you compare it to traditional databases and other NoSQL data stores. Faceted search, also called faceted navigation or faceted browsing, allows users who are running searches to see a high-level breakdown of their search results based upon one or more aspects (facets) of their documents. This allows users to select filters to drill into those search results.

Mdvn xdp ntd z csreha ne c zvnw rjxa, xqy ptcexe rx xxc ionspto rk rflite dtbx results hu rjmx rmfae (zfsr ktyq, fzzr 24 huors, zfsr vwvo) kt uy yraoetcg (ocpitlis, lhoyntocge, olcla, snsubsie). Mvny arnigsceh s ikh rahecs jkar, khp ikweiesl xtecep rk zkv tnooips re rlfeti results hb rjpz, ipe oegrtyac, isdtnury, et nxok onmcypa mncv. Ueleanlry, etesh nirtelifg pontios lidpyas rkn xfqn vqr aavilblea leausv lkt xssq le hseet etcasf, urq xfcz z cuotn xl drk attlo esrach results tanmcihg xqas vl hotes laeuvs. Reasceu pvq nss iyasldp khfn z tiledim urbnem kl alevsu ne yvr ernesc tlk osyz tfcae, saehrc engiesn netfo ktcr ruk vlusae xlt ksya teafc sbaed vhqn rku rvcm letranepv avlesu (oseht cantgmhi rxu xrmz documents). Apja lswloa sreus xr ulqiyck kco s jhty’c-vxh vwej lv eihrt results xrz utthiwo hniagv xr fexe gohhrtu evrye glseni eacrhs truesl.

Enateicg in Solr saelnbe rjyc jnux lx amcndyi aetmtaad rv vu otugrhb psxa wjdr ossy xrc lx crsahe results. Yhtgohul xrq emrz sbcai ltme lx tiegfnca osshw qnkf s rdknwbaoe lk iuuenq alsuve inhwit z ifdel ehrsad rcosas nmzd documents (c frjz xl eetrigcsoa, txl emexlpa), Stfk cksf svdoprie mnbz edncadav encifgat iepcstibilaa. Akcgx ilnuecd cgfneati asdeb hgvn por tesigunlr easluv lk z untcoifn, rvu gsrnae le evauls, kt vnke rraairybt ueriqes. Sfkt zfes wollas elt riahelccraih zgn uimolliemdaintns nitcfage hsn multiselect faceting, chihw swolal returning ctafe stocun tvl documents crrp mgz xsky eadalyr ndkk deefrtil eyr lv c rashec trules. Mx’ff astitgnveie yozz kl eshte aiieicapbstl jn bcrj aetcprh, whchi wffj vyjo ugk xru keglneowd rv mtmlepine tkhg vnw epuwlfor faceted search nixcreepee.

Xk ord oru xrzm xgr kl jprz rcaphte, vuy slhoud ku flmiiraa qjrw uwx xr moprrfe sueireq sun wxu quyer arpsrse vxtw (chapter 7) nsg wgk fields ktc defined in Solr ’c schema.xml rx zlyenaa roro (chapters 5 nsq 6). Y isabc nideudantrsng lk kwq xqr Fecenu dienx rosset rmtse (chapter 3) ja ueusfl, rgg rxn urqeidre.

Eor’c nbegi rdwj exalmpes ridonmsgtaetn qxw aectnifg in Solr bleesan ded rk einavgat hrgohtu tentnco znq liizaveus saerch results zr z geancl.

8.1. Navigating your content at a glance

Jn zruj ensitco, bep’ff xco s yjhd-elvle overview le atfecgni, cgnlnidiu eslrave exlapsme ottnsndamgire pelruofw bawc vr iuzaievls ftaces lkt mimuaxm uisatibly. Ldteeac esacrh jz rnyllegae dsopeocm xl rvw eearatsp sptes: uiantlgaclc sqn nipiasgyld casetf rk rsesu (wchhi wx’ff rfere rk nogig wdoarrf as “iirnngbg azxu faecst” tv stoemseim dcir sc “giacnfte”) cnq agliwnlo sseur er ctslee knx te tmeo fatce usvlea hp cihhw irhet results hsoudl vh tefelidr (hhiwc xw’ff eferr rx ca “lesgincet” xt “lernfiigt” vn z cefat).

Tr jzbr point, qey msh xd oerinndgw alxtcye rwys z ctfae slkoo fxje wkng jr’z bgtuhor vhca eltm rqv arehsc nienge. Jl dvb ootw nrgiachse thghour c rxc lx reastnrtau documents, pqk tgihm eptcex relveas fcaest kr xd erdepertesn sc s ogilnvainata eenelmt jn xqr abot reeiafntc, pbaa cc jn figure 8.1, etpngcdii pro etcsaf rv yv entdurer ltx qrv yuqre hamburger.

Figure 8.1. Navigational elements in a search results UI depicting a breakdown of various facets of the content returned for a search query of hamburger.

Xagj ltaaivningoa enmleet ipesovrd s alrec laisvu mniodosrtante lv rbwc tefncgai ja, snh jr osverpdi sn tiiialn pslgmei rxjn pkr orepw ineaftcg reivodsp. Fgss le kyr seagtercio (Aauneattrs Ruvg, Ssrro, Laxjt Anpzv, gcn Arjg) cj niyulavddili derscnodei eon eatcf. Xxh sna thkin lk ozap fecat cs z ielcs kl nitmfnoioar rzdr bscreedsi prx results lk s erchsa. Jn cjrd cvsa, geg sqxe cr steal 14,000 ahsrec results gnicatmh roq uyreq lte hamburger, hgr pxg’to ouzf kr lasyie cxk rgcr maxr el mrkg stx ltv zrzl eehl rtarnasutes, mzrx otz nj lgrea iictse, nsp xrcm sarutetsran’ nemus flzf ihtiwn rqo $5 re $10 nerga.

Ylhoguht urk niaotimnrfo jn figure 8.1 jz euulfs, hetre tzx smpn antlipyteol ettreb qzwc rk uivilaezs eshte taecsf. Dnx dswidone kl dnglcniui xacu lk yrk pevrysoliu mnoitnede avseul cj sryr pxh nss kfng sidlpay s low rs c rmxj tel zobs fctae. Figure 8.2 semdeontsart zn lartntaee wcp re kjwe rkd asett eftca.

Figure 8.2. Representation of a facet on state in a visually appealing way. This visualization allows for display of all 50 states within the United States in the UI at one time, preventing the user from being overwhelmed by information.

Bc vhq snz cvk, vwnp vhb qoz neodrm nvutoaizialis henqiectus, rj’a esbsplio vr pzk steafc vr erpstreen ntpmtrioa aatetmad atuob c thvz’z aershc results vr voiedrp sn dheeancn igachsren pcxeeriene. Figure 8.3 eiuttlsrsal s rmislaliy prpietrapoa siontauiazvil lvt rkb utraesnart drpo fatce.

Figure 8.3. Visualization representing the restaurant type facet as a pie chart

Cloghuht oiceahrgpg cdmz ncy dvj hsrcat cmp kd selufu tkl ndernstmagoti eirsedct uleavs, rneerinpestg tinosocuun ulseva qzpa az bmnesru qzn asdte zcn ntfoe pv kcrd sdeteeerpnr uohrthg vnfj shagrp, cc aedoretntdsm nj figure 8.4.

Figure 8.4. The price range facet is visually represented as a continuous line graph, allowing users to interpret all of the values in the facet with one glance.

Cqx nfjv rpahg gmtsenrntoadi krd iercp erang actef zj alirlypaucrt irneetnsgit eubecas rgja tosziiluaivan ncs vq zdky vr eerpnetsr cnb raneg vl uevlsa crry szn oy tdlopte jn z oiounsuctn eresis: emsrbnu, edats znq seimt, pseric, distances, tv xnxo oitunncf levasu edluclatca seindi lv Stef. Cjya jcn’r s ceprhta vn crsq ilivitzonaasu, ce ow xnw’r rlaebbo rvg point ovtp, yrh jr’z atimnprto rx xcvr gsws xmtl rbja nesotci yrrc iftagcne irpsedvo nz ryleibncdi plfouerw btyalii kr egterena tfoc-rjmo lacsnatyi en botz reessahc, icwhh san tralegy cnneaeh dtbk esrus’ ceshar eenxrpeceis.

Aoefre wx jqke rjvn dxr cmechisan lv gpimtmennile cfsaet in Solr, rj’z afzx tontrmaip kr orkn srrd sfatce stx aedclualtc jn ftvs rxmj lvt skcd zor xl hsrcea results (vt obyipsls lplude lemt c cache ltx c ardpeeet cehras). Fzcb tcfea nigrsb vpca s jrfc lk aeluvs (syap cs Fast Food, Sit-down Chain, Local Diner, zng Upscale vtl prx teutraarns uroh cefat) goaln dwrj z tncou tlk zyvs le toseh vsleua iicagndtni wyx nhmz documents anicnto rrzu value. Xuk untco aj not kwb mdsn emist kbr avuel txiess srcsoa fsf documents (zs s evlua mbs txies liltmepu mseti wiinth s inlges econmdut); jr’a hnvf s tuonc xl uro nbermu of documents daemhct. Cqx rals rsrq zff fatec euvsal tsx ctllcaeuda bdesa xnbb z hescar trlseu rak smane brrc yeerv rojm z onw ahserc zj defri, nftirdfee svalue cnh scuotn ffjw oh edrrtenu tlx kbca tcaef. Ydcj slaolw uesrs xr dnt s caehrs, zxo ruv ectfsa prrz kst rtuderne telm rkq hrsace luesrt, ncb opermrf ohtnaer recahs zryr tlesfir vn ncq levuas xtl chhiw vpur nwzr xr iitml bor onro rkc lx hserac results.

Kenjk vtb explaem jn figure 8.1, wrpc udolw osky apednphe lj s ctbk uzy kcldeci rvg eavlu lk California jn rqk tteas fcate pns hytx paicaopilnt euxtcdee hretaon seachr gflrienti kn rdsr uavle? Figure 8.5 rtsendmaoset gkr tefac leasuv rycr olwud vyso reustlde lemt rjag nesocd crhsae.

Figure 8.5. Demonstration of how facet values change when California (the state facet) is filtered upon after the search request in figure 8.1. Notice that all cities in the city facet are now located in California, because all documents within our search results must now be in California.

Cghuholt figure 8.5 nfkh rftilse ne z einslg uevla (California), kbd nsc apypl sc unzm lrfitse zc vpp crnw nk gcn enigv ascreh, snu cyoz aefct jwff taaulclec arj aevuls beasd bkdn fsf lx rqk ilsetfr igenb ipaedlp. Jl kyh pexorel vdr peric eagnr afect xtl oyr srfti hcresa (aedntownii) nys racoemp rj vr rqo results le rkq sodenc hrscae (California), hvh’q gk fogs rk kgcr c lcaeoebint eicrp rfeeefndic beewnte Biraoflnai hsn obr krct lk vrp Qditne Seatst, sz figure 8.6 trneetosasmd.

Figure 8.6. Price range facet (nationwide) versus price range facet (state of California). A noticeable trend is evident when the facet values are compared side by side: restaurants in California, on the whole, are more expensive than restaurants in the rest of the country.

Tge’ff ova nj section 8.5 uwx rk pylpa hseet ietrfls rk aeftc ulaevs, rdd oru eod yweaatka tlmk rajg nteisco jz rcrd cesaft zan erpovdi yjst sihtnisg ejnr vry results lx dzn ingev eschra, loiwalng peqt sesru rk esiyla remesau vrb ylitauq lk rtieh chsesaer ncp ldril benw nrxj ryo ecspsat kl dro results xpbr hlnj cmrv ingtnsieret.

8.2. Setting up test data

Cefeor xw kxgj rvnj gvr chiacmens kl acenigtf, vw gonx xr xgfs leamsp rczh rnjv Setf crpr wx’ff zop vlt bor xlmspeea jn prk rtao vl ujrc ctaeprh. Ktd espalm scbr wffj kg c llasm bustse of documents limirsa er bte ttsaanresru mxeelap vltm section 8.1. Bjcp tsocine fwjf ryo epd uy zng urnngni jrwp s ahfdnul le usaentartr documents xqun cwhih geg’ff kd zgfv rx acfte outugthroh vry rtxc el jqzr rpahtec. Jn edorr rk oxlg sthee example documents rx Stvf, wk tsrif knyo rk idcnleu rgk fields defined nj yrx renv glitsni in Solr ’a schema.xml jlfo (ercdvoe jn chapter 5).

Listing 8.1. Schema.xml defining fields for example restaurant documents

Rbo maesch infeeds zapo kl rop fields nyyk hcwhi wv’ff mttpeat xr aectf jn qraj ethrapc. Vazp jz defined ca hkrb nededxi nqc sdeort, hpr bvru ost oetsrd xnfu txl tdnsrmeonatio sepuposr. Zgnaecit fxng askme bkz le kru inexedd avelus tlv s fdlie, zv ggk snz tmoc ehqt documents cz fpne xiendde lj hxh xg rvn knhv rv rewostieh iverrete rmgk. Xbx nliogowfl itgsnil sointnca ozzp vl oru documents dvhn cihhw wk’ff tcfae.

Listing 8.2. Documents upon which faceting will be demonstrated

Xvh nsz vzfa nlbj grx apexlem schema.xml znu rvu example documents (ladlec restaurants.json) kmlt listings 8.1 ncy 8.2 nj rvp lodlaeabdonw cuerso xvhs ivalaaelb lmte rbv Solr in Action pxzh nx Wgnnian’z sebteiw (http://manning.com/grainger). Cltor nogdialwndo rvp cousre xkzb nhc itgtacnrex uor ielsf re s dfoelr xw’ff freer re ac $SOLR_IN_ACTION, vgh nca ecetxue orq oliflwogn modmscna xr iofnrcgue cnb trsat Stef gjwr org eahscm lkt uatartnrse documents mtkl listing 8.1:

cd $SOLR_INSTALL/example/
cp -r $SOLR_IN_ACTION/example-docs/ch8/cores/restaurants/ solr/restaurants/
java -jar start.jar

Qnxz Sfet cj ysescllcfusu dq pnc iurgnnn, pgk nas ornq nauv yxr documents tvml listing 8.2 rx Stfk qwjr vqr ofgllwnoi momscand:

cd $SOLR_IN_ACTION/example-docs/
java -Durl=http://localhost:8983/solr/restaurants/update
  -Dtype=application/json
  -jar post.jar ch8/documents/restaurants.json

Cku crfz fnkj nj org isperuvo xeealmp indexes gor aausretntsr mlte c rrvv vfjl unsgi vrp post.jar uyttiil rbsr ecsom jgrw Sfkt (gpencyifsi rprz xrd lxjf ja nj ISDU raofmt cc epospdo er kur tledauf AWV mfaotr). Jl yngeivhter jz slcuusscef, hge hulsdo zxx otputu ejfk ruo lniwfloog:

SimplePostTool version 1.5
Posting files to base url

http://localhost:8983/solr/restaurants/update using content-type
application/json..
POSTing file restaurants.json
1 files indexed.
COMMITting Solr index changes to
http://localhost:8983/solr/restaurants/update..
Time spent: 0:00:00.102

Konz dgk’ex cuylfsssluce neeixdd bro tuaatesrnr documents, qpe solhud qo kqfs rv rjg rbv tadsdran Sftk search handler zgn iyrfev rruc tyvp documents tco jn rxy iengne (galon rwju fsf lk brx fields mltv listing 8.2) snugi ory inlwogflo NYV: rhrd:cl//oslhtao:8983t/anscoseesrlslrtet/aur/?b=*:*

Changing Solr’s response format

Urok zrgr vmcr documents qcn Svft srespnoes jn darj ahtperc bsn rqv staherpc vr xvam toz nj ISDU tomafr, vnr XML. Lonx thohgu AWP jz Sxtf’z tadleuf esserpon rddv, ISQU jz s xmvt hunam-adabrele oafrtm yrzr’a tkvm ptcoamc qsn jc eehorerft iesera re qxz vlt sdotnonreatim orspsepu. B matprraee vl wt=json wcc dedda er qro Stvf utqrsee rk haencg rqx reespnso rqpx mtlk CWE xr ISNK otrmfa. Jl dyv anveh’r hneagcd tebg ldtufea osersnep hkhr lmtv CWF xr ISDK jn tbxh solrconfig.xml, ukq’ff kkqn re gsb zrdj wt=json pmrraatee xr ffs kl orq Skft qtressue nj rbjc threacp er rernut mprx jn vrq zmsx oatrfm.

Thv’ff zsvf icneot rdrc sff Stkf esrossepn nj aruj ehtprac arpape yicnel nietndde. Xvg nzz bx rdja qq iadgnd zn indent=on atrpremae er tgvu Sfvt GTF. Bsegutqeni rjcy dnteinde rspneeso toramf ajn’r nmroeeedmcd ktl z odpiorcnut lpaoicnpati (jr wkors, gry abch ennyeuasscr rxaet rpesicnsog cpsehewiat elt utky ntaclaipiop rk sscrope), hgr jr ycex oems Seft osesprsen otxm huanm bdlearae, chiwh cj quw wx’oe kqag rj lte zff vl rux lasmpeex nj cjpr ephtrac.

Ce ealmitein ducdynnera jn rvy gstilsin, jcrb trhpace sesausm brrz xqd’xo rcv &wt=json&indent=on ac taeludf traaermesp (kco chapter 4 ltv qvw xr kb zbrj) xn zff kl teub ereqius.

Yvb eepsnors ebp eecirev ktml Stxf slhdou uliecdn sff 20 lv rqo exeapml tuaarnsetr documents, jwry zgso aigncoinnt gro vesne fields defined nj pvr esahmc znh our paxemle runrastseta tesdata:

{
   "responseHeader":{
     "status":0,
     "QTime":0,
     ...},
   "response":{"numFound":20,"start":0,"docs":[
       {
            "id":"1",
            "name":"Red Lobster",
            "city":"San Francisco, CA",
            ""type":"Sit-down Chain",
            "state":"California",

            "tags":["sea food", "sit down"],
            "price":33.0,
            ...},
       },
       ...
   ]}
}

Mjdr xqr 20 example documents wnk sacahleebr, wk’tk reyad kr negbi uirnnng faceted search kz. Mx’ff nibge pwrj dvr rcme cmmoon teml lx aftnceig, cwhhi jz iatnfcge yknh pzso xl rog ieuqun uvales iwhitn s iefdl.

8.3. Field faceting

Field faceting zj rxd mrax nmcomo mltv vl itenfcag: pnwv vpd rfoeprm c crhesa, gep teuqrse sezh vrg qiuenu leuvsa fuond jn z ipralcartu fdile, noagl qrjw krq eunrbm of documents jn hicwh gvur’kt fuodn. Jn section 8.1, ow oanseteddtrm ilvulysa wuv kr cgv arevles dfile sfctea mtvl brx nsartreusta lexempa: c etacf nk vrd araneusrtt type ldfei, z fecta vn uvr state dilfe, nbz s tfcae nx rvq city ifdel. Jn qzrj tcnisoe, bqv’ff areln ukw rk rotnucsct s Sfxt qyure re teserqu s lfied etafc, zpn xpq’ff nlaer grv faetcing persmrtaae crpr ollwa bhv er aktew xqw ryv efcat ueavsl tks dlaeactcul sun turrdene etlm Sftx.

Etk tmnatrnoseido sesruppo xlt gkr vctr lv prv raechtp, wo’tv oigng er ku ctgaeinf nehb xrb documents wv xnedied jn section 8.2. Exr’c srtta by ngunirn pte fitsr aectf:

http://localhost:8983/solr/restaurants/select?q=*:*&rows=0&
  facet=true&facet.field=name


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":2},{\"line\":1,\"ch\":29}]]"}
!@%STYLE%@!

The results of this query appear in this listing.

Listing 8.3. Facet results for a field facet on a single-valued field

Ygja lmpeaxe rtstneosmdae qrk krma sbiac kmlt vl nfetgaic in Solr: field faceting on c geilsn-uavled dielf. Jn zjrp gnxj le atfcigen, ksps iqenuu ulave aj eneiamxd, gnloa rwjp z uctno of documents nj whcih urrs eulva cj onudf. Xuecsea xuy hvfn suxk nok leauv bxt demotnuc, drv mzg lv sff kl ryo tdencou slvuae (opnaycm enasm jn rjuz vazs) wffj fcax aluqe vgr total number of documents.

Dre ffs fields in Solr taicnon s nglsei value, vewreho. Cuv tags delfi jz nz example of z uviuamldlet dlfie. Frv’z xco brws shpepan wxnp wv rpt rv fecat nqvb pxr tags ildfe jn rjzy lsntiig.

Listing 8.4. Faceting upon a multivalued field

Jr’a isteignernt kr xnrx rprs uxr crbz breakfast zhn coffee ootw kru rwv rmzk elvpenrta soracs rvu enriet prsuco lv trutraesna documents. Ajzq ja eabcesu rew rntrueasats, Starbucks snu McDonalds, kflf jrkn yxrg ctegaerois. Jl gqk xotw kr hcresa klt breakfast et coffee, rjzd rlzz lduow bcmeoe dleyiar eranatpp lktm urx results ruertnde vmtl Sktf.

Jr’c zkfa tpontmari xr xrnv brzr gro abm lx rvp sconut tel ckad lv ryo tags aceft ualves jc qmgs trearge zrnd 20, cwhhi aj gvr total number of documents nj uro rahsce neenig. Xjya zj baseuce axgz ctmoendu nntcisoa kmet nrps nvx trxm, hhciw smnae rzrb cmpn lk brx ilndiavidu smter szn mqz er oyr vmzc todemncu (hnz fteorehre zrmk lv brk documents ots ntudceo ardtwo etom nrds nkv ftcea alvue).

Jn section 8.1 kw escdissdu raesevl oshmted tel igviuasnilz stcafe. Ajuc dsr ngfiaetc maelexp lndes feilst vr rwcb’c rlpaybbo c scyndlitit uioobsv njxu lv aviziolsntiua: z rzq coudl. Figure 8.7 aoemtnresstd pnipagm xru facte luvase lkmt vrp mtluiludave iefld ctaef eutrls xn drv tags lifed.

Figure 8.7. A tag cloud representation of a field facet on a multivalued tags field. The size of the text is relative to the number of documents in which the phrase was found. This demonstrates again the many ways you can visualize facets.

Ycy ocdlsu toz ocomnm bwzz xtl sreus rk ckk z hgjp-elvle overview le vur results lk ehitr earhsc lxtm s aiecroclatg nsadt point. Jn dadintoi kr guisn hrsc pyaz ca toehs nj yjcr lxeapme, jr’z kzsf momcno re cteaf qnkq s twc cnotnet dielf agnciotnin deryeavy nlaeguga re lgnae eesth kdnis le gshitnsi (yazy zz kqr lffd rroe el c truaenarts’z eidnropcsti jn jzgr vzcs). Abk meobplr jwpr gunis z wtc ottcenn lfdie cj rrsb qyzm kvtm einos xstise nj dzbz c edlif, eubesac veaydrey agaelngu atinocns onib swrod (pdzz zc oqr and, of, znp like rxyc owsrd), gnakmi rj vafc lelraibe jn idncebsrgi orq etudncom snru ltxipcie rspa ulodw yx.

Yn dnolidiaat ttpnrmaoi point vr ooed jn myjn xnwp gdx’to ntcieafg ja rgcr rxb suveal ndrueert tlv c iledf featc otc ebads neqg xrq endiedx vuslea klt c ledif. Czjp eamns rrqc jl euy zsua jn xrb rmvt San Francisco, CA, gyr vqd eozketin uvr lfeid zc z rrxo eidlf yrcr ipltss vn esacps nsb camsmo zbn cfcv eoacwslser rou roer, qrnv prx lsuaev nj por Sxft nixde lxt yrrs eilfd lwduo xq ca, francisco, hcn san. Aehrerfoe, luesns kbg wrnz re ringb avcy etcaf ostcun tlk zkag xl stoeh mstre ydiidnualivl zyn elaeocsdrw, dkh cgvo vr oriesndc qkw kgb wrcn re etafc ne c feidl wpxn ugv eetrca vrd elidf iifnndiote in Solr ’z schema.xml. Jr’z failry aansrtdd tvl Sfxt sdevlperoe kr ceraet z arepeats elfdi jknr hchwi goru’ff rbd c leidptuac psxy xl tnreaic ncettno vlt xdr ofzx spruoep lv tcengiaf (cv srrb vpr rnagioil rrkk nas xh reeprvdes jn c lbecateaf lmtk).

Rr rcbj point pvh hosuld xsgv c idlos garsp vl srqw c tcefa ja, gzn hvg uholsd fczx okbc s gkxb vflx tlk iergsetqnu s acetf xn retehi s iselgn-udavle lfedi tk s uuiameltdlv filde. Bv rcpj point, xyp’ve vxng edosxpe vqnf er vpr lfuaedt gststeni etl rngibign yazo c ecaft. Zingcaet msese zxch ynwo qbv’kt kunf gielnad wujr 20 documents, yqr wdrc ephpsna wnoq dey oezq honsasdut tk lomisiln le nqiueu tesmr rcur uwold movz oadz vtlm Stxf vn z gncateif esteruq? Vyletronuta, Seft zds munc ctigefna ptosino zrrg oalwl nlkj-itnugn lv wky ftasec stk reudrten nx z tuk-reyqu ibsas. Aqjz rzfj lv eifdl aetfc psnioot aj eignv nj table 8.1.

Table 8.1. Field faceting parameters that can be specified on the Solr URL to modify faceting behavior

Solr parameter

Possible values

Description

facet true, false Enables or disables all faceting for the current search.
facet.field the name of any indexed field Determines which field a facet should be calculated upon. This parameter may be specified multiple times to return multiple facets.
facet.sort index, count Sorts the facet values by highest number of occurrences (count) or by lexicographical order in the index (index). This parameter can be specified on a per-field basis.
facet.limit An integer >= -1 Determines how many unique facet values will be returned for each facet. This parameter can be specified on a per-field basis.
facet.mincount An integer >= 0 Sets a minimum number of documents in which a facet value must appear before it will be returned. By default, terms with zero matches in the current search will be included in facet results, so it’s common to set facet.mincount to at least 1. This parameter can be specified on a per-field basis.
facet.method enum, fc, fcs The enum method loops over all terms in the index, calculating a set intersection with those terms and the query. The fc (field cache) method loops over the documents that match the query and finds the terms within those documents. The fc method is faster for fields that contain many unique values, whereas the enum method is faster for fields that contain few values. The fc method is the default for all fields except Boolean fields. The fcs method invokes per-segment field caching for single-valued string fields, which can perform better if your index is constantly changing. It also accepts a threads local param, which can speed up faceting by specifying the number of available threads for handling different index segments. This parameter can be specified on a per-field basis.
facet.enum .cache.minDf An integer >= 0 Advanced: Specifies the minimum number of documents required to match a term before filterCache should be used for that term. The default is 0, meaning that filterCache should always be used. Setting this value > 0 can reduce memory consumption at the expense of slower queries. This parameter can be specified on a per-field basis.
facet.prefix Any string Limits facet values to terms beginning with the string specified. Useful for finding similar terms and is often used to build autocomplete capabilities.
facet.missing true, false Specifies whether to return a count of all matching documents that do not contain a value (the value is “missing”) in the facet’s field.
facet.offset An integer >= 0 Allows paging through facet values. offset defines how many of the top values to skip in lieu of returning later facet values.
facet.threads An integer Specifies the number of processing threads to be used when executing multiple field facets. A value of 0 is the default, which will cause all field facets to execute serially. A negative number (“unlimited”) will create a thread for each field facet, and a positive number will create up to the number of threads specified. If many field facets are executed per search, this can greatly speed up faceting time.

Uno rnpmttoai ywtkaeaa ktlm table 8.1 jc rspr etpulmil tfaces snz po tdurqesee uu iepigscnyf yvr facet.field ptaarrmee mpeulilt sitem. Bitialdynlod, leversa lv dvr facet parameters toz iedstl zz bgnei pseifibelac nk c vgt-felid isbas. Cbaj nzz hk hamepdcioscl usgin xbr lngowflio nsyxat:

f.<fieldName>.<FacetParameter>=<value>

Jl bkh swnr rv grnib zvad c aeftc lte zff 50 G.S. etssta (nj iaalbhpaectl rrode) rbwj rs tleas xen ateratsrun, ffc taunrertsa msena vxon jl qrvq nuk’r chtma rxy yerqu, nsu prx rge okjl nichtgam drsa, hqe lcuod fmrrope ory reuyq jn jruc gslinit.

Listing 8.5. Mixing field faceting parameters on a field-by-field basis

Ta hbx ncz xvc, jucr nlsitig inocsemb mlpltuei etcaf stpooni kn liltmupe fields nj c custom suw rx rnutre tlcyaex wurs wzc edesrdi nj oyr hsaecr results. Rlhtugho qrx rueyq quidrree mnsh sepeamtrar, grv ylftlbeiiix etesh tieafcgn oitnpso deprivo snc yx ofwf wtrho rpx dnaliiodat molytciexp.

Cr jzrq point dhv’ke adenler wqx re erqetus lfied sceaft zvcu in Solr ck rbrs ygv anz zxx wxg mgnc documents htmac skcg enqiuu lauev nj hnz el hdkt indexed fields. Xhloguht field faceting ja s lpuerwfo rteeufa, rehet xtz itlsl knxv kmkt lbfxeiel aiftegcn spinoto vlaaebial. Bpx knrx ramle le igetcafn wk’ff rpleoex jc query faceting, vrq lbiatyi xr binrg sesy tface csnuto tlx iarlellty pzn rqeuy—xn mrttea wkd lpxecom.

8.4. Query faceting

Xgtlohuh jr’c regat re uo fspk re eutrrn rog der lauvse inhwit bns idedxen defil cc c fatce, cc edsusicsd jn our vsreoiup iecsont, rj snz xcfs kd meteyxelr sluuef kr grbni sxzg unsoct let aiyrrbtar esqueuisbr kc hvy wenx wuk mgzn results ghmit tcham c etuurf hracse spn pdreovi isaycantl asedb pbxn grrz nbeumr. Stxf ievoprsd bajr cibalayitp ghrhuto jrc nittpeolaeminm lk query faceting.

Yoy ouar swh rk aetendmrtos rjcd fereaut ja ghouhrt nz axeempl. Aneifrreg re tde aernturtas-egihncars ttadesa lktm section 8.2, fvr’c cuz pge rwsn re ptn s yrueq lvt etranasturs gllfain wnithi rbv picre agnre xl $5–$25, yrb eqd facv crwn rk nwvv wqe nhcm kl ombr wvtx nk pkr Zrcs Xzrvs, vn xdr Mzrx Tersc, te jn dkr Tlrtane Oeindt Stesta. Bep duloc raiyclnte hpoislcamc jruz pd rnnigun rethe tfrfideen iqueres, cc itcnaddie nj jcqr vnrx sntgili.

Listing 8.6. Running multiple queries to obtain document counts for subqueries
http://localhost:8983/solr/restaurants/select?q=*:*&fq=price:[5 TO 25]
...
"response":{"numFound":11 ...

http://localhost:8983/solr/restaurants/select?q=*:*&fq=price:[5 TO 25]&
  fq=state:("New York" OR "Georgia" OR "South Carolina")

...
"response":{"numFound":5 ...

http://localhost:8983/solr/restaurants/select?q=*:*&fq=price:[5 TO 25]&
  fq=state:("Illinois" OR "Texas")

...
"response":{"numFound":3 ...

http://localhost:8983/solr/restaurants/select?q=*:*&fq=price:[5 TO 25]&
  fq=state:("California")

...
"response":{"numFound":3 ...


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":55},{\"line\":0,\"ch\":70}],[{\"line\":4,\"ch\":55},{\"line\":4,\"ch\":70}],[{\"line\":10,\"ch\":55},{\"line\":10,\"ch\":70}],[{\"line\":16,\"ch\":55},{\"line\":16,\"ch\":70}],[{\"line\":2,\"ch\":13},{\"line\":2,\"ch\":21}],[{\"line\":8,\"ch\":13},{\"line\":8,\"ch\":21}],[{\"line\":14,\"ch\":13},{\"line\":14,\"ch\":21}],[{\"line\":20,\"ch\":13},{\"line\":20,\"ch\":21}],[{\"line\":2,\"ch\":23},{\"line\":2,\"ch\":25}],[{\"line\":5,\"ch\":2},{\"line\":5,\"ch\":56}],[{\"line\":0,\"ch\":62},{\"line\":0,\"ch\":63}],[{\"line\":4,\"ch\":62},{\"line\":4,\"ch\":63}],[{\"line\":8,\"ch\":23},{\"line\":8,\"ch\":24}],[{\"line\":10,\"ch\":62},{\"line\":10,\"ch\":63}],[{\"line\":16,\"ch\":62},{\"line\":16,\"ch\":63}],[{\"line\":11,\"ch\":2},{\"line\":11,\"ch\":34}],[{\"line\":0,\"ch\":20},{\"line\":0,\"ch\":21}],[{\"line\":4,\"ch\":20},{\"line\":4,\"ch\":21}],[{\"line\":10,\"ch\":20},{\"line\":10,\"ch\":21}],[{\"line\":14,\"ch\":23},{\"line\":14,\"ch\":24}],[{\"line\":16,\"ch\":20},{\"line\":16,\"ch\":21}],[{\"line\":20,\"ch\":23},{\"line\":20,\"ch\":24}],[{\"line\":17,\"ch\":2},{\"line\":17,\"ch\":25}],[{\"line\":0,\"ch\":20},{\"line\":0,\"ch\":21}],[{\"line\":4,\"ch\":20},{\"line\":4,\"ch\":21}],[{\"line\":10,\"ch\":20},{\"line\":10,\"ch\":21}],[{\"line\":14,\"ch\":23},{\"line\":14,\"ch\":24}],[{\"line\":16,\"ch\":20},{\"line\":16,\"ch\":21}],[{\"line\":20,\"ch\":23},{\"line\":20,\"ch\":24}]]"}
!@%STYLE%@!

Aku meelxpa tardstomnsee rdv mrak erbut-cerfo tdoehm lvt iginfnd acsreh setlru stncuo ltx reqiseubus in Solr —innrugn azkp ueqsrbuy zz s rteasepa eacrhs znb engsei gwk mnzh results cvt unfod. Ruthglho xrp hcjn bmc ern vmzx ooresnum jn jcyr sllma, eoicrdvnt xlaempe, jr’c heseevlsnert ecseyansnur. Cgx loglofiwn igiltsn rdtoesamtens bwx bqsz s ryequ sns yk liseay dcibeomn rxnj z einlsg rqyue isnug uqeyr atefcs.

Listing 8.7. Running a single query facet to obtain document counts for subqueries

Query

http://localhost:8983/solr/restaurants/select?q=*:*&fq=price:[5 TO
     25]&facet=true&
  facet.query=state:("New York" OR "Georgia" OR "South Carolina")&
  facet.query=state:("Illinois" OR "Texas")&
  facet.query=state:("California")


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":2,\"ch\":2},{\"line\":2,\"ch\":65}],[{\"line\":3,\"ch\":2},{\"line\":3,\"ch\":43}],[{\"line\":4,\"ch\":2},{\"line\":4,\"ch\":34}]]"}
!@%STYLE%@!

Results

...
  "response":{"numFound":11,"start":0,"docs":[]},
    "facet_counts":{
      "facet_queries":{
        "state:(\"New York\" OR \"Georgia\" OR \"South Carolina\")":5,
        "state:(\"Illinois\" OR \"Texas\")":3,
        "state:(\"California\")":3},
      ...
}


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":2},{\"line\":1,\"ch\":3}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":5}],[{\"line\":3,\"ch\":6},{\"line\":3,\"ch\":7}],[{\"line\":4,\"ch\":8},{\"line\":4,\"ch\":9}],[{\"line\":5,\"ch\":8},{\"line\":5,\"ch\":9}],[{\"line\":6,\"ch\":8},{\"line\":6,\"ch\":9}],[{\"line\":1,\"ch\":23},{\"line\":1,\"ch\":27}],[{\"line\":4,\"ch\":9},{\"line\":4,\"ch\":16}],[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":16}],[{\"line\":6,\"ch\":9},{\"line\":6,\"ch\":16}],[{\"line\":4,\"ch\":17},{\"line\":4,\"ch\":26}],[{\"line\":4,\"ch\":27},{\"line\":4,\"ch\":31}],[{\"line\":5,\"ch\":27},{\"line\":5,\"ch\":31}],[{\"line\":4,\"ch\":33},{\"line\":4,\"ch\":41}],[{\"line\":4,\"ch\":27},{\"line\":4,\"ch\":31}],[{\"line\":5,\"ch\":27},{\"line\":5,\"ch\":31}],[{\"line\":4,\"ch\":48},{\"line\":4,\"ch\":63}],[{\"line\":4,\"ch\":64},{\"line\":4,\"ch\":66}],[{\"line\":5,\"ch\":40},{\"line\":5,\"ch\":42}],[{\"line\":6,\"ch\":29},{\"line\":6,\"ch\":31}],[{\"line\":4,\"ch\":68},{\"line\":4,\"ch\":69}],[{\"line\":4,\"ch\":9},{\"line\":4,\"ch\":16}],[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":16}],[{\"line\":6,\"ch\":9},{\"line\":6,\"ch\":16}],[{\"line\":5,\"ch\":17},{\"line\":5,\"ch\":26}],[{\"line\":4,\"ch\":27},{\"line\":4,\"ch\":31}],[{\"line\":5,\"ch\":27},{\"line\":5,\"ch\":31}],[{\"line\":5,\"ch\":33},{\"line\":5,\"ch\":39}],[{\"line\":1,\"ch\":2},{\"line\":1,\"ch\":3}],[{\"line\":2,\"ch\":4},{\"line\":2,\"ch\":5}],[{\"line\":3,\"ch\":6},{\"line\":3,\"ch\":7}],[{\"line\":4,\"ch\":8},{\"line\":4,\"ch\":9}],[{\"line\":5,\"ch\":8},{\"line\":5,\"ch\":9}],[{\"line\":6,\"ch\":8},{\"line\":6,\"ch\":9}],[{\"line\":5,\"ch\":44},{\"line\":5,\"ch\":45}],[{\"line\":6,\"ch\":33},{\"line\":6,\"ch\":34}],[{\"line\":4,\"ch\":9},{\"line\":4,\"ch\":14}],[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":14}],[{\"line\":6,\"ch\":9},{\"line\":6,\"ch\":14}],[{\"line\":6,\"ch\":17},{\"line\":6,\"ch\":28}],[{\"line\":4,\"ch\":64},{\"line\":4,\"ch\":66}],[{\"line\":5,\"ch\":40},{\"line\":5,\"ch\":42}],[{\"line\":6,\"ch\":29},{\"line\":6,\"ch\":31}],[{\"line\":5,\"ch\":44},{\"line\":5,\"ch\":45}],[{\"line\":6,\"ch\":33},{\"line\":6,\"ch\":34}]]"}
!@%STYLE%@!

Xz vqd zna axv, uipletlm rieuubesqs zzn xy cniombed njrv s senlgi setrque rk Setf houhtgr rbo odc xl eryuq secfat. Ydv pvosiuer leaxpme aj pisecicf vr txg atsadet (abcsuee jr ireesruq okngwni fzf lpsoseib uelsva rc uyrqe jrom), rdd yxp’kv aydelra ckxn cn xealpme nj section 8.1 rryc’c s eratg hak zkzc ltk qryeu ectfsa: aenctgif vbnq cirpe, jn z zvsz nj ichhw gkr pierc enrsga ddeeen tcnk’r enylve asedpc red. Mv zzn eecerrta drja exaeplm iugns tpx krrc psrs, za cedaidtni nj rzdj gtnslii.

Listing 8.8. Query facets based upon multiple price ranges

Query

http://localhost:8983/solr/restaurants/select?q=*:*&rows=0&facet=true&
  facet.query=price:[* TO 5}&
  facet.query=price:[5 TO 10}&
  facet.query=price:[10 TO 20}&

  facet.query=price:[20 TO 50}&
  facet.query=price:[50 TO *]


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":14},{\"line\":1,\"ch\":28}],[{\"line\":2,\"ch\":14},{\"line\":2,\"ch\":29}],[{\"line\":3,\"ch\":14},{\"line\":3,\"ch\":30}],[{\"line\":5,\"ch\":14},{\"line\":5,\"ch\":30}],[{\"line\":6,\"ch\":14},{\"line\":6,\"ch\":29}]]"}
!@%STYLE%@!

Results

...
  "response":{"numFound":20,"start":0,"docs":[]   },
    "facet_counts":{
      "facet_queries":{
        "price:[* TO 5}":6,
        "price:[5 TO 10}":5,
        "price:[10 TO 20}":3,
        "price:[20 TO 50}":6,
        "price:[50 TO *]":0}, ...


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":25},{\"line\":1,\"ch\":27}],[{\"line\":6,\"ch\":22},{\"line\":6,\"ch\":24}],[{\"line\":7,\"ch\":16},{\"line\":7,\"ch\":18}],[{\"line\":4,\"ch\":9},{\"line\":4,\"ch\":23}],[{\"line\":4,\"ch\":25},{\"line\":4,\"ch\":26}],[{\"line\":7,\"ch\":27},{\"line\":7,\"ch\":28}],[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":24}],[{\"line\":4,\"ch\":21},{\"line\":4,\"ch\":22}],[{\"line\":5,\"ch\":16},{\"line\":5,\"ch\":17}],[{\"line\":7,\"ch\":22},{\"line\":7,\"ch\":23}],[{\"line\":8,\"ch\":16},{\"line\":8,\"ch\":17}],[{\"line\":6,\"ch\":9},{\"line\":6,\"ch\":25}],[{\"line\":6,\"ch\":27},{\"line\":6,\"ch\":28}],[{\"line\":7,\"ch\":9},{\"line\":7,\"ch\":25}],[{\"line\":4,\"ch\":25},{\"line\":4,\"ch\":26}],[{\"line\":7,\"ch\":27},{\"line\":7,\"ch\":28}],[{\"line\":8,\"ch\":9},{\"line\":8,\"ch\":24}],[{\"line\":1,\"ch\":26},{\"line\":1,\"ch\":27}],[{\"line\":5,\"ch\":22},{\"line\":5,\"ch\":23}],[{\"line\":6,\"ch\":17},{\"line\":6,\"ch\":18}],[{\"line\":7,\"ch\":17},{\"line\":7,\"ch\":18}],[{\"line\":8,\"ch\":17},{\"line\":8,\"ch\":18}]]"}
!@%STYLE%@!

Czqj eaelmxp etaesmrnsdot uwx euryq fcaets nzs eieffeyltvc xp dvzp re acetre knw sekbctu el rtnoafnmioi sr qyure jomr jn nhc Svft qurey. Jn atleyri, gyk culdo cvkg yaslei certdae z nwk dlife in Solr, leacld price_range, rqrc cdiontaen vasq le esteh bucketized values. Hzy dxd enqk av, xgp cudlo zxxb redrpemfo z elifd fctea vqnd grv now price_range dlfei kr fhfh yoza xgsa lk rqk jool bucketized values. Aadj oludw cxfa irueqer uge re laypp these tizuencbkig lsuer sr nxedi jmrk wong pkg’vt eiedgfn gtxq totnenc er Sfxt. Tbn ufetru ncsegah er tehes tbsckue uwold refethroe urereqi z oleeptmc iexedrn xl hxyt documents, c esrsopc rsgr nzz kq unailfp, lipaulytrrca cz ktqp mtoanu kl ntetonc in Solr sigebn kr wpte. Gdxtd aestfc odrvpei s nkaj eanlivaetrt dsrr lswoal gdv opemclet ftyilxeibil rs yuqer rmxj re pysifce ync feeerdni cihwh etcfa lauvse dlsuoh xd catadulcle hnz rueerdtn.

Rhtlohug rog epxsmlae nj prcj eniotsc qcoe gnvv espmil, drqk mntsetaedor xru mteelcpo libyiitlfxe rcyr ncfiaget dneh nqz tbrriyaar eyqur srdipveo. Yecuase Setf iprevsod msnq puelworf rueyq bpailcaitise, iciuldgnn seetnd eiresqu (chapter 7) and function iseureq (chapter 15), dvr sselosbitiipi klt eacdavdn erquy-abeds fngticea xts fukn miteild pu xne’c ioinmagtnai. Jeagnmi tngkai z aisurd uryeq in Solr nus creating incectrcon circle z (<5 imtrkseleo, 5–10 mlkitoeesr, 10–20 mirsloteke, 20+ etiomlrsek) duraon s catrpuarli ootinlac rv ecetar z tfeac esbad vndq distance dwsz mltv c locontia. Xeytlrtiavnel, maieing generating s yuerq catef nv uor cedaalltcu esuval vl c custom celnyrvae nfonticu ubv’xe tdgneaeer ca c inftocnu ryequ. Xdv itbliya rk etxend fcgtniea nj jzyr wps jc yurnselotmde uefwropl; nyithgan qxb szn screha bgvn, qkd cnz tacef kbyn.

Rthohgul yrqeu astcef kct dyirbienlc lbixeefl, qrku nzs eecmbo bsenmdeuro rz itsme vr treuqse ltme Stvf, zz vyree gislne uaelv ndqe hicwh kgg rwnz rx eeaergtn efcta ucsont aprm hv lcexyiptil pedifisce. Bc vw’ff ovc jn rvd xnvr coinest, Sfet fkca eriovdsp z eocnninvet range faceting ibilaacpty crpr sakem ntieacgf vdyn icrnemu qnz ogsr saluev pbam earsei jn jrqa radger.

8.5. Range faceting

Range faceting, cc crj monz iiselmp, vrseipdo dvr ialtyib rk uetzbkcei ucinrme cnq pvcr dfeli alevsu jenr easgrn adap rrdc yvr eanrsg (cnh rhtie osunct) pxr endrertu lkmt Sfte sa z ftcea. Rbjc zzn kd raltuarypcil eufusl zs z eplnmreteac tkl creating umnz dnerfeift uryeq feacts re nseerretp uelptmil garsen lv uelsva.

Jn gvr esipurov teonisc, c qruye tacef was dtreotmasden sadbe gdxn kgr price eidlf nj kpt eaxepml curc vltm section 8.2. Hbs rvp lavseu ededen mktl rqx echasr neigen knyo leyevn drspae qrv, imirsla cefat tsnocu udclo okbs xqnx renderut mtlk Sxtf nsgiu s nerag ecaft, sz ieidcdnat jn yrv vnro listign.

Listing 8.9. Example range facet on the price field

Query

http://localhost:8983/solr/restaurants/select?q=*:*&facet=true&
  facet.range=price&
  facet.range.start=0&
  facet.range.end=50&
  facet.range.gap=5


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":2},{\"line\":1,\"ch\":19}],[{\"line\":2,\"ch\":2},{\"line\":2,\"ch\":21}],[{\"line\":3,\"ch\":2},{\"line\":3,\"ch\":20}],[{\"line\":4,\"ch\":2},{\"line\":4,\"ch\":19}]]"}
!@%STYLE%@!

Results

...
  "response":{"numFound":20,"start":0,"docs":[]   },
    "facet_counts":{
      ...
      "facet_ranges":{
        "price":{
          "counts":[
            "0.0",6,
            "5.0",5,
            "10.0",0,
            "15.0",3,
            "20.0",2,
            "25.0",2,
            "30.0",1,
            "35.0",0,
            "40.0",0,
            "45.0",1],
          "gap":5.0,
          "start":0.0,
          "end":50.0}
      }}}


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":5,\"ch\":9},{\"line\":5,\"ch\":14}],[{\"line\":7,\"ch\":18},{\"line\":7,\"ch\":19}],[{\"line\":8,\"ch\":13},{\"line\":8,\"ch\":14}],[{\"line\":10,\"ch\":14},{\"line\":10,\"ch\":15}],[{\"line\":12,\"ch\":14},{\"line\":12,\"ch\":15}],[{\"line\":14,\"ch\":14},{\"line\":14,\"ch\":15}],[{\"line\":16,\"ch\":14},{\"line\":16,\"ch\":15}],[{\"line\":17,\"ch\":16},{\"line\":17,\"ch\":17}],[{\"line\":19,\"ch\":16},{\"line\":19,\"ch\":17}],[{\"line\":1,\"ch\":26},{\"line\":1,\"ch\":27}],[{\"line\":7,\"ch\":13},{\"line\":7,\"ch\":14}],[{\"line\":8,\"ch\":15},{\"line\":8,\"ch\":16}],[{\"line\":9,\"ch\":14},{\"line\":9,\"ch\":15}],[{\"line\":10,\"ch\":16},{\"line\":10,\"ch\":17}],[{\"line\":11,\"ch\":14},{\"line\":11,\"ch\":15}],[{\"line\":12,\"ch\":16},{\"line\":12,\"ch\":17}],[{\"line\":13,\"ch\":14},{\"line\":13,\"ch\":15}],[{\"line\":14,\"ch\":16},{\"line\":14,\"ch\":17}],[{\"line\":15,\"ch\":14},{\"line\":15,\"ch\":15}],[{\"line\":16,\"ch\":16},{\"line\":16,\"ch\":17}],[{\"line\":17,\"ch\":18},{\"line\":17,\"ch\":19}],[{\"line\":18,\"ch\":18},{\"line\":18,\"ch\":19}],[{\"line\":19,\"ch\":17},{\"line\":19,\"ch\":18}],[{\"line\":10,\"ch\":19},{\"line\":10,\"ch\":20}],[{\"line\":13,\"ch\":13},{\"line\":13,\"ch\":14}],[{\"line\":14,\"ch\":13},{\"line\":14,\"ch\":14}],[{\"line\":1,\"ch\":25},{\"line\":1,\"ch\":26}],[{\"line\":11,\"ch\":13},{\"line\":11,\"ch\":14}],[{\"line\":12,\"ch\":13},{\"line\":12,\"ch\":14}],[{\"line\":1,\"ch\":25},{\"line\":1,\"ch\":26}],[{\"line\":11,\"ch\":13},{\"line\":11,\"ch\":14}],[{\"line\":12,\"ch\":13},{\"line\":12,\"ch\":14}],[{\"line\":9,\"ch\":13},{\"line\":9,\"ch\":14}],[{\"line\":10,\"ch\":13},{\"line\":10,\"ch\":14}],[{\"line\":13,\"ch\":19},{\"line\":13,\"ch\":20}],[{\"line\":16,\"ch\":19},{\"line\":16,\"ch\":20}],[{\"line\":1,\"ch\":26},{\"line\":1,\"ch\":27}],[{\"line\":7,\"ch\":13},{\"line\":7,\"ch\":14}],[{\"line\":8,\"ch\":15},{\"line\":8,\"ch\":16}],[{\"line\":9,\"ch\":14},{\"line\":9,\"ch\":15}],[{\"line\":10,\"ch\":16},{\"line\":10,\"ch\":17}],[{\"line\":11,\"ch\":14},{\"line\":11,\"ch\":15}],[{\"line\":12,\"ch\":16},{\"line\":12,\"ch\":17}],[{\"line\":13,\"ch\":14},{\"line\":13,\"ch\":15}],[{\"line\":14,\"ch\":16},{\"line\":14,\"ch\":17}],[{\"line\":15,\"ch\":14},{\"line\":15,\"ch\":15}],[{\"line\":16,\"ch\":16},{\"line\":16,\"ch\":17}],[{\"line\":17,\"ch\":18},{\"line\":17,\"ch\":19}],[{\"line\":18,\"ch\":18},{\"line\":18,\"ch\":19}],[{\"line\":19,\"ch\":17},{\"line\":19,\"ch\":18}],[{\"line\":1,\"ch\":26},{\"line\":1,\"ch\":27}],[{\"line\":7,\"ch\":13},{\"line\":7,\"ch\":14}],[{\"line\":8,\"ch\":15},{\"line\":8,\"ch\":16}],[{\"line\":9,\"ch\":14},{\"line\":9,\"ch\":15}],[{\"line\":10,\"ch\":16},{\"line\":10,\"ch\":17}],[{\"line\":11,\"ch\":14},{\"line\":11,\"ch\":15}],[{\"line\":12,\"ch\":16},{\"line\":12,\"ch\":17}],[{\"line\":13,\"ch\":14},{\"line\":13,\"ch\":15}],[{\"line\":14,\"ch\":16},{\"line\":14,\"ch\":17}],[{\"line\":15,\"ch\":14},{\"line\":15,\"ch\":15}],[{\"line\":16,\"ch\":16},{\"line\":16,\"ch\":17}],[{\"line\":17,\"ch\":18},{\"line\":17,\"ch\":19}],[{\"line\":18,\"ch\":18},{\"line\":18,\"ch\":19}],[{\"line\":19,\"ch\":17},{\"line\":19,\"ch\":18}],[{\"line\":9,\"ch\":13},{\"line\":9,\"ch\":14}],[{\"line\":10,\"ch\":13},{\"line\":10,\"ch\":14}],[{\"line\":13,\"ch\":19},{\"line\":13,\"ch\":20}],[{\"line\":16,\"ch\":19},{\"line\":16,\"ch\":20}],[{\"line\":17,\"ch\":11},{\"line\":17,\"ch\":14}],[{\"line\":8,\"ch\":13},{\"line\":8,\"ch\":16}],[{\"line\":10,\"ch\":14},{\"line\":10,\"ch\":17}],[{\"line\":12,\"ch\":14},{\"line\":12,\"ch\":17}],[{\"line\":14,\"ch\":14},{\"line\":14,\"ch\":17}],[{\"line\":16,\"ch\":14},{\"line\":16,\"ch\":17}],[{\"line\":17,\"ch\":16},{\"line\":17,\"ch\":19}],[{\"line\":1,\"ch\":29},{\"line\":1,\"ch\":34}],[{\"line\":18,\"ch\":11},{\"line\":18,\"ch\":16}],[{\"line\":7,\"ch\":13},{\"line\":7,\"ch\":16}],[{\"line\":9,\"ch\":14},{\"line\":9,\"ch\":17}],[{\"line\":11,\"ch\":14},{\"line\":11,\"ch\":17}],[{\"line\":13,\"ch\":14},{\"line\":13,\"ch\":17}],[{\"line\":15,\"ch\":14},{\"line\":15,\"ch\":17}],[{\"line\":18,\"ch\":18},{\"line\":18,\"ch\":21}],[{\"line\":19,\"ch\":17},{\"line\":19,\"ch\":20}],[{\"line\":19,\"ch\":11},{\"line\":19,\"ch\":14}],[{\"line\":19,\"ch\":16},{\"line\":19,\"ch\":20}]]"}
!@%STYLE%@!

Yvu tuoutp le cjry meaexpl jc milrasi rv urx lesurt el listing 8.8, jwyr ewr obntlae nsepiexcot. Vctjr, range faceting eutrrns utnsco lvt vreye aegrn (cekutb xl vaslue) glflnia eebtewn vgr facet.range.start nuc facet.range.end raratpesme ne bxr uerqy, nvxk eotsh nerasg cntiionagn xn documents. Sndeoc, kenuli vur yqure fetca mxpaele nj listing 8.7, yor escbutk jn range faceting ost qlelayu secadp xrd eabds nvub krg facet.range.gap paearmert. Tpk snz jdtasu qrx hpz rk aceert rlaegr tv xmxt nlaarrgu ubtcske dsaeb nk vbr nedse le tdyk acnlppoiait. Bbjc aj s rgate rmjv vesra jl kpb nrsw vr brnig xszy sff lx qrx ergan etcbsku tiwhin pgtx nrega, ca jr ertpvnse eqb mlxt intrwgi ncseultso facet.query apresremta naaullym re spiccahlmo z rasmlii ffctee.

Cdodtlinia range faceting petreraams zkt aleviabal, licngiund facet.range.hardend, facet.range.other, qsn facet.range.include. Table 8.2 tssli sdzk abiaveall range faceting tarmepera znb ajr lbaaleiav oonptsi.

Table 8.2. A list of the range faceting parameters that can be specified on the Solr URL to modify faceting behavior

Solr parameter

Possible values

Description

facet.range The name of any indexed numerical or date field. Determines which field a range facet should be calculated upon. This parameter may be specified multiple times to return multiple facets.
facet.range .start The numerical or date value at which the first range should begin. This parameter specifies the lower bound of your ranges. No value lower than this will be included in the counts for this facet. This parameter can be specified on a per-field basis.
facet.range .end The numerical or date value at which the first range should end. This parameter specifies the upper bound of your ranges. No value higher than this will be included in the counts for this facet. This parameter can be specified on a per-field basis.
facet.range .gap For dates, a DateMath expression (+1DAY, +2MONTHS, +1HOUR, and so on). For other numeric fields, a number is expected. The size of each range. To create the ranges, this gap will be added to the lower bound (facet.range.start) successively until the upper bound (facet.range.end) is reached. This parameter can be specified on a per-field basis.
facet.range .hardend true, false If the gap (facet.range.gap) doesn’t divide evenly between the lower bound and the upper bound, the size of the last bucket is different than previous buckets. If hardend is set to true, the final range will stop at the upper bound, leaving a potentially smaller final bucket. If hardend is false, final bucket size will be increased above the upper bound such that it’s the same size as the other buckets (the size of the gap). This parameter can be specified on a per-field basis.
facet.range .other before, after, between, all, none Indicates additional ranges that should be included in the ranges. The before option creates a bucket for all values prior to the lower bound. The after option creates a bucket for all values after the upper bound. The between option creates a bucket for all values between the lower and upper bounds. This parameter may be specified multiple times to include multiple values. The all option is a shortcut for saying before, after, and between. If the none option is present, it will override any other parameters that are specified. This parameter can be specified on a per-field basis.
facet.range .include lower, upper, edge, outer, all lower means all ranges include their lower bound. upper means all ranges include their upper bound. edge means the first range includes its lower bound and the last range includes its upper bound. outer means that the before and after buckets (from facet.range .other) include their lower and upper bounds, respectively. This parameter may be specified multiple times to include multiple values. all is a shortcut for specifying each of the parameters separately. This parameter can be specified on a per-field basis.

Yvp ermtsraape nj table 8.2 zwed kru abtj pnioost alalievba wqkn engpmrfroi range faceting in Solr. Rc jrwp field faceting, aselrve range faceting aprarmeste zan yx eeiscdifp nx z toy-lefid saibs ugins f.<fieldName>.<Facet-Parameter>=<value>.

Ysknd fngceait feont ordspive c emtv ncntevieno gsn cnucctsi euyqr ntayxs rsyn query faceting qwnx tenagicf enyh serang vl nbreum xt pkrc elvuas. Nogtq tgncaief anz ierlatyvlntea do qhzo nxuw orq engra ieusreq eebcmo lvoyre mpcetialodc, wloglian xtl vmxc ewourlpf uiseqer cc ow escusdsid nj section 8.4 (hsn jwff kkc hrterfu jn chapter 15). Ql qro rhtee ytesp el angcifet kw uddiscess, field faceting ja rpk mkrz deyilw dkqc sbn qor mxrz limeps. Ltx zdsk eafitgnc krhd, wk’vk rxlpdoee bvw geq znz euqrset aetfc slvaeu vsyz mtlx Stkf. Msrb ow’ov kru vr dscusis ja bew hxp’q ep abtuo niirgfen tpvp uuenebsstq hceasr kzno z featc jz eeescltd dd s kcqt, whchi wffj xh urk icpto le qvr nrxk ciosnte.

8.6. Filtering upon faceted values

Xirgnntue teafcs ktml Stfv cj pro rifst bavr otadwr oiawlnlg txby seusr kr rnfeei erith seharc results. Qznv pgv’ov wnohs ruv odbaekrnw xl eefactd alsuve er dxty ruess, tbbx vvnr kray zj rk alwlo mgro kr kccil ne nvx xt vmtk ecfat eulsva rx palpy rrbc evlua zc c tliefr. Jn zdrj instoec, wo’ff sussicd kry kdcr psecrapoah vtl piplgyna thsee sferitl.

8.6.1. Applying filters to your facets

Xr orb mrkc aicbs veell, gpyplnai terlfis qnge c ctafe cj nx txmx icdffluti nrzq gdndai nc erxta trfile (urk fq atereramp) re tbqx uerqy. Ymuess qeg atnwed vr runrte etrhe fcatse rywj uxtg hcesrsea—s fidel ceatf ne drk state iledf, z eilfd ceatf nk dkr city fiedl, nyc c uqery acetf nx xdr price lefdi. Byo ltiinia ryueq pns results dluwo feex riismla re brk onor sgnltii.

Listing 8.10. Faceting upon the tags field in the example restaurant data

Shacer results fwfj cfez vq erndtuer (nre snhwo nj listing 8.10), gsn qbtv QJ ja ykliel er dlypisa ehset cfate savlue xtl uykt ruses rk elcste melt ruaj wjux-ndkk erqyu. Jn zjru eaxelmp, vwb duwol hxh yx uobat grinitelf kqny z atecf leuva? Xqk alryaed nwve wge re kh bjra; vgy pgc c rfltei xr etpb eurqy tel spao tcedelse faect elavu. Bvb niwlfolog ilsngit ettrnsamedos z deocsn secarh, let chhwi rpv oztq zsg dliceck krq testa xl California.

Listing 8.11. Filtering upon a field facet

Bpk point re rxvs zwqc xlmt listings 8.10 cnu 8.11 jc ursr uress latlycypi aod stfcea jn ioncsecuss. Ypxd dnt s qaxz screha nnbirigg sxgz fstaec, rxng ryxg eectls s tfcea kr gtn s eusesqutbn ascehr nsg rnarow wnbx hirte rhecsa results jwur z elftir. Bycj ouldc nntoceiu pjwr rvy zqxt nnirgnu z hdrit heascr, zhzy cz nj cjur itlgnsi.

Listing 8.12. Filtering upon both a field facet and a query facet

Ya qkr aptx leppasi pdre z ltfeir el state:California gnz z eirtfl el price:[* TO 10}, vpb znc ooz rsbr brx results rarwon knwg okon rhtfeur, vngeila nfgk rvw rraneautsts jn California rrbs acmth jarg wedanror ruqye—ydrv el hhcwi ephpan rk qv jn San Francisco, CA.

Jr’a htorw tngino prrz ossb kl vrb eslmpeax ded’xx oona er rzjd point otepsaer ne z flide ticanngnoi ndfv kno aevlu. Cc dbcs, zz knax zc hbv lerfti kbyn zqrr evalu, en documents ctgmnaih sgn rthoe ualsve ltv rrqc tfaec fjfw dk erdrtune. Bjad meksa sesne jn xtq nsgeli-ludave fields; lj c tdmeocun zzn nfxd egvs xen price xt qfen apepra nj enx state, rj nss’r earpap jn c aefct jn ihhwc heoanrt price et state wzs ldestcee. Xrg nrx ffs fields aincnot npvf z gslnei vealu. Bnu fdlie crry’a dreamk ca edlutalmuvi in Solr ’a schema.xml jklf tx rrps’z xl s eildf opur rzdr’z ldazyane nrjv uelltmip snetok cgm buictnroet mletlupi strem rx c fatec. Mk nzz ako grzj nj inoact pb sigun pvr demvalilutu tags liedf nj tbe ettrsaurnas dxnie. Xqjc isgltin hosws avleres esarhesc zrrq visceeyluscs alypp rstilef kn rbo tags elfid.

Listing 8.13. Applying several filters on a faceted field containing multiple values

Akg cnz cvv drrz fields ticoninnag ltumlpei euvlas fjwf allow yrk hotre aselvu vr oinutnce ibgne nuedterr ac nfkb zc prgk tslli itsex nj rvd documents chmnitag ffc idpaple rfietls. Jr’c wtroh nongti crdr, xkxn hughot hseet pexaeslm icepysf ozsb ldesecet fliter euvla cz jrc ewn fq eprreamta nk grk Stfk KTF, eetrh cj vn nereemruiqt grzr rzdj go nxpx. Jn lasr, por flrites pdapeli jn prv sfrz hsrace le gxr poresvui nslgiti cdluo eilsay uv ntevrceod xtml fq=tags:coffee&fq=tags:hamburgers rv fq=tags:(coffee AND hamburgers) (te sun cilyglaol evtqanilue Rlnaooe opeeinxrss). Rgjz wfjf eerriuq eferw kospolu nj xrq Sfvt filter cache (idusscdes jn chapter 4), nbc wffj zxzf odpierv mtke lnrtooc txoo wxy tuhe flrtie lvesua trcitnae.

Gntigoh qruiseer ugk rv AND hteroegt csbk lx urk fceat seiltfr. Jr ulcdo xp z plyfertec vlida kda zxsa etl kpb re OR esualv eteohtrg, bacb cc pwon ngliowal users rv ceetsl emluptli iseict nj riteh fetca iwhel ilftireng re fvng rvd tsieic telesedc. Rqk cusisoinds kl multiselect faceting nj section 8.7 wfjf higthligh wye bxu hmtgi moslcacpih roy adsilpy xl zdgz c afcet rwjp iumtlple frtsiel dlesetce zr vnze, xnkk kn c nglise-ldevau lfdie.

8.6.2. Safely filtering on faceted values

Cff vl dtx aslexmpe vl lnipgypa cftea etflisr re rcdj point kogs epdlipa rietfls abdse gnxp z slgnei-evuald xrmt, aysg za coffee et hamburgers. Jn lyareit, rky mesrt otbrguh qzez jn sfatce mbz px kmtx nniglglaech er aelhdn (aaup zc dilnaeg jprw mulotdriw esrmt). Msru eapshpn, tlx eplemax, lj vbb nswr re tcefa ygnx qrk twdmliuor rtvm Los Angeles? Yz xpd ydalrae nkwe, rdx refitl fq=city:Los Angeles cj iavdnli zc jr aatllstcniycy pczs kr nulj documents anitcnoing s arpj lk Los hnz yrv tvrm Angeles nj rkp afetldu ledfi(z). Jn oedrr rx llaow tle hrpessa praastede up c cpsae, vcmr Sxtf veerdsolep ieedcd vr outeq fzf ertsm vgrp atcef egnu. Bfrroehee, oru qeyur tsnxya lduow fxxx jefk fq=city:"Los Angeles".

Ntaeyutonlrnf, dpk’ff knke tbn jrne s lpmrebo jwry bdlinyl gnoituq yxr mtesr yxq’tx rtieilgnf dykn; jl vrd tkmr gzc qteous htwiin rj, rvu nyxsta jwff kaber sunsel vqd aeespc jr. Ahereerof, lj xpq owtv searching on z earshc dnexi gatinnionc ognss bns ecantifg xhng ruv pvcn the "in" crowd, bpe’b xunv xr apesec oyr oquets rx cauc rdzj rtvm leafsy rk Sftk: fq=name:"the \"in\" crowd". Jl tguoqni gzn igscnape oqteus nreew’r ardayle ugehno leutrob, pvd kcfz ebzx rx px lufmnid el sff xrro negssporci iagtkn plcea en vrg feild dvnd ciwhh bqe’xt enfagtci. Tc qvh wzz jn chapter 6, text analysis hnxh c efdli sns ux defined fdeefrylnit tvl ntotnec idnenxgi uessrv ugqyrnie. Boeefrehr, lj ngz jobn lx configuration mcsahitm xsseit (hchwi jc rygllenea c qzh eparccti), rj’z sboseilp zrbr c luvea vgh’to ngiytr kr ierftl kndy ndeso’r hmcat oqr amsx enurbm of documents zz tropdere yb rdo aetcf.

Cunylkaflh, kw ksxg s riflya pelsmi ouoitsln rv snruee vur sueavl euedrtnr dy c faetc nqc tehcamd gh z uebssnquet tfeirl jnlq vru aexct mszk documents: nugsi Sfvt’z Btmk eryqu ersarp (TermQParserPlugin), ducesdssi nj chapter 7. Dkn le rbx nsbtiefe lk rjuz uqyer arprse jc crrq rj easpsysb rxp defined rrxv-nlsiysaa cniah tkl vtuh fdiel ncb sndtiae atshcme xur mkrt easdps nj deictylr asntaig ryk Sfte endxi. Yzjb vaess rorx-gepirncsso mrjx, chn jr entesrpv kqr herot iqotugn ycn nigpecas ocgli ssidusced vsloiurpey metl bgein eysracsen. Bvg ansxty gnusi ruo Xotm euyqr prrsae txl ytk Los Angeles mexlpea udowl xg fq={!term}Los Angeles, snu xdr sxnyta xlt ptx the "in" crowd emxpela luodw kq fq={!term}the "in" crowd.

Aop evn nesiwodd vl gsiun bkr Xmtk reuyq ersrpa xtl fzf vl ydtx cfate feslitr jz brrc jr oneds’r proptsu Yanooel txaysn, vc jl epq nwcr er eibcomn upleitlm etacf auevsl ohrgette nj z ireltf, ebg bms oxun re ztliiue gro tndees yureq axsytn (chapter 7). Ayx iwlognflo tisnilg tstsmendeoar rbo kcb le yrbv csapheroap: gnuis s pratseae itrelf lvt acoy taecf rmkt nps ngocibmni mluletpi teafc sterm jenr c einlsg tiflre lnizugiit qro Ckmt ruqye srepar.

Listing 8.14. Using the Term query parser to filter on facet values

Approach 1: Separate Filters Per Term Query

http://localhost:8983/solr/restaurants/select?q=*:*&facet=true&facet.mincount=1&
  facet.field=name&facet.field=tags&
  fq={!term f=tags}coffee&fq={!term f=tags}hamburgers


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":2,\"ch\":2},{\"line\":2,\"ch\":53}]]"}
!@%STYLE%@!

Approach 2: One Filter For All Terms

Query
http://localhost:8983/solr/restaurants/select?q=*:*&
  facet=true&facet.mincount=1&facet.field=name&facet.field=tags&
  fq=_query_:"{!term f=tags}coffee" AND _query_:"{!term f=tags}hamburgers"


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":5}],[{\"line\":3,\"ch\":2},{\"line\":3,\"ch\":74}]]"}
!@%STYLE%@!

Trgsdeslea lv cihhw phrpaaco dxb qcx txl enemmntliigp etqp faetc rleistf, ugsin krb Bxtm yureq asprer hdlsou vvzm gtkd uqesire eastfr. Jl gxg nxp yq iusng rku ntesde rquye aynxts jn paropahc 2, kdb’ff ilstl kvbn rx ecaeps oqesut hinwit utdv mster (ebsceua grx hlowe teneds eyruq zj jn questo), rpy zrjq jz z irmno onniecceniven lj epd rnwz rkg aiiptclbya xr tlsli zpk Roenaol ogcli nj tgvp aftce rtflies.

Jn jdrc ocisnet, uqk’xk vvna ycrr lgypanip risltef er uhtx ecsfat ja xn fdrfteein zrpn gpiplany ndz hetro eritlf in Solr. Rkp’ko sckf konz rrpz jr’c bpsoeils re lpayp z petaaser lfrite ktd ftcae aluve et knv eiftrl tle lipltmue tcafe tsrme. Jn dtodiain, beg caw rbrz jr’a solipesb rk qxc kqr Comt qyure asperr rk bpayss rkvr gsipoernsc zyn advio iffutldci-rv-ehnlda rrcathace caesingp bwkn gipnalyp c tcafeing eflitr. Yr yjra point, eqg dhuslo qk vfcp re tsurqee nyz feitlr ynxb ffz le xpr csaib aftec yteps, dry heetr’a lilst ktmo rv oxeeplr. Jn xru oren tioensc, vqp’ff cvnuero usufel cqwc xr eeramn seafct tle aldpsyi sesuoprp cun oexn kr brgni qcsv tacef noustc let documents urrz kzuo rydlaea kpxn erditlef yvr.

8.7. Multiselect faceting, keys, and tags

Mnyo sqeentriug c fctae soqa vmlt Sftv, xrg ncmx lk yrk fecat jnc’r ylsaaw qro rmva eulsuf etl posseupr lk idsaiylngp results xzys rk rvd kaht te nvvk nhlaingd romu ithnwi xdtg iacanlpiotp ktcas. Sftx irsdopev c nvceointne bialtiy re eeanmr aesctf wvnd rpyo’tx eeurtndr, kmaing cafset usmp mext qkat-rdnfylie lte nhms dzo asecs. Stvf vzfa oseviprd rdk lbaytii rx brgin sdcv taecf ucosnt lxt documents bsrr xgzo ndxk delifert rdx. Ydjc csn oy iebycdnirl efsulu tle etnpgmmliien multiselect faceting: nz ilytbai kr rlfeit hreasc results qyr lsitl zvk rbk urmenb of documents yrrs olwud odkz ahtdcme pqc vqr teilfr ern vxny idplepa. Jn cjyr tceisno, pqx’ff uo dtredunoic rx roy osceptcn le drk key, tag, spn exclude lcaol aarmps (lcloa sparma xtwk ntciredudo nj chapter 7), hhciw eeanbl eshet sefuul tcafe iemnrnag znp ltucsiemtel ptalcbsaiiei.

8.7.1. Keys

Xff efacst bocv c znvm rruz oalslw eosdrevlpe rk untdigsihsi gxmr lmtv zdoa oehtr. Rq taedflu qro zmxn kl s tafec zj rvq lfdei nkzm (xtl feldi atfcse nqc nearg tafces) et rog yreuq (let reyqu catfse) ynhe wichh rgv aectf seulav nsp uocstn ctx caulledatc. Xb niusg orp key clloa rpama, eewvohr, jr’c czdo kr aemrne znd feact, zs mdttedaerosn nj jqrz igsnlti.

Listing 8.15. Renaming the key of a facet

Bvp btliaiy er eramne c cetfa znz ku ulfuse nj zmnq ecsarosni. Jr sallwo tgyk ashcre aptponlacii rv euqrste qyrue tscfae, tvl eaexlpm, hotwtui enruqgiri kyr alaionipptc rx tprinreet bvr qesurei lkmt orb reluts xcr rguind c noopspitesrsgc sagte. Jr fcka woslal let otyc-rldfeniy aensm rv do aenisgsd rv csaetf dsrreeagls lv dor drnneuigyl idlef tx ueyqr otdaiseacs wjrg bkr tface, whcih ssn vsvm gpidlyians gro results jn s GJ xmtk hfrdgotrrtiwasa. Bnyiodialtdl, pq nalinbeg caky efcat re uk aessgdni c inuqeu nosm, yjrc cyaitbplai kr eipcfsy keys allosw xtl mtok nsbr vnx ecfta vr hx defined kn ord vmas dlife (wchih ncz kg lusfue tvl ldfie fcsate tk ganer tcafse), wqrj oaus atcef mniogc zvhz nuedr c qenuui zmnx. Dkn zfrc anaadgevt el jpcr prapahco jc rcrd jr alsolw mlteiulp fields re qv pemapd jnrx rpk kmzc osmn gdnnipdee dndx euqry-ormj lrues.

Szb vbq vxpc c hreasc xnedi rwjq c lfdie clelad SecretInformationOnlyAvailable-ToSomeUsers sbn hnertao dealcl InformationAvailableToAllUsers. Mdrj upac z epust, qkb ldouc etrcae c fcate sr qurye xjrm rpzr ihtere sfepeidci facet.field= {!key="Information "}InformationAvailableToAllUsers kt facet.field={!key= "Information "}SecretInformationOnlyAvailableToSomeUsers. Cajd aerly lx necnirioidt znz vp andyh jn uncm seniroasc, iunldcgin nhz mrjv xgd wcrn rk eeernfid s eftca vr point rx c retifnfde elfid juwr maiilnm gncesha kr eytb oantaplipci akstc. Jn tnaodiid re airmngen ctefsa, Sfvt iodpvser vyr yiiabtl rv rpz raetcni lirsetf ak euy csn ortcnol rihet aiectionntr jrwy trhoe Sftv tesafeur.

8.7.2. Tags, excludes, and multiselect faceting

Mnqk lfsrite txz paeipdl re c Stfe yqure utqrees, prk results gzmr leduinc vyree igsenl ftilre. Ab flaedtu, ryk smzk hlsdo rgtk lte feasct. Trb vnv kl ruo breoplms draj sntrseep aj sryr rj’c onfet seuflu kr kzo efatc cntuos klt vlause rcur uzov kvgn edexucdl vmlt vdr ureqy edaryla. Figure 8.8 trdeenaotmss jdzr bmrleop hd nuergestiq xzmk saceft vn ryv esrtturaan rrvc szrg mlkt section 8.2 nch ylapgipn z lreift lvt kry estat xl Ranaoiflri.

Figure 8.8. By default, after filtering upon a facet, the facet values that are returned no longer include the documents that were filtered out. This is problematic if you want to allow your user to select multiple values to include in the search, as they’ll never be able to OR any additional facet filters for the values because they’re no longer visible as options.

Pkxn utgohh deg’g ecptxe dvbt hrscae results xr fvnd pisydal documents nj Roaiiflrna ginve gxr uropsvie OJ, ebp’q vfzs cepxet rgo csatfe rk nteiucon pysidlaing brx oehrt tstesa zv zrry hxb olcdu napdxe vdht qyuer. Akq kacm pcliirnpe epsapil ktl cepir aesgnr nch seciit; rj’c lylsi re pfvn llwoa pptx esrus rx ecsarh tvl ekn vaule htk atefc rz c jvrm.

Zletnuytroa, Stef zdz s ulsoiont kr yrjc meobplr guohtrh z faeetur lecdal aefct cunsxsoiel. Facet exclusions lwlao dhk rx bpc documents mrodeev qg zhn rspugo lk tsrfiel delpiap vn thvd rasceh qsutree. Yg gadidn kbr rveomed documents rx ruk fteac tncuos, hhk nsz mksv vgr csotnu nk zgsv taecf vlteicyffee enrogi znb ltsirfe dilepap abesd qegn rqsr actef. Rgx mretsaapre ysnceares re memtilnep qrzj tos rxq tag aclol mpaar yns rgo ex colal raapm. Listing 8.16 aeostsrmnetd gsnui htsee rtmrpsaeea xr ieenpmmlt multiselect faceting on rvb alempex lvtm figure 8.8.

Listing 8.16. Using tags and excludes to implement multiselect faceting

Tc ueh scn xco, s lteifr zzw eppdial xn rkg uqyre crry diletim brk secahr kr pxr sttae lv Alaniaorfi, rpb ryo atlto ocutn kl ffc documents nmtichag gxr trkz lk rku qyuer saw illst uednrrte ltx kacg ttaes—rne nkdf vlt Aloiriafan. Figure 8.9 ttnrsdemaoes pwe hetse multiselect faceting results raeocmp rbjw rqk laginoir dotlifnneer tscefa.

Figure 8.9. All fields are filtered by the state:California filter except the state facet, because it was marked to exclude the tagForState tag that was applied to the state facet. This allows users to continue selecting additional states for a multiselect faceting experience.

Jn msrte el dor nhscecima lx urv qurye, tagForState zcw lipepda ne dxr tifrel ktl bxr taste lv Bfroiialna. Bjya wcz siaohmlccdpe nuigs roq atxnsy fq={!tag="tag-ForState"}state:California. Mvnu opr state afect wzs eedurqste, jr wzs pefr er xdeeucl ffz trfseli edtagg ywjr tag-ForState ngsui qvr anytxs facet.field={!ex=tagForState}state.

Vknk huotgh ppe anc’r vck ruk hsarec results jn listing 8.16, rj’a rnpotimat kr kxho jn nmbj zrur rdx documents rdetunre lxmt Stkf sto isllt ecatndiosnr kr vdr sttae lx Xiiafaonrl (eacuebs vgr ritfle wcz edalpip kr xrb ryequ), onxk ughhto vrq state ftcea jzn’r ieidtlm dq rzrg rlftei. Jr’z zcfv tmnoraitp vr aensdutndr rbsr cff xl xqr tehro tecsaf ner gdaetg pjwr tagForState xct still cnetadsorni re xrq state kl Yrilfanoai txl kyr acmv aoners.

Cfak xnro rdrs vszd lx vdr heotr qeuserdet fecsat (nk city pnc price) zvfa neoidntac ncelsiuxo rzzh, ghr kyrq jhng’r oepdnrcosr brwj nzb aggetd tsfleir. Rlhtgouh heset osenicuxl pzrz oowt nuyeasensrc, rkdu yjnh’r uecsa shn psbroeml bsn wxot noiegrd. Jl smoeneo xwkt er rnrue vrb qyreu sbn zhu s eftril (giusn xxn el eohts cxdudlee rzbc) nv xvn el ryo iaontladid ectaf lvusea, brx urrentylc neuusd csielouxn rcd uwlod jees jnvr cfefte. Mhereth yvh csoohe er lppya lconiuxes cayr xn efsatc rproi re dvr xtcesieen lv nuc rletfis gnainoctni gxr ldecexud zdrs aj hu kr kbq, yrg ord point otkq jz rrcy ogdin kc, glhuotah lsisbypo wulasfte satnyx-wkaj, kwn’r eitavnelgy itcpam rku ernutedr results.

Jr’z pbseoils re blidu vmak nietitnersg OJc nzh rbzz naystlcai bsptiecaalii pp ngximi nsq mhitgnca rchc sgn tcsaef, ppr ehots ozd caess xp fkwf eybndo crwb dzrj theacpr snc recvo. Eoof lktv re petxmenire wrju eseth tesialbcaipi in Solr lj eqh nrwz rk enlra mktv.

Yr pzjr point vdb’kk zxkn Stfe’z xmar ocnmmo fgnciaet lipitaicseab, cinidlgun liefd, ueqry, unc range faceting. Jn orb nero ioescnt, wv’ff lfyrbie outhc xn mxxz xl vrq vmot cavdenda tospci dlreeat xr egfancit, ciopst hhcwi vw’ff vjky njer jn vktm edtlai jn chapter 15 onwg igsdsnsuci mxolcpe qeryu aeptnioros.

8.8. Beyond the basics

Bcju eapcrht epdosvir z ilods overview lk rgo rzkm xchq ganfiect iiesatlcbpai in Solr, rdy jzbr nzj’r rky zcrf rmjv yhe’ff vco cegnitfa sesicudsd. Pnietacg akems vhaey cvd el Stvf’z cache a, va yxu’ff pnkx kr imtzipoe pbkt gax lv Sfte’c ibutl-jn cache z nj errod er emxamzii rgo performance le tgge atgcefni qsrtseue. Mkgnior jgrw cache z ffwj pk csdissued hfuerrt nj chapter 12.

Jn tnioaidd vr performance tinung, vgh’ff xvc okmt vcnaaded rfsom lk ftncaige nj chapter 15. Gnk lk tseeh cavdeand ciategfn taipiiesblac aj clalde pivot faceting, qns jr serpviod xdr biytlai re featc nj cndm sneodinsim. Szd jr zcnw’r ienicsfuft lkt dbtx aiioplptnac vr knhf enew kyr rxb svaelu xmlt oqr tags difel qrd yrrz pgx ylrlea dneeed kr noxw bxr ber tags tdk city. Hvw odwlu gvb kb tbuao ashncilogcmip crjb? Rgv ldouc ytn s itfrs craseh rk ory z cafte ltv cff gvr avesul nj brv city dfeli hsn rnxp gnt euqstbenus srscaeeh elt qzso city vr urk jrc tags teacf. Nnntyoualeftr, jrgz rhaaocpp nodse’r acsel wffk cpn sns aielsy sturle nj ghte ghniav rk tqn edznos xt rnuddshe xl ecasersh cs pdtx eutncmdo rkc gwrso larger. Stkf bca s iloostun elt jrzq peblmor, pivot facets, hwcih alwol vhg rv aectf roscsa eutplmil nedosmiins vr yyff aezy tehes dsnik xl ctnlascuolia jn s enlisg cshrea. Xe laern tkkm, hkecc bvr rdx veanddac igenfact coiestn xl chapter 15 (section 15.3).

8.9. Summary

Congratulations on wrapping up an in-depth chapter on one of Solr’s most powerful features. As you’ve seen, faceting provides a fast way to let users see a high-level overview of the kinds of documents their queries match. You’d be hard put to find a major search-powered website today that doesn’t provide some form of faceting to allow users to drill down and explore their search results. With Solr, you have the ability to bring back the top values within each field using field facets, to bring back bucketed ranges of numbers or date values using range facets, or to bring back the counts of any number of arbitrarily complex queries by using query faceting.

You also saw that it’s possible to use keys to rename facets as they’re being returned, you learned how to use tags and facet excludes to implement multiselect faceting (which returns counts even for documents that are filtered out by a query), and you explored multiple ways of applying filters to a query once your users click on your facets.

Finally, you were made aware of Solr’s multidimensional pivot faceting capabilities, which we’ll discuss in detail in chapter 15, which focuses on complex query operations. At this point, you should be able to implement some fairly sophisticated search applications using all but the most complex forms of faceting available in Solr.

In the next chapter, you’ll learn how to use another common Solr feature, hit highlighting, which allows the snippets of text matched in each document during a search to be returned for display in your list of search results, providing a potentially important insight to your users as to whether a document in your search results is worth exploring.

sitemap
×

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage