Changeset 1023
- Timestamp:
- 04/21/07 14:07:37 (19 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 modified
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (1 diff)
-
lib/OpenGuides/Search.pm (modified) (5 diffs)
-
t/30_search_raw.t (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changes
r1022 r1023 15 15 the whole form. 16 16 Added links to the "revision N" and "Last edited" text in the navbar. 17 Added format => "raw" option to OpenGuides::Search->run to let you get 18 your results back as a hash. 17 19 Add JavaScript to the Create New Page page so the prefilled 18 20 "New page name" disappears when you click in the field (it doesn't -
trunk/MANIFEST
r1020 r1023 93 93 t/27_geo_data_edit_form.t 94 94 t/28_wgs84_coords.t 95 t/30_search_raw.t 95 96 t/31_search.t 96 97 t/32_search_simple_metadata.t -
trunk/lib/OpenGuides/Search.pm
r992 r1023 119 119 want to use them in production. 120 120 121 You can also request just the raw search results: 122 123 my %results = $search->run( 124 os_x => 528864, 125 os_y => 180797, 126 os_dist => 750, 127 format => "raw", 128 ); 129 130 Results are returned as a hash, keyed on the page name. All results 131 are returned, not just the first C<page>. The values in the hash are 132 hashes themselves, with the following key/value pairs: 133 134 =over 4 135 136 =item * name 137 138 =item * wgs84_lat - WGS-84 latitude 139 140 =item * wgs84_long - WGS-84 longitude 141 142 =item * summary 143 144 =item * distance - distance (in metres) from origin, if origin exists 145 146 =item * score - relevance to search string, if search string exists; higher score means more relevance 147 148 =back 121 149 122 150 In case you're struggling to follow the code, it does the following: … … 140 168 $self->{return_output} = $args{return_output} || 0; 141 169 $self->{return_tt_vars} = $args{return_tt_vars} || 0; 170 171 my $want_raw; 172 if ( $args{format} && $args{format} eq "raw" ) { 173 $want_raw = 1; 174 } 142 175 143 176 $self->process_params( $args{vars} ); … … 185 218 } 186 219 187 # If we're not doing a search then just print the search form. 188 unless ( $doing_search ) { 189 return $self->process_template( tt_vars => \%tt_vars ); 220 # If we're not doing a search then just print the search form (or return 221 # an empty hash if we were asked for raw results). 222 if ( !$doing_search ) { 223 if ( $want_raw ) { 224 return ( ); 225 } else { 226 return $self->process_template( tt_vars => \%tt_vars ); 227 } 190 228 } 191 229 … … 208 246 209 247 my %results_hash = %{ $self->{results} || [] }; 248 249 # If we were asked for just the raw results, return them now, after 250 # grabbing additional info. 251 if ( $want_raw ) { 252 foreach my $node ( keys %results_hash ) { 253 my %data = $self->wiki->retrieve_node( $node ); 254 $results_hash{$node}{summary} = $data{metadata}{summary}[0]; 255 my $lat = $data{metadata}{latitude}[0]; 256 my $long = $data{metadata}{longitude}[0]; 257 my ( $wgs84_lat, $wgs84_long ) = OpenGuides::Utils->get_wgs84_coords( latitude => $lat, longitude => $long, config => $self->config ); 258 $results_hash{$node}{wgs84_lat} = $wgs84_lat; 259 $results_hash{$node}{wgs84_long} = $wgs84_long; 260 } 261 return %results_hash; 262 } 263 210 264 my @results = values %results_hash; 211 265 my $numres = scalar @results; … … 605 659 delete $self->{distance_in_metres}; 606 660 delete $self->{search_string}; 661 delete $self->{results}; 607 662 608 663 # Strip out any non-digits from distance and OS co-ords.
