Changeset 52 in bookmarks for trunk/BookmarkApp.pm


Ignore:
Timestamp:
08/15/13 15:58:10 (11 years ago)
Author:
peter
Message:
  • Bookmarks::get_bookmarks() and Bookmarks::get_cotags() support a query argument that limits the results to the bookmarks whose titles contain the query (implemented using SQL LIKE)
  • the bookmark application takes a q query parameter and uses it as the bookmark text query
  • added a text input to enter a text query
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BookmarkApp.pm

    r51 r52  
    4545sub _get_list_links { 
    4646    my $self = shift; 
    47     my ($self_type, $tags) = @_; 
     47    my ($self_type, $query) = @_; 
    4848    my @links = ( 
    4949        { 
     
    5151            type => 'application/json', 
    5252            query => { 
    53                 tag => $tags, 
     53                %$query, 
    5454                format => 'json', 
    5555            }, 
     
    5959            type => 'application/xml', 
    6060            query => { 
    61                 tag => $tags, 
     61                %$query, 
    6262                format => 'xbel', 
    6363            }, 
     
    6868            path => 'feed', 
    6969            query => { 
    70                 tag => $tags, 
     70                %$query, 
    7171            }, 
    7272        }, 
     
    7575            type => 'text/csv', 
    7676            query => { 
    77                 tag => $tags, 
     77                %$query, 
    7878                format => 'csv', 
    7979            }, 
     
    8383            type => 'text/uri-list', 
    8484            query => { 
    85                 tag => $tags, 
     85                %$query, 
    8686                format => 'text', 
    8787            }, 
     
    9191            type => 'text/html', 
    9292            query => { 
    93                 tag => $tags, 
     93                %$query, 
    9494            }, 
    9595        }, 
     
    140140 
    141141    my @tags = grep { $_ ne '' } $q->param('tag'); 
     142    my $query = $q->param('q'); 
    142143    my $limit = $q->param('limit'); 
    143144    my $offset = $q->param('offset'); 
    144145    my @resources = $self->_bookmarks->get_bookmarks({ 
     146        query  => $query, 
    145147        tag    => \@tags, 
    146148        limit  => $limit, 
     
    148150    }); 
    149151    my @all_tags = $self->_bookmarks->get_tags({ selected => $tags[0] }); 
    150     my @cotags = $self->_bookmarks->get_cotags({ tag => \@tags }); 
     152    my @cotags = $self->_bookmarks->get_cotags({ 
     153        query  => $query, 
     154        tag    => \@tags, 
     155    }); 
    151156     
    152     my $title = 'Bookmarks' . (@tags ? " tagged as " . join(' & ', @tags) : ''); 
     157    my $title = 'Bookmarks' . (@tags ? " tagged as " . join(' & ', @tags) : '') . ($query ? " matching '$query'" : ''); 
    153158 
    154159    if ($format eq 'json') { 
     
    247252                base_url     => $base_url, 
    248253                title        => $title, 
     254                query        => $query, 
    249255                selected_tag => $tags[0], 
    250256                search_tags  => \@tags, 
    251                 links        => [ $self->_get_list_links('text/html', \@tags) ], 
     257                links        => [ $self->_get_list_links('text/html', { q => $query, tag => \@tags }) ], 
    252258                all_tags     => \@all_tags, 
    253259                cotags       => \@cotags, 
     
    262268    my $q = $self->query; 
    263269 
     270    my $query = $q->param('q'); 
    264271    my @tags = grep { $_ ne '' } $q->param('tag'); 
    265272    my $title = 'Bookmarks' . (@tags ? " tagged as " . join(' & ', @tags) : ''); 
     
    280287    $feed->id($feed_uri->canonical); 
    281288 
    282     for my $link ($self->_get_list_links('application/atom+xml', \@tags)) { 
     289    for my $link ($self->_get_list_links('application/atom+xml', { q => $query, tag => \@tags })) { 
    283290        my $atom_link = XML::Atom::Link->new; 
    284291        $atom_link->type($link->{type}); 
     
    289296 
    290297    # construct a feed from the most recent 12 bookmarks 
    291     for my $bookmark ($self->_bookmarks->get_bookmarks({ tag => \@tags, limit => 12 })) { 
     298    for my $bookmark ($self->_bookmarks->get_bookmarks({ query => $query, tag => \@tags, limit => 12 })) { 
    292299        my $entry = XML::Atom::Entry->new; 
    293300        $entry->id($bookmark->bookmark_uri->canonical); 
Note: See TracChangeset for help on using the changeset viewer.