0% found this document useful (0 votes)
75 views5 pages

Solr Requirements For Advanced Search: - Query - :" (!dismax QF $ (QF - Name1) PF $ (PF - Name1) ) (Xform-Query

1. The document describes how to map terms entered in an advanced search form to a Solr query. Each text box is mapped to a set of Solr fields and boost values. 2. The terms are transformed by adding required symbols or parentheses to preserve Boolean logic. Terms joined by AND have "+" added before and after. Terms in parentheses are treated as a single term. 3. Examples show how terms with AND, OR, and NOT are transformed to the proper Solr query syntax.

Uploaded by

vsnikam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views5 pages

Solr Requirements For Advanced Search: - Query - :" (!dismax QF $ (QF - Name1) PF $ (PF - Name1) ) (Xform-Query

1. The document describes how to map terms entered in an advanced search form to a Solr query. Each text box is mapped to a set of Solr fields and boost values. 2. The terms are transformed by adding required symbols or parentheses to preserve Boolean logic. Terms joined by AND have "+" added before and after. Terms in parentheses are treated as a single term. 3. Examples show how terms with AND, OR, and NOT are transformed to the proper Solr query syntax.

Uploaded by

vsnikam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

AdvancedSearch FromForminputtoSolrrequest 2/17/101:26PM

Page 1 of 5

SolrRequirementsforAdvancedSearch

ThisapproachtoBlacklightAdvancedSearchispredicatedonthefollowingrequirements: 1. Booleansyntaxmustbesupported 2. GroupsofSolrfieldsmustbesearchedforindividualtextboxesinthehtmlsearch form. 3. ThegroupofSolrfieldsforasingletextboxhavedifferentweightsamong themselves(querytermsmatchedinparticularSolrfieldsinthegrouphave differentboostfactorsthanquerytermmatchesinotherSolrfieldsinthegroup)

MappingTextBoxesinAdvancedSearchFormtoSolrquerypieces

Eachtextbox(orcheckbox)intheadvancedsearchqueryformmapstoaparticularsetof Solrfieldsandboostingvalues(plainboostingandphraseboosting)tobeusedintheSolr query.Theparticularfieldsandboostvalues(andphrasefieldsandboostvalues)foreach textboxwillbeconfiguredontheSolrserver,viatheadvancedrequesthandler. Theuserqueryitselfisalsotransformed;seebelowunderQueryTransformation. Foreachtextboxcontainingusersuppliedtext,therewillbeachunkinthevalueofqsent tosolrthatlookslikethis: Piecesinsquarebracketswillbereplacedwithspecificstrings.Theboldareallpartofthe actualstringsenttosolr:quotes,curlybraces,exclamationpointanddollarsignsareall senttoSolr. Soiftheuserhastypedintotwotextboxes,andthetextboxesaretobecombined(AND), thentheqparamsenttoSolrwouldhavethisform:
q=_query_:{!dismax qf=$[qf_name1] pf=$[pf_name1]}[xformed-queryterms1] AND _query_:{!dismax qf=$[qf_name2] pf=$[pf_name2]}[xformed-queryterms2] _query_:{!dismax qf=$[qf_name1] pf=$[pf_name1]}[xform-queryterms]

IftheuserchoosestocombinethetextboxeswithanOR,theqparamsenttoSolrwould havethisform:
q=_query_:{!dismax qf=$[qf_name1] pf=$[pf_name1]}[xformed-queryterms1] OR _query_:{!dismax qf=$[qf_name2] pf=$[pf_name2]}[xformed-queryterms2]

Atthistime,theqtargumentfortheSolrrequestMUSTbesettoastandardrequest handler(inourcase,advanced).OtherwiseSolrwillalwaysreturn0results.

AdvancedSearch FromForminputtoSolrrequest 2/17/101:26PM

Page 2 of 5

Iwillprovideamappingofadvancedsearchformtextboxestoparticularqfandpf argumentsintheconfig/initializer/stanford_config.rb,alongthelinesof:
config[:advanced] = { author => { :qf => qf_author, :pf => pf_author }, title => { :qf => qf_title, :pf => pf_title }, pub_info => { :qf => qf_publisher, :pf => pf_publisher } }

QueryTransformations

RecognizedBooleanOperators AND OR NOT Booleanoperatorswillalwaysbeallcharsuppercase(i.e.AND,OR,NOT).Lowercaseand mixedcaseexpressionsofthesewordscanbetreatedlikeanyotherword.Jennifer explainsthatthisisgood,becausewhenpeoplecutandpastetitlesorwhatever,theydont wantandAndorOrnotNotinterpretedasBoolean. ThedefaultoperatorisAND.Thatis,whenthereisnooperator,ANDisimplicit. Term: Booleanoperatorsworkwithterms:aword,oragroupofwords.Atermcanbe: charactersnotseparatedbywhitespace or aclausejoinedbytheAND(orplain,whichisimplicitAND)orORoperator: o dogANDcat o dogcat o dogORcat or asetofparenthesesandthecharactersinside o EACHsetofparensisaterm o whatiswithineachsetofparensneedstogothroughtreatmentbelowbut preservetheparens

AdvancedSearch FromForminputtoSolrrequest 2/17/101:26PM

Page 3 of 5

or

o example:(lesbianORgay)AND(videoORbook)has6terms: 1. (lesbianORgay) 2. lesbian 3. gay 4. (videoORbook) 5. video 6. book o parenscanbenested: o example:creamAND((filoANDdough)ORpastry)has6terms 1. cream 2. ((filoANDdough)ORpastry) 3. (filoANDdough) 4. filo 5. dough 6. pastry aclausejoinedbytheAND(orplain,whichisimplicitAND)orORoperator: o (lesbianORgay)(videoORbook)has6terms: 1. (lesbianORgay) 2. lesbian 3. gay 4. (videoORbook) 5. video 6. book

NestedParens EACHsetofparensisaterm whatiswithineachsetofparensneedstogothroughtreatmentbelowbutpreservethe parensandtreattheparentheticalexpressionasatermaswell.


(dog cat) AND mouse +(+dog +cat) +mouse (lesbian OR gay) (video OR book) +(lesbian OR gay) +(video OR book) (klezmer OR accordion) NOT Russian AND (score OR recording) +(klezmer OR accordion) NOT Russian +(score OR recording)

AND WhenANDisinuserquery,addarequiredsymbol(+)totheprecedingandfollowing termsandremovetheAND:


vladimir AND nabokov +vladimir +nabokov tom AND lynn AND jessie +tom +lynn +jessie (dog cat) AND mouse +(+dog +cat) +mouse (dog AND cat) AND mouse +(+dog +cat) +mouse ((dog cat) AND (mouse bug)) house +(+(+dog +cat) +(+mouse +bug)) +house ((dog AND cat) (mouse AND bug)) house +(+(+dog +cat) +(+mouse +bug)) +house ((dog cat) (mouse bug)) AND house +(+(+dog +cat) +(+mouse +bug)) +house

AdvancedSearch FromForminputtoSolrrequest 2/17/101:26PM

Page 4 of 5

Plain ThedefaultoperatorisAND,solackofaBooleanoperatorimpliesAND.Whenatermhas noprecedingNOT,ANDorOR,andhasnofollowingANDorOR,addarequiredsymbol (+):


vladimir nabokov +vladimir +nabokov black and tan +black +and +tan black not white +black +not +white (dog cat) mouse +(+dog +cat) +mouse ((dog cat) (mouse bug)) house +(+(+dog +cat) +(+mouse +bug)) +house

Combos:ANDandPlain
tom lynn AND jessie tom AND lynn mcrae +tom +lynn +jessie +tom +lynn +mcrae

OR ORcanbeleftalone.
nabokov OR pushkin nabokov OR pushkin (tom lynn) OR Jessie (tom lynn) OR Jessie

Combos:ANDandOR
(dog AND cat) OR mouse (dog OR cat) AND mouse tom lynn OR jessie (Lynn AND Naomi) OR (Stu +Jessie) (Lynn OR Naomi) AND (Stu Jessie) AND (+dog +cat) OR mouse +(dog OR cat) +mouse +tom lynn jessie Jessie) (+Lynn +Naomi) OR (+Stu +(Lynn OR Naomi) +(Stu OR

OR Jessie)

implicitparensinthesecases,theexplicitORtakesprecedenceovertheplain operator,e.g.betweengayandvideo.Wemustmakethatprecedenceexplicit withparens.


lesbian OR gay video OR book +(lesbian OR gay) +(video OR book)

NOT Whenthereisasingletermfortheuserqueryinatextbox,anditisprecededbyNOT, NOTwillmoveinfrontofthe_query_piece.


NOT cat q=NOT _query_:{!dismax qf=stuff pf=stuff}cat NOT (dog OR cat) q=NOT _query_:{!dismax qf=stuff pf=stuff}(dog OR cat) NOT (dog AND cat) q=NOT _query_:{!dismax qf=stuff pf=stuff}(+dog +cat)

WhentherearemultipletermsinatextboxandoneormoreisprecededbyNOT,theNOT shouldbeleftalone.
cat NOT cat NOT NOT dog NOT mouse +cat NOT mouse mouse cat NOT mouse +cat AND NOT mouse +cat NOT mouse mouse AND cat NOT mouse +cat mouse cat dog NOT mouse +cat +dog NOT mouse cat +dog NOT mouse +cat

AdvancedSearch FromForminputtoSolrrequest 2/17/101:26PM


dog AND cat NOT mouse dog OR cat NOT mouse cat NOT mouse OR dog

+dog +cat NOT mouse dog OR cat NOT mouse cat NOT mouse OR dog

Page 5 of 5

termsinparens:
(dog AND cat) NOT mouse +(+dog +cat) NOT mouse (dog OR cat) NOT mouse +(dog OR cat) NOT mouse NOT mouse (dog OR cat) NOT mouse +(dog OR cat) NOT (dog OR cat) AND mouse NOT (dog OR cat) +mouse

Note:NOThasprecedence,soiftheNOTtermisimmediatelyfollowedbyANDorOR,then thetermprecedingtheNOTisthefirsttermoftheAND/OR(thefollowingareequivalent duetothisrule):


cat NOT mouse AND dog +cat NOT mouse +dog (klezmer OR accordion) NOT Russian AND (score OR recording) +(klezmer OR accordion) NOT Russian +(score OR recording)

SingleTerm Asingleterminasearchbox,withoutanyoperator,maybeleftalone:
fred fred

singletermcanbeaparentheticalphrase
(joe OR fred) (joe OR fred) ((dog cat) AND (mouse bug)) (+(+dog +cat) +(+mouse +bug))

NOT blahthisisnottreatedasasingleterm,becauseoftheNOTSeeabove.

You might also like