[Xapian-discuss] For more UI functionality: OmegaScript, C++ or other?

xapian at catcons.co.uk xapian at catcons.co.uk
Thu May 5 13:48:58 BST 2011


Hello  :-)

Thanks to information given in this mailing list, here's an OmegaScript
solution to allow the user to restrict the search by filename extensions.
For illustrative purposes it only covers three extensions -- ods, pdf and
xls.  It uses the CGI parameter B=E* functionality introduced in Xapian
Omega 1.2.5.

Here are the changes to the as-installed Omega template "query" (sorry about
the line wrapping):

root at CW8vDS:/var/lib/omega/templates# diff -u query
query_with_extension_checkboxes 
--- query	2011-04-04 20:48:48.000000000 +0530
+++ query_with_extension_checkboxes	2011-05-05 17:41:11.016731118 +0530
@@ -52,6 +52,8 @@
 <INPUT TYPE=SUBMIT VALUE="Search">
 <hr>
 $if{,$include{inc/anyalldropbox},$include{inc/anyallradio}}
+<br>
+$include{inc/file_ext_checkboxes}
 $if{$opt{topterms},
  <div title="Suggested terms to add to your query"
  style="text-align:left;background:#cfc;border:1px solid
green;padding:2px;font:11px verdana$. arial$. helvetica$. sans-serif;">
@@ -136,9 +138,6 @@
 <INPUT TYPE=hidden NAME=xFILTERS VALUE="$html{$filters}">
 $list{$relevants,<INPUT TYPE=hidden NAME=R VALUE=",.,">}
 $if{$cgi{THRESHOLD},<INPUT TYPE=hidden NAME=THRESHOLD
VALUE="$html{$cgi{THRESHOLD}}">}
-${Preserve any B filters used - this needs modifying if you modify this
template
-  to have B on radio buttons, SELECT, etc}
-$map{$cgilist{B},<INPUT TYPE=hidden NAME=B VALUE="$html{$_}">}
 </FORM>
 <hr><div align=right><i><small><a
href="http://xapian.org/">$html{$version}</a></small></i></div>
 </body>

Here is the "helper fragment" in the inc subdirectory of the templates
directory (sorry about the line wrapping):

root at CW8vDS:/var/lib/omega/templates# cat inc/file_ext_checkboxes
$if{$cgilist{B},$setmap{BE,ods,0,pdf,0,xls,0}$map{$cgilist{B},$setmap{BE,$su
bstr{$_,1},1}},$setmap{BE,ods,1,pdf,1,xls,1}}
Extensions: 
ods:<INPUT TYPE=checkbox NAME=B VALUE=Eods $if{$eq{$opt{BE,ods},1},CHECKED}>
pdf:<INPUT TYPE=checkbox NAME=B VALUE=Epdf $if{$eq{$opt{BE,pdf},1},CHECKED}>
xls:<INPUT TYPE=checkbox NAME=B VALUE=Exls $if{$eq{$opt{BE,xls},1},CHECKED}>

Pseudocode to explain the algorithm of the $if{ ... } line:

if there are any B CGI parameters then
    set all members of array BE to 0
    for each B parameter that is set
        set the corresponding member of array BE to 1
else
    set all members of array BE to 1
endif

Best

Charles




More information about the Xapian-discuss mailing list