Changeset 1889

Show
Ignore:
Timestamp:
02/06/07 14:53:36 (1 year ago)
Author:
moseley
Message:

More updates getting ready to move to the new host
Combined the two search scripts into one.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • swish_website/README

    r1887 r1889  
    276276 
    277277 
     278            It might be necessary to specify the full path to the modules unless 
     279            the modules are located "modules" in ServerRoot. 
     280 
     281 
    278282            For debugging locally, say just the web site 
    279283 
     
    285289                    --ipaddr    `hostname` \ 
    286290                    --domain    `hostname` \ 
     291                    --user      `whoami` \ 
     292                    --group     `whoami` \ 
    287293                    --nodev_site \ 
    288294                    --nolists_site \ 
    289295                    --nosvn_site \ 
     296                    --module_dir /usr/lib/apache2/modules \ 
    290297                > httpd.test 
    291298 
  • swish_website/bin/build

    r1887 r1889  
    364364    # Thise have defaults so this should not fail 
    365365    die "Must specify top-level web source directory with -src\n" unless $config->src; 
    366     die "Must specify either -dest\n" unless $config->dest;  # not really true 
     366    die "Must specify either -dest or -root\n" unless $config->dest;  # not really true 
    367367 
    368368 
  • swish_website/bin/index_hypermail.pl

    r1886 r1889  
    6565<title>$title</title> 
    6666$metas 
     67<meta name="section" content="archive"> 
    6768</head> 
    6869<body> 
  • swish_website/etc/archive.conf

    r1886 r1889  
    1 MetaNames swishtitle name email 
    2 PropertyNames name email 
     1ReplaceRules regex !^.*archive/!/archive/! 
     2MetaNames swishtitle name email section 
     3PropertyNames name email section 
    34IndexContents HTML* .html 
    45StoreDescription HTML* <body> 100000 
  • swish_website/etc/httpd.conf.tt

    r1887 r1889  
    6868    END; 
    6969 
     70 
    7071    MACRO load_modules( modules ) BLOCK; 
    7172        FOR module = modules; 
     
    7374            mod_path = "$module_dir/mod_${module}.so"; 
    7475 
     76 
     77            # This requires that the module directory is absolute 
     78            # but also makes the code Apache 2.2-aware. 
    7579            TRY; 
    7680                USE File( mod_path ); 
     
    202206    </Directory> 
    203207    [% END %] 
     208 
     209 
     210    ErrorDocument 404 /404.html 
     211    <Files 404.html> 
     212        Options +ExecCGI 
     213        SetHandler cgi-script 
     214    </Files> 
     215 
     216    <Directory [% dest %]/search> 
     217        <Files index.html> 
     218            Options +ExecCGI 
     219            SetHandler cgi-script 
     220        </Files> 
     221    </Directory> 
    204222 
    205223</VirtualHost> 
  • swish_website/lib/config/macros

    r1587 r1889  
    11[%- 
     2    page.javascript = []; 
     3 
     4    MACRO include_javascript( name ) BLOCK; 
     5        js_found = 0; 
     6        FOR js = page.javascript; 
     7            IF js == name; 
     8                js_found = 1; 
     9                LAST; 
     10            END; 
     11        END; 
     12        page.javascript.push( name ) UNLESS js_found; 
     13    END; 
    214 
    315 
  • swish_website/lib/config/map

    r1871 r1889  
    251251            search      = { 
    252252                name   = 'Search' 
    253                 hidden = 1 # don't show on main menu 
     253                # hidden = 1 # don't show on main menu 
    254254                menu   = []  # make it /search/ instead of search.html 
    255255            } 
  • swish_website/lib/page/footer.html

    r1871 r1889  
    77</span> 
    88 
     9[%#  This is slow as can be 
    910<p> 
    1011<script type='text/javascript' src='http://www.ohloh.net/projects/3196;badge_js'></script> 
    1112</p> 
     13%] 
    1214 
    1315<p> 
  • swish_website/lib/page/html.html

    r1869 r1889  
    2020 
    2121    <title>Swish-e :: [% page.title | html %]</title> 
     22 
     23    [%- FOREACH js = page.javascript %] 
     24        [%- IF js.match('^http:') %] 
     25            <script type="text/javascript" src="[% "js" %]"></script> 
     26        [%- ELSE %] 
     27            <script type="text/javascript" src="[% "/${js}.js" %]"></script> 
     28        [%- END %] 
     29    [%- END %] 
     30 
    2231  </head> 
    2332 
  • swish_website/lib/page/search.html

    r1629 r1889  
    11[%- # $id$ 
    2     # Page for shwoing search results 
     2    # Page for showing search results 
    33-%] 
    44[%- META 
     
    1111 
    1212    page.title = 'Search'; 
     13    page.no_search = 1; 
     14 
     15    include_javascript( 'search' ); 
    1316 
    1417 
     
    2023    END; 
    2124 
     25    page_ids = {}; 
     26    MACRO radio( name, value, label, checked ) BLOCK; 
     27        page_ids.$name = page_ids.$name + 1; 
     28        id = page_ids.$name; 
     29        ck = checked ? ' checked="checked"' : ''; 
     30        %] 
     31        <input id="[% name; id %]" type="radio" name="[% name %]" value="[% value | html %]"[% ck %]/> 
     32        <label for="[% name; id %]">[% label | html %]</label> 
     33        [% 
     34    END; 
     35 
     36 
     37    MACRO select( name, value, label, checked ) BLOCK; 
     38        ck = checked ? ' selected="selected"' : ''; 
     39        %] 
     40        <option id="[% name; value %]" value="[% value | html %]"[% ck %]>[% label | html %]</option> 
     41        [% 
     42    END; 
     43 
    2244    USE myurl = url( request.myself, query=request.query,  
    2345                     metaname=request.metaname, size=request.pagesize ); 
     
    2648 
    2749 
    28     UNLESS result; 
    29         message( "Must enter a query" ); 
    30     ELSE; 
    31  
     50 
     51    PROCESS search_form; 
     52 
     53 
     54    IF result; 
    3255        # Show results 
    3356 
    3457        message( result.message ) IF result.message; 
     58 
    3559 
    3660        IF result.results.size; 
     
    4973</div> 
    5074 
     75<div id="hidingplace" style="display:none"></div> 
     76 
     77 
     78 
     79[% BLOCK search_form %] 
     80<form id="searchform" method="get" action="index.html"> 
     81    <h2>Enter your query</h2> 
     82    <div id="simpleform"> 
     83        <input type="text" size="30" name="query" /> 
     84        <input type="submit" name="submit" value="Search!" /> 
     85    </div> 
     86    <div id="advancedform" style="display: none"> 
     87        <input id="advflag" name="adv" type="hidden" value="0" /> 
     88        Limit to: 
     89        [% 
     90            radio( 'meta', '', 'Subject/Title & Body', 1 ); 
     91            radio( 'meta', 'title', 'Subject/Title' ); 
     92            radio( 'meta', 'name', "Poster's Name" ); 
     93            radio( 'meta', 'email', "Poster's Email" ); 
     94        %] 
     95 
     96        <br /> 
     97 
     98        Search: 
     99        <select name="section"> 
     100        [% 
     101            select( 'section', '', 'Everywhere',1 ); 
     102            select( 'section', 'docs', 'Documentation' ); 
     103            select( 'section', 'devel', 'Development Docs' ); 
     104            select( 'section', 'archive', 'List Archives' ); 
     105            select( 'section', 'website', 'Site web pages' ); 
     106        %] 
     107        </select> 
     108 
     109        Sort by: 
     110        <select name="sort"> 
     111            <option value="rank">Rank</option> 
     112            <option value="title">Subject/Title</option> 
     113            <option value="email">Email</option> 
     114            <option value="date">Date</option> 
     115        </select> 
     116        <input id="rsort" type="checkbox" name="reverse" /><label for="rsort">Reverse Sort</label> 
     117 
     118        <br /> 
     119        Limit to date: 
     120        [% 
     121            radio( 'date', '', 'All', 1); 
     122            radio( 'date', 'day', 'Today' ); 
     123            radio( 'date', 'week', 'This Week' ); 
     124            radio( 'date', 'month', 'This Month' ); 
     125            radio( 'date', '90', 'Last 90 Days' ); 
     126            '<br />'; 
     127            radio( 'date', 'select', 'Select date range' ); 
     128 
     129 
     130            PROCESS select_date name = 's'; 
     131            ' through '; 
     132            PROCESS select_date name = 'e'; 
     133        %] 
     134    </div><!-- /#advancedform --> 
     135</form> 
     136[% END %] 
     137 
     138[% BLOCK select_date %] 
     139    <select name="[% name %]month"> 
     140        <option value="1">Jan</option> 
     141        <option value="2">Feb</option> 
     142        <option value="3">Mar</option> 
     143        <option value="4">Apr</option> 
     144        <option value="5">May</option> 
     145        <option value="6">Jun</option> 
     146        <option value="7">Jul</option> 
     147        <option value="8">Aug</option> 
     148        <option value="9">Sep</option> 
     149        <option value="10">Oct</option> 
     150        <option value="11">Nov</option> 
     151        <option value="12">Dec</option> 
     152    </select> 
     153    &nbsp; 
     154    <select name="[% name %]day"> 
     155    [% i = 1;  WHILE i < 32 %] 
     156        <option value="[% i %]">[% i %]</option> 
     157    [% i = i + 1; END %] 
     158    </select> 
     159    &nbsp; 
     160    <select name="[% name %]year"> 
     161    [% i = cur_year; WHILE i > 1995 %] 
     162        <option value="[% i %]">[% i %]</option> 
     163    [% i = i - 1; END %] 
     164    </select> 
     165[% END %] 
     166 
     167 
     168 
    51169 
    52170 
     
    67185<div class="search-header"> 
    68186    Results for <b>[% request.query | html %]</b><br /> 
     187</div> 
     188[% END %] 
     189 
     190 
     191 
     192 
     193[% BLOCK next_links %] 
    69194    Showing page [% result.page %]  
    70195    ([% result.start +1 %] - [% (result.start + result.shown) %] of [% result.hits %] hits)  
    71196 
    72 </div> 
    73 [% END %] 
    74  
    75  
    76  
    77  
    78 [% BLOCK next_links %] 
    79197    [% IF result.prev %] 
    80198       <a class="next" href="[% myurl( page=result.prev ) %]">Previous</a> 
     
    94212    %] 
    95213 
    96     <div class="search-title"> 
    97  
     214    <h2 id="result-heading"> 
     215        <a href="[% item.Property('swishdocpath') %]"> 
     216            [%  item.Property('swishtitle') || 'missing title' | highlight('swishtitle', item ) %] 
     217        </a> 
     218    </h2> 
     219 
     220    <div class="search-subtitle"> 
    98221        [% IF is_list %] 
    99222            <span class='indxtype'>[List Archive]</span> 
     
    104227        [% END %] 
    105228 
    106         <a href="[% item.Property('swishdocpath') %]"> 
    107             [%  item.Property('swishtitle') || 'missing title' | highlight('swishtitle', item ) %]</a> 
    108  
    109         <span class="search-rank"> -- rank: <b>[% item.Property('swishrank') %]</b></span> 
     229        <span class="search-rank">Rank: <b>[% item.Property('swishrank') %]</b></span> 
    110230    </div> 
    111231 
     
    134254        SET name    = item.Property('name'); 
    135255        SET email   = item.Property('email'); 
    136         SET name_href = myurl( query="name=\"$name\"" ); 
    137         SET email_href = myurl( query="email=\"$email\"" ); 
     256        SET name_href = myurl( query="\"$name\"", meta="name" ); 
     257        SET email_href = myurl( query="\"$email\"", meta="email" ); 
    138258    %] 
    139259 
  • swish_website/lib/page/searchform.html

    r1699 r1889  
    1   <!-- noindex --> 
    2   <div class="subHeader"> 
    3  
    4    <form method="get" 
    5         action="[% link_to_page('search','', 1 ) %]" 
    6         enctype="application/x-www-form-urlencoded" 
    7         class="srchform"> 
    8  
    9          <table width='100%'> 
    10           <tr> 
    11            <td align='left'> 
    12             [% link_to_page( 'index' )     %] | 
    13             [% link_to_page( 'support' )   %] | 
    14             [% link_to_page( 'download' ) %] 
    15            </td> 
    16  
    17            <td align='right'> 
     1<!-- noindex --> 
     2<div class="subHeader"> 
     3    <table width='100%'> 
     4        <tr> 
     5            <td align='left'> 
     6                [% link_to_page( 'index' )     %] | 
     7                [% link_to_page( 'support' )   %] | 
     8                [% link_to_page( 'download' ) %] 
     9            </td> 
    1810 
    1911 
    20      <label for="searchfield">Search for</label> 
    21      <input maxlength="200" value="" id="searchfield" size="30" name="query" type="text" alt="Search input field"/> 
    22      <input value="[% this.abslinks ? "search swish-e.org" : "search" %]" name="submit" type="submit" class='button' /> 
     12            [% UNLESS page.no_search %] 
     13            <td align='right'> 
    2314 
    24                 </td> 
    25            </tr> 
    26           </table> 
     15                <form method="get" 
     16                    action="[% link_to_page('search','', 1 ) %]" 
     17                    enctype="application/x-www-form-urlencoded" 
     18                    class="srchform"> 
    2719 
    28    </form> 
     20                    <label for="searchfield">Search for</label> 
     21                    <input maxlength="200" value="" id="searchfield" size="30" name="query" type="text" alt="Search input field" /> 
     22                    <input value="[% this.abslinks ? "search swish-e.org" : "search" %]" name="submit" type="submit" class='button' /> 
     23                </form> 
    2924 
    30   </div> 
    31   <!-- index --> 
     25            </td> 
     26            [% END %] 
     27        </tr> 
     28    </table> 
     29</div> 
     30<!-- index --> 
  • swish_website/src/discuss.html

    r1885 r1889  
    4444 
    4545    <blockquote> 
    46         <form method="get" action="/search_archive/swish.cgi" enctype= 
     46        <form method="get" action="/search/index.html" enctype= 
    4747        "application/x-www-form-urlencoded" class="form"> 
    4848 
    4949        <p> 
    50             <input maxlength="200" value="" size="32" type="text" 
    51             name="query" /> <input value="Search!" type="submit" 
    52             name="submit" /><br /> 
    53             Limit search to: <input value="swishdefault" type= 
    54             "radio" checked="checked" name="metaname" />Message 
    55             text <input value="subject" type="radio" name= 
    56             "metaname" />Message Subject <input value="name" type= 
    57             "radio" name="metaname" />Poster's Name <input value= 
    58             "email" type="radio" name="metaname" />Poster's 
    59             Email<br /> 
    60             Sort by: <select name="sort"> 
    61                 <option value="swishrank"> 
    62                     Rank 
    63                 </option> 
    64  
    65                 <option value="subject"> 
    66                     Message Subject 
    67                 </option> 
    68  
    69                 <option value="name"> 
    70                     Poster's Name 
    71                 </option> 
    72  
    73                 <option value="email"> 
    74                     Poster's Email 
    75                 </option> 
    76  
    77                 <option value="sent"> 
    78                     Message Date 
    79                 </option> 
    80             </select> <input value="1" type="checkbox" name= 
    81             "reverse" />Reverse Sort 
     50            <input maxlength="200" value="" size="32" type="text" name="query" /> 
     51            <input value="Search!" type="submit" name="submit" /><br /> 
     52            <input type="hidden" name="section" value="archive" /> 
    8253          </p> 
    8354        </form> 
  • swish_website/src/search/index.html

    r1611 r1889  
    1 #![%- META type = 'text' -%] 
    2 [% locate.in_path( 'speedy') || locate.in_path( 'perl' ) %] 
     1#![% locate.in_path( 'speedy') || locate.in_path( 'perl' ) %] 
     2 
     3[% META type = 'text' %] 
    34 
    45package SwishAPISearch; 
    56use strict; 
    67use warnings; 
     8use DateTime; 
     9 
     10 
    711 
    812###################################################################### 
    913# Skeleton CGI script for searching a Swsih-e index with SWISH::API. 
    10 # see below for documenation or run "perldoc search.cgi" 
     14# see below for documentation or run "perldoc search.cgi" 
    1115# 
    1216# Copyright 2003, 2004 Bill Moseley - All rights reserved. 
     
    1519# 
    1620####################################################################### 
     21 
     22 
     23# Lookup hash for which metanames are defined 
     24our %METANAMES = ( 
     25    title       => 'swishtitle', 
     26    name        => 'name', 
     27    email       => 'email', 
     28); 
     29 
     30our %PROPERTIES = ( 
     31    name        => 'name', 
     32    email       => 'email', 
     33    title       => 'swishtitle', 
     34    rank        => 'swishrank', 
     35    date        => 'swishlastmodified', 
     36); 
     37 
     38our %REVERSE_SORT = ( 
     39    swishrank           => 1, 
     40    swishlastmodified   => 1, 
     41); 
     42 
     43# Valid section metaname values -- to limit to sections of the site. 
     44our %SECTIONS = ( 
     45    website     => 1, 
     46    devel       => 1, 
     47    docs        => 1, 
     48    archive     => 1, 
     49); 
     50 
     51 
    1752 
    1853use vars '$VERSION'; 
     
    163198    $instance->{request} = $request; 
    164199 
     200    $instance->{cur_year} = (gmtime(time))[5] + 1900; 
     201 
    165202    $instance->{rooturl} = '[% site.url.root %]'; 
    166203 
     
    169206    if ( $request->{query} ) { 
    170207 
    171         #  Limit by metaname 
    172         $request->{swish_query} = $request->{metaname} 
    173             ? "$request->{metaname}=( $request->{query} )" 
    174             : $request->{query}; 
    175  
    176         $instance->{result} = run_query( $instance ); 
     208        # Update to handle a bit more complex queries 
     209        generate_query( $request ); 
     210 
     211 
     212        $instance->{result} = $request->{message} 
     213            ? { message => $request->{message } } 
     214            : run_query( $instance ); 
    177215    } 
    178216 
     
    188226    print $fill_in_object->fill( scalarref => $output, fobject => $cgi ); 
    189227 
     228    warn sprintf("Query=[%s] Hits=[%d]\n", 
     229        $instance->{request}->{swish_query} || '',  
     230        $instance->{result}->{hits} || 0 ); 
     231 
    190232    delete $instance->{request};  # clean up the request 
    191233    delete $instance->{result}; 
     
    195237 
    196238 
     239 
     240 
     241 
     242 
     243 
     244 
     245=item generate_query 
     246 
     247Looks at request and build up query, sorts, and limits 
     248 
     249=cut 
     250 
     251sub generate_query { 
     252    my $request = shift; 
     253 
     254    my $query       = $request->{query}; 
     255    my $cgi         = $request->{cgi}; 
     256 
     257 
     258    # Limit query to a specific metaname? 
     259    if ( my $meta = $cgi->param('meta') ) { 
     260 
     261        $query = "$METANAMES{$meta}=($query)" if $METANAMES{$meta}; 
     262    } 
     263 
     264 
     265    # Limit the query to sections of the site 
     266 
     267    my $sections = join " or ", grep { $SECTIONS{$_} } $cgi->param('section'); 
     268    $query .= " section=$sections" if $sections; 
     269 
     270 
     271    $request->{swish_query} = $query; 
     272 
     273 
     274 
     275 
     276    # Set sort 
     277    if ( $cgi->param('sort') && (my $sort = $PROPERTIES{ $cgi->param('sort')}) ) { 
     278 
     279        my $reverse = $cgi->param('reverse') ? 1 : 0; 
     280        $reverse = ! $reverse if $REVERSE_SORT{ $sort }; 
     281 
     282        $sort .= ' desc' if $reverse; 
     283 
     284        $request->{sort} = $sort; 
     285    } 
     286 
     287 
     288    # Limit by dates 
     289    my $limit = $cgi->param('date') || return; 
     290 
     291 
     292    my $low     = DateTime->now; 
     293    my $high    = DateTime->now; 
     294 
     295    my @limit_range; 
     296 
     297    if ( $limit =~ /^(day|month|year|week)$/ ) { 
     298        @limit_range = ( 
     299            DateTime->now->truncate( to => $1 )->epoch, 
     300            time, 
     301        ); 
     302    } 
     303 
     304 
     305    if ( $limit =~ /^\d+$/ && $limit < 5000 ) { 
     306        @limit_range = ( 
     307            DateTime->now->truncate( to => $1 )->subtract( days => $limit ), 
     308            time, 
     309        ); 
     310    } 
     311 
     312    if ( $limit eq 'select' ) { 
     313 
     314        my %params; 
     315        for my $t ( 's', 'e' ) { 
     316            for my $x ( qw/ year month day / ) { 
     317                my $value = $cgi->param( $t . $x ); 
     318                next unless $value; 
     319                $params{$t}{$x} = $value; 
     320            } 
     321        } 
     322        unless ( $params{s}{year} && $params{e}{year} ) { 
     323            $request->{message} = 'Incomplete date submitted'; 
     324            return; 
     325        } 
     326 
     327 
     328        eval { 
     329            @limit_range = ( 
     330                DateTime->new( %{$params{s}} )->epoch, 
     331                DateTime->new( %{$params{e}} 
     332                    )->add( days => 1 )->subtract( seconds => 1 )->epoch, 
     333            ); 
     334        }; 
     335 
     336        if ( $@ ) { 
     337            warn "Bad date submitted $@\n"; 
     338            $request->{message} = "Invalid date submitted"; 
     339            @limit_range = (); 
     340        } else { 
     341            if ( $limit_range[0] > $limit_range[1] ) { 
     342                $request->{message} = "Start date must be before end date"; 
     343                @limit_range = (); 
     344            } 
     345        } 
     346    } 
     347 
     348 
     349    $request->{limit_search} = [ 'swishlastmodified' , @limit_range ] if @limit_range; 
     350} 
     351 
     352 
     353 
     354 
     355 
     356 
    197357# Subroutine to run the Swish query.  Returns a hash reference. 
    198358# A better design might be to return an object with methods for accessing the data. 
     
    218378 
    219379    # $$$ TODO need to test for index file being modified 
    220     # one trick is to touch public_html/seach/index.html and then speedy will reload. 
     380    # one trick is to touch this script and then speedy will reload. 
    221381 
    222382    if ( ! $swish ) { 
     
    240400 
    241401 
    242     # Run the search.  See SWISH::API for more options (like sorting) 
    243  
    244     my $results = $swish->Query( $request->{swish_query} ); 
     402    # Run the search 
     403    my $search = $swish->New_Search_Object; 
     404 
     405 
     406    $search->SetSort( $request->{sort} ) if $request->{sort}; 
     407    $search->SetSearchLimit( @{ $request->{limit_search} } ) if $request->{limit_search}; 
     408 
     409    my $results = $search->Execute( $request->{swish_query} ); 
    245410 
    246411    return { message => check_swish_error( $swish ) } if $swish->Error; 
  • swish_website/src/swish.css

    r1871 r1889  
    527527/* ## Search Results ## */ 
    528528 
     529form#searchform { 
     530    margin-bottom: 2em; 
     531} 
     532 
    529533div.search-page {  /* enclosing div */ 
    530534    margin: 2em 2em 0 0em; 
     
    563567} 
    564568 
    565 .search-title { 
    566     font-size: 1.2em; 
     569h2#result-heading { 
     570    font-size: 100%; 
     571    border-bottom: 1px solid gray; 
     572
     573h2#result-heading a:hover { 
     574    text-decoration: none; 
     575
     576 
     577#showform, #hideform { 
     578    text-decoration: underline; 
     579    font-size: 80%; 
     580    color: rgb(61,92,122); 
    567581} 
    568582