Changeset 2528
- Timestamp:
- 02/22/10 22:43:48 (2 years ago)
- Location:
- Search-OpenSearch/trunk
- Files:
-
- 3 edited
-
Makefile.PL (modified) (1 diff)
-
lib/Search/OpenSearch/Engine.pm (modified) (5 diffs)
-
lib/Search/OpenSearch/Response/XML.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Search-OpenSearch/trunk/Makefile.PL
r2477 r2528 20 20 'Data::Pageset' => 0, 21 21 'Search::Tools' => 0, 22 'CHI' => 0, 22 23 }, 23 24 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, -
Search-OpenSearch/trunk/lib/Search/OpenSearch/Engine.pm
r2527 r2528 8 8 use Search::OpenSearch::Response::XML; 9 9 use Search::OpenSearch::Response::JSON; 10 11 __PACKAGE__->mk_accessors(qw( index facets fields link )); 10 use CHI; 11 12 __PACKAGE__->mk_accessors(qw( index facets fields link cache cache_ttl )); 12 13 13 14 our $VERSION = '0.05'; … … 23 24 Search::OpenSearch::Facets->new( %{ $self->facets } ) ); 24 25 } 26 $self->{cache} ||= CHI->new( 27 driver => 'File', 28 dir_create_mode => 0770, 29 file_create_mode => 0660, 30 root_dir => "/tmp/opensearch_cache", 31 ); 32 $self->{cache_ttl} = 60 * 60 * 1; # 1 hour 33 25 34 return $self; 26 35 } … … 73 82 : $response_class->new( 74 83 results => $results, 75 facets => $self->get_facets( $results),84 facets => $self->get_facets( $query, $results ), 76 85 fields => $self->fields, 77 86 offset => $offset, … … 92 101 93 102 sub get_facets { 94 croak "Engine " . ref( $_[0] ) . " must implement get_facets"; 103 my $self = shift; 104 my $query = shift; 105 my $results = shift; 106 my $cache_key = ref($self) . $query; 107 my $cache = $self->cache or return; 108 109 my %facets; 110 if ( $cache->get($cache_key) ) { 111 %facets = %{ $cache->get($cache_key) }; 112 } 113 else { 114 my $facets = $self->build_facets( $query, $results ); 115 $cache->set( $cache_key, $facest, $self->cache_ttl ); 116 %facets = %$facets; 117 } 118 return \%facets; 119 } 120 121 sub build_facets { 122 croak ref(shift) . " must implement build_facets()"; 95 123 } 96 124 … … 186 214 The base URI for Responses. Passed to Response->link. 187 215 216 =head2 get_facets( I<query>, I<results> ) 217 218 Checks the cache for facets related to I<query> and, if found, 219 returns them. If not found, calls build_facets(), which must 220 be implemented by each Engine subclass. 221 222 =head2 cache 223 224 Get/set the internal CHI object. Defaults to the File driver. 225 226 =head2 cache_ttl 227 228 Get/set the cache key time-to-live. Default is 1 hour. 229 230 =cut 231 188 232 =head1 AUTHOR 189 233 -
Search-OpenSearch/trunk/lib/Search/OpenSearch/Response/XML.pm
r2527 r2528 8 8 use URI::Encode qw( uri_encode ); 9 9 use POSIX qw( strftime ); 10 use Data::UUID; 10 11 11 12 our $VERSION = '0.05'; … … 20 21 21 22 sub stringify { 22 my $self = shift;23 my $pager = $self->fetch_pager();24 25 my @entries = $self->_build_entries;23 my $self = shift; 24 my $pager = $self->fetch_pager(); 25 my $UUID_maker = Data::UUID->new; 26 my @entries = $self->_build_entries; 26 27 27 28 my $now = strftime '%Y-%m-%dT%H:%M:%SZ', gmtime; … … 34 35 'opensearch:startIndex' => $self->offset, 35 36 'opensearch:itemsPerPage' => $self->page_size, 37 'id' => $UUID_maker->create(), 36 38 }, 37 39 'feed', … … 49 51 ); 50 52 51 # TODO generate uuid? cache per query?52 53 53 # main link 54 54 my $link = $XMLer->singleton( 'link', { href => $self->link } ); … … 128 128 my $results = $self->fetch_results(); 129 129 my @entries; 130 131 #my $UUID_maker = Data::UUID->new; 132 130 133 for my $result (@$results) { 131 134 my $entry = $XMLer->perl_to_xml( 132 135 { title => $result->{title}, 133 136 content => $result->{summary}, 134 id => $result->{uri}, 137 id => $result->{uri}, # or uuid? 135 138 }, 136 'entry', 0, 1 139 'entry', 140 0, 141 1 137 142 ); 138 143 my $link = $XMLer->singleton( 'link', { href => $result->{uri} } );
Note: See TracChangeset
for help on using the changeset viewer.