- Timestamp:
- 11/19/14 00:26:51 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Bookmarks.pm
r76 r78 74 74 } 75 75 76 sub get_bookmarks { 77 my $self = shift; 78 my $params = shift || {}; 79 my $search = Bookmarks::Search->new($params); 80 81 # build the query 76 sub _sql_where_clause { 77 my $self = shift; 78 my $search = shift; 79 80 # build the where clause 82 81 my @sql; 83 84 82 if (@{ $search->tags }) { 83 push @sql, 'where resources.uri in'; 84 # subquery to find tagged URIs 85 push @sql, '('; 85 86 my $intersect = 0; 86 87 for my $tag (@{ $search->tags }) { 87 88 push @sql, 'intersect' if $intersect; 88 push @sql, 'select resources.*, bookmarks.* from resources join bookmarks on resources.uri = bookmarks.uri'; 89 push @sql, 'join tags on resources.uri = tags.uri where tags.tag =', \$tag; 89 push @sql, 'select uri from tags where tag =', \$tag; 90 90 $intersect++; 91 91 } 92 } else { 93 push @sql, 'select * from resources join bookmarks on resources.uri = bookmarks.uri'; 92 push @sql, ')'; 94 93 } 95 94 if ($search->query) { … … 97 96 push @sql, (@{ $search->tags } ? 'and' : 'where'), 'title like', \$fuzzy_match; 98 97 } 98 return @sql; 99 } 100 101 sub get_bookmarks { 102 my $self = shift; 103 my $params = shift || {}; 104 my $search = Bookmarks::Search->new($params); 105 106 # build the query 107 my @sql; 108 109 push @sql, 'select * from resources join bookmarks on resources.uri = bookmarks.uri'; 110 push @sql, $self->_sql_where_clause($search); 99 111 push @sql, 'order by ctime desc'; 100 112 push @sql, ('limit', \$search->limit) if $search->limit;
Note: See TracChangeset
for help on using the changeset viewer.