Changeset 22053


Ignore:
Timestamp:
2010-05-06T13:07:08+12:00 (14 years ago)
Author:
davidb
Message:

Macro support for sql-query page added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/macros/query.dm

    r17929 r22053  
    2222_advformlist_ {}
    2323_regformlist_ {}
     24_sqladvformlist_ {}
     25_sqlregformlist_ {}
    2426#_fqfselection_ {}
    2527
     
    7173#######################################################################
    7274
    73 _pagescriptextra_ {_If_("_cgiargqt_" eq "1", _formpagescriptextra_, _selectpagescriptextra_)
     75_pagescriptextra_ {_If_("_cgiargqt_" ge "1", _formpagescriptextra_, _selectpagescriptextra_)
    7476_If_("_cgiarghd_" ne "0",_historypagescriptextra_) }
    7577
     
    8890  var args="";
    8991  args = "&fqa=0&fqv="+argfqv+"&fqf="+argfqf;
    90   _If_(_cgiargb_,args += "&fqk="+argfqk+"&fqs="+argfqs+"&fqc="+argfqc;)
     92  _If_(_cgiargb_,
     93     args += "&fqk="+argfqk+"&fqs="+argfqs+"&fqc="+argfqc;
     94  )
     95  _If_("_cgiarga_" eq "sqlq",args += "&sqlfqf="+argsqlfqf + "&sqlfqc="+argsqlfqc;)
    9196
    9297  return args;
     
    97102function getqueryargs () \{
    98103  return "&fqa=1"+"&q="+argq+"&fqv="+argfqv+"&fqf="+argfqf+
    99      "&fqk="+argfqk+"&fqs="+argfqs+"&fqc="+argfqc ;
     104     "&fqk="+argfqk+"&fqs="+argfqs+"&fqc="+argfqc+
     105         "&sqlfqf="+argsqlfqf + "&sqlfqc="+argsqlfqc ;
    100106\}
    101107
     
    152158    _If_(_jselection_,_getjarg_)
    153159    _If_(_nselection_,_getnarg_)
     160    _If_(_sqlsfselection_,_getsqlsfarg_)
    154161    _If_(_sfselection_,_getsfarg_)
     162     
    155163    if (document.QueryForm.t != null) \{
    156164      value = document.QueryForm.t.options[document.QueryForm.t.selectedIndex].value;
     
    180188}
    181189
     190# currently only supported in lucene
    182191_getsfarg_{
     192_If_("_cgiarga__cgiargct_" eq "q2",
    183193    value = document.QueryForm.sf.options[document.QueryForm.sf.selectedIndex].value;
    184194    if (value != "_cgiargsf_") stdarg += "&sf="+value;
     195)
     196}
     197
     198# only when in sql mode
     199_getsqlsfarg_{
     200_If_("_cgiarga__cgiargqt_" eq "sqlq2",
     201    value = document.QueryForm.sqlsf.options[document.QueryForm.sqlsf.selectedIndex].value;
     202    if (value != "_cgiargsqlsf_") stdarg += "&sqlsf="+value;
     203)
    185204}
    186205
     
    192211argfqs="_cgiargfqs_";
    193212argfqc="_cgiargfqc_";
     213_If_("_cgiarga_" eq "sqlq",
     214argsqlfqf="_cgiargsqlfqf_";
     215argsqlfqc="_cgiargsqlfqc_";
     216)
    194217argq = "";
    195218
     
    201224   if (document.QueryForm.fqk != null) \{initfqk(); \}
    202225   if (document.QueryForm.fqc != null) \{initfqc(); \}
     226_If_("_cgiarga_" eq "sqlq",
     227   if (document.QueryForm.sqlfqf != null) \{initsqlfqf(); \}
     228   if (document.QueryForm.sqlfqc != null) \{initsqlfqc(); \}
     229)
    203230   if (document.QueryForm.q != null) \{initq(); \}   
    204231\}
     
    272299\}
    273300
     301   
     302// sqlfqf - the field selection box
     303function initsqlfqf() \{
     304   var i;
     305   sqlfqf = argsqlfqf.split(",");
     306   num_opts = document.QueryForm.sqlfqf[0].options.length; // assumes all have the same  options   
     307   for (i=0; i<sqlfqf.length && i<document.QueryForm.sqlfqf.length; i++) \{
     308     if (sqlfqf[i] != "")\{         
     309       for (j=0;j<num_opts;j++) \{
     310       if (sqlfqf[i]== document.QueryForm.sqlfqf[i].options[j].value) \{
     311          document.QueryForm.sqlfqf[i].options[j].selected = true;
     312          break;   
     313       \}
     314    \}
     315     \}
     316   \}
     317   if (sqlfqf.length < document.QueryForm.sqlfqf.length) \{ // initialize remaining ones
     318      for (i=sqlfqf.length;i<document.QueryForm.sqlfqf.length;i++) \{
     319      var z=i;
     320      while (z >= num_opts) \{
     321         z = z-(num_opts);
     322      \}
     323      document.QueryForm.sqlfqf[i].options[z].selected = true;
     324     
     325      \}
     326   \}
     327   updatesqlfqf();
     328
     329\}
     330
     331function updatesqlfqf() \{
     332
     333   var i;
     334   argsqlfqf = "";
     335   var j = document.QueryForm.sqlfqf[0].selectedIndex;
     336   argsqlfqf += document.QueryForm.sqlfqf[0].options[j].value;
     337   for (i=1; i<document.QueryForm.sqlfqf.length;i++) \{
     338      j = document.QueryForm.sqlfqf[i].selectedIndex;
     339      argsqlfqf += "," + document.QueryForm.sqlfqf[i].options[j].value;
     340   \}
     341
     342\}
     343
     344
     345function clearsqlfqf() \{
     346   var i;
     347   for (i=0;i<document.QueryForm.sqlfqf.length;i++) \{
     348       var z = i;
     349       if (i >= document.QueryForm.sqlfqf[i].options.length) z = z-document.QueryForm.sqlfqf[i].options.length;
     350       document.QueryForm.sqlfqf[i].options[z].selected = true;
     351   \}
     352   updatesqlfqf();
     353\}
     354
     355
     356
     357
    274358// fqc - the boolean operator selection box
    275359function initfqc() \{
     
    332416\}
    333417
     418
     419
     420// sqlfqc - the SQL operator selection box
     421function initsqlfqc() \{
     422   var i,j;
     423   sqlfqc = argsqlfqc.split(",");
     424   if (_cgiargsqlfqn_ == 2) \{ // there will only be one sqlfqc element
     425       for (j=0;j<document.QueryForm.sqlfqc.options.length;j++) \{
     426       if (sqlfqc[0] == document.QueryForm.sqlfqc.options[j].value) \{
     427          document.QueryForm.sqlfqc.options[j].selected = true;
     428          break;
     429       \}
     430       \}   
     431   \}
     432   else \{   
     433   for (i=0; i<sqlfqc.length;i++) \{
     434       for (j=0;j<document.QueryForm.sqlfqc[i].options.length;j++) \{
     435       if (sqlfqc[i] == document.QueryForm.sqlfqc[i].options[j].value) \{
     436          document.QueryForm.sqlfqc[i].options[j].selected = true;
     437          break;
     438       \}
     439       \}
     440   \}
     441   \}
     442   updatesqlfqc();
     443
     444\}
     445
     446function updatesqlfqc() \{
     447 
     448   var i,j;
     449   argsqlfqc = "";
     450   if (_cgiargsqlfqn_ == 2) \{
     451      j = document.QueryForm.sqlfqc.selectedIndex;
     452      argsqlfqc += document.QueryForm.sqlfqc.options[j].value;
     453   \}
     454   else \{
     455    j = document.QueryForm.sqlfqc[0].selectedIndex;
     456    argsqlfqc += document.QueryForm.sqlfqc[0].options[j].value;
     457    for (i=1;i<document.QueryForm.sqlfqc.length;i++) \{
     458        j = document.QueryForm.sqlfqc[i].selectedIndex;
     459        argsqlfqc += "," + document.QueryForm.sqlfqc[i].options[j].value;
     460    \}
     461   \}
     462
     463\}
     464
     465
     466function clearsqlfqc() \{
     467   
     468   var i;
     469   if (_cgiargsqlfqn_ == 2) \{
     470       document.QueryForm.sqlfqc.options[0].selected = true;
     471   \}
     472   else \{
     473    for (i=0; i<document.QueryForm.sqlfqc.length; i++) \{
     474        document.QueryForm.sqlfqc[i].options[0].selected = true;
     475    \}
     476   \}
     477   updatesqlfqc();
     478\}
     479
     480
     481
     482
    334483// fqv - the query word/phrase text box       
    335484function initfqv() \{
     
    473622       ch=str.charAt(j);
    474623       if (ch == " "|| ch == ",") \{
    475            if ( flag == 0) \{     
     624           if (flag == 0) \{     
    476625          out += "+";
    477626          flag=1;
     
    480629    \}
    481630    if (ch == ";" || ch == ":" || ch == "/" || ch == "?" ||
    482             ch == "@" || ch == "&" || ch == "=" || ch == "#") \{
     631            ch == "@" || ch == "&" || ch == "=" || ch == "#" ||
     632        ch == "%") \{
    483633        out += escape(ch);
    484634        flag=0;
     
    500650
    501651function beginSearch() \{
    502 window.location="_httpquery_"+getstdargs()+"_advformargs_"+getsearchargs();
     652  window.location="_httpquery_"+getstdargs()+"_advformargs_"+getsearchargs();
    503653\}
    504654
     
    509659function clearForm() \{
    510660   clearfqf();
     661_If_("_cgiarga_" eq "sqlq",
     662   clearsqlfqf();
     663)
    511664   clearfqv();
    512665
     
    515668      clearfqs();
    516669      clearfqc();
     670_If_("_cgiarga_" eq "sqlq",
     671      clearsqlfqc();
     672)
    517673   \}
    518674
     
    551707<div class="document">
    552708<div class="queryform">
    553 _If_(_cgiargct_,_selectqueryform_,_queryform_)
     709
     710_If_("_cgiarga_" eq "sqlq",
     711
     712  _If_("_cgiargqt_" eq "2",_sqlfieldqueryform_,_sqlqueryform_)
     713,
     714  _If_(_cgiargct_,_selectqueryform_,_queryform_)
     715)
     716
    554717</div>
    555718
     
    567730}
    568731
    569 _selectqueryform_{_If_("_cgiargqt_" eq "1",_fieldqueryform_,_queryform_)}
     732_selectqueryform_{_If_("_cgiargqt_" ge "1",_fieldqueryform_,_queryform_)}
    570733
    571734_queryform_ {
     
    584747}
    585748
     749
     750_sqlqueryform_ {
     751
     752<!-- simple query box that requires you to type SQL where clause directly -->
     753<!-- sqlquery form (\_query:plainqueryform\_) -->
     754<form name="QueryForm" method="get" action="_gwcgi_">
     755<p>
     756<input type="hidden" name="a" value="sqlq">
     757<input type="hidden" name="r" value="1">
     758<input type="hidden" name="hs" value="1">
     759<input type="hidden" name="e" value="_decodedcompressedoptions_">
     760_sqlqueryformcontent_
     761</p>
     762</form>
     763<!-- end of sqlquery form -->
     764}
     765
     766
    586767_ifeellucky_ { <br><input type="checkbox" name="ifl" value="1">_textifeellucky_ }
    587768_useifeellucky_ { }  # Set this to _ifeellucky_ if you want this functionality available
     
    597778_If_(_cgiargqb_,_largequerybox_,_smallquerybox_)
    598779_useifeellucky_
     780</span>
     781}
     782
     783
     784_sqlqueryformcontent_ {
     785<span class="querybox">
     786_If_(_cgiargqb_,_query:largequerybox_,_query:smallquerybox_)
     787_query:useifeellucky_
    599788</span>
    600789}
     
    648837
    649838<table><tr><td align="left">
     839
    650840_textformselect_
    651841</td></tr>
     
    660850<!-- end of query form -->
    661851}
     852
     853_sqlfieldqueryform_ {
     854sf = _cgiargsf_ <br>
     855sqlsf = _cgiargsqlsf_ <br>
     856
     857<noscript>
     858<p><b>_textnojsformwarning_</b></p>
     859</noscript>
     860<!--sql  field query form (\_query:fieldqueryform\_) -->
     861<form name="QueryForm" method="get" action="_gwcgi_">
     862
     863<table><tr><td align="left">
     864_textformselect_
     865</td></tr>
     866<tr><td>
     867_If_(_cgiargb_,_sqladvancedforms_,_sqlsimpleforms_)
     868</td></tr>
     869</table>
     870_If_(_cgiargb_,<div class="divbar">&nbsp;</div>
     871_advancedformextra_)
     872
     873</form>
     874<!-- end of sql query form -->
     875}
     876
     877
    662878
    663879_advancedforms_{
     
    672888}
    673889
     890_sqladvancedforms_{
     891<table border="0" cellspacing="0" cellpadding="0" width="90%">
     892  <tr>
     893    <th></th>
     894    <th align="left">_textfieldphrase_</th>
     895    <th></th>
     896    <th align="center">&nbsp;&nbsp;_textinwords_</th>
     897  </tr>
     898    _sqladvformlist_
     899  <tr>
     900    <td colspan="2" align="left">
     901      <input type="button" value="_textclearform_" onClick="clearForm();">
     902    </td>
     903    <td colspan="3" align="right">
     904      <input type="button" value="_textbeginsearch_" onClick="beginSearch();">
     905    </td>
     906  </tr>
     907</table>
     908}
     909
     910
     911
    674912_advancedformextra_{
    675913<table>
     
    679917<input type="button" value="_textrunquery_" onClick="runQuery();"></td></tr>
    680918</table>
     919
     920
     921_If_("_cgiarga_" eq "sqlq",
     922<p>For example:<br>
     923<i>
     924  element in ('dc.Keywords') AND value='Farming'<br>
     925  element in ('dls.Title') AND value LIKE 'F%'<br>
     926  element in ('dls.Title') AND value<'F%'<br>
     927</i>
     928)
     929
    681930}
    682931
     
    691940</table>}
    692941
     942_sqlsimpleforms_{
     943<table border="0" cellspacing="0" cellpadding="0" width="90%">
     944  <tr>
     945    <th align="left">_textfieldphrase_</th>
     946    <th></th>
     947    <th align="left">&nbsp;&nbsp;_textinwords_</th>
     948  </tr>
     949    _sqlregformlist_
     950  <tr>
     951    <td align="left">
     952      <input type="button" value="_textclearform_" onClick="clearForm();">
     953    </td>
     954    <td align="right">
     955      <input type="button" value="_textbeginsearch_" onClick="beginSearch();">
     956    </td>
     957  </tr>
     958</table>
     959}
     960
     961#
     962# Full-text versions
     963#
     964
    693965_regformelement_{
    694966<tr><td><input type="text" size="39" name="fqv" onChange="updatefqv();" onkeypress="updatefqv(); entersubmit(event);"></td>
     
    718990</select>}
    719991
    720 _textselect_ {_If_(_cgiargb_,_chooseadvancedsearch_,_textsimplesearch_)}
    721 _chooseadvancedsearch_ {_If_(_cgiargct_,_If_("_cgiargct_" eq "2",_textadvancedlucenesearch_,_textadvancedmgppsearch_),_textadvancedsearch_}
    722 _textformselect_ {_If_(_cgiargb_,_chooseformadvancedsearch_,_textformsimplesearch_)}
    723 _chooseformadvancedsearch_ {_If_("_cgiargct_" eq "1",_textformadvancedsearchmgpp_)_If_("_cgiargct_" eq "2",_textformadvancedsearchlucene_)}
     992
     993_andorfqcselection_ {
     994<select name="fqc" onChange="updatefqc();">
     995<option value="and">_textand_
     996<option value="or">_textor_
     997</select>}
     998
     999
     1000#
     1001# SQL versions of regformelement, firstsqladvformelement, advformelement
     1002#
     1003
     1004_sqlregformelement_{
     1005<tr>
     1006  <td>
     1007    _sqlfqfselection_
     1008  </td>
     1009  <td>
     1010    _sqlfqcselection_
     1011  </td>
     1012  <td>
     1013    <input type="text" size="39" name="fqv" onChange="updatefqv();"
     1014           onkeypress="updatefqv(); entersubmit(event);">
     1015  </td>
     1016</tr>
     1017}
     1018
     1019_firstsqladvformelement_{
     1020<tr>
     1021  <td>
     1022  </td>
     1023  <td align="right">
     1024    _sqlfqfselection_
     1025  </td>
     1026  <td>
     1027    _sqlfqcselection_
     1028  </td>
     1029  <td>
     1030    <input type="text" size="31" name="fqv" onChange="updatefqv();"
     1031           onkeypress="updatefqv(); entersubmit(event);">
     1032  </td>
     1033</tr>
     1034}
     1035
     1036_sqladvformelement_{
     1037<tr>
     1038  <td>
     1039    _andorfqcselection_
     1040  </td>
     1041  <td align="right">
     1042    _sqlfqfselection_
     1043  </td>
     1044  <td>
     1045    _sqlfqcselection_
     1046  </td>
     1047  <td>
     1048    <input type="text" size="31" name="fqv" onChange="updatefqv();" onkeypress="updatefqv(); entersubmit(event);">
     1049  </td>
     1050</tr>
     1051}
     1052
     1053
     1054_sqlfqcselection_ {
     1055<select name="sqlfqc" onChange="updatesqlfqc();">
     1056  <option value="=">matches
     1057  <option value="&lt;">&lt;
     1058  <option value="&lt;=">&lt;=
     1059  <option value="LIKE">like
     1060  <option value="&gt;=">&gt;=
     1061  <option value="&gt;">&gt;
     1062  <option value="&lt;&gt;">&lt;&gt;
     1063
     1064</select>}
     1065
     1066#
     1067# end of SQL version
     1068#
     1069
     1070_textselect_ {_If_(_cgiargb_,_chooseadvancedsearch_,_choosesimplesearch_)}
     1071
     1072_choosesimplesearch_ {_If_("_cgiargqt_" eq "2",_textsimplesqlsearch_,_textsimplesearch_)}
     1073
     1074_chooseadvancedsearch_ {_If_("_cgiarqt_" eq "2",_textadvancedsqlsearch_,_choosesimplesearchct_)}
     1075_chooseadvancedsearchct_ {_If_(_cgiargct_,_If_("_cgiargct_" eq "2",_textadvancedlucenesearch_,_textadvancedmgppsearch_),_textadvancedsearch_}
     1076
     1077# formed based versions
     1078_textformselect_ {_If_(_cgiargb_,_chooseformadvancedsearch_,_chooseformsimplesearch_)}
     1079_chooseformsimplesearch_ {_If_("_cgiargqt_" eq "2",_textformsimplesearchsql_,_textformsimplesearch_)}
     1080
     1081_chooseformadvancedsearch_ {_If_("_cgiargqt_" eq "2",_textformadvancedsearchsql_,_chooseformadvancedsearchct_)}
     1082_chooseformadvancedsearchct_ {_If_("_cgiargct_" eq "1",_textformadvancedsearchmgpp_)_If_("_cgiargct_" eq "2",_textformadvancedsearchlucene_)}
    7241083
    7251084# mg uses hselection for index, mgpp uses fqfselection
Note: See TracChangeset for help on using the changeset viewer.