Changeset 52 in bookmarks for trunk/Bookmarks.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/Bookmarks.pm

    r47 r52  
    7171    my $self = shift; 
    7272    my $params = shift; 
     73    my $query = $params->{query}; 
    7374    my $tags = $params->{tag} || []; 
    7475    my $limit = $params->{limit}; 
     
    9293        push @sql, 'select * from resources join bookmarks on resources.uri = bookmarks.uri'; 
    9394    } 
     95    if ($query) { 
     96        push @sql, (@$tags ? 'and' : 'where'), 'title like', \"%$query%"; 
     97    } 
    9498    push @sql, 'order by ctime desc'; 
    9599    push @sql, ('limit', \$limit) if $limit; 
     
    98102 
    99103    my ($sql, @bind) = sql_interp(@sql); 
     104    #die $sql; 
    100105 
    101106    my $sth_resource = $self->dbh->prepare($sql); 
     
    133138    my $self = shift; 
    134139    my $params = shift; 
     140    my $query = $params->{query}; 
    135141    my $tags = $params->{tag} || []; 
    136142    if (!ref $tags) { 
     
    140146 
    141147    push @sql, 'select tag, count(tag) as count from tags'; 
     148    push @sql, 'join resources on tags.uri = resources.uri' if $query; 
     149 
     150    # build the where clause 
    142151    if (@$tags) { 
    143         push @sql, 'where uri in ('; 
     152        push @sql, 'where tags.uri in ('; 
    144153        my $intersect = 0; 
    145154        for my $tag (@{ $tags }) { 
     
    150159        push @sql, ') and tag not in ', $tags, ''; 
    151160    } 
     161    if ($query) { 
     162        push @sql, (@$tags ? 'and' : 'where'), 'title like', \"%$query%"; 
     163    } 
     164 
    152165    push @sql, 'group by tag order by tag'; 
    153166 
Note: See TracChangeset for help on using the changeset viewer.